I have as frontend Angular App which has functionality to connect with ActiveMQ and read messages from queue.
To connect with ActiveMQ will be used login and password for ActiveMQ which I would like to get from secret manager from AWS and use them in code.
I dont know exactly what is the right way to do this. My deployment configuration already use secret like this:
externalSecrets:
service:
key: my.test.secrets
here is my code:
I tried to define SecretManagerService which should retrieve secrets by secretName but I was getting error “Error retrieving secret. Credential is missing”
may be there is another way how to retrieve secret values ?
export class SecretManagerService {
private client: SecretsManagerClient;
constructor() {
this.client = new SecretsManagerClient({
region: 'eu-west-1',
});
}
async getSecret(secretName: string): Promise<string | undefined> {
try {
const response = await this.client.send(
new GetSecretValueCommand({
SecretId: secretName,
VersionStage: 'AWSCURRENT',
})
);
return response.SecretString;
} catch (error) {
console.error('Error retrieving secret', error);
throw error;
}
}
}
export class MyService {
constructor(
private rxStompService: RxStompService,
private secretManagerService: SecretManagerService) {
}
private async initStompService(clientId: string) {
const secretString = await this.secretManagerService.getSecret(environment.secretName);
if (!secretString) {
throw new Error('Failed to retrieve secrets');
}
const secret = JSON.parse(secretString);
const stompConfig = {
brokerURL: environment.activeMqURL,
connectHeaders: {
'client-id': clientId,
login: secret.login,
passcode: secret.password,
},
heartbeatIncoming: 0,
heartbeatOutgoing: 20000,
reconnectDelay: 200,
debug: (msg: string): void => {
console.log(new Date(), msg);
},
};
this.rxStompService.configure(stompConfig);
this.rxStompService.activate();
}