-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage): add an adapter interface for storage browser (#13576)
--------- Co-authored-by: Jim Blanchard <[email protected]>
- Loading branch information
1 parent
bcd8c9d
commit 335315a
Showing
12 changed files
with
170 additions
and
62 deletions.
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