|
1 | 1 | import { createCustomApiCallAction } from '@openops/blocks-common'; |
2 | 2 | import { Property } from '@openops/blocks-framework'; |
3 | | -import { |
4 | | - authenticateUserWithAzure, |
5 | | - azureAuth, |
6 | | - getUseHostSessionProperty, |
7 | | -} from '@openops/common'; |
8 | | -import { runCommand } from '../azure-cli'; |
| 3 | +import { azureAuth, getUseHostSessionProperty } from '@openops/common'; |
| 4 | +import { getAzureAccessToken } from '../auth/get-azure-access-token'; |
9 | 5 | import { getSubscriptionsDropdownForHostSession } from '../common-properties'; |
10 | 6 |
|
11 | | -const getHostAccessToken = async ( |
12 | | - auth: unknown, |
13 | | - subscription: string, |
14 | | -): Promise<string> => { |
15 | | - const output = await runCommand( |
16 | | - 'account get-access-token --resource https://management.azure.com --output json', |
17 | | - auth, |
18 | | - true, |
19 | | - subscription, |
20 | | - ); |
21 | | - const parsed = JSON.parse(output ?? '{}'); |
22 | | - const token = parsed?.accessToken; |
23 | | - if (!token) { |
24 | | - throw new Error('Failed to obtain Azure access token'); |
25 | | - } |
26 | | - return token as string; |
27 | | -}; |
28 | | - |
29 | 7 | export const customAzureApiCallAction = createCustomApiCallAction({ |
30 | 8 | auth: azureAuth, |
31 | 9 | name: 'custom_azure_api_call', |
@@ -65,9 +43,11 @@ export const customAzureApiCallAction = createCustomApiCallAction({ |
65 | 43 | const selectedSubscription = |
66 | 44 | context.propsValue?.subscriptions?.['subDropdown']; |
67 | 45 |
|
68 | | - const token = shouldUseHostCredentials |
69 | | - ? await getHostAccessToken(context.auth, selectedSubscription) |
70 | | - : (await authenticateUserWithAzure(context.auth)).access_token; |
| 46 | + const token = await getAzureAccessToken( |
| 47 | + context.auth, |
| 48 | + !!shouldUseHostCredentials, |
| 49 | + selectedSubscription, |
| 50 | + ); |
71 | 51 |
|
72 | 52 | return { |
73 | 53 | Authorization: `Bearer ${token}`, |
|
0 commit comments