Skip to content

Commit ff1719d

Browse files
authored
Added support for personal tokens DEVRL-440 (#5)
1 parent a904b58 commit ff1719d

6 files changed

Lines changed: 91 additions & 23 deletions

File tree

.github/workflows/test.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Test
33
on: [push, pull_request]
44

55
jobs:
6-
test:
6+
service-token-test:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v2
@@ -15,3 +15,17 @@ jobs:
1515
env:
1616
NODE_ENV: development
1717
DOPPLER_TOKEN: ${{ secrets.TEST_DOPPLER_TOKEN }}
18+
personal-token-test:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v2
22+
- uses: actions/setup-node@v2
23+
with:
24+
node-version: 16
25+
- run: npm install
26+
- run: npm run test
27+
env:
28+
NODE_ENV: development
29+
DOPPLER_TOKEN: ${{ secrets.TEST_DOPPLER_PERSONAL_TOKEN }}
30+
DOPPLER_PROJECT: github-actions-secrets-fetch-test
31+
DOPPLER_CONFIG: prd

README.md

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,39 @@ This action enables you to fetch Doppler secrets for use in your GitHub Actions.
66
77
## Configuration
88

9-
This action requires a [Doppler Service Token](https://docs.doppler.com/docs/service-tokens) to provide read-only access to secrets for a specific Config within a [Project](https://docs.doppler.com/docs/create-project).
9+
The action can be configured in two ways:
10+
11+
* Service Token (recommended)
12+
* Personal Token with Project and Config
13+
14+
### Service Token
15+
16+
A [Doppler Service Token](https://docs.doppler.com/docs/service-tokens) provides read-only access to a single config and is recommended due to its limited access scope.
1017

1118
Create a GitHub repository secret named `DOPPLER_TOKEN` or if using multiple Service Tokens (e.g. for a Monorepo), you can prefix the secret name using with application name, e.g. `AUTH_API_DOPPLER_TOKEN`.
1219

20+
Then supply the Service Token using the `doppler-token` input:
21+
22+
```yaml
23+
- uses: dopplerhq/secrets-fetch-action@v1.1.0
24+
id: doppler
25+
with:
26+
doppler-token: ${{ secrets.DOPPLER_TOKEN }}
27+
```
28+
29+
### Personal Token
30+
31+
A Doppler Personal Token provides read/write access to every Project and Config accessible for that account and should only be used when necessary. The `doppler-project` and `doppler-config` inputs must be provided when using a Personal Token:
32+
33+
```yaml
34+
- uses: dopplerhq/secrets-fetch-action@v1.1.0
35+
id: doppler
36+
with:
37+
doppler-token: ${{ secrets.PERSONAL_DOPPLER_TOKEN }}
38+
doppler-project: auth-api
39+
doppler-config: ci-cd
40+
```
41+
1342
## Usage
1443

1544
Secrets can be accessed in two ways:
@@ -30,7 +59,7 @@ jobs:
3059
secrets-fetch:
3160
runs-on: ubuntu-latest
3261
steps:
33-
- uses: doppleruniversity/secrets-fetch-action@v1
62+
- uses: dopplerhq/secrets-fetch-action@v1.1.0
3463
id: doppler
3564
with:
3665
doppler-token: ${{ secrets.DOPPLER_TOKEN }}
@@ -53,7 +82,7 @@ jobs:
5382
secrets-fetch:
5483
runs-on: ubuntu-latest
5584
steps:
56-
- uses: doppleruniversity/secrets-fetch-action@v0.0.1
85+
- uses: dopplerhq/secrets-fetch-action@v1.1.0
5786
id: doppler
5887
with:
5988
doppler-token: ${{ secrets.DOPPLER_TOKEN }}
@@ -67,4 +96,8 @@ All secret values are masked with the exception of the Doppler meta variables:
6796

6897
- `DOPPLER_PROJECT`
6998
- `DOPPLER_ENVIRONMENT`
70-
- `DOPPLER_CONFIG`
99+
- `DOPPLER_CONFIG`
100+
101+
# Development and Testing
102+
103+
Export the `NODE_ENV` and `DOPPLER_TOKEN` environment variables, then run `npm test`.

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ inputs:
99
Doppler Service Token that grants access to a single Config within a Project.
1010
See https://docs.doppler.com/docs/service-tokens
1111
required: true
12+
doppler-project:
13+
description: >-
14+
Doppler Project
15+
required: false
16+
doppler-config:
17+
description: >-
18+
Doppler Config slug (e.g. prd)
19+
required: false
1220
inject-env-vars:
1321
description: >-
1422
Inject secrets as environment variables for subsequent steps if set to `true`.

doppler.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
import https from "https";
2-
import { VERSION } from './meta.js'
2+
import { VERSION } from "./meta.js";
33

44
/**
5-
* Fetch secrets from Doppler the API.
6-
* Requires the `DOPPLER_TOKEN` environment variable to be set. See https://docs.doppler.com/docs/enclave-service-tokens
5+
* Fetch secrets from Doppler the API
6+
* @param {string} dopplerToken
7+
* @param {string | null} [dopplerProject]
8+
* @param {string | null} [dopplerConfig]
79
* @returns {() => Promise<Record<string, string>>}
810
*/
9-
async function fetch(dopplerToken) {
11+
async function fetch(dopplerToken, dopplerProject, dopplerConfig) {
1012
return new Promise(function (resolve, reject) {
1113
const encodedAuthData = Buffer.from(`${dopplerToken}:`).toString("base64");
1214
const authHeader = `Basic ${encodedAuthData}`;
1315
const userAgent = `secrets-fetch-github-action/${VERSION}`;
16+
17+
const url = new URL("https://api.doppler.com/v3/configs/config/secrets/download?format=json");
18+
if (dopplerProject && dopplerConfig) {
19+
url.searchParams.append("project", dopplerProject);
20+
url.searchParams.append("config", dopplerConfig);
21+
}
22+
1423
https
1524
.get(
16-
"https://api.doppler.com/v3/configs/config/secrets/download?format=json",
25+
url.href,
1726
{
1827
headers: {
1928
Authorization: authHeader,
@@ -44,5 +53,4 @@ async function fetch(dopplerToken) {
4453
});
4554
}
4655

47-
export default fetch
48-
56+
export default fetch;

index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@ import fetch from "./doppler.js";
44
// For local testing
55
if (process.env.NODE_ENV === "development" && process.env.DOPPLER_TOKEN) {
66
process.env["INPUT_DOPPLER-TOKEN"] = process.env.DOPPLER_TOKEN;
7+
process.env["INPUT_DOPPLER-PROJECT"] = process.env.DOPPLER_PROJECT;
8+
process.env["INPUT_DOPPLER-CONFIG"] = process.env.DOPPLER_CONFIG;
79
}
810

9-
const DOPPLER_META = [
10-
"DOPPLER_PROJECT",
11-
"DOPPLER_CONFIG",
12-
"DOPPLER_ENVIRONMENT",
13-
];
14-
11+
const DOPPLER_META = ["DOPPLER_PROJECT", "DOPPLER_CONFIG", "DOPPLER_ENVIRONMENT"];
1512
const DOPPLER_TOKEN = core.getInput("doppler-token", { required: true });
1613
core.setSecret(DOPPLER_TOKEN);
1714

18-
const secrets = await fetch(DOPPLER_TOKEN);
15+
const IS_PERSONAL_TOKEN = DOPPLER_TOKEN.startsWith("dp.pt.");
16+
const DOPPLER_PROJECT = IS_PERSONAL_TOKEN ? core.getInput("doppler-project") : null;
17+
const DOPPLER_CONFIG = IS_PERSONAL_TOKEN ? core.getInput("doppler-config") : null;
18+
if (IS_PERSONAL_TOKEN && !(DOPPLER_PROJECT && DOPPLER_CONFIG)) {
19+
core.setFailed("doppler-project and doppler-config inputs are required when using a Personal token");
20+
process.exit();
21+
}
22+
23+
const secrets = await fetch(DOPPLER_TOKEN, DOPPLER_PROJECT, DOPPLER_CONFIG);
1924

2025
for (const [key, value] of Object.entries(secrets)) {
2126
core.setOutput(key, value);

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"name": "doppler-secrets-fetch-github-action",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "GitHub Action to fetch secrets from Doppler's API",
55
"author": "Doppler",
66
"license": "Apache-2.0",
77
"bugs": {
8-
"url": "https://github.com/DopplerUniversity/secrets-fetch-action/issues"
8+
"url": "https://github.com/dopplerhq/secrets-fetch-action/issues"
99
},
1010
"main": "index.js",
1111
"repository": {
1212
"type": "git",
13-
"url": "git+https://github.com/DopplerUniversity/secrets-fetch-action"
13+
"url": "git+https://github.com/dopplerhq/secrets-fetch-action"
1414
},
1515
"type": "module",
1616
"scripts": {
1717
"test": "node index.js"
1818
},
1919
"keywords": [],
20-
"homepage": "https://github.com/DopplerUniversity/#readme",
20+
"homepage": "https://github.com/dopplerhq/secrets-fetch-action/#readme",
2121
"dependencies": {
2222
"@actions/core": "^1.8.0"
2323
}

0 commit comments

Comments
 (0)