-
Notifications
You must be signed in to change notification settings - Fork 174
Fix AWS get_price action to use assumed role credentials #2104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ import { Property, createAction } from '@openops/blocks-framework'; | |
| import { | ||
| amazonAuth, | ||
| getAttributeValues, | ||
| getAwsAccountsSingleSelectDropdown, | ||
| getCredentialsForAccount, | ||
| getCredentialsFromAuth, | ||
| getPriceListWithCache, | ||
| getServices, | ||
|
|
@@ -17,22 +19,26 @@ export const getPriceAction = createAction({ | |
| displayName: 'Get Price from Price Catalog', | ||
| isWriteAction: false, | ||
| props: { | ||
| account: getAwsAccountsSingleSelectDropdown().accounts, | ||
| service: Property.Dropdown({ | ||
| displayName: 'Service Code', | ||
| description: 'Service code for which to fetch the price', | ||
| refreshers: ['auth'], | ||
| refreshers: ['auth', 'account', 'account.accounts'], | ||
| required: true, | ||
| options: async ({ auth }: any) => { | ||
| if (!auth) { | ||
| options: async ({ auth, account }: any) => { | ||
| if (!auth || !account) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. || !account) this assertion doesnt do anything, account itself is a dynamic property, so its not visible but its also not undefined, this will never be true. Even if it were to work, it would be wrong, as it would mean accounts without roles can not be used in this action i think you can just remove the check entirely, if its not set we will get the error of no credentials found with account, and anyways account is a required property when shown |
||
| return { | ||
| disabled: true, | ||
| options: [], | ||
| placeholder: 'Please authenticate first', | ||
| placeholder: 'Please authenticate first and select account', | ||
| }; | ||
| } | ||
|
|
||
| const credentials = await getCredentialsFromAuth(auth); | ||
| try { | ||
| const credentials = await getCredentialsForAccount( | ||
| auth, | ||
| account?.['accounts'], | ||
| ); | ||
| const services = await getServices(credentials, PRICING_REGION); | ||
|
|
||
| if (!services.length) { | ||
|
|
@@ -66,9 +72,9 @@ export const getPriceAction = createAction({ | |
| displayName: '', | ||
| description: '', | ||
| required: true, | ||
| refreshers: ['auth', 'service'], | ||
| props: async ({ auth, service }, { input }) => { | ||
| if (!auth || !service) { | ||
| refreshers: ['auth', 'account', 'account.accounts', 'service'], | ||
| props: async ({ auth, account, service }, { input }) => { | ||
| if (!auth || !account || !service) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here about the account |
||
| return {}; | ||
| } | ||
|
|
||
|
|
@@ -101,7 +107,10 @@ export const getPriceAction = createAction({ | |
| }; | ||
| } | ||
|
|
||
| const credentials = await getCredentialsFromAuth(auth); | ||
| const credentials = await getCredentialsForAccount( | ||
| auth, | ||
| account?.['accounts'], | ||
| ); | ||
| try { | ||
| const attributeValues: AttributeValue[] = | ||
| await getAttributeValues( | ||
|
|
@@ -139,17 +148,20 @@ export const getPriceAction = createAction({ | |
| }, | ||
| async run(context) { | ||
| try { | ||
| const { service, queryFilters } = context.propsValue; | ||
| const { account, service, queryFilters } = context.propsValue; | ||
| const filters = queryFilters['queryFilters'].map((filter: any) => { | ||
| return { | ||
| Field: filter.attributeName, | ||
| Type: FilterType.TERM_MATCH, | ||
| Value: filter.attributeValue, | ||
| }; | ||
| }); | ||
| const credentials = account?.['accounts'] | ||
| ? await getCredentialsForAccount(context.auth, account['accounts']) | ||
| : await getCredentialsFromAuth(context.auth); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a fallback for those existing flows which doesn't have the |
||
|
|
||
| const priceList = getPriceListWithCache( | ||
| context.auth, | ||
| credentials, | ||
| service.ServiceCode!, | ||
| filters, | ||
| PRICING_REGION, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we show account selection in the UI? In this case, you're not displaying the list of accounts in the block properties.