Skip to content

Commit 4817161

Browse files
committed
upd catalog list
1 parent 7d10656 commit 4817161

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

src/controllers/v3/OrgProductController.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import { ProductCatalog, ProductCatalogOperation } from './types-extra';
3131
import { gql } from 'graphql-request';
3232
import { Environment } from '../../services/keystone/types';
3333
import YAML from 'yaml';
34+
import { getGwaProductEnvironment } from '../../services/workflow';
35+
import { NamespaceService } from '../../services/org-groups';
36+
import { OrgNamespace } from '../../services/org-groups/types';
3437

3538
@injectable()
3639
@Route('/organizations')
@@ -60,9 +63,10 @@ export class OrgProductController extends Controller {
6063
(e: Environment) => e.product.organization != null
6164
);
6265

63-
return envs.map((env: any) => {
66+
const output = envs.map((env: any) => {
6467
const spec = YAML.parse(env.spec?.blob || '{}');
6568

69+
6670
const operations = spec?.paths && Object.keys(spec.paths).map((path) => {
6771
return Object.keys(spec.paths[path]).map((method) => {
6872
const op = spec.paths[path][method];
@@ -100,6 +104,15 @@ export class OrgProductController extends Controller {
100104
},
101105
};
102106
});
107+
108+
const promises = output.filter((env:any) => env.product.namespace).map(async (env: any) => {
109+
const nsAttributes = await getNamespaceAttributes(
110+
env.product.namespace
111+
);
112+
env.ns = nsAttributes;
113+
});
114+
await Promise.all(promises);
115+
return output;
103116
}
104117

105118
/**
@@ -178,10 +191,21 @@ const list = gql`
178191
}
179192
product {
180193
name
194+
namespace
181195
organization {
182196
name
183197
}
184198
}
185199
}
186200
}
187201
`;
202+
203+
204+
async function getNamespaceAttributes(ns: string) : Promise<OrgNamespace> {
205+
const prodEnv = await getGwaProductEnvironment(this.keystone.sudo(), false);
206+
const envConfig = prodEnv.issuerEnvConfig;
207+
208+
const svc = new NamespaceService(envConfig.issuerUrl);
209+
await svc.login(envConfig.clientId, envConfig.clientSecret);
210+
return await svc.getNamespaceOrganizationDetails(ns);
211+
}

src/controllers/v3/openapi.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,11 +731,37 @@ components:
731731
- organization
732732
- name
733733
type: object
734+
ns:
735+
properties:
736+
updatedAt:
737+
type: number
738+
format: double
739+
enabled:
740+
type: boolean
741+
permDomains:
742+
items:
743+
type: string
744+
type: array
745+
permDataPlane:
746+
type: string
747+
orgUnit:
748+
type: string
749+
name:
750+
type: string
751+
required:
752+
- updatedAt
753+
- enabled
754+
- permDomains
755+
- permDataPlane
756+
- orgUnit
757+
- name
758+
type: object
734759
required:
735760
- appId
736761
- name
737762
- spec
738763
- product
764+
- ns
739765
type: object
740766
additionalProperties: false
741767
DraftDatasetRefID:

src/controllers/v3/routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ const models: TsoaRoute.Models = {
424424
"name": {"dataType":"string","required":true},
425425
"spec": {"dataType":"nestedObjectLiteral","nestedProperties":{"operations":{"dataType":"array","array":{"dataType":"refObject","ref":"ProductCatalogOperation"},"required":true},"description":{"dataType":"string","required":true},"version":{"dataType":"string","required":true},"title":{"dataType":"string","required":true}},"required":true},
426426
"product": {"dataType":"nestedObjectLiteral","nestedProperties":{"organization":{"dataType":"nestedObjectLiteral","nestedProperties":{"name":{"dataType":"string","required":true}},"required":true},"name":{"dataType":"string","required":true}},"required":true},
427+
"ns": {"dataType":"nestedObjectLiteral","nestedProperties":{"updatedAt":{"dataType":"double","required":true},"enabled":{"dataType":"boolean","required":true},"permDomains":{"dataType":"array","array":{"dataType":"string"},"required":true},"permDataPlane":{"dataType":"string","required":true},"orgUnit":{"dataType":"string","required":true},"name":{"dataType":"string","required":true}},"required":true},
427428
},
428429
"additionalProperties": false,
429430
},

src/controllers/v3/types-extra.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,12 @@ export interface ProductCatalog {
100100
name: string;
101101
}
102102
}
103+
ns: {
104+
name: string;
105+
orgUnit: string;
106+
permDataPlane: string;
107+
permDomains: string[];
108+
enabled: boolean;
109+
updatedAt: number;
110+
}
103111
}

src/services/org-groups/namespace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ export class NamespaceService {
184184
async getNamespaceOrganizationDetails(ns: string): Promise<OrgNamespace> {
185185
const nsGroup = await this.groupService.findByName('ns', ns, false);
186186

187-
if ('org' in nsGroup.attributes && 'org-unit' in nsGroup.attributes) {
187+
if ('org' in nsGroup.attributes) {
188188
return {
189189
name: nsGroup.attributes['org'].pop(),
190-
orgUnit: nsGroup.attributes['org-unit'].pop(),
190+
orgUnit: 'org-unit' in nsGroup.attributes ? nsGroup.attributes['org-unit'].pop() : '',
191191
permDataPlane:
192192
'perm-data-plane' in nsGroup.attributes
193193
? nsGroup.attributes['perm-data-plane'] : '',

0 commit comments

Comments
 (0)