From d933df45834be3c65abb6b4d7632fc321fb65af1 Mon Sep 17 00:00:00 2001 From: Kaixiang-AWS Date: Tue, 4 Feb 2020 19:36:36 -0800 Subject: [PATCH] feat(codebuild): Add stopBuild API in AwsCodeBuildController (#612) --- .../spinnaker/igor/codebuild/AwsCodeBuildAccount.java | 5 +++++ .../spinnaker/igor/codebuild/AwsCodeBuildController.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/igor-web/src/main/java/com/netflix/spinnaker/igor/codebuild/AwsCodeBuildAccount.java b/igor-web/src/main/java/com/netflix/spinnaker/igor/codebuild/AwsCodeBuildAccount.java index 5de4f7c76..34feb7f57 100644 --- a/igor-web/src/main/java/com/netflix/spinnaker/igor/codebuild/AwsCodeBuildAccount.java +++ b/igor-web/src/main/java/com/netflix/spinnaker/igor/codebuild/AwsCodeBuildAccount.java @@ -22,6 +22,7 @@ import com.amazonaws.services.codebuild.model.BatchGetBuildsRequest; import com.amazonaws.services.codebuild.model.Build; import com.amazonaws.services.codebuild.model.StartBuildRequest; +import com.amazonaws.services.codebuild.model.StopBuildRequest; import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient; import java.util.Objects; import lombok.RequiredArgsConstructor; @@ -59,6 +60,10 @@ public Build getBuild(String buildId) { return client.batchGetBuilds(new BatchGetBuildsRequest().withIds(buildId)).getBuilds().get(0); } + public Build stopBuild(String buildId) { + return client.stopBuild(new StopBuildRequest().withId(buildId)).getBuild(); + } + private String getRoleArn(String accountId, String assumeRole) { String assumeRoleValue = Objects.requireNonNull(assumeRole, "assumeRole"); if (!assumeRoleValue.startsWith("arn:")) { diff --git a/igor-web/src/main/java/com/netflix/spinnaker/igor/codebuild/AwsCodeBuildController.java b/igor-web/src/main/java/com/netflix/spinnaker/igor/codebuild/AwsCodeBuildController.java index 54f2e4685..a765be6c7 100644 --- a/igor-web/src/main/java/com/netflix/spinnaker/igor/codebuild/AwsCodeBuildController.java +++ b/igor-web/src/main/java/com/netflix/spinnaker/igor/codebuild/AwsCodeBuildController.java @@ -50,4 +50,9 @@ Build startBuild(@PathVariable String account, @RequestBody Map Build getBuild(@PathVariable String account, @PathVariable String buildId) { return awsCodeBuildAccountRepository.getAccount(account).getBuild(buildId); } + + @RequestMapping(value = "/builds/stop/{account}/{buildId}", method = RequestMethod.POST) + Build stopBuild(@PathVariable String account, @PathVariable String buildId) { + return awsCodeBuildAccountRepository.getAccount(account).stopBuild(buildId); + } }