Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Support for GoogleDrive DataSources #83

Merged
merged 1 commit into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 78 additions & 1 deletion aws-kendra-datasource/aws-kendra-datasource.json
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,74 @@
"IndexFieldName"
]
},
"GoogleDriveConfiguration": {
"type": "object",
"properties": {
"SecretArn": {
"$ref": "#/definitions/SecretArn"
},
"InclusionPatterns": {
"$ref": "#/definitions/DataSourceInclusionsExclusionsStrings"
},
"ExclusionPatterns": {
"$ref": "#/definitions/DataSourceInclusionsExclusionsStrings"
},
"FieldMappings": {
"$ref": "#/definitions/DataSourceToIndexFieldMappingList"
},
"ExcludeMimeTypes": {
"$ref": "#/definitions/ExcludeMimeTypesList"
},
"ExcludeUserAccounts": {
"$ref": "#/definitions/ExcludeUserAccountsList"
},
"ExcludeSharedDrives": {
"$ref": "#/definitions/ExcludeSharedDrivesList"
}
},
"required": [
"SecretArn"
]
},
"ExcludeMimeTypesList": {
"type": "array",
"minLength": 0,
"maxLength": 30,
"items": {
"$ref": "#/definitions/MimeType"
}
},
"MimeType": {
"type": "string",
"minLength": 1,
"maxLength": 256
},
"ExcludeUserAccountsList": {
"type": "array",
"minLength": 0,
"maxLength": 100,
"items": {
"$ref": "#/definitions/UserAccount"
}
},
"UserAccount": {
"type": "string",
"minLength": 1,
"maxLength": 256
},
"ExcludeSharedDrivesList": {
"type": "array",
"minLength": 0,
"maxLength": 100,
Comment on lines +1065 to +1093
Copy link

@PatMyron PatMyron Jan 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think minLength/maxLength can be applied to array types:
aws-cloudformation/cloudformation-cli#414
https://json-schema.org/understanding-json-schema/reference/array.html#length
(more spots in this file from other PRs as well)

"items": {
"$ref": "#/definitions/SharedDriveId"
}
},
"SharedDriveId": {
"type": "string",
"minLength": 1,
"maxLength": 256
},
"ConfluenceAttachmentFieldName": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -1071,6 +1139,9 @@
},
"ConfluenceConfiguration": {
"$ref": "#/definitions/ConfluenceConfiguration"
},
"GoogleDriveConfiguration": {
"$ref": "#/definitions/GoogleDriveConfiguration"
}
},
"oneOf": [
Expand Down Expand Up @@ -1108,6 +1179,11 @@
"required": [
"ConfluenceConfiguration"
]
},
{
"required": [
"GoogleDriveConfiguration"
]
}
]
},
Expand All @@ -1128,7 +1204,8 @@
"SERVICENOW",
"DATABASE",
"CUSTOM",
"CONFLUENCE"
"CONFLUENCE",
"GOOGLEDRIVE"
]
},
"Description": {
Expand Down
2 changes: 1 addition & 1 deletion aws-kendra-datasource/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>kendra</artifactId>
<version>2.15.23</version>
<version>2.15.58</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.cloudformation/aws-cloudformation-rpdk-java-plugin -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import software.amazon.awssdk.services.kendra.model.UntagResourceRequest;
import software.amazon.awssdk.services.kendra.model.UpdateDataSourceRequest;
import software.amazon.kendra.datasource.convert.DatabaseConverter;
import software.amazon.kendra.datasource.convert.GoogleDriveConverter;
import software.amazon.kendra.datasource.convert.ListConverter;
import software.amazon.kendra.datasource.convert.OneDriveConverter;
import software.amazon.kendra.datasource.convert.S3Converter;
Expand Down Expand Up @@ -217,6 +218,7 @@ static software.amazon.awssdk.services.kendra.model.DataSourceConfiguration toSd
modelDataSourceConfiguration.serviceNowConfiguration(ServiceNowConverter.toSdkDataSourceConfiguration(dataSourceConfiguration.getServiceNowConfiguration()));
modelDataSourceConfiguration.oneDriveConfiguration(OneDriveConverter.toSdkDataSourceConfiguration(dataSourceConfiguration.getOneDriveConfiguration()));
modelDataSourceConfiguration.confluenceConfiguration(ConfluenceConverter.toSdkDataSourceConfiguration(dataSourceConfiguration.getConfluenceConfiguration()));
modelDataSourceConfiguration.googleDriveConfiguration(GoogleDriveConverter.toSdkDataSourceConfiguration(dataSourceConfiguration.getGoogleDriveConfiguration()));
return modelDataSourceConfiguration.build();
}

Expand All @@ -236,6 +238,8 @@ static DataSourceConfiguration toModelDataSourceConfiguration(
return OneDriveConverter.toModelDataSourceConfiguration(dataSourceConfiguration.oneDriveConfiguration());
} else if (DataSourceType.CONFLUENCE.toString().equals(dataSourceType)) {
return ConfluenceConverter.toModelDataSourceConfiguration(dataSourceConfiguration.confluenceConfiguration());
} else if (DataSourceType.GOOGLEDRIVE.toString().equals(dataSourceType)) {
return GoogleDriveConverter.toModelDataSourceConfiguration(dataSourceConfiguration.googleDriveConfiguration());
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package software.amazon.kendra.datasource.convert;

import software.amazon.kendra.datasource.DataSourceConfiguration;
import software.amazon.kendra.datasource.GoogleDriveConfiguration;

/**
* GoogleDriveConverter is responsible for converting between the RPK models used
* by CloudFormation and those used by the AWS Sdk.
*
* @see software.amazon.kendra.datasource.Translator - where this class is used
*/
public class GoogleDriveConverter {

/**
* Given an RPK model, return the SDK representation of that model.
* @param model the RPK model
* @return The sdk representation
*/
public static software.amazon.awssdk.services.kendra.model.GoogleDriveConfiguration toSdkDataSourceConfiguration(GoogleDriveConfiguration model) {
if (model == null) {
return null;
}
return software.amazon.awssdk.services.kendra.model.GoogleDriveConfiguration.builder()
.secretArn(model.getSecretArn())
.inclusionPatterns(StringListConverter.toSdk(model.getInclusionPatterns()))
.exclusionPatterns(StringListConverter.toSdk(model.getExclusionPatterns()))
.fieldMappings(ListConverter.toSdk(model.getFieldMappings(), FieldMappingConverter::toSdk))
.excludeMimeTypes(StringListConverter.toSdk(model.getExcludeMimeTypes()))
.excludeUserAccounts(StringListConverter.toSdk(model.getExcludeUserAccounts()))
.excludeSharedDrives(StringListConverter.toSdk(model.getExcludeSharedDrives()))
.build();
}

/**
* Given an SDK model, return an RPK model representation of that model (wrapped in a DataSourceConfiguration)
* @param sdk the sdk model
* @return The rpk representation of the model in a DataSourceConfiguration
*/
public static DataSourceConfiguration toModelDataSourceConfiguration(software.amazon.awssdk.services.kendra.model.GoogleDriveConfiguration sdk) {
return DataSourceConfiguration.builder()
.googleDriveConfiguration(toModel(sdk))
.build();
}

/**
* Converts an SDK GoogleDriveConfiguration to the same structure as an RPK model
* @param sdk the sdk configuration
* @return the same structure as an RPK model
*/
private static GoogleDriveConfiguration toModel(software.amazon.awssdk.services.kendra.model.GoogleDriveConfiguration sdk) {
if (sdk == null) {
return null;
}
return GoogleDriveConfiguration.builder()
.secretArn(sdk.secretArn())
.inclusionPatterns(StringListConverter.toModel(sdk.inclusionPatterns()))
.exclusionPatterns(StringListConverter.toModel(sdk.exclusionPatterns()))
.fieldMappings(ListConverter.toModel(sdk.fieldMappings(), FieldMappingConverter::toModel))
.excludeMimeTypes(StringListConverter.toModel(sdk.excludeMimeTypes()))
.excludeUserAccounts(StringListConverter.toModel(sdk.excludeUserAccounts()))
.excludeSharedDrives(StringListConverter.toModel(sdk.excludeSharedDrives()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,33 @@ void testTranslateToSdkConfluence() {
.build());
}

@Test
void testTranslateToModelGoogleDrive() {

software.amazon.awssdk.services.kendra.model.DataSourceConfiguration dataSourceConfiguration =
software.amazon.awssdk.services.kendra.model.DataSourceConfiguration.builder()
.googleDriveConfiguration(software.amazon.awssdk.services.kendra.model.GoogleDriveConfiguration.builder().build())
.build();

assertThat(Translator.toModelDataSourceConfiguration(dataSourceConfiguration, DataSourceType.GOOGLEDRIVE.toString()))
.isEqualTo(DataSourceConfiguration.builder()
.googleDriveConfiguration(GoogleDriveConfiguration.builder().build())
.build());
}

@Test
void testTranslateToSdkGoogleDrive() {
DataSourceConfiguration dataSourceConfiguration = DataSourceConfiguration
.builder()
.googleDriveConfiguration(GoogleDriveConfiguration.builder().build())
.build();

assertThat(Translator.toSdkDataSourceConfiguration(dataSourceConfiguration))
.isEqualTo(software.amazon.awssdk.services.kendra.model.DataSourceConfiguration.builder()
.googleDriveConfiguration(software.amazon.awssdk.services.kendra.model.GoogleDriveConfiguration.builder().build())
.build());
}

@Test
void translateToSdkConfiguration_WHEN_Configuration_Null(){
assertThat(Translator.toSdkDataSourceConfiguration(null))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package software.amazon.kendra.datasource.convert.gdrive;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Arrays;
import java.util.stream.Stream;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import software.amazon.kendra.datasource.DataSourceConfiguration;
import software.amazon.kendra.datasource.convert.GoogleDriveConverter;

/**
* GoogleDriveConverterTest tests that GoogleDriveConverter properly converts between AWS SDK and RPK models.
* @see GoogleDriveConverter - the unit under test
* @see GoogleDriveConverterTestCases - test cases for this class
*/
public class GoogleDriveConverterTest {

/**
* Given an SDK input, assert the converter produces the proper RPK output.
*/
@ParameterizedTest
@MethodSource("provideModelToSdkTests")
public void testModelToSdk(GoogleDriveConverterTestCase testCase) {
Assertions.assertThat(GoogleDriveConverter.toSdkDataSourceConfiguration(testCase.getInput().asModel()))
.as(testCase.getDescription())
.isEqualTo(testCase.getExpectedOutput().asSdk());
}

/**
* Given an RPK input, assert the converter produces the proper SDK output.
*/
@ParameterizedTest
@MethodSource("provideSdkToModelTests")
public void testSdkToModel(GoogleDriveConverterTestCase testCase) {
assertThat(GoogleDriveConverter.toModelDataSourceConfiguration(testCase.getInput().asSdk()))
.as(testCase.getDescription())
.isEqualTo(DataSourceConfiguration.builder()
.googleDriveConfiguration(testCase.getExpectedOutput().asModel())
.build());
}

/**
* @return All (model -> sdk) tests.
*/
private static Stream<GoogleDriveConverterTestCase> provideModelToSdkTests() {
return provideTestCases(false);
}

/**
* @return All (sdk -> model) tests.
*/
private static Stream<GoogleDriveConverterTestCase> provideSdkToModelTests() {
return provideTestCases(true);
}

/**
* Utility method used to generate a list of test cases for either (sdk -> model) or (model -> sdk).
* @param sdkInput - If this is true then the "mode" of this method is (sdk -> model) otherwise (model -> sdk)
* @return All test cases for the desired input mode.
*/
private static Stream<GoogleDriveConverterTestCase> provideTestCases(boolean sdkInput) {
return Arrays.stream(GoogleDriveConverterTestCases.TEST_CASES)
// either the test case has the proper input, or it does not but is symmetrical
.filter(testCase -> testCase.getInput().isSdk() == sdkInput || testCase.isSymmetrical())
// if the test case has the proper input then it's a straightforward test, otherwise test in the opposite direction
.map(testCase -> testCase.getInput().isSdk() == sdkInput ? testCase : testCase.symmetricalTestCase());
}
}
Loading