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

feat(data): support .data in the secretDescriptor #40

Merged
merged 1 commit into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/backends/kv-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class KVBackend extends AbstractBackend {
* object, this is the property name of the value to use.
* @returns {Promise} Promise object representing secret property values.
*/
_fetchSecretPropertyValues ({ secretProperties }) {
return Promise.all(secretProperties.map(async secretProperty => {
_fetchSecretPropertyValues ({ externalData }) {
return Promise.all(externalData.map(async secretProperty => {
this._logger.info(`fetching secret property ${secretProperty.name}`)
const value = await this._get({ secretKey: secretProperty.key })

Expand All @@ -48,10 +48,12 @@ class KVBackend extends AbstractBackend {
*/
async getSecretManifestData ({ secretDescriptor }) {
const data = {}
// Use secretDescriptor.properties to be backwards compatible.
const externalData = secretDescriptor.data || secretDescriptor.properties
const secretPropertyValues = await this._fetchSecretPropertyValues({
secretProperties: secretDescriptor.properties
externalData
})
secretDescriptor.properties.forEach((secretProperty, index) => {
externalData.forEach((secretProperty, index) => {
data[secretProperty.name] = (Buffer.from(secretPropertyValues[index], 'utf8')).toString('base64')
})
return data
Expand Down
6 changes: 3 additions & 3 deletions lib/backends/kv-backend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('SecretsManagerBackend', () => {
it('handles secrets values that are objects', async () => {
kvBackend._get.onFirstCall().resolves({ foo: 'bar' })
const secretPropertyValues = await kvBackend._fetchSecretPropertyValues({
secretProperties: [{
externalData: [{
key: 'mocked-key',
name: 'mocked-name',
property: 'foo'
Expand All @@ -42,7 +42,7 @@ describe('SecretsManagerBackend', () => {
kvBackend._get.onSecondCall().resolves('fakePropertyValue2')

const secretPropertyValues = await kvBackend._fetchSecretPropertyValues({
secretProperties: [{
externalData: [{
key: 'fakePropertyKey1',
name: 'fakePropertyName1'
}, {
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('SecretsManagerBackend', () => {
})

expect(kvBackend._fetchSecretPropertyValues.calledWith({
secretProperties: [{
externalData: [{
key: 'fakePropertyKey1',
name: 'fakePropertyName1'
}, {
Expand Down