From 66d4aa61de5937eaf987870ffde2d7bb57b21e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Wed, 5 Jan 2022 10:40:22 +0100 Subject: [PATCH] fix: correct format for API tokens --- src/lib/create-config.test.ts | 10 +++++----- src/lib/create-config.ts | 3 ++- src/server-dev.ts | 2 +- website/docs/deploy/configuring-unleash.md | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/lib/create-config.test.ts b/src/lib/create-config.test.ts index afb764e706..ac4852213f 100644 --- a/src/lib/create-config.test.ts +++ b/src/lib/create-config.test.ts @@ -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', }; @@ -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: { @@ -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; @@ -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', }; diff --git a/src/lib/create-config.ts b/src/lib/create-config.ts index d79a696d53..3722bcb4c5 100644 --- a/src/lib/create-config.ts +++ b/src/lib/create-config.ts @@ -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, diff --git a/src/server-dev.ts b/src/server-dev.ts index 0f6485b106..67f5e1666f 100644 --- a/src/server-dev.ts +++ b/src/server-dev.ts @@ -36,7 +36,7 @@ process.nextTick(async () => { { environment: '*', project: '*', - secret: '*:*:964a287e1b728cb5f4f3e0120df92cb5', + secret: '*:*.964a287e1b728cb5f4f3e0120df92cb5', type: ApiTokenType.ADMIN, username: 'some-user', }, diff --git a/website/docs/deploy/configuring-unleash.md b/website/docs/deploy/configuring-unleash.md index 87faa4d808..867c5bace8 100644 --- a/website/docs/deploy/configuring-unleash.md +++ b/website/docs/deploy/configuring-unleash.md @@ -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`.