Skip to content

Commit

Permalink
fix: correct format for API tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarconr committed Jan 5, 2022
1 parent ce1cc8f commit 66d4aa6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/lib/create-config.test.ts
Expand Up @@ -22,7 +22,7 @@ test('should add initApiToken from options', async () => {
const token = {
environment: '*',
project: '*',
secret: '*:*:some-random-string',
secret: '*:*.some-random-string',
type: ApiTokenType.ADMIN,
username: 'admin',
};
Expand Down Expand Up @@ -53,7 +53,7 @@ test('should add initApiToken from options', async () => {
});

test('should add initApiToken from env var', async () => {
process.env.INIT_ADMIN_API_TOKENS = '*:*:some-token1, *:*:some-token2';
process.env.INIT_ADMIN_API_TOKENS = '*:*.some-token1, *:*.some-token2';

const config = createConfig({
db: {
Expand All @@ -75,7 +75,7 @@ test('should add initApiToken from env var', async () => {
ApiTokenType.ADMIN,
);
expect(config.authentication.initApiTokens[1].secret).toBe(
'*:*:some-token2',
'*:*.some-token2',
);

delete process.env.INIT_ADMIN_API_TOKENS;
Expand All @@ -92,11 +92,11 @@ test('should validate initApiToken from env var', async () => {
});

test('should merge initApiToken from options and env vars', async () => {
process.env.INIT_ADMIN_API_TOKENS = '*:*:some-token1, *:*:some-token2';
process.env.INIT_ADMIN_API_TOKENS = '*:*.some-token1, *:*.some-token2';
const token = {
environment: '*',
project: '*',
secret: '*:*:some-random-string',
secret: '*:*.some-random-string',
type: ApiTokenType.ADMIN,
username: 'admin',
};
Expand Down
3 changes: 2 additions & 1 deletion src/lib/create-config.ts
Expand Up @@ -185,7 +185,8 @@ const loadInitApiTokens = () => {
if (process.env.INIT_ADMIN_API_TOKENS) {
const initApiTokens = process.env.INIT_ADMIN_API_TOKENS.split(/,\s?/);
const tokens = initApiTokens.map((secret) => {
const [project = '*', environment = '*'] = secret.split(':');
const [project = '*', rest] = secret.split(':');
const [environment = '*'] = rest.split('.');
const token = {
createdAt: undefined,
project,
Expand Down
2 changes: 1 addition & 1 deletion src/server-dev.ts
Expand Up @@ -36,7 +36,7 @@ process.nextTick(async () => {
{
environment: '*',
project: '*',
secret: '*:*:964a287e1b728cb5f4f3e0120df92cb5',
secret: '*:*.964a287e1b728cb5f4f3e0120df92cb5',
type: ApiTokenType.ADMIN,
username: 'some-user',
},
Expand Down
4 changes: 2 additions & 2 deletions website/docs/deploy/configuring-unleash.md
Expand Up @@ -107,12 +107,12 @@ unleash.start(unleashOptions);
[{
environment: '*',
project: '*',
secret: '*:*:964a287e1b728cb5f4f3e0120df92cb5',
secret: '*:*.964a287e1b728cb5f4f3e0120df92cb5',
type: ApiTokenType.ADMIN,
username: 'some-user',
}]
```
You can also use the environment variable `INIT_ADMIN_API_TOKENS`. This variable should be set to a comma-separated list of API tokens to initialize (for instance `*:*:some-random-string, *:*:some-other-token`). All admin tokens **must** target all environments and projects.
You can also use the environment variable `INIT_ADMIN_API_TOKENS`. This variable should be set to a comma-separated list of API tokens to initialize (for instance `*:*.some-random-string, *:*.some-other-token`). All admin tokens **must** target all environments and projects.
- **ui** (object) - Set of UI specific overrides. You may set the following keys: `environment`, `slogan`.
- **getLogger** (function) - Used to register a [custom log provider](#how-do-i-configure-the-log-output).
- **logLevel** (`debug` | `info` | `warn` | `error` | `fatal`) - The lowest level to log at, also configurable using environment variable `LOG_LEVEL`.
Expand Down

0 comments on commit 66d4aa6

Please sign in to comment.