-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Support for GoogleDrive DataSources (#83)
This commit adds support for creating, updating, and deleting GoogleDrive data sources.
- Loading branch information
Showing
9 changed files
with
587 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...asource/src/main/java/software/amazon/kendra/datasource/convert/GoogleDriveConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
.../test/java/software/amazon/kendra/datasource/convert/gdrive/GoogleDriveConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
Oops, something went wrong.