Skip to content

Commit

Permalink
feat: improve intention api descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mbystedt committed Jan 2, 2025
1 parent f0c7759 commit 0acf449
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 52 deletions.
13 changes: 0 additions & 13 deletions src/intention/dto/action.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ import { UserDto } from './user.dto';
import { TransactionDto } from './transaction.dto';
import { ENVIRONMENT_NAMES } from './constants.dto';

// export const ACTION_NAMES = [
// 'backup',
// 'database-access',
// 'server-access',
// 'package-build',
// 'package-configure',
// 'package-installation',
// 'package-provision',
// 'process-end',
// 'process-start',
// ] as const;
// export type ActionName = (typeof ACTION_NAMES)[number];

export enum ACTION_NAMES {
BACKUP = 'backup',
DATABASE_ACCESS = 'database-access',
Expand Down
12 changes: 12 additions & 0 deletions src/intention/dto/constants.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ export const VAULT_PROVISIONED_ACTION_SET = new Set([
ACTION_PROVISION_APPROLE_SECRET_ID,
]);

export enum INTENTION_CLOSE_STATUSES {
SUCCESS = 'success',
FAILURE = 'failure',
UNKNOWN = 'unknown',
}

export enum ACTION_END_STATUSES {
SUCCESS = 'success',
FAILURE = 'failure',
UNKNOWN = 'unknown',
}

export enum ENVIRONMENT_NAMES {
PRODUCTION = 'production',
TEST = 'test',
Expand Down
40 changes: 35 additions & 5 deletions src/intention/intention.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
UsePipes,
ValidationPipe,
} from '@nestjs/common';
import { ApiBearerAuth, ApiHeader } from '@nestjs/swagger';
import { ApiBearerAuth, ApiHeader, ApiQuery } from '@nestjs/swagger';
import { Request } from 'express';

import { HEADER_BROKER_TOKEN } from '../constants';
Expand All @@ -28,6 +28,10 @@ import { ArtifactDto } from './dto/artifact.dto';
import { ArtifactSearchQuery } from './dto/artifact-search-query.dto';
import { ActionPatchRestDto } from './dto/action-patch-rest.dto';
import { IntentionDto } from './dto/intention.dto';
import {
ACTION_END_STATUSES,
INTENTION_CLOSE_STATUSES,
} from './dto/constants.dto';

@Controller({
path: 'intention',
Expand Down Expand Up @@ -74,16 +78,25 @@ export class IntentionController {

@Post('close')
@ApiHeader({ name: HEADER_BROKER_TOKEN, required: true })
@ApiQuery({
name: 'outcome',
required: false,
enum: INTENTION_CLOSE_STATUSES,
})
@ApiQuery({
name: 'reason',
required: false,
})
async closeIntention(
@Req() request: Request,
@Query('outcome') outcome: string | undefined,
@Query('outcome') outcome: INTENTION_CLOSE_STATUSES | undefined,
@Query('reason') reason: string | undefined,
): Promise<IntentionCloseDto> {
const tokenHeader = request.headers[HEADER_BROKER_TOKEN];
const token =
typeof tokenHeader === 'string' ? tokenHeader : tokenHeader[0];
if (outcome === undefined) {
outcome = 'success';
outcome = INTENTION_CLOSE_STATUSES.SUCCESS;
}
if (
outcome !== 'failure' &&
Expand Down Expand Up @@ -112,13 +125,30 @@ export class IntentionController {

@Post('action/end')
@ApiHeader({ name: HEADER_BROKER_TOKEN, required: true })
@ApiQuery({
name: 'outcome',
required: false,
enum: ACTION_END_STATUSES,
})
@UseGuards(ActionGuard)
async actionEnd(
@Req() request: ActionGuardRequest,
@Query('outcome') outcome: string | undefined,
@Query('outcome') outcome: ACTION_END_STATUSES | undefined,
) {
if (outcome === undefined) {
outcome = 'success';
outcome = ACTION_END_STATUSES.SUCCESS;
}
if (
outcome !== 'failure' &&
outcome !== 'success' &&
outcome !== 'unknown'
) {
throw new BadRequestException({
statusCode: 400,
message: 'Illegal outcome',
error:
'The outcome parameter must be undefined or be one of failure, success or unknown.',
});
}
await this.intentionService.actionLifecycle(
request,
Expand Down
40 changes: 22 additions & 18 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@angular/router": "^19.0.5",
"@bcgov/bc-sans": "^2.1.0",
"class-validator": "^0.14.1",
"echarts": "^5.5.1",
"echarts": "^5.6.0",
"filesize": "^10.1.6",
"ngx-echarts": "^19.0.0",
"ngx-sse-client": "^18.0.0",
Expand All @@ -33,7 +33,7 @@
"rxjs": "^7.8.1",
"tslib": "^2.7.0",
"url-regex-safe": "^4.0.0",
"uuid": "^10.0.0",
"uuid": "^11.0.3",
"zone.js": "^0.15.0"
},
"devDependencies": {
Expand All @@ -44,7 +44,7 @@
"@types/lodash.get": "^4.4.9",
"@types/url-regex-safe": "^1.0.2",
"@types/uuid": "^10.0.0",
"jasmine-core": "^5.4.0",
"jasmine-core": "^5.5.0",
"karma": "^6.4.4",
"karma-chrome-launcher": "^3.2.0",
"karma-coverage": "^2.2.1",
Expand Down
13 changes: 0 additions & 13 deletions ui/src/app/service/intention/dto/action.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ import { UserDto } from './user.dto';
import { TransactionDto } from './transaction.dto';
import { ENVIRONMENT_NAMES } from './constants.dto';

// export const ACTION_NAMES = [
// 'backup',
// 'database-access',
// 'server-access',
// 'package-build',
// 'package-configure',
// 'package-installation',
// 'package-provision',
// 'process-end',
// 'process-start',
// ] as const;
// export type ActionName = (typeof ACTION_NAMES)[number];

export enum ACTION_NAMES {
BACKUP = 'backup',
DATABASE_ACCESS = 'database-access',
Expand Down
12 changes: 12 additions & 0 deletions ui/src/app/service/intention/dto/constants.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ export const VAULT_PROVISIONED_ACTION_SET = new Set([
ACTION_PROVISION_APPROLE_SECRET_ID,
]);

export enum INTENTION_CLOSE_STATUSES {
SUCCESS = 'success',
FAILURE = 'failure',
UNKNOWN = 'unknown',
}

export enum ACTION_END_STATUSES {
SUCCESS = 'success',
FAILURE = 'failure',
UNKNOWN = 'unknown',
}

export enum ENVIRONMENT_NAMES {
PRODUCTION = 'production',
TEST = 'test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
margin: 16px;
}

.collection-flex-container button {
margin-right: 16px;
}

.spacer {
flex: 1;
}
Expand Down

0 comments on commit 0acf449

Please sign in to comment.