1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-11 00:08:30 +01:00

fix: correct format for API tokens

This commit is contained in:
Ivar Conradi Østhus 2022-01-05 10:40:22 +01:00
parent ce1cc8f3a8
commit 66d4aa61de
No known key found for this signature in database
GPG Key ID: 31AC596886B0BD09
4 changed files with 10 additions and 9 deletions

View File

@ -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',
};

View File

@ -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,

View File

@ -36,7 +36,7 @@ process.nextTick(async () => {
{
environment: '*',
project: '*',
secret: '*:*:964a287e1b728cb5f4f3e0120df92cb5',
secret: '*:*.964a287e1b728cb5f4f3e0120df92cb5',
type: ApiTokenType.ADMIN,
username: 'some-user',
},

View File

@ -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`.