Skip to content

Commit

Permalink
v1.11.1 (#153)
Browse files Browse the repository at this point in the history
* #148 - POST /documents/{documentId}/actions fails to run new actions

* #149 - adjusting chatgpt response

* Updated console to v3.2.2

* GET /configuration - Adding mask keys
  • Loading branch information
mfriesen committed Jul 18, 2023
1 parent a81978f commit 1c16172
Show file tree
Hide file tree
Showing 23 changed files with 387 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,24 @@ public static String getFilename(final String path) {
public static boolean isEmpty(final CharSequence cs) {
return cs == null || cs.length() == 0;
}

/**
* Remove single/double quotes from {@link String}.
*
* @param s {@link String}
* @return {@link String}
*/
public static String removeQuotes(final String s) {
return s.replaceAll("^['\"]|['\"]$", "");
}

/**
* Remove single/double quotes from {@link String}.
*
* @param s {@link String}
* @return {@link String}
*/
public static String removeEndingPunctuation(final String s) {
return s.replaceAll("[!\\.,?]$", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,22 @@ void testFilename() {
assertEquals("test (something).txt",
Strings.getFilename("/bleh/something/test (something).txt"));
}

@Test
void replaceQuotes() {
assertEquals("text", Strings.removeQuotes("text"));
assertEquals("text", Strings.removeQuotes("\"text\""));
assertEquals("text", Strings.removeQuotes("\"text"));
assertEquals("text", Strings.removeQuotes("'text'"));
assertEquals("text", Strings.removeQuotes("\"text'"));
}

@Test
void removeEndingPunctuation() {
assertEquals("text", Strings.removeEndingPunctuation("text"));
assertEquals("\"text\"", Strings.removeEndingPunctuation("\"text\","));
assertEquals("\"text", Strings.removeEndingPunctuation("\"text!"));
assertEquals("'text?'", Strings.removeEndingPunctuation("'text?'"));
assertEquals("\"text'", Strings.removeEndingPunctuation("\"text'"));
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def getCmdParam() {
repositories { mavenCentral() }

allprojects {
version = '1.11.0'
version = '1.11.1'
ext.awsCognitoVersion = '1.5.0'
group = 'com.formkiq.stacks'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void testS3Buckets() {
*/
@Test
public void testSsmParameters() {
assertEquals("v3.1.0",
assertEquals("v3.2.2",
ssmService.getParameterValue("/formkiq/" + appenvironment + "/console/version"));
assertTrue(ssmService.getParameterValue("/formkiq/" + appenvironment + "/s3/Console")
.contains(appenvironment + "-console-"));
Expand Down
2 changes: 1 addition & 1 deletion console/src/main/resources/cloudformation/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Parameters:
ConsoleVersion:
Type: String
Description: Version of FormKiQ console to deploy
Default: v3.1.0
Default: v3.2.2

FormKiQType:
Description: The type of FormKiQ installation
Expand Down
4 changes: 2 additions & 2 deletions docs/openapi/openapi-iam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
description: FormKiQ IAM API
version: 1.11.0
description: 'Formkiq API: Document Management Platform API using AWS IAM Authentication'
version: 1.11.1
paths:
/version:
get:
Expand Down
4 changes: 2 additions & 2 deletions docs/openapi/openapi-jwt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
description: FormKiQ HTTP API
version: 1.11.0
description: 'Formkiq API: Document Management Platform API using JWT Authentication'
version: 1.11.1
paths:
/version:
get:
Expand Down
4 changes: 2 additions & 2 deletions docs/openapi/openapi-key.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
description: FormKiQ Api Key
version: 1.11.0
description: 'Formkiq API: Document Management Platform API using API Key(s) Authentication'
version: 1.11.1
paths:
/version:
get:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,31 @@
public class DocumentEvent {

/** Document SiteId. */
@Reflectable
private String siteId;
/** Document Id. */
@Reflectable
private String documentId;
/** S3 Key. */
@Reflectable
private String s3key;
/** S3 Bucket. */
@Reflectable
private String s3bucket;
/** Document Type. */
@Reflectable
private String type;
/** User Id. */
@Reflectable
private String userId;
/** Document Content. */
@Reflectable
private String content;
/** Document Content Type. */
@Reflectable
private String contentType;
/** Docuemnt Path. */
@Reflectable
private String path;

/**
Expand Down
1 change: 1 addition & 0 deletions lambda-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {

annotationProcessor group: 'com.formkiq', name: 'graalvm-annotations-processor', version: '1.3.0'

implementation project(':document-events')
implementation project(':fkq-lambda-services')
implementation project(':fkq-lambda-core')
implementation project(':fkq-validation')
Expand Down
1 change: 1 addition & 0 deletions lambda-api/config/checkstyle/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<allow pkg="com.formkiq.aws.ssm" />
<allow pkg="com.formkiq.aws.sns" />

<allow pkg="com.formkiq.module.documentevents" />
<allow pkg="com.formkiq.graalvm.annotations" />
<allow pkg="com.formkiq.lambda.apigateway" />
<allow pkg="com.formkiq.module.actions" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.formkiq.graalvm.annotations.Reflectable;
import com.formkiq.graalvm.annotations.ReflectableImport;
import com.formkiq.module.actions.Action;
import com.formkiq.module.documentevents.DocumentEvent;
import com.formkiq.plugins.tagschema.DocumentTagSchemaPluginEmpty;
import com.formkiq.stacks.dynamodb.DocumentItemDynamoDb;
import com.formkiq.stacks.dynamodb.DocumentTags;
Expand All @@ -58,7 +59,7 @@
@ReflectableImport(classes = {DocumentItemDynamoDb.class, DocumentTagType.class, DocumentTag.class,
DocumentMetadata.class, DocumentTags.class, PaginationMapToken.class, SearchQuery.class,
SearchTagCriteria.class, SearchMetaCriteria.class, SearchResponseFields.class, PresetTag.class,
Preset.class, ApiGatewayRequestEvent.class, ApiMapResponse.class,
Preset.class, ApiGatewayRequestEvent.class, ApiMapResponse.class, DocumentEvent.class,
ApiGatewayRequestContext.class, ApiMessageResponse.class, ApiResponseError.class,
ApiPagination.class, Action.class, ValidationErrorImpl.class,
DocumentVersionServiceDynamoDb.class, DocumentVersionServiceNoVersioning.class})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.formkiq.stacks.api.handler;

import static com.formkiq.aws.dynamodb.objects.Strings.isEmpty;
import static com.formkiq.aws.services.lambda.ApiResponseStatus.SC_OK;
import static com.formkiq.stacks.dynamodb.ConfigService.CHATGPT_API_KEY;
import static com.formkiq.stacks.dynamodb.ConfigService.MAX_DOCUMENTS;
Expand All @@ -47,18 +48,15 @@
public class ConfigurationRequestHandler
implements ApiGatewayRequestHandler, ApiGatewayRequestEventUtil {

/** Mask Value, must be even number. */
private static final int MASK = 4;

/**
* constructor.
*
*/
public ConfigurationRequestHandler() {}

@Override
public void beforeGet(final LambdaLogger logger, final ApiGatewayRequestEvent event,
final ApiAuthorizer authorizer, final AwsServiceCache awsServices) throws Exception {
checkPermissions(authorizer);
}

@Override
public void beforePatch(final LambdaLogger logger, final ApiGatewayRequestEvent event,
final ApiAuthorizer authorizer, final AwsServiceCache awsServices) throws Exception {
Expand All @@ -71,6 +69,16 @@ private void checkPermissions(final ApiAuthorizer authorizer) throws Unauthorize
}
}

/**
* Mask {@link String}.
*
* @param s {@link String}
* @return {@link String}
*/
private String mask(final String s) {
return !isEmpty(s) ? s.subSequence(0, MASK) + "*******" + s.substring(s.length() - MASK) : s;
}

@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger,
final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer,
Expand All @@ -81,7 +89,7 @@ public ApiRequestHandlerResponse get(final LambdaLogger logger,

DynamicObject obj = configService.get(siteId);
Map<String, Object> map = new HashMap<>();
map.put("chatGptApiKey", obj.getOrDefault(CHATGPT_API_KEY, ""));
map.put("chatGptApiKey", mask(obj.getOrDefault(CHATGPT_API_KEY, "").toString()));
map.put("maxContentLengthBytes", obj.getOrDefault(MAX_DOCUMENT_SIZE_BYTES, ""));
map.put("maxDocuments", obj.getOrDefault(MAX_DOCUMENTS, ""));
map.put("maxWebhooks", obj.getOrDefault(MAX_WEBHOOKS, ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import static com.formkiq.aws.dynamodb.SiteIdKeyGenerator.DEFAULT_SITE_ID;
import static com.formkiq.aws.services.lambda.ApiResponseStatus.SC_OK;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
Expand All @@ -40,7 +41,6 @@
import com.formkiq.aws.ssm.SsmConnectionBuilder;
import com.formkiq.aws.ssm.SsmService;
import com.formkiq.module.lambdaservices.AwsServiceCache;
import com.formkiq.stacks.dynamodb.ConfigService;
import software.amazon.awssdk.services.ssm.SsmClient;

/** {@link ApiGatewayRequestHandler} for "/sites". */
Expand Down Expand Up @@ -80,13 +80,12 @@ public ApiRequestHandlerResponse get(final LambdaLogger logger,
final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer,
final AwsServiceCache awsservice) throws Exception {

ConfigService configService = awsservice.getExtension(ConfigService.class);

SsmConnectionBuilder ssm = awsservice.getExtension(SsmConnectionBuilder.class);
try (SsmClient ssmClient = ssm.build()) {

List<DynamicObject> sites = authorizer.getSiteIds().stream().map(siteId -> {
DynamicObject config = configService.get(siteId);

DynamicObject config = new DynamicObject(new HashMap<>());
config.put("siteId", siteId != null ? siteId : DEFAULT_SITE_ID);

boolean write = authorizer.getWriteSiteIds().contains(siteId);
Expand All @@ -95,11 +94,6 @@ public ApiRequestHandlerResponse get(final LambdaLogger logger,
return config;
}).collect(Collectors.toList());

sites.forEach(ob -> {
ob.remove("PK");
ob.remove("SK");
});

updateUploadEmail(logger, awsservice, authorizer, sites);

return new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(Map.of("sites", sites)));
Expand Down
3 changes: 2 additions & 1 deletion lambda-api/src/main/resources/cloudformation/api-apikey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Resources:
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
description: "FormKiQ Api Key"
description: |-
Formkiq API: Document Management Platform API using API Key(s) Authentication
version: #@ data.values.version or assert.fail("missing version")
paths:
/version:
Expand Down
3 changes: 2 additions & 1 deletion lambda-api/src/main/resources/cloudformation/api-iam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Resources:
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
description: "FormKiQ IAM API"
description: |-
Formkiq API: Document Management Platform API using AWS IAM Authentication
version: #@ data.values.version or assert.fail("missing version")
paths:
/version:
Expand Down
3 changes: 2 additions & 1 deletion lambda-api/src/main/resources/cloudformation/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Resources:
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
description: "FormKiQ HTTP API"
description: |-
Formkiq API: Document Management Platform API using JWT Authentication
version: #@ data.values.version or assert.fail("missing version")
paths:
/version:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void testHandleGetSites01() throws Exception {
final int expected = 4;
DynamicObject resp = new DynamicObject(fromJson(mget.get("body"), Map.class));
assertEquals(expected, resp.size());
assertEquals("anothervalue", resp.getString("chatGptApiKey"));
assertEquals("anot*******alue", resp.getString("chatGptApiKey"));
assertEquals("", resp.getString("maxContentLengthBytes"));
assertEquals("", resp.getString("maxDocuments"));
assertEquals("", resp.getString("maxWebhooks"));
Expand All @@ -124,6 +124,8 @@ public void testHandleGetSites02() throws Exception {
// given
String siteId = null;
String group = "default";
ConfigService config = getAwsServices().getExtension(ConfigService.class);
config.save(siteId, new DynamicObject(Map.of(CHATGPT_API_KEY, "somevalue")));

ApiGatewayRequestEvent event = getRequest(siteId, group);

Expand All @@ -132,12 +134,15 @@ public void testHandleGetSites02() throws Exception {

// then
Map<String, String> m = GsonUtil.getInstance().fromJson(response, Map.class);
verifyResponse(m);

final int mapsize = 3;
assertEquals(mapsize, m.size());
assertEquals("401.0", String.valueOf(m.get("statusCode")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
assertEquals("{\"message\":\"user is unauthorized\"}", String.valueOf(m.get("body")));
final int expected = 4;
DynamicObject resp = new DynamicObject(fromJson(m.get("body"), Map.class));
assertEquals(expected, resp.size());
assertEquals("some*******alue", resp.getString("chatGptApiKey"));
assertEquals("", resp.getString("maxContentLengthBytes"));
assertEquals("", resp.getString("maxDocuments"));
assertEquals("", resp.getString("maxWebhooks"));
}

/**
Expand Down Expand Up @@ -168,7 +173,7 @@ public void testHandleGetSites03() throws Exception {
final int expected = 4;
DynamicObject resp = new DynamicObject(fromJson(m.get("body"), Map.class));
assertEquals(expected, resp.size());
assertEquals("somevalue", resp.getString("chatGptApiKey"));
assertEquals("some*******alue", resp.getString("chatGptApiKey"));
assertEquals("", resp.getString("maxContentLengthBytes"));
assertEquals("", resp.getString("maxDocuments"));
assertEquals("", resp.getString("maxWebhooks"));
Expand Down Expand Up @@ -203,7 +208,7 @@ public void testHandleGetSites04() throws Exception {
final int expected = 4;
DynamicObject resp = new DynamicObject(fromJson(m.get("body"), Map.class));
assertEquals(expected, resp.size());
assertEquals("anothervalue", resp.getString("chatGptApiKey"));
assertEquals("anot*******alue", resp.getString("chatGptApiKey"));
assertEquals("", resp.getString("maxContentLengthBytes"));
assertEquals("", resp.getString("maxDocuments"));
assertEquals("", resp.getString("maxWebhooks"));
Expand Down Expand Up @@ -241,7 +246,7 @@ public void testHandlePutSites01() throws Exception {
final int expected = 4;
DynamicObject resp = new DynamicObject(fromJson(mget.get("body"), Map.class));
assertEquals(expected, resp.size());
assertEquals("anotherkey", resp.getString("chatGptApiKey"));
assertEquals("anot*******rkey", resp.getString("chatGptApiKey"));
assertEquals("1000000", resp.getString("maxContentLengthBytes"));
assertEquals("1000", resp.getString("maxDocuments"));
assertEquals("5", resp.getString("maxWebhooks"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ private ApiGatewayRequestEvent getRequest(final String siteId, final String grou
@Test
public void testHandleGetSites01() throws Exception {
// given
String siteId = null;
ConfigService config = getAwsServices().getExtension(ConfigService.class);
config.save(siteId, new DynamicObject(Map.of("chatGptApiKey", "somevalue")));

putSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/maildomain", "tryformkiq.com");
ApiGatewayRequestEvent event = getRequest(null, "default Admins finance");
ApiGatewayRequestEvent event = getRequest(siteId, "default Admins finance");

// when
String response = handleRequest(event);
Expand All @@ -96,6 +100,8 @@ public void testHandleGetSites01() throws Exception {

List<DynamicObject> sites = resp.getList("sites");
assertEquals(2, sites.size());
final int expected = 3;
assertEquals(expected, sites.get(0).size());
assertEquals(DEFAULT_SITE_ID, sites.get(0).get("siteId"));
assertEquals("READ_WRITE", sites.get(0).get("permission"));
assertNotNull(sites.get(0).get("uploadEmail"));
Expand Down Expand Up @@ -246,7 +252,5 @@ public void testHandleGetSites04() throws Exception {
assertEquals(1, resp.getList("sites").size());
assertEquals(siteId, resp.getList("sites").get(0).getString("siteId"));
assertEquals("READ_WRITE", resp.getList("sites").get(0).getString("permission"));
assertEquals("5", resp.getList("sites").get(0).getString(MAX_DOCUMENTS));
assertEquals("10", resp.getList("sites").get(0).getString(MAX_WEBHOOKS));
}
}
Loading

0 comments on commit 1c16172

Please sign in to comment.