-
Notifications
You must be signed in to change notification settings - Fork 19
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 toarray
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)