Merge pull request #1229 from Unleash/fix/init-api-token-format

fix: correct format for API tokens
This commit is contained in:
Thomas Heartman
2022-01-05 11:30:55 +01:00
committed by GitHub
4 changed files with 10 additions and 9 deletions
+5 -5
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',
};
+2 -1
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,
+1 -1
View File
@@ -36,7 +36,7 @@ process.nextTick(async () => {
{
environment: '*',
project: '*',
secret: '*:*:964a287e1b728cb5f4f3e0120df92cb5',
secret: '*:*.964a287e1b728cb5f4f3e0120df92cb5',
type: ApiTokenType.ADMIN,
username: 'some-user',
},
+2 -2
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`.