Skip to content

Commit 2b6c48c

Browse files
committed
Configurable API domain for testing
1 parent bfccfd8 commit 2b6c48c

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ inputs:
3131
description: >-
3232
Identity to use, required when auth-method is "oidc".
3333
required: false
34+
doppler-api-domain:
35+
default: "api.doppler.com"
36+
required: false
3437
runs:
3538
using: 'node20'
3639
main: 'index.js'

doppler.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ import { VERSION } from "./meta.js";
66
* @param {string} dopplerToken
77
* @param {string | null} [dopplerProject]
88
* @param {string | null} [dopplerConfig]
9+
* @param {string} apiDomain
910
* @returns {() => Promise<Record<string, Record>>}
1011
*/
11-
export async function fetch(dopplerToken, dopplerProject, dopplerConfig) {
12+
export async function fetch(dopplerToken, dopplerProject, dopplerConfig, apiDomain) {
1213
return new Promise(function (resolve, reject) {
1314
const encodedAuthData = Buffer.from(`${dopplerToken}:`).toString("base64");
1415
const authHeader = `Basic ${encodedAuthData}`;
1516
const userAgent = `secrets-fetch-github-action/${VERSION}`;
1617

17-
const url = new URL("https://api.doppler.com/v3/configs/config/secrets");
18+
const url = new URL(`https://${apiDomain}/v3/configs/config/secrets`);
1819
if (dopplerProject && dopplerConfig) {
1920
url.searchParams.append("project", dopplerProject);
2021
url.searchParams.append("config", dopplerConfig);
@@ -58,13 +59,14 @@ export async function fetch(dopplerToken, dopplerProject, dopplerConfig) {
5859
* Exchange an OIDC token for a short lived Doppler service account token
5960
* @param {string} identityId
6061
* @param {string} oidcToken
62+
* @param {string} apiDomain
6163
* @returns {() => Promise<string>}
6264
*/
63-
export async function oidcAuth(identityId, oidcToken) {
65+
export async function oidcAuth(identityId, oidcToken, apiDomain) {
6466
return new Promise(function (resolve, reject) {
6567
const userAgent = `secrets-fetch-github-action/${VERSION}`;
6668

67-
const url = new URL("https://api.doppler.com/v3/auth/oidc");
69+
const url = new URL(`https://${apiDomain}/v3/auth/oidc`);
6870
const body = JSON.stringify({
6971
identity: identityId,
7072
token: oidcToken

index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ if (process.env.NODE_ENV === "development" && process.env.DOPPLER_TOKEN) {
99
}
1010

1111
const AUTH_METHOD = core.getInput("auth-method");
12+
const API_DOMAIN = core.getInput("doppler-api-domain");
1213
let DOPPLER_TOKEN = "";
1314

1415
if (AUTH_METHOD === "oidc") {
1516
const DOPPLER_IDENTITY_ID = core.getInput("doppler-identity-id", { required: true });
1617
const oidcToken = await core.getIDToken();
1718
core.setSecret(oidcToken);
18-
DOPPLER_TOKEN = await oidcAuth(DOPPLER_IDENTITY_ID, oidcToken)
19+
DOPPLER_TOKEN = await oidcAuth(DOPPLER_IDENTITY_ID, oidcToken, API_DOMAIN);
1920
} else if (AUTH_METHOD === "token") {
2021
DOPPLER_TOKEN = core.getInput("doppler-token", { required: true });
2122
}else {
@@ -39,7 +40,7 @@ if (IS_SA_TOKEN && !(DOPPLER_PROJECT && DOPPLER_CONFIG)) {
3940
process.exit();
4041
}
4142

42-
const secrets = await fetch(DOPPLER_TOKEN, DOPPLER_PROJECT, DOPPLER_CONFIG);
43+
const secrets = await fetch(DOPPLER_TOKEN, DOPPLER_PROJECT, DOPPLER_CONFIG, API_DOMAIN);
4344

4445
for (const [key, secret] of Object.entries(secrets)) {
4546
const value = secret.computed || "";

0 commit comments

Comments
 (0)