-
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.
- Loading branch information
1 parent
ce1fc76
commit ce16fb7
Showing
9 changed files
with
130 additions
and
60 deletions.
There are no files selected for viewing
8 changes: 0 additions & 8 deletions
8
packages/storage/__tests__/storageBrowser/managedAuthAdapter/createManagedAuthAdapter.ts
This file was deleted.
Oops, something went wrong.
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
35 changes: 0 additions & 35 deletions
35
packages/storage/src/storageBrowser/managedAuthAdapter/createManagedAuthAdapter.ts
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
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 StorageBrowserAuthConfigAdapter { | ||
listLocations: ListLocations; | ||
getLocationCredentials: GetLocationCredentials; | ||
region: string; | ||
} | ||
|
||
/** | ||
* Create configuration including handlers for StorageBrowser to call S3 Access Grants | ||
* APIs to list and get credentials for different locations. | ||
* | ||
* @param options - Configuration options for the adapter. | ||
* @returns - An object containing the handlers for StorageBrowser to call S3 Access Grants APIs and region | ||
*/ | ||
export const createManagedAuthConfigAdapter = ({ | ||
credentialsProvider, | ||
region, | ||
accountId, | ||
}: CreateManagedAuthConfigAdapterInput): StorageBrowserAuthConfigAdapter => { | ||
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