get credentials from AWS secrets manager

This commit is contained in:
Gabriel Rosa
2022-06-23 16:26:49 -03:00
parent a42ec164c3
commit d6552678a8
11 changed files with 112 additions and 53 deletions
+16 -14
View File
@@ -8,22 +8,24 @@ class OauthSecretsObject {
client_secret = '';
redirect_uri = '';
}
export class OauthScrets {
// @Injectable()
export class OauthSecrets {
hubspot = new OauthSecretsObject();
google = new OauthSecretsObject();
mailchimp = new OauthSecretsObject();
async init() {
const path = process.env.SM_OAUTH_PATH;
const secretsManagerClient = new SecretsManagerClient({});
for (const key in this) {
const getSecretComand = new GetSecretValueCommand({
SecretId: `${path}/${key}`,
});
const res = await secretsManagerClient
.send(getSecretComand)
.catch(() => null);
if (res) this[key] = JSON.parse(res.SecretString);
}
}
export async function getOauthSecrets() {
const secrets = new OauthSecrets();
const path = process.env.SM_OAUTH_PATH;
const secretsManagerClient = new SecretsManagerClient({});
for (const key in secrets) {
const getSecretComand = new GetSecretValueCommand({
SecretId: `${path}/${key}`,
});
const res = await secretsManagerClient
.send(getSecretComand)
.catch(() => null);
if (res) secrets[key] = JSON.parse(res.SecretString);
}
return secrets;
}