mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
fix: correct format for API tokens
This commit is contained in:
parent
ce1cc8f3a8
commit
66d4aa61de
@ -22,7 +22,7 @@ test('should add initApiToken from options', async () => {
|
|||||||
const token = {
|
const token = {
|
||||||
environment: '*',
|
environment: '*',
|
||||||
project: '*',
|
project: '*',
|
||||||
secret: '*:*:some-random-string',
|
secret: '*:*.some-random-string',
|
||||||
type: ApiTokenType.ADMIN,
|
type: ApiTokenType.ADMIN,
|
||||||
username: 'admin',
|
username: 'admin',
|
||||||
};
|
};
|
||||||
@ -53,7 +53,7 @@ test('should add initApiToken from options', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should add initApiToken from env var', 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({
|
const config = createConfig({
|
||||||
db: {
|
db: {
|
||||||
@ -75,7 +75,7 @@ test('should add initApiToken from env var', async () => {
|
|||||||
ApiTokenType.ADMIN,
|
ApiTokenType.ADMIN,
|
||||||
);
|
);
|
||||||
expect(config.authentication.initApiTokens[1].secret).toBe(
|
expect(config.authentication.initApiTokens[1].secret).toBe(
|
||||||
'*:*:some-token2',
|
'*:*.some-token2',
|
||||||
);
|
);
|
||||||
|
|
||||||
delete process.env.INIT_ADMIN_API_TOKENS;
|
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 () => {
|
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 = {
|
const token = {
|
||||||
environment: '*',
|
environment: '*',
|
||||||
project: '*',
|
project: '*',
|
||||||
secret: '*:*:some-random-string',
|
secret: '*:*.some-random-string',
|
||||||
type: ApiTokenType.ADMIN,
|
type: ApiTokenType.ADMIN,
|
||||||
username: 'admin',
|
username: 'admin',
|
||||||
};
|
};
|
||||||
|
@ -185,7 +185,8 @@ const loadInitApiTokens = () => {
|
|||||||
if (process.env.INIT_ADMIN_API_TOKENS) {
|
if (process.env.INIT_ADMIN_API_TOKENS) {
|
||||||
const initApiTokens = process.env.INIT_ADMIN_API_TOKENS.split(/,\s?/);
|
const initApiTokens = process.env.INIT_ADMIN_API_TOKENS.split(/,\s?/);
|
||||||
const tokens = initApiTokens.map((secret) => {
|
const tokens = initApiTokens.map((secret) => {
|
||||||
const [project = '*', environment = '*'] = secret.split(':');
|
const [project = '*', rest] = secret.split(':');
|
||||||
|
const [environment = '*'] = rest.split('.');
|
||||||
const token = {
|
const token = {
|
||||||
createdAt: undefined,
|
createdAt: undefined,
|
||||||
project,
|
project,
|
||||||
|
@ -36,7 +36,7 @@ process.nextTick(async () => {
|
|||||||
{
|
{
|
||||||
environment: '*',
|
environment: '*',
|
||||||
project: '*',
|
project: '*',
|
||||||
secret: '*:*:964a287e1b728cb5f4f3e0120df92cb5',
|
secret: '*:*.964a287e1b728cb5f4f3e0120df92cb5',
|
||||||
type: ApiTokenType.ADMIN,
|
type: ApiTokenType.ADMIN,
|
||||||
username: 'some-user',
|
username: 'some-user',
|
||||||
},
|
},
|
||||||
|
@ -107,12 +107,12 @@ unleash.start(unleashOptions);
|
|||||||
[{
|
[{
|
||||||
environment: '*',
|
environment: '*',
|
||||||
project: '*',
|
project: '*',
|
||||||
secret: '*:*:964a287e1b728cb5f4f3e0120df92cb5',
|
secret: '*:*.964a287e1b728cb5f4f3e0120df92cb5',
|
||||||
type: ApiTokenType.ADMIN,
|
type: ApiTokenType.ADMIN,
|
||||||
username: 'some-user',
|
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`.
|
- **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).
|
- **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`.
|
- **logLevel** (`debug` | `info` | `warn` | `error` | `fatal`) - The lowest level to log at, also configurable using environment variable `LOG_LEVEL`.
|
||||||
|
Loading…
Reference in New Issue
Block a user