From 4a1fa314af2b825dabff845207fa2fae9cbefc64 Mon Sep 17 00:00:00 2001 From: Raghunandan Date: Wed, 17 Jun 2020 16:31:22 +0200 Subject: [PATCH] Consume identity data from ts instead of Json --- .../src/adapters/StaticJsonAdapter.ts | 13 ++----- .../src/adapters/data/userGroups.json | 20 ----------- .../src/adapters/userGroups.ts | 35 +++++++++++++++++++ .../identity-backend/src/service/router.ts | 3 +- 4 files changed, 40 insertions(+), 31 deletions(-) delete mode 100644 plugins/identity-backend/src/adapters/data/userGroups.json create mode 100644 plugins/identity-backend/src/adapters/userGroups.ts diff --git a/plugins/identity-backend/src/adapters/StaticJsonAdapter.ts b/plugins/identity-backend/src/adapters/StaticJsonAdapter.ts index cd2a40ea78..9a58da2e85 100644 --- a/plugins/identity-backend/src/adapters/StaticJsonAdapter.ts +++ b/plugins/identity-backend/src/adapters/StaticJsonAdapter.ts @@ -16,24 +16,17 @@ import { Group, - GroupsJson, GroupsResponse, IdentityApi, GroupsRequest, + GroupsJson, } from './types'; -import fs from 'fs-extra'; -import path from 'path'; - -const GROUPS_JSON_FILE = path.join(__dirname, 'data', 'userGroups.json'); export class StaticJsonAdapter implements IdentityApi { private readonly groups: Group[]; - constructor() { - const groupsJson: GroupsJson = fs.readJsonSync(GROUPS_JSON_FILE, { - encoding: 'utf8', - }); - this.groups = groupsJson.groups; + constructor(userGroups: GroupsJson) { + this.groups = userGroups.groups; } getUserGroups(req: GroupsRequest): Promise { diff --git a/plugins/identity-backend/src/adapters/data/userGroups.json b/plugins/identity-backend/src/adapters/data/userGroups.json deleted file mode 100644 index 9ab83480df..0000000000 --- a/plugins/identity-backend/src/adapters/data/userGroups.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "groups": [ - { - "name": "engineering", - "type": "org", - "children": [ - { - "name": "authentication", - "type": "team", - "members": [{ "name": "kent" }, { "name": "dobbs" }] - }, - { - "name": "checkout", - "type": "team", - "members": [{ "name": "don" }, { "name": "abramev" }] - } - ] - } - ] -} diff --git a/plugins/identity-backend/src/adapters/userGroups.ts b/plugins/identity-backend/src/adapters/userGroups.ts new file mode 100644 index 0000000000..806ca1f43f --- /dev/null +++ b/plugins/identity-backend/src/adapters/userGroups.ts @@ -0,0 +1,35 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const userGroups = { + groups: [ + { + name: 'engineering', + type: 'org', + children: [ + { + name: 'authentication', + type: 'team', + members: [{ name: 'kent' }, { name: 'dobbs' }], + }, + { + name: 'checkout', + type: 'team', + members: [{ name: 'don' }, { name: 'abramev' }], + }, + ], + }, + ], +}; diff --git a/plugins/identity-backend/src/service/router.ts b/plugins/identity-backend/src/service/router.ts index 256ef6ce3c..9c6515ac04 100644 --- a/plugins/identity-backend/src/service/router.ts +++ b/plugins/identity-backend/src/service/router.ts @@ -19,6 +19,7 @@ import Router from 'express-promise-router'; import { Logger } from 'winston'; import { StaticJsonAdapter } from '../adapters'; import { IdentityApi } from '../adapters/types'; +import { userGroups } from '../adapters/userGroups'; export interface RouterOptions { logger: Logger; @@ -42,6 +43,6 @@ export async function createRouter( const logger = options.logger; logger.info('Initializing identity API backend'); - const adapter = new StaticJsonAdapter(); + const adapter = new StaticJsonAdapter(userGroups); return makeRouter(adapter); }