Consume identity data from ts instead of Json
This commit is contained in:
@@ -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<GroupsResponse> {
|
||||
|
||||
@@ -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" }]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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' }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user