Skip to content

Commit 8649b8b

Browse files
Use getCredentialsforaccount instead of list and fix refresher (#2116)
Fixes OPS-3904
1 parent 6b9a581 commit 8649b8b

2 files changed

Lines changed: 22 additions & 39 deletions

File tree

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

Lines changed: 11 additions & 23 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,
@@ -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', 'accounts', 'accounts.accounts', 'region'],
3837
required: true,
39-
options: async ({ auth, accounts, region }) => {
38+
options: async ({ auth, accounts, region }: any) => {
4039
if (!auth) {
4140
return {
4241
disabled: true,
@@ -46,24 +45,14 @@ export const runAthenaQueryAction = createAction({
4645
}
4746

4847
try {
49-
const authProp = auth as {
50-
accessKeyId: string;
51-
secretAccessKey: string;
52-
defaultRegion: string;
53-
};
54-
const selectedAccounts = (
55-
accounts as unknown as {
56-
accounts?: string[];
57-
}
58-
)?.accounts;
59-
const credentialsList = await getCredentialsListFromAuth(
60-
authProp,
61-
selectedAccounts,
48+
const credentials = await getCredentialsForAccount(
49+
auth,
50+
accounts?.['accounts'],
6251
);
6352

6453
const databases = await listAthenaDatabases(
65-
credentialsList[0],
66-
(region as string | undefined) ?? authProp.defaultRegion,
54+
credentials,
55+
(region as string | undefined) ?? auth.defaultRegion,
6756
);
6857

6958
return {
@@ -119,14 +108,13 @@ export const runAthenaQueryAction = createAction({
119108
}
120109

121110
try {
122-
const selectedAccounts = context.propsValue.accounts?.['accounts'];
123-
const credentialsList = await getCredentialsListFromAuth(
111+
const credentials = await getCredentialsForAccount(
124112
context.auth,
125-
selectedAccounts,
113+
context.propsValue.accounts?.['accounts'],
126114
);
127115

128116
return await runAndWaitForQueryResult(
129-
credentialsList[0],
117+
credentials,
130118
context.propsValue.region ?? context.auth.defaultRegion,
131119
query,
132120
database,

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

Lines changed: 11 additions & 16 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 = {
@@ -76,7 +76,7 @@ describe('runAthenaQueryAction tests', () => {
7676
...jest.requireActual('@openops/blocks-framework'),
7777
auth: auth,
7878
propsValue: {
79-
accounts: { accounts: ['some-account-id'] },
79+
accounts: { accounts: 'some-account-id' },
8080
query: 'some query',
8181
database: 'some database',
8282
outputBucket: 'some outputBucket',
@@ -87,12 +87,10 @@ 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,
95-
['some-account-id'],
93+
'some-account-id',
9694
);
9795
});
9896

@@ -138,7 +136,6 @@ describe('runAthenaQueryAction tests', () => {
138136
...jest.requireActual('@openops/blocks-framework'),
139137
auth: auth,
140138
propsValue: {
141-
accounts: { accounts: ['some-account-id'] },
142139
region: 'some region',
143140
query: 'some query',
144141
database: 'some database',
@@ -158,12 +155,10 @@ describe('runAthenaQueryAction tests', () => {
158155
'some database',
159156
'some outputBucket',
160157
);
161-
expect(openopsCommonMock.getCredentialsListFromAuth).toHaveBeenCalledTimes(
162-
1,
163-
);
164-
expect(openopsCommonMock.getCredentialsListFromAuth).toHaveBeenCalledWith(
158+
expect(openopsCommonMock.getCredentialsForAccount).toHaveBeenCalledTimes(1);
159+
expect(openopsCommonMock.getCredentialsForAccount).toHaveBeenCalledWith(
165160
auth,
166-
['some-account-id'],
161+
undefined,
167162
);
168163
});
169164

0 commit comments

Comments
 (0)