Skip to content

Commit 442c559

Browse files
Use getcredentialsforaccount instead of list
1 parent 64b49db commit 442c559

2 files changed

Lines changed: 18 additions & 29 deletions

File tree

packages/blocks/aws-athena/src/lib/actions/query-athena-action.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
amazonAuth,
44
dryRunCheckBox,
55
getAwsAccountsSingleSelectDropdown,
6-
getCredentialsListFromAuth,
6+
getCredentialsForAccount,
77
getRegionsDropdownState,
88
listAthenaDatabases,
99
runAndWaitForQueryResult,
@@ -16,7 +16,7 @@ export const runAthenaQueryAction = createAction({
1616
displayName: 'Query Athena database',
1717
isWriteAction: false,
1818
props: {
19-
accounts: getAwsAccountsSingleSelectDropdown().accounts,
19+
account: getAwsAccountsSingleSelectDropdown().accounts,
2020
region: Property.StaticDropdown({
2121
displayName: 'Region',
2222
description:
@@ -33,10 +33,9 @@ export const runAthenaQueryAction = createAction({
3333
database: Property.Dropdown<string>({
3434
displayName: 'Database',
3535
description: 'Database that contains the table to query on',
36-
37-
refreshers: ['auth', 'accounts', 'region'],
36+
refreshers: ['auth', 'account', 'region'],
3837
required: true,
39-
options: async ({ auth, accounts, region }) => {
38+
options: async ({ auth, account, region }: any) => {
4039
if (!auth) {
4140
return {
4241
disabled: true,
@@ -51,18 +50,13 @@ export const runAthenaQueryAction = createAction({
5150
secretAccessKey: string;
5251
defaultRegion: string;
5352
};
54-
const selectedAccounts = (
55-
accounts as unknown as {
56-
accounts?: string[];
57-
}
58-
)?.accounts;
59-
const credentialsList = await getCredentialsListFromAuth(
53+
const credentials = await getCredentialsForAccount(
6054
authProp,
61-
selectedAccounts,
55+
account?.['accounts'],
6256
);
6357

6458
const databases = await listAthenaDatabases(
65-
credentialsList[0],
59+
credentials,
6660
(region as string | undefined) ?? authProp.defaultRegion,
6761
);
6862

@@ -119,14 +113,13 @@ export const runAthenaQueryAction = createAction({
119113
}
120114

121115
try {
122-
const selectedAccounts = context.propsValue.accounts?.['accounts'];
123-
const credentialsList = await getCredentialsListFromAuth(
116+
const credentials = await getCredentialsForAccount(
124117
context.auth,
125-
selectedAccounts,
118+
context.propsValue.account?.['accounts'],
126119
);
127120

128121
return await runAndWaitForQueryResult(
129-
credentialsList[0],
122+
credentials,
130123
context.propsValue.region ?? context.auth.defaultRegion,
131124
query,
132125
database,

packages/blocks/aws-athena/test/athena-query-action.test.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const openopsCommonMock = {
22
...jest.requireActual('@openops/common'),
3-
getCredentialsListFromAuth: jest.fn(),
3+
getCredentialsForAccount: jest.fn(),
44
runAndWaitForQueryResult: jest.fn(),
55
};
66

@@ -12,9 +12,9 @@ describe('runAthenaQueryAction tests', () => {
1212
beforeEach(() => {
1313
jest.clearAllMocks();
1414

15-
openopsCommonMock.getCredentialsListFromAuth.mockResolvedValue([
16-
{ someCreds: 'some creds' },
17-
]);
15+
openopsCommonMock.getCredentialsForAccount.mockResolvedValue({
16+
someCreds: 'some creds',
17+
});
1818
});
1919

2020
const auth = {
@@ -87,10 +87,8 @@ describe('runAthenaQueryAction tests', () => {
8787
const result = (await runAthenaQueryAction.run(context)) as any;
8888

8989
expect(result).toEqual('mockResult');
90-
expect(openopsCommonMock.getCredentialsListFromAuth).toHaveBeenCalledTimes(
91-
1,
92-
);
93-
expect(openopsCommonMock.getCredentialsListFromAuth).toHaveBeenCalledWith(
90+
expect(openopsCommonMock.getCredentialsForAccount).toHaveBeenCalledTimes(1);
91+
expect(openopsCommonMock.getCredentialsForAccount).toHaveBeenCalledWith(
9492
auth,
9593
['some-account-id'],
9694
);
@@ -158,10 +156,8 @@ describe('runAthenaQueryAction tests', () => {
158156
'some database',
159157
'some outputBucket',
160158
);
161-
expect(openopsCommonMock.getCredentialsListFromAuth).toHaveBeenCalledTimes(
162-
1,
163-
);
164-
expect(openopsCommonMock.getCredentialsListFromAuth).toHaveBeenCalledWith(
159+
expect(openopsCommonMock.getCredentialsForAccount).toHaveBeenCalledTimes(1);
160+
expect(openopsCommonMock.getCredentialsForAccount).toHaveBeenCalledWith(
165161
auth,
166162
['some-account-id'],
167163
);

0 commit comments

Comments
 (0)