Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
feat: support Secret Binary from AWS Secrets Manager (#197)
Browse files Browse the repository at this point in the history
* Retrieve binary secrets from AWS Secrets Manager
  • Loading branch information
arruzk authored and Flydiverny committed Nov 7, 2019
1 parent 165662c commit 731edb1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/backends/secrets-manager-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ class SecretsManagerBackend extends KVBackend {
.getSecretValue({ SecretId: secretKey })
.promise()

return data.SecretString
if ('SecretBinary' in data) {
return data.SecretBinary
} else if ('SecretString' in data) {
return data.SecretString
}

this._logger.error(`Unexpected data from Secrets Manager secret ${secretKey}`)
return null
}
}

Expand Down
17 changes: 17 additions & 0 deletions lib/backends/secrets-manager-backend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ describe('SecretsManagerBackend', () => {
expect(secretPropertyValue).equals('fakeSecretPropertyValue')
})

it('returns binary secret', async () => {
getSecretValuePromise.promise.resolves({
SecretBinary: Buffer.from('fakeSecretPropertyValue', 'utf-8')
})

const secretPropertyValue = await secretsManagerBackend._get({
secretKey: 'fakeSecretKey'
})

expect(clientMock.getSecretValue.calledWith({
SecretId: 'fakeSecretKey'
})).to.equal(true)
expect(clientFactoryMock.getCall(0).args).deep.equals([])
expect(assumeRoleMock.callCount).equals(0)
expect(secretPropertyValue.toString()).equals('fakeSecretPropertyValue')
})

it('returns secret property value assuming a role', async () => {
getSecretValuePromise.promise.resolves({
SecretString: 'fakeAssumeRoleSecretValue'
Expand Down

0 comments on commit 731edb1

Please sign in to comment.