Skip to content

Commit

Permalink
add ConnectedAppSecret type
Browse files Browse the repository at this point in the history
  • Loading branch information
david-pepper committed Jun 25, 2024
1 parent 172eba5 commit 94945d4
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions handlers/zuora-salesforce-link-remover/src/getBillingAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ import {
SecretsManagerClient,
} from '@aws-sdk/client-secrets-manager';

export function handler() {
export async function handler() {
console.log('getting secret...');
const secretName = 'DEV/Salesforce/ConnectedApp/AwsConnectorSandbox';

const secret = getSecretValue({ secretName });
const secret = await getSecretValue({ secretName });
console.log('secret = ', secret);
return 'abcdef';
}

export const getSecretValue = async <T>({
export const getSecretValue = async ({
secretName,
}: {
secretName: string;
}): Promise<T> => {
console.log('1. secretName:', secretName);
}): Promise<ConnectedAppSecret> => {

const secretsManagerClient = new SecretsManagerClient({
region: process.env.region,
Expand All @@ -29,18 +28,23 @@ export const getSecretValue = async <T>({
});

const response = await secretsManagerClient.send(command);
console.log('2. secret response:', response);
if (!response.SecretString) {
throw new Error('No secret found');
}
console.log('3. response.SecretString:', response.SecretString);

const secretValue = JSON.parse(response.SecretString) as T;
console.log('4. secretValue:', secretValue);
const secretValue = JSON.parse(response.SecretString) as ConnectedAppSecret;

console.log('secretValue.name:', secretValue.name);
console.log('secretValue.authUrl:', secretValue.authUrl);

return secretValue;
} catch (error) {
console.error('error:', error);
throw error;
}
};

type ConnectedAppSecret = {
name: string;
authUrl: string;
};

0 comments on commit 94945d4

Please sign in to comment.