Skip to content

Commit

Permalink
upd controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
ikethecoder committed Jul 3, 2023
1 parent 8407d2a commit 30bc4da
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 31 deletions.
23 changes: 9 additions & 14 deletions src/api-openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ class ApiOpenapiApp {

RegisterRoutes(app);

// RFC 8631 service-desc link relation
// https://datatracker.ietf.org/doc/html/rfc8631
app.get('/ds/api', (req, res) => {
res.setHeader('Link', '</ds/api/openapi.yaml>; rel="service-desc"');
res.status(204).end();
});

app.get('/ds/api/openapi.yaml', (req, res) => {
res.setHeader('Content-Type', 'application/yaml');
res.send(spec);
Expand All @@ -54,14 +47,9 @@ class ApiOpenapiApp {
*/
specObject.components.securitySchemes.jwt.flows.clientCredentials.tokenUrl = `${process.env.OIDC_ISSUER}/protocol/openid-connect/token`;

RegisterRoutes(app);
specObject.components.securitySchemes.openid.openIdConnectUrl = `${process.env.OIDC_ISSUER}/.well-known/openid-configuration`;

// RFC 8631 service-desc link relation
// https://datatracker.ietf.org/doc/html/rfc8631
app.get('/ds/api/v2', (req, res) => {
res.setHeader('Link', '</ds/api/openapi.yaml>; rel="service-desc"');
res.status(204).end();
});
RegisterRoutes(app);

app.get('/ds/api/v2/openapi.yaml', (req, res) => {
res.setHeader('Content-Type', 'application/yaml');
Expand All @@ -86,6 +74,13 @@ class ApiOpenapiApp {
this.prepareV2(app);
this.prepareV1(app);

// RFC 8631 service-desc link relation
// https://datatracker.ietf.org/doc/html/rfc8631
app.get('/ds/api', (req, res) => {
res.setHeader('Link', '</ds/api/v2/openapi.yaml>; rel="service-desc"');
res.status(204).end();
});

app.use(function errorHandler(err, req, res, next) {
if (err instanceof UnauthorizedError) {
return res.status(err.status).json({
Expand Down
14 changes: 14 additions & 0 deletions src/controllers/v2/GatewayController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
Security,
Body,
Tags,
FormField,
UploadedFile,
} from 'tsoa';
import { KeystoneService } from '../ioc/keystoneInjector';
import { inject, injectable } from 'tsyringe';
Expand All @@ -20,6 +22,7 @@ import {
removeKeys,
} from '../../batch/feed-worker';
import { GatewayRoute } from './types';
import { PublishResult } from './types-extra';

@injectable()
@Route('/namespaces/{ns}/gateway')
Expand All @@ -31,6 +34,17 @@ export class GatewayController extends Controller {
this.keystone = _keystone;
}

@Put()
@OperationId('publish-gateway-config')
@Security('jwt', ['Gateway.Config'])
public async put(
@FormField() dryRun: boolean,
@UploadedFile() configFile: Express.Multer.File
): Promise<PublishResult> {
// stub - gwa-api implements this
return { error: 'Stub - not implemented' };
}

/**
* Get a summary of your Gateway Services
* > `Required Scope:` Namespace.Manage
Expand Down
57 changes: 51 additions & 6 deletions src/controllers/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ components:
- tag2
organization: ministry-of-citizens-services
organizationUnit: databc
PublishResult:
properties:
message:
type: string
results:
type: string
error:
type: string
type: object
additionalProperties: false
GatewayServiceRefID:
type: string
GatewayRouteRefID:
Expand Down Expand Up @@ -277,9 +287,7 @@ components:
clientRegistration: managed
clientId: a-client-id
clientSecret: a-client-secret
CredentialIssuerRefID:
type: string
UserRefID:
undefinedRefID:
type: string
CredentialIssuer:
properties:
Expand Down Expand Up @@ -338,9 +346,9 @@ components:
type: string
type: array
inheritFrom:
$ref: '#/components/schemas/CredentialIssuerRefID'
$ref: '#/components/schemas/undefinedRefID'
owner:
$ref: '#/components/schemas/UserRefID'
$ref: '#/components/schemas/undefinedRefID'
type: object
additionalProperties: false
example:
Expand All @@ -350,7 +358,7 @@ components:
clientAuthenticator: client-secret
mode: auto
environmentDetails: []
owner: acope@idir
owner: janis@gov.bc.ca
Maybe_Scalars-at-String_:
type: string
nullable: true
Expand Down Expand Up @@ -539,6 +547,8 @@ components:
type: string
LegalRefID:
type: string
CredentialIssuerRefID:
type: string
Environment:
properties:
appId:
Expand Down Expand Up @@ -621,6 +631,10 @@ components:
description: 'Authz Portal Login'
scheme: bearer
bearerFormat: JWT
openid:
type: openIdConnect
description: 'OIDC Login'
openIdConnectUrl: 'https://well_known_endpoint'
info:
title: 'APS Directory API'
version: 1.1.0
Expand Down Expand Up @@ -961,6 +975,37 @@ paths:
schema:
type: string
'/namespaces/{ns}/gateway':
put:
operationId: publish-gateway-config
responses:
'200':
description: Ok
content:
application/json:
schema:
$ref: '#/components/schemas/PublishResult'
tags:
- 'Gateway Services'
security:
-
jwt:
- Gateway.Config
parameters: []
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
dryRun:
type: string
configFile:
type: string
format: binary
required:
- dryRun
- configFile
get:
operationId: get-gateway-routes
responses:
Expand Down
59 changes: 51 additions & 8 deletions src/controllers/v2/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const promiseAny = require('promise.any');
import { iocContainer } from './../ioc';
import { IocContainer, IocContainerFactory } from '@tsoa/runtime';
import * as express from 'express';
const multer = require('multer');
const upload = multer();

// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa

Expand Down Expand Up @@ -128,6 +130,16 @@ const models: TsoaRoute.Models = {
"additionalProperties": false,
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"PublishResult": {
"dataType": "refObject",
"properties": {
"message": {"dataType":"string"},
"results": {"dataType":"string"},
"error": {"dataType":"string"},
},
"additionalProperties": false,
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"GatewayServiceRefID": {
"dataType": "refAlias",
"type": {"dataType":"string","validators":{}},
Expand Down Expand Up @@ -185,12 +197,7 @@ const models: TsoaRoute.Models = {
"additionalProperties": false,
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"CredentialIssuerRefID": {
"dataType": "refAlias",
"type": {"dataType":"string","validators":{}},
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"UserRefID": {
"undefinedRefID": {
"dataType": "refAlias",
"type": {"dataType":"string","validators":{}},
},
Expand All @@ -215,8 +222,8 @@ const models: TsoaRoute.Models = {
"resourceScopes": {"dataType":"array","array":{"dataType":"string"}},
"clientRoles": {"dataType":"array","array":{"dataType":"string"}},
"clientMappers": {"dataType":"array","array":{"dataType":"string"}},
"inheritFrom": {"ref":"CredentialIssuerRefID"},
"owner": {"ref":"UserRefID"},
"inheritFrom": {"ref":"undefinedRefID"},
"owner": {"ref":"undefinedRefID"},
},
"additionalProperties": false,
},
Expand Down Expand Up @@ -355,6 +362,11 @@ const models: TsoaRoute.Models = {
"type": {"dataType":"string","validators":{}},
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"CredentialIssuerRefID": {
"dataType": "refAlias",
"type": {"dataType":"string","validators":{}},
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"Environment": {
"dataType": "refObject",
"properties": {
Expand Down Expand Up @@ -780,6 +792,37 @@ export function RegisterRoutes(app: express.Router) {
}
});
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
app.put('/ds/api/v2/namespaces/:ns/gateway',
authenticateMiddleware([{"jwt":["Gateway.Config"]}]),
upload.single('configFile'),

async function GatewayController_put(request: any, response: any, next: any) {
const args = {
dryRun: {"in":"formData","name":"dryRun","required":true,"dataType":"string"},
configFile: {"in":"formData","name":"configFile","required":true,"dataType":"file"},
};

// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa

let validatedArgs: any[] = [];
try {
validatedArgs = getValidatedArgs(args, request, response);

const container: IocContainer = typeof iocContainer === 'function' ? (iocContainer as IocContainerFactory)(request) : iocContainer;

const controller: any = await container.get<GatewayController>(GatewayController);
if (typeof controller['setStatus'] === 'function') {
controller.setStatus(undefined);
}


const promise = controller.put.apply(controller, validatedArgs as any);
promiseHandler(controller, promise, response, undefined, next);
} catch (err) {
return next(err);
}
});
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
app.get('/ds/api/v2/namespaces/:ns/gateway',
authenticateMiddleware([{"jwt":["Namespace.Manage"]}]),

Expand Down
9 changes: 9 additions & 0 deletions src/controllers/v2/types-extra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ export interface ActivityDetail {
activityAt: Scalars['DateTime'];
blob?: any;
}

/**
* @tsoaModel
*/
export interface PublishResult {
message?: string;
results?: string;
error?: string;
}
12 changes: 9 additions & 3 deletions src/controllers/v2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export interface Environment {
* "clientAuthenticator": "client-secret",
* "mode": "auto",
* "environmentDetails": [],
* "owner": "acope@idir"
* "owner": "janis@gov.bc.ca"
* }
*/
export interface CredentialIssuer {
Expand All @@ -336,8 +336,8 @@ export interface CredentialIssuer {
resourceScopes?: string[];
clientRoles?: string[];
clientMappers?: string[];
inheritFrom?: CredentialIssuerRefID;
owner?: UserRefID;
inheritFrom?: undefinedRefID;
owner?: undefinedRefID;
}


Expand Down Expand Up @@ -477,6 +477,7 @@ export interface User {
name?: string;
email?: string;
legalsAgreed?: UserLegalsAgreed[];
provider?: string;
}


Expand Down Expand Up @@ -554,3 +555,8 @@ export type OrganizationUnitRefID = string
* @tsoaModel
*/
export type UserRefID = string

/**
* @tsoaModel
*/
export type undefinedRefID = string

0 comments on commit 30bc4da

Please sign in to comment.