-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat(storage): add an adapter interface for storage browser #13576
Merged
AllanZhengYP
merged 10 commits into
aws-amplify:storage-browser/main
from
AllanZhengYP:storage-browser-managed-auth-adaptor-types
Jul 15, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7a86ea4
feat(storage): initial commit to create managed auth adapter
AllanZhengYP 46e7373
feat(storage): renaming ListLocations and GetLocationCredentials inte…
AllanZhengYP d6ba042
feat(storage): export StorageBrowser config adapter interface
AllanZhengYP a6368bc
fix(storage): simplify adapter interface
AllanZhengYP fca6ef8
feat(storage): address feedbacks
AllanZhengYP f1bab7e
Revert "feat(storage): use WeakMap for store registry"
AllanZhengYP 4654105
fix(storage): remove storagebrower from interface naming
AllanZhengYP 4de03e6
chore(storage): address feedbacks
AllanZhengYP 8918e33
Revert "doc(storage): add disclaimer"
AllanZhengYP 25d487e
chore: fix merge conflicts
AllanZhengYP 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
72 changes: 72 additions & 0 deletions
72
...torage/__tests__/storageBrowser/managedAuthAdapter/createManagedAuthConfigAdapter.test.ts
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 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { createManagedAuthConfigAdapter } from '../../../src/storageBrowser/managedAuthConfigAdapter'; | ||
import { createListLocationsHandler } from '../../../src/storageBrowser/managedAuthConfigAdapter/createListLocationsHandler'; | ||
import { createLocationCredentialsHandler } from '../../../src/storageBrowser/managedAuthConfigAdapter/createLocationCredentialsHandler'; | ||
|
||
jest.mock( | ||
'../../../src/storageBrowser/managedAuthConfigAdapter/createListLocationsHandler', | ||
); | ||
jest.mock( | ||
'../../../src/storageBrowser/managedAuthConfigAdapter/createLocationCredentialsHandler', | ||
); | ||
|
||
describe('createManagedAuthConfigAdapter', () => { | ||
const region = 'us-foo-2'; | ||
const accountId = 'XXXXXXXXXXXX'; | ||
const credentialsProvider = jest.fn(); | ||
|
||
beforeEach(() => { | ||
jest | ||
.mocked(createListLocationsHandler) | ||
.mockReturnValue('LIST_LOCATIONS_FN' as any); | ||
jest | ||
.mocked(createLocationCredentialsHandler) | ||
.mockReturnValue('GET_LOCATION_CREDENTIALS_FN' as any); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should pass region to the adapter', () => { | ||
expect(createManagedAuthConfigAdapter({ region } as any)).toMatchObject({ | ||
region, | ||
}); | ||
}); | ||
|
||
it('should create list locations handler', () => { | ||
expect( | ||
createManagedAuthConfigAdapter({ | ||
region, | ||
accountId, | ||
credentialsProvider, | ||
}), | ||
).toMatchObject({ | ||
listLocations: 'LIST_LOCATIONS_FN', | ||
}); | ||
expect(createListLocationsHandler).toHaveBeenCalledWith({ | ||
region, | ||
accountId, | ||
credentialsProvider, | ||
}); | ||
}); | ||
|
||
it('should create get location credentials handler', () => { | ||
expect( | ||
createManagedAuthConfigAdapter({ | ||
region, | ||
accountId, | ||
credentialsProvider, | ||
}), | ||
).toMatchObject({ | ||
getLocationCredentials: 'GET_LOCATION_CREDENTIALS_FN', | ||
}); | ||
expect(createLocationCredentialsHandler).toHaveBeenCalledWith({ | ||
region, | ||
accountId, | ||
credentialsProvider, | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,20 +1,6 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/** | ||
* NOTE: The APIs exported from this file are ONLY intended for usage by | ||
* Amplify UI. To use location-related features, please use | ||
* @aws-amplify/ui-react-storage | ||
*/ | ||
|
||
export { | ||
listCallerAccessGrants, | ||
ListCallerAccessGrantsInput, | ||
ListCallerAccessGrantsOutput, | ||
} from './listCallerAccessGrants'; | ||
export { createLocationCredentialsHandler } from './createLocationCredentialsHandler'; | ||
export { createLocationCredentialsStore } from './locationCredentialsStore'; | ||
export { | ||
managedAuthAdapter, | ||
ManagedAuthAdapterInput, | ||
} from './managedAuthAdapter'; | ||
export { createManagedAuthConfigAdapter } from './managedAuthConfigAdapter/createManagedAuthConfigAdapter'; | ||
export { GetLocationCredentials, ListLocations } from './types'; |
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
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 was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
packages/storage/src/storageBrowser/managedAuthConfigAdapter/createListLocationsHandler.ts
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,18 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { CredentialsProvider, ListLocations } from '../types'; | ||
|
||
export interface CreateListLocationsHandlerInput { | ||
accountId: string; | ||
credentialsProvider: CredentialsProvider; | ||
region: string; | ||
} | ||
|
||
export const createListLocationsHandler = ( | ||
// eslint-disable-next-line unused-imports/no-unused-vars | ||
input: CreateListLocationsHandlerInput, | ||
): ListLocations => { | ||
// TODO(@AllanZhengYP) | ||
throw new Error('Not Implemented'); | ||
}; |
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
52 changes: 52 additions & 0 deletions
52
...ges/storage/src/storageBrowser/managedAuthConfigAdapter/createManagedAuthConfigAdapter.ts
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,52 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { | ||
CredentialsProvider, | ||
GetLocationCredentials, | ||
ListLocations, | ||
} from '../types'; | ||
|
||
import { createListLocationsHandler } from './createListLocationsHandler'; | ||
import { createLocationCredentialsHandler } from './createLocationCredentialsHandler'; | ||
|
||
interface CreateManagedAuthConfigAdapterInput { | ||
accountId: string; | ||
region: string; | ||
credentialsProvider: CredentialsProvider; | ||
} | ||
|
||
interface AuthConfigAdapter { | ||
listLocations: ListLocations; | ||
getLocationCredentials: GetLocationCredentials; | ||
region: string; | ||
} | ||
|
||
/** | ||
* Create configuration including handlers to call S3 Access Grant APIs to list and get | ||
* credentials for different locations. | ||
* | ||
* @param options - Configuration options for the adapter. | ||
* @returns - An object containing the handlers to call S3 Access Grant APIs and region | ||
*/ | ||
export const createManagedAuthConfigAdapter = ({ | ||
credentialsProvider, | ||
region, | ||
accountId, | ||
}: CreateManagedAuthConfigAdapterInput): AuthConfigAdapter => { | ||
const listLocations = createListLocationsHandler({ | ||
credentialsProvider, | ||
accountId, | ||
region, | ||
}); | ||
const getLocationCredentials = createLocationCredentialsHandler({ | ||
credentialsProvider, | ||
accountId, | ||
region, | ||
}); | ||
|
||
return { | ||
listLocations, | ||
getLocationCredentials, | ||
region, | ||
}; | ||
}; |
4 changes: 4 additions & 0 deletions
4
packages/storage/src/storageBrowser/managedAuthConfigAdapter/index.ts
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,4 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export { createManagedAuthConfigAdapter } from './createManagedAuthConfigAdapter'; |
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
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.
Should this all be deriving from base type
CreateManagedAuthConfigAdapterInput
since these handler Input have same type?