Skip to content

Commit

Permalink
feat(core-lib): add enabled for auth config (cloudforet-io#2446)
Browse files Browse the repository at this point in the history
Signed-off-by: Wanjin Noh <[email protected]>
  • Loading branch information
WANZARGEN authored Dec 12, 2023
1 parent bd381aa commit 2445ff2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ Follow the example at `apps/web/public/config/development.sample.json`.

Configuration for `DEV.MOCK` in the config file.

| Name | Description | Required |
|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|
| ENABLED | boolean(false). Whether apply mock mode to api requests except for reflection apis. | X |
| REFLECTION_V1 | boolean(false). Whether to apply mock mode to reflection api v1 or not. | X |
| REFLECTION_V2 | boolean(false). Whether to apply mock mode to reflection api v2 or not. | X |
| ENDPOINT_V1 | string(""). Mock server endpoint for console api v1. | X |
| ENDPOINT_V2 | string(""). Mock server endpoint for console api v2. | X |
| Name | Description | Required |
|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|
| ENABLED | boolean(false). Whether apply mock mode to api requests except for reflection apis. | X |
| REFLECTION_V1 | boolean(false). Whether to apply mock mode to reflection api v1 or not. | X |
| REFLECTION_V2 | boolean(false). Whether to apply mock mode to reflection api v2 or not. | X |
| ENDPOINT_V1 | string(""). Mock server endpoint for console api v1. | X |
| ENDPOINT_V2 | string(""). Mock server endpoint for console api v2. | X |
| API_LIST_V1 | array of string([]). List of api v1 to enable mock mock mode. Refer to the [Rules for API_LIST](#####Rules for DEV.MOCK.API_LIST_V1 and DEV.MOCK.API_LIST_V2) section for details. | X |
| API_LIST_V2 | List of api v2 to enable mock mock mode. Refer to the [Rules for API_LIST](#####Rules for DEV.MOCK.API_LIST_V1 and DEV.MOCK.API_LIST_V2) section for details. | X |
| API_LIST_V2 | List of api v2 to enable mock mock mode. Refer to the [Rules for API_LIST](#####Rules for DEV.MOCK.API_LIST_V1 and DEV.MOCK.API_LIST_V2) section for details. | X |

##### Rules for DEV.MOCK.API_LIST_V1 and DEV.MOCK.API_LIST_V2

Expand All @@ -136,10 +136,11 @@ e.g. ["/identity/*", "!/identity/domain/*"] : All apis in the `/identity/*` will

Configuration for `DEV.AUTH` in the config file.

| Name | Description | Required |
|------------------|------------------------------------------------|----------|
| SKIP_TOKEN_CHECK | Whether to skip checking token. | X |
| API_KEY | API key which is used instead of access token. | X |
| Name | Description | Required |
|------------------|----------------------------------------------------|----------|
| ENABLED | boolean(false). Whether to use auth config or not. | X |
| SKIP_TOKEN_CHECK | Whether to skip checking token. | X |
| API_KEY | API key which is used instead of access token. | X |


## Testing
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/lib/site-initializer/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const getMockConfig = (config): MockConfig => ({
});

const getAuthConfig = (config): AuthConfig => ({
enabled: config.get('DEV.AUTH.ENABLED'),
skipTokenCheck: config.get('DEV.AUTH.SKIP_TOKEN_CHECK'),
apiKey: config.get('DEV.AUTH.API_KEY'),
});
Expand Down
4 changes: 2 additions & 2 deletions packages/core-lib/src/space-connector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class SpaceConnector {
}

static get isTokenAlive(): boolean {
if (SpaceConnector.isDevMode && SpaceConnector.authConfig.skipTokenCheck) return true;
if (SpaceConnector.isDevMode && SpaceConnector.authConfig.enabled && SpaceConnector.authConfig.skipTokenCheck) return true;
return TokenAPI.checkToken();
}

Expand Down Expand Up @@ -192,7 +192,7 @@ export class SpaceConnector {
const axiosConfig = { ...config };

// set api key
if (SpaceConnector.authConfig.apiKey) {
if (SpaceConnector.authConfig.enabled && SpaceConnector.authConfig.apiKey) {
axiosConfig.headers = Object.assign(
axiosConfig.headers ?? {},
{ Authorization: `Bearer ${SpaceConnector.authConfig.apiKey}` },
Expand Down
1 change: 1 addition & 0 deletions packages/core-lib/src/space-connector/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export interface MockConfig {
apiList?: string[][]; // [[v1_api_1, v1_api_2], [v2_api_1, v2_api_2, v2_api_3]]
}
export interface AuthConfig {
enabled?: boolean;
skipTokenCheck?: boolean;
apiKey?: string;
}
Expand Down

0 comments on commit 2445ff2

Please sign in to comment.