Skip to content

Commit

Permalink
feat: added secret controller for fixes (#11488)
Browse files Browse the repository at this point in the history
  • Loading branch information
bashleigh authored Oct 22, 2024
1 parent bfc0efd commit 9a8c87f
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/deployment-service/src/pipeline-runner/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AuthModule } from '@reapit/utils-nest'
import { TaskProvider } from './task-provider'
import { DeploymentModule } from '../deployment'
import { S3Module } from '../s3'
import { SecretPipelineController } from './secret.pipeline.controller'

@Module({
imports: [
Expand All @@ -22,7 +23,7 @@ import { S3Module } from '../s3'
S3Module,
],
providers: [PipelineRunnerProvider, TaskProvider],
controllers: [PipelineRunnerController],
controllers: [PipelineRunnerController, SecretPipelineController],
exports: [PipelineRunnerProvider, TaskProvider],
})
export class PipelineRunnerModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Controller, Get, Inject, NotFoundException, Param, Post, forwardRef } from '@nestjs/common'
import { PipelineProvider } from '../pipeline/pipeline-provider'
import { EventDispatcher } from '../events'
import { PipelineRunnerProvider } from './pipeline-runner-provider'

@Controller('secret')
export class SecretPipelineController {
constructor(
@Inject(forwardRef(() => PipelineProvider)) private readonly pipelineProvider: PipelineProvider,
private readonly eventDispatcher: EventDispatcher,
private readonly pipelineRunnerProvider: PipelineRunnerProvider,
) {}

@Get('developerId/:developerId')
async findByDeveloper(@Param('developerId') developerId: string) {
const pipelines = await this.pipelineProvider.findByDeveloperId(developerId)

return pipelines
}

@Get('subdomain/:subdomain')
async findBySubdomain(@Param('subdomain') subdomain: string) {
const pipeline = await this.pipelineProvider.findBySubDomain(subdomain)

if (!pipeline) throw NotFoundException

return pipeline
}

// app / pipelineid
@Get(':pipelineId')
async findById(@Param('pipelineId') pipelineId: string) {
const pipeline = await this.pipelineProvider.findById(pipelineId)

if (!pipeline) throw NotFoundException

return pipeline
}

@Post('provision/:pipelineId')
async startProvisioning(@Param('pipelineId') pipelineId: string) {
const pipeline = await this.pipelineProvider.findById(pipelineId)

if (!pipeline) throw new NotFoundException()

const updatedPipeline = await this.pipelineProvider.update(pipeline, {
buildStatus: 'PROVISION_REQUEST',
})

await this.eventDispatcher.triggerPipelineSetup(updatedPipeline)

return updatedPipeline
}

@Post('deploy/:pipelineId')
async startDeployment(@Param('pipelineId') pipelineId: string) {
const pipeline = await this.pipelineProvider.findById(pipelineId)

if (!pipeline) throw new NotFoundException()

const pipelineRunner = await this.pipelineRunnerProvider.create({
pipeline,
})

await this.eventDispatcher.triggerCodebuildExecutor(pipelineRunner)

return pipelineRunner
}
}
16 changes: 16 additions & 0 deletions packages/deployment-service/src/pipeline/pipeline-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ export class PipelineProvider {
})
}

async findBySubDomain(subDomain: string): Promise<PipelineEntity | null> {
return this.repository.findOne({
where: {
subDomain,
},
})
}

async findByDeveloperId(developerId: string): Promise<PipelineEntity[]> {
return this.repository.find({
where: {
developerId,
},
})
}

async saveAll(pipelines: PipelineEntity[]): Promise<PipelineEntity[]> {
return this.repository.save(pipelines)
}
Expand Down

0 comments on commit 9a8c87f

Please sign in to comment.