Skip to content

Commit

Permalink
Merge pull request #40 from DopplerHQ/watsonian/service-account-support
Browse files Browse the repository at this point in the history
Update Doppler provider to accept Project and Config params
  • Loading branch information
watsonian authored Jul 26, 2023
2 parents 455e5de + 3c52ae7 commit c5bf197
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
## 0.0.5 (May 25, 2022)

- Enable Doppler Service Token to be passed as a parameter to the Doppler provider

## 0.0.6 (July 25, 2023)

- Enable Doppler Project and Doppler Config to be passed as a parameter to the Doppler provider
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gitops-secrets",
"version": "0.0.5",
"version": "0.0.6",
"author": "Ryan Blunden <[email protected]>",
"description": "SecretOps workflow for bundling encrypted secrets into your deployments to safely decrypt at runtime.",
"repository": {
Expand Down
13 changes: 8 additions & 5 deletions src/providers/doppler.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
const https = require("https");
const querystring = require("querystring");
const { VERSION } = require("../meta");

/**
* Fetch secrets from Doppler the API.
* @param {{dopplerToken: string}} [{dopplerToken: process.env.DOPPLER_TOKEN}] Requires a Doppler Service Token for API authentication. See https://docs.doppler.com/docs/enclave-service-tokens
* @param {{dopplerToken: string}} [{dopplerToken: process.env.DOPPLER_TOKEN}] Requires a Doppler Token for API authentication. See https://docs.doppler.com/docs/enclave-service-tokens
* @param {{dopplerProject: string}} [{dopplerProject: null}] Optional Doppler Project. Required when using any token type other than Service Tokens.
* @param {{dopplerConfig: string}} [{dopplerConfig: null}] Optional Doppler Config. Required when using any token type other than Service Tokens.
* @returns {() => Promise<Record<string, string>>}
*/
async function fetch({ dopplerToken = process.env.DOPPLER_TOKEN } = {}) {
async function fetch({ dopplerToken = process.env.DOPPLER_TOKEN, dopplerProject = null, dopplerConfig = null } = {}) {
if (!dopplerToken) {
throw new Error("Doppler API Error: The 'DOPPLER_TOKEN' environment variable is required");
}

return new Promise(function (resolve, reject) {
const encodedAuthData = Buffer.from(`${dopplerToken}:`).toString("base64");
const authHeader = `Basic ${encodedAuthData}`;
const authHeader = `Bearer ${dopplerToken}`;
const userAgent = `gitops-secrets-nodejs/${VERSION}`;
const query = { format: "json", project: dopplerProject, config: dopplerConfig };
https
.get(
"https://api.doppler.com/v3/configs/config/secrets/download?format=json",
`https://api.doppler.com/v3/configs/config/secrets/download?${querystring.stringify(query)}`,
{
headers: {
Authorization: authHeader,
Expand Down

0 comments on commit c5bf197

Please sign in to comment.