Skip to content

Commit

Permalink
feat: support isBinary for GCP (external-secrets#353)
Browse files Browse the repository at this point in the history
* feat: support isBinary for GCP

Fixes external-secrets#352

Signed-off-by: Pete Muir <[email protected]>

* chore: jsdoc

Co-authored-by: Markus Maga <[email protected]>
  • Loading branch information
pmuir and Flydiverny committed Apr 23, 2020
1 parent 1d9d237 commit de20a1b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/backends/gcp-secrets-manager-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ class GCPSecretsManagerBackend extends KVBackend {
/**
* Get secret property value from GCP Secrets Manager.
* @param {string} key - Key used to store secret property value in GCP Secrets Manager.
* @param {boolean} keyOptions.isBinary - Is the secret base64 encoded? Set to true to handle as binary.
* @returns {Promise} Promise object representing secret property value.
*/
async _get ({ key }) {
async _get ({ key, keyOptions }) {
this._logger.info(`fetching secret ${key} from GCP Secret Manager`)
const version = await this._client.accessSecretVersion({
name: key
})
const secret = { value: version[0].payload.data.toString('utf8') }
// Handle binary files - this is useful when you've stored a base64 encoded string
if (keyOptions && keyOptions.isBinary) {
return Buffer.from(secret.value, 'base64')
}
return JSON.stringify(secret)
}
}
Expand Down

0 comments on commit de20a1b

Please sign in to comment.