-
Notifications
You must be signed in to change notification settings - Fork 203
Expand file tree
/
Copy pathdeployments.controller.ts
More file actions
191 lines (185 loc) · 5.71 KB
/
Copy pathdeployments.controller.ts
File metadata and controls
191 lines (185 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import {
Body,
Controller,
Delete,
Get,
Param,
Post,
Put,
UseGuards,
Request,
} from '@nestjs/common';
import { DeploymentsService } from './deployments.service';
import {
ApiBearerAuth,
ApiBody,
ApiForbiddenResponse,
ApiOperation,
ApiParam,
} from '@nestjs/swagger';
import { IUser } from '../auth/auth.interface';
import { CreateBuild } from './dto/CreateBuild.dto';
import { OKDTO } from '../common/dto/ok.dto';
import { JwtAuthGuard } from '../auth/strategies/jwt.guard';
import { PermissionsGuard } from '../auth/permissions.guard';
import { Permissions } from '../auth/permissions.decorator';
import { ReadonlyGuard } from '../common/guards/readonly.guard';
@Controller({ path: 'api/deployments', version: '1' })
export class DeploymentsController {
constructor(private readonly deploymentsService: DeploymentsService) {}
@Get('/:pipeline/:phase/:app')
@UseGuards(JwtAuthGuard, PermissionsGuard)
@Permissions('app:read', 'app:write')
@ApiForbiddenResponse({
description: 'Error: Unauthorized',
type: OKDTO,
isArray: false,
})
@ApiBearerAuth('bearerAuth')
@ApiOperation({ summary: 'List deployments for a specific app' })
@ApiParam({ name: 'pipeline', description: 'Pipeline name' })
@ApiParam({ name: 'phase', description: 'Phase name' })
@ApiParam({ name: 'app', description: 'App name' })
async getDeployments(
@Param('pipeline') pipeline: string,
@Param('phase') phase: string,
@Param('app') app: string,
@Request() req: any,
) {
return this.deploymentsService.listBuildjobs(pipeline, phase, app, req.user.userGroups);
}
@Post('/build/:pipeline/:phase/:app')
@UseGuards(JwtAuthGuard, PermissionsGuard, ReadonlyGuard)
@Permissions('app:write')
@ApiForbiddenResponse({
description: 'Error: Unauthorized',
type: OKDTO,
isArray: false,
})
@ApiBearerAuth('bearerAuth')
@ApiOperation({ summary: 'Build a specific app' })
@ApiParam({ name: 'pipeline', description: 'Pipeline name' })
@ApiParam({ name: 'phase', description: 'Phase name' })
@ApiParam({ name: 'app', description: 'App name' })
@ApiBody({
type: CreateBuild,
required: true,
schema: { $ref: '#/components/schemas/CreateBuild' },
})
async buildApp(
@Param('pipeline') pipeline: string,
@Param('phase') phase: string,
@Param('app') app: string,
@Body() body: CreateBuild,
@Request() req: any,
) {
const user: IUser = {
id: req.user.userId,
strategy: req.user.strategy,
username: req.user.username,
};
return this.deploymentsService.triggerBuildjob(
pipeline,
phase,
app,
body.buildstrategy,
body.repository,
body.reference,
body.dockerfilePath,
user,
);
}
@Delete('/:pipeline/:phase/:app/:buildName')
@UseGuards(JwtAuthGuard, PermissionsGuard, ReadonlyGuard)
@Permissions('app:write')
@ApiBearerAuth('bearerAuth')
@ApiForbiddenResponse({
description: 'Error: Unauthorized',
type: OKDTO,
isArray: false,
})
@ApiOperation({ summary: 'Delete a specific build' })
@ApiParam({ name: 'pipeline', description: 'Pipeline name' })
@ApiParam({ name: 'phase', description: 'Phase name' })
@ApiParam({ name: 'app', description: 'App name' })
@ApiParam({ name: 'buildName', description: 'Build name' })
async deleteApp(
@Param('pipeline') pipeline: string,
@Param('phase') phase: string,
@Param('app') app: string,
@Param('buildName') buildName: string,
@Request() req: any,
) {
const user: IUser = {
id: req.user.userId,
strategy: req.user.strategy,
username: req.user.username,
};
return this.deploymentsService.deleteBuildjob(
pipeline,
phase,
app,
buildName,
user,
);
}
@Get('/:pipeline/:phase/:app/:build/:container/history')
@UseGuards(JwtAuthGuard, PermissionsGuard)
@Permissions('logs:ok', 'app:read', 'app:write')
@ApiBearerAuth('bearerAuth')
@ApiForbiddenResponse({
description: 'Error: Unauthorized',
type: OKDTO,
isArray: false,
})
@ApiOperation({ summary: 'Get logs for a specific build' })
@ApiParam({ name: 'pipeline', description: 'Pipeline name' })
@ApiParam({ name: 'phase', description: 'Phase name' })
@ApiParam({ name: 'app', description: 'App name' })
@ApiParam({ name: 'build', description: 'Build name' })
@ApiParam({ name: 'container', description: 'Container name' })
async getLogs(
@Param('pipeline') pipeline: string,
@Param('phase') phase: string,
@Param('app') app: string,
@Param('build') build: string,
@Param('container') container: string,
@Request() req: any,
) {
return this.deploymentsService.getBuildLogs(
pipeline,
phase,
app,
build,
container,
req.user.userGroups,
);
}
@Put('/:pipeline/:phase/:app/:tag')
@UseGuards(JwtAuthGuard, PermissionsGuard, ReadonlyGuard)
@Permissions('app:write')
@ApiBearerAuth('bearerAuth')
@ApiForbiddenResponse({
description: 'Error: Unauthorized',
type: OKDTO,
isArray: false,
})
@ApiOperation({ summary: 'Deploy a specific tag for an app' })
@ApiParam({ name: 'pipeline', description: 'Pipeline name' })
@ApiParam({ name: 'phase', description: 'Phase name' })
@ApiParam({ name: 'app', description: 'App name' })
@ApiParam({ name: 'tag', description: 'Tag to deploy' })
async deployTag(
@Param('pipeline') pipeline: string,
@Param('phase') phase: string,
@Param('app') app: string,
@Param('tag') tag: string,
@Request() req: any,
): Promise<OKDTO> {
this.deploymentsService.deployApp(pipeline, phase, app, tag, req.user.userGroups);
return {
message: `Deployment triggered for ${app} in ${pipeline} phase ${phase} with tag ${tag}`,
status: 'success',
};
}
}