Skip to content

Commit

Permalink
#126 add GET/PATCH /configuration API endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
mfriesen committed May 30, 2023
1 parent e32b1ce commit 854d6e0
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 95 deletions.
16 changes: 3 additions & 13 deletions docs/openapi/openapi-iam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi200'
/configs:
/configuration:
get:
operationId: GetConfigs
description: Returns the list of sites that the user has access to
Expand All @@ -93,7 +93,7 @@
content:
application/json:
schema:
$ref: '#/components/schemas/GetConfigsRequest'
$ref: '#/components/schemas/GetConfigurationResponse'
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
Expand Down Expand Up @@ -3453,17 +3453,7 @@
type: string
format: date-time
description: Inserted Timestamp
GetConfigsRequest:
type: object
properties:
sites:
$ref: '#/components/schemas/Configs'
Configs:
type: array
description: List of configs
items:
$ref: '#/components/schemas/Config'
Config:
GetConfigurationResponse:
type: object
properties:
chatGptApiKey:
Expand Down
16 changes: 3 additions & 13 deletions docs/openapi/openapi-jwt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi200'
/configs:
/configuration:
get:
operationId: GetConfigs
description: Returns the list of sites that the user has access to
Expand All @@ -93,7 +93,7 @@
content:
application/json:
schema:
$ref: '#/components/schemas/GetConfigsRequest'
$ref: '#/components/schemas/GetConfigurationResponse'
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
Expand Down Expand Up @@ -3453,17 +3453,7 @@
type: string
format: date-time
description: Inserted Timestamp
GetConfigsRequest:
type: object
properties:
sites:
$ref: '#/components/schemas/Configs'
Configs:
type: array
description: List of configs
items:
$ref: '#/components/schemas/Config'
Config:
GetConfigurationResponse:
type: object
properties:
chatGptApiKey:
Expand Down
16 changes: 3 additions & 13 deletions docs/openapi/openapi-key.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/lambdaApi200'
/configs:
/configuration:
get:
operationId: GetConfigs
description: Returns the list of sites that the user has access to
Expand All @@ -93,7 +93,7 @@
content:
application/json:
schema:
$ref: '#/components/schemas/GetConfigsRequest'
$ref: '#/components/schemas/GetConfigurationResponse'
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
Expand Down Expand Up @@ -3453,17 +3453,7 @@
type: string
format: date-time
description: Inserted Timestamp
GetConfigsRequest:
type: object
properties:
sites:
$ref: '#/components/schemas/Configs'
Configs:
type: array
description: List of configs
items:
$ref: '#/components/schemas/Config'
Config:
GetConfigurationResponse:
type: object
properties:
chatGptApiKey:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import com.formkiq.module.lambdaservices.AwsServiceCache;
import com.formkiq.stacks.dynamodb.ConfigService;

/** {@link ApiGatewayRequestHandler} for "/configs". */
/** {@link ApiGatewayRequestHandler} for "/configuration". */
public class ConfigsRequestHandler implements ApiGatewayRequestHandler, ApiGatewayRequestEventUtil {

/**
Expand Down Expand Up @@ -90,7 +90,7 @@ public ApiRequestHandlerResponse get(final LambdaLogger logger,

@Override
public String getRequestUrl() {
return "/configs";
return "/configuration";
}

@SuppressWarnings("unchecked")
Expand Down
16 changes: 3 additions & 13 deletions lambda-api/src/main/resources/cloudformation/api-apikey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Resources:
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: "#/components/x-amazon-apigateway-integrations/lambdaApi200"
/configs:
/configuration:
get:
operationId: GetConfigs
description: Returns the list of sites that the user has access to
Expand All @@ -106,7 +106,7 @@ Resources:
content:
application/json:
schema:
"$ref": "#/components/schemas/GetConfigsRequest"
"$ref": "#/components/schemas/GetConfigurationResponse"
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
Expand Down Expand Up @@ -3456,18 +3456,8 @@ Resources:
type: "string"
format: "date-time"
description: "Inserted Timestamp"
GetConfigsRequest:
GetConfigurationResponse:
type: object
properties:
sites:
$ref: "#/components/schemas/Configs"
Configs:
type: "array"
description: "List of configs"
items:
$ref: "#/components/schemas/Config"
Config:
type: "object"
properties:
chatGptApiKey:
type: "string"
Expand Down
16 changes: 3 additions & 13 deletions lambda-api/src/main/resources/cloudformation/api-iam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Resources:
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: "#/components/x-amazon-apigateway-integrations/lambdaApi200"
/configs:
/configuration:
get:
operationId: GetConfigs
description: Returns the list of sites that the user has access to
Expand All @@ -106,7 +106,7 @@ Resources:
content:
application/json:
schema:
"$ref": "#/components/schemas/GetConfigsRequest"
"$ref": "#/components/schemas/GetConfigurationResponse"
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
Expand Down Expand Up @@ -3456,18 +3456,8 @@ Resources:
type: "string"
format: "date-time"
description: "Inserted Timestamp"
GetConfigsRequest:
GetConfigurationResponse:
type: object
properties:
sites:
$ref: "#/components/schemas/Configs"
Configs:
type: "array"
description: "List of configs"
items:
$ref: "#/components/schemas/Config"
Config:
type: "object"
properties:
chatGptApiKey:
type: "string"
Expand Down
16 changes: 3 additions & 13 deletions lambda-api/src/main/resources/cloudformation/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Resources:
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: "#/components/x-amazon-apigateway-integrations/lambdaApi200"
/configs:
/configuration:
get:
operationId: GetConfigs
description: Returns the list of sites that the user has access to
Expand All @@ -106,7 +106,7 @@ Resources:
content:
application/json:
schema:
"$ref": "#/components/schemas/GetConfigsRequest"
"$ref": "#/components/schemas/GetConfigurationResponse"
security:
- ApiAuthorization: []
x-amazon-apigateway-integration:
Expand Down Expand Up @@ -3456,18 +3456,8 @@ Resources:
type: "string"
format: "date-time"
description: "Inserted Timestamp"
GetConfigsRequest:
GetConfigurationResponse:
type: object
properties:
sites:
$ref: "#/components/schemas/Configs"
Configs:
type: "array"
description: "List of configs"
items:
$ref: "#/components/schemas/Config"
Config:
type: "object"
properties:
chatGptApiKey:
type: "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@
public class ConfigsRequestTest extends AbstractRequestHandler {

/**
* Get /configs request.
* Get /configuration request.
*
* @param siteId {@link String}
* @param group {@link String}
* @return {@link ApiGatewayRequestEvent}
*/
private ApiGatewayRequestEvent getRequest(final String siteId, final String group) {
ApiGatewayRequestEvent event = new ApiGatewayRequestEventBuilder().method("get")
.resource("/configs").path("/configs").group(group).user("joesmith")
.resource("/configuration").path("/configuration").group(group).user("joesmith")
.queryParameters(siteId != null ? Map.of("siteId", siteId) : null).build();
return event;
}

/**
* Patch /configs request.
* Patch /configuration request.
*
* @param siteId {@link String}
* @param group {@link String}
Expand All @@ -67,7 +67,7 @@ private ApiGatewayRequestEvent getRequest(final String siteId, final String grou
private ApiGatewayRequestEvent patchRequest(final String siteId, final String group,
final String body) {
ApiGatewayRequestEvent event = new ApiGatewayRequestEventBuilder().method("patch")
.resource("/configs").path("/configs").group(group).user("joesmith")
.resource("/configuration").path("/configuration").group(group).user("joesmith")
.queryParameters(siteId != null ? Map.of("siteId", siteId) : null).body(body).build();
return event;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
import org.junit.Test;
import com.formkiq.stacks.client.FormKiqClientV1;
import com.formkiq.stacks.client.models.AddDocumentAction;
import com.formkiq.stacks.client.models.Config;
import com.formkiq.stacks.client.models.Configuration;
import com.formkiq.stacks.client.models.DocumentActionType;
import com.formkiq.stacks.client.models.DocumentTags;
import com.formkiq.stacks.client.requests.AddDocumentActionRequest;
import com.formkiq.stacks.client.requests.GetDocumentTagsRequest;
import com.formkiq.stacks.client.requests.UpdateConfigsRequest;
import com.formkiq.stacks.client.requests.UpdateConfigurationRequest;
import software.amazon.awssdk.utils.IoUtils;

/**
Expand All @@ -63,10 +63,10 @@ public static void beforeClass() throws IOException {
}

FormKiqClientV1 client = getFormKiqClients(null).get(0);
Config config = new Config();
Configuration config = new Configuration();
config.chatGptApiKey(System.getProperty("chatGptApiKey"));
try {
client.updateConfigs(new UpdateConfigsRequest().config(config));
client.updateConfiguration(new UpdateConfigurationRequest().config(config));
} catch (InterruptedException e) {
throw new IOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
import java.util.List;
import org.junit.Test;
import com.formkiq.stacks.client.FormKiqClientV1;
import com.formkiq.stacks.client.models.Config;
import com.formkiq.stacks.client.models.Configuration;
import software.amazon.awssdk.services.cognitoidentityprovider.model.AuthenticationResultType;

/**
* Process Urls.
* <p>
* GET /configs tests
* GET /configuration tests
* </p>
*
*/
Expand All @@ -46,7 +46,7 @@ public class ConfigsRequestTest extends AbstractApiTest {
private static final int TEST_TIMEOUT = 20000;

/**
* Test GET /configs.
* Test GET /configuration.
*
* @throws Exception Exception
*/
Expand All @@ -61,7 +61,7 @@ public void testConfigs01() throws Exception {
FormKiqClientV1 client = clients.get(0);

// when
Config c = client.getConfigs();
Configuration c = client.getConfiguration();

// then
assertNotNull(c.chatGptApiKey());
Expand All @@ -70,7 +70,7 @@ public void testConfigs01() throws Exception {
for (FormKiqClientV1 fc : Arrays.asList(clients.get(1), clients.get(2))) {

// when
HttpResponse<String> response = fc.getConfigsAsHttpResponse();
HttpResponse<String> response = fc.getConfigurationAsHttpResponse();

// then
assertEquals("401", String.valueOf(response.statusCode()));
Expand All @@ -79,7 +79,7 @@ public void testConfigs01() throws Exception {
}

/**
* Test GET /configs as readuser user.
* Test GET /configuration as readuser user.
*
* @throws Exception Exception
*/
Expand All @@ -90,7 +90,7 @@ public void testConfigs02() throws Exception {
FormKiqClientV1 client = createHttpClient(token);

// when
HttpResponse<String> response = client.getConfigsAsHttpResponse();
HttpResponse<String> response = client.getConfigurationAsHttpResponse();

// then
assertEquals("401", String.valueOf(response.statusCode()));
Expand Down

0 comments on commit 854d6e0

Please sign in to comment.