@@ -3,6 +3,8 @@ import { Property, createAction } from '@openops/blocks-framework';
33import {
44 amazonAuth ,
55 getAttributeValues ,
6+ getAwsAccountsSingleSelectDropdown ,
7+ getCredentialsForAccount ,
68 getCredentialsFromAuth ,
79 getPriceListWithCache ,
810 getServices ,
@@ -17,12 +19,13 @@ export const getPriceAction = createAction({
1719 displayName : 'Get Price from Price Catalog' ,
1820 isWriteAction : false ,
1921 props : {
22+ account : getAwsAccountsSingleSelectDropdown ( ) . accounts ,
2023 service : Property . Dropdown ( {
2124 displayName : 'Service Code' ,
2225 description : 'Service code for which to fetch the price' ,
23- refreshers : [ 'auth' ] ,
26+ refreshers : [ 'auth' , 'account' , 'account.accounts' ] ,
2427 required : true ,
25- options : async ( { auth } : any ) => {
28+ options : async ( { auth, account } : any ) => {
2629 if ( ! auth ) {
2730 return {
2831 disabled : true ,
@@ -31,8 +34,11 @@ export const getPriceAction = createAction({
3134 } ;
3235 }
3336
34- const credentials = await getCredentialsFromAuth ( auth ) ;
3537 try {
38+ const credentials = await getCredentialsForAccount (
39+ auth ,
40+ account ?. [ 'accounts' ] ,
41+ ) ;
3642 const services = await getServices ( credentials , PRICING_REGION ) ;
3743
3844 if ( ! services . length ) {
@@ -66,8 +72,8 @@ export const getPriceAction = createAction({
6672 displayName : '' ,
6773 description : '' ,
6874 required : true ,
69- refreshers : [ 'auth' , 'service' ] ,
70- props : async ( { auth, service } , { input } ) => {
75+ refreshers : [ 'auth' , 'account' , 'account.accounts' , ' service'] ,
76+ props : async ( { auth, account , service } , { input } ) => {
7177 if ( ! auth || ! service ) {
7278 return { } ;
7379 }
@@ -101,7 +107,10 @@ export const getPriceAction = createAction({
101107 } ;
102108 }
103109
104- const credentials = await getCredentialsFromAuth ( auth ) ;
110+ const credentials = await getCredentialsForAccount (
111+ auth ,
112+ account ?. [ 'accounts' ] ,
113+ ) ;
105114 try {
106115 const attributeValues : AttributeValue [ ] =
107116 await getAttributeValues (
@@ -139,17 +148,20 @@ export const getPriceAction = createAction({
139148 } ,
140149 async run ( context ) {
141150 try {
142- const { service, queryFilters } = context . propsValue ;
151+ const { account , service, queryFilters } = context . propsValue ;
143152 const filters = queryFilters [ 'queryFilters' ] . map ( ( filter : any ) => {
144153 return {
145154 Field : filter . attributeName ,
146155 Type : FilterType . TERM_MATCH ,
147156 Value : filter . attributeValue ,
148157 } ;
149158 } ) ;
159+ const credentials = account ?. [ 'accounts' ]
160+ ? await getCredentialsForAccount ( context . auth , account [ 'accounts' ] )
161+ : await getCredentialsFromAuth ( context . auth ) ;
150162
151163 const priceList = getPriceListWithCache (
152- context . auth ,
164+ credentials ,
153165 service . ServiceCode ! ,
154166 filters ,
155167 PRICING_REGION ,
0 commit comments