Skip to content

Commit

Permalink
feat(storage): address feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Jul 11, 2024
1 parent ce1fc76 commit ce16fb7
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 60 deletions.

This file was deleted.

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,
});
});
});
8 changes: 2 additions & 6 deletions packages/storage/src/storageBrowser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@
// SPDX-License-Identifier: Apache-2.0

export { createLocationCredentialsStore } from './locationCredentialsStore';
export { createManagedAuthAdapter } from './managedAuthAdapter/createManagedAuthAdapter';
export {
GetLocationCredentials,
ListLocations,
StorageBrowserConfigAdapter,
} from './types';
export { createManagedAuthConfigAdapter } from './managedAuthConfigAdapter/createManagedAuthConfigAdapter';
export { GetLocationCredentials, ListLocations } from './types';

This file was deleted.

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,
};
};
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';
11 changes: 0 additions & 11 deletions packages/storage/src/storageBrowser/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,3 @@ export interface LocationCredentialsStore {
*/
destroy(): void;
}

/**
* Common interface for handlers to configure StorageBrowser behaviors
*
* @internal
*/
export interface StorageBrowserConfigAdapter {
listLocations: ListLocations;
getLocationCredentials: GetLocationCredentials;
region: string;
}

0 comments on commit ce16fb7

Please sign in to comment.