Skip to content

Commit

Permalink
[IOPAE-11133] Dynamic Apim Auth config params get (#231)
Browse files Browse the repository at this point in the history
* Dynamic Apim Auth config params get

* lint fix
  • Loading branch information
giamma1295 committed May 10, 2024
1 parent 4ee5f0c commit a27a4dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,23 @@ export const servicePrincipalSecret = process.env
export const servicePrincipalTenantId = process.env
.SERVICE_PRINCIPAL_TENANT_ID as string;

export type ApimAuthConfig = t.TypeOf<typeof ApimAuthConfig>;
export const ApimAuthConfig = t.interface({
clientId: NonEmptyString,
clientSecret: NonEmptyString,
subscriptionId: NonEmptyString,
tenantId: NonEmptyString
});

export const getApimAuthConfig = (): ApimAuthConfig => {
return {
clientId: process.env.SERVICE_PRINCIPAL_CLIENT_ID as NonEmptyString,
clientSecret: process.env.SERVICE_PRINCIPAL_SECRET as NonEmptyString,
subscriptionId: process.env.ARM_SUBSCRIPTION_ID as NonEmptyString,
tenantId: process.env.SERVICE_PRINCIPAL_TENANT_ID as NonEmptyString
};
};

export const sandboxFiscalCode = process.env.SANDBOX_FISCAL_CODE as FiscalCode;

export const logoUrl = process.env.LOGO_URL;
Expand Down
9 changes: 5 additions & 4 deletions src/middlewares/api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ export function getApiClientMiddleware(): IRequestMiddleware<
ApiManagementClient
> {
return async _ => {
const apiAuthConfig = config.getApimAuthConfig();
return right(
new ApiManagementClient(
new ClientSecretCredential(
config.servicePrincipalTenantId,
config.servicePrincipalClientId,
config.servicePrincipalSecret
apiAuthConfig.tenantId,
apiAuthConfig.clientId,
apiAuthConfig.clientSecret
),
config.subscriptionId
apiAuthConfig.subscriptionId
)
);
};
Expand Down

0 comments on commit a27a4dd

Please sign in to comment.