Skip to content

Commit

Permalink
feat(codebuild): Add support for manipulating AWS CodeBuild accounts (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaixiang-AWS authored Feb 6, 2020
1 parent eff6b69 commit e21b588
Show file tree
Hide file tree
Showing 15 changed files with 665 additions and 1 deletion.
170 changes: 170 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@
* [**hal config canary signalfx disable**](#hal-config-canary-signalfx-disable)
* [**hal config canary signalfx enable**](#hal-config-canary-signalfx-enable)
* [**hal config ci**](#hal-config-ci)
* [**hal config ci codebuild**](#hal-config-ci-codebuild)
* [**hal config ci codebuild account**](#hal-config-ci-codebuild-account)
* [**hal config ci codebuild account add**](#hal-config-ci-codebuild-account-add)
* [**hal config ci codebuild account delete**](#hal-config-ci-codebuild-account-delete)
* [**hal config ci codebuild account edit**](#hal-config-ci-codebuild-account-edit)
* [**hal config ci codebuild account get**](#hal-config-ci-codebuild-account-get)
* [**hal config ci codebuild account list**](#hal-config-ci-codebuild-account-list)
* [**hal config ci codebuild disable**](#hal-config-ci-codebuild-disable)
* [**hal config ci codebuild enable**](#hal-config-ci-codebuild-enable)
* [**hal config ci concourse**](#hal-config-ci-concourse)
* [**hal config ci concourse disable**](#hal-config-ci-concourse-disable)
* [**hal config ci concourse enable**](#hal-config-ci-concourse-enable)
Expand Down Expand Up @@ -3667,12 +3676,173 @@ hal config ci [subcommands]
```

#### Subcommands
* `codebuild`: Manage and view Spinnaker configuration for AWS CodeBuild
* `concourse`: Manage and view Spinnaker configuration for the concourse ci
* `gcb`: Manage and view Spinnaker configuration for Google Cloud Build
* `jenkins`: Manage and view Spinnaker configuration for the jenkins ci
* `travis`: Manage and view Spinnaker configuration for the travis ci
* `wercker`: Manage and view Spinnaker configuration for the wercker ci

---
## hal config ci codebuild

Manage and view Spinnaker configuration for AWS CodeBuild

#### Usage
```
hal config ci codebuild [parameters] [subcommands]
```

#### Parameters
* `--deployment`: If supplied, use this Halyard deployment. This will _not_ create a new deployment.
* `--no-validate`: (*Default*: `false`) Skip validation.

#### Subcommands
* `account`: Manage and view Spinnaker configuration for AWS CodeBuild service account.
* `disable`: Set the codebuild ci as disabled
* `enable`: Set the codebuild ci as enabled

---
## hal config ci codebuild account

Manage and view Spinnaker configuration for AWS CodeBuild service account.

#### Usage
```
hal config ci codebuild account ACCOUNT [parameters] [subcommands]
```

#### Parameters
`ACCOUNT`: The name of the account to operate on.
* `--deployment`: If supplied, use this Halyard deployment. This will _not_ create a new deployment.
* `--no-validate`: (*Default*: `false`) Skip validation.

#### Subcommands
* `add`: Add a AWS CodeBuild account.
* `delete`: Delete a AWS CodeBuild account.
* `edit`: Edit a AWS CodeBuild account.
* `get`: Get the account details for AWS CodeBuild.
* `list`: List the AWS CodeBuild accounts.

---
## hal config ci codebuild account add

Add a AWS CodeBuild account.

#### Usage
```
hal config ci codebuild account add ACCOUNT [parameters]
```

#### Parameters
`ACCOUNT`: The name of the account to operate on.
* `--account-id`: (*Required*) The AWS account ID that will be used to trigger CodeBuild build.
* `--assume-role`: (*Required*) If set, Halyard will configure a credentials provider that uses AWS Security Token Service to assume the specified role.

Example: "user/spinnaker" or "role/spinnakerManaged"
* `--deployment`: If supplied, use this Halyard deployment. This will _not_ create a new deployment.
* `--no-validate`: (*Default*: `false`) Skip validation.
* `--region`: (*Required*) The AWS region in which your CodeBuild projects live.


---
## hal config ci codebuild account delete

Delete a AWS CodeBuild account.

#### Usage
```
hal config ci codebuild account delete ACCOUNT [parameters]
```

#### Parameters
`ACCOUNT`: The name of the account to operate on.
* `--deployment`: If supplied, use this Halyard deployment. This will _not_ create a new deployment.
* `--no-validate`: (*Default*: `false`) Skip validation.


---
## hal config ci codebuild account edit

Edit a AWS CodeBuild account.

#### Usage
```
hal config ci codebuild account edit ACCOUNT [parameters]
```

#### Parameters
`ACCOUNT`: The name of the account to operate on.
* `--account-id`: The AWS account ID that will be used to trigger CodeBuild build.
* `--assume-role`: If set, Halyard will configure a credentials provider that uses AWS Security Token Service to assume the specified role.

Example: "user/spinnaker" or "role/spinnakerManaged"
* `--deployment`: If supplied, use this Halyard deployment. This will _not_ create a new deployment.
* `--no-validate`: (*Default*: `false`) Skip validation.
* `--region`: The AWS region in which your CodeBuild projects live.


---
## hal config ci codebuild account get

Get the account details for AWS CodeBuild.

#### Usage
```
hal config ci codebuild account get ACCOUNT [parameters]
```

#### Parameters
`ACCOUNT`: The name of the account to operate on.
* `--deployment`: If supplied, use this Halyard deployment. This will _not_ create a new deployment.
* `--no-validate`: (*Default*: `false`) Skip validation.


---
## hal config ci codebuild account list

List the AWS CodeBuild accounts.

#### Usage
```
hal config ci codebuild account list [parameters]
```

#### Parameters
* `--deployment`: If supplied, use this Halyard deployment. This will _not_ create a new deployment.
* `--no-validate`: (*Default*: `false`) Skip validation.


---
## hal config ci codebuild disable

Set the codebuild ci as disabled

#### Usage
```
hal config ci codebuild disable [parameters]
```

#### Parameters
* `--deployment`: If supplied, use this Halyard deployment. This will _not_ create a new deployment.
* `--no-validate`: (*Default*: `false`) Skip validation.


---
## hal config ci codebuild enable

Set the codebuild ci as enabled

#### Usage
```
hal config ci codebuild enable [parameters]
```

#### Parameters
* `--deployment`: If supplied, use this Halyard deployment. This will _not_ create a new deployment.
* `--no-validate`: (*Default*: `false`) Skip validation.


---
## hal config ci concourse

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.beust.jcommander.Parameters;
import com.netflix.spinnaker.halyard.cli.command.v1.NestableCommand;
import com.netflix.spinnaker.halyard.cli.command.v1.config.ci.codebuild.AwsCodeBuildCommand;
import com.netflix.spinnaker.halyard.cli.command.v1.config.ci.concourse.ConcourseCommand;
import com.netflix.spinnaker.halyard.cli.command.v1.config.ci.gcb.GoogleCloudBuildCommand;
import com.netflix.spinnaker.halyard.cli.command.v1.config.ci.jenkins.JenkinsCommand;
Expand All @@ -42,6 +43,7 @@ public class CiCommand extends NestableCommand {
"Configure, validate, and view the specified Continuous Integration service.";

public CiCommand() {
registerSubcommand(new AwsCodeBuildCommand());
registerSubcommand(new ConcourseCommand());
registerSubcommand(new GoogleCloudBuildCommand());
registerSubcommand(new JenkinsCommand());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2020 Amazon, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.netflix.spinnaker.halyard.cli.command.v1.config.ci.account;

import com.beust.jcommander.Parameters;
import com.netflix.spinnaker.halyard.cli.services.v1.Daemon;
import com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler;
import com.netflix.spinnaker.halyard.cli.ui.v1.AnsiFormatUtils;
import com.netflix.spinnaker.halyard.config.model.v1.node.CIAccount;
import lombok.Getter;

@Parameters(separators = "=")
public abstract class AbstractGetAccountCommand<T extends CIAccount>
extends AbstractHasAccountCommand {
@Getter private String commandName = "get";

public String getShortDescription() {
return "Get the account details for " + getCiFullName() + ".";
}

@Override
protected void executeThis() {
String currentDeployment = getCurrentDeployment();
String masterName = getAccountName();
String ciName = getCiName();
new OperationHandler<CIAccount>()
.setOperation(Daemon.getMaster(currentDeployment, ciName, masterName, !noValidate))
.setFailureMesssage(String.format("Failed to get %s account.", getCiFullName()))
.setFormat(AnsiFormatUtils.Format.STRING)
.setUserFormatted(true)
.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2020 Amazon.com, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.netflix.spinnaker.halyard.cli.command.v1.config.ci.codebuild;

import com.beust.jcommander.Parameters;
import com.netflix.spinnaker.halyard.cli.command.v1.config.ci.AbstractAccountCommand;

/** Interact with AWS CodeBuild's accounts */
@Parameters(separators = "=")
public class AwsCodeBuildAccountCommand extends AbstractAccountCommand {
protected String getCiName() {
return "codebuild";
}

@Override
protected String getCiFullName() {
return "AWS CodeBuild";
}

@Override
public String getCommandName() {
return "account";
}

public AwsCodeBuildAccountCommand() {
super();
registerSubcommand(new AwsCodeBuildAddAccountCommand());
registerSubcommand(new AwsCodeBuildEditAccountCommand());
registerSubcommand(new AwsCodeBuildGetAccountCommand());
}

@Override
public String getShortDescription() {
return "Manage and view Spinnaker configuration for AWS CodeBuild service account.";
}

@Override
protected void executeThis() {
showHelp();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2020 Amazon.com, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.spinnaker.halyard.cli.command.v1.config.ci.codebuild;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.netflix.spinnaker.halyard.cli.command.v1.config.ci.account.AbstractAddAccountCommand;
import com.netflix.spinnaker.halyard.config.model.v1.ci.codebuild.AwsCodeBuildAccount;

@Parameters(separators = "=")
public class AwsCodeBuildAddAccountCommand extends AbstractAddAccountCommand {
protected String getCiName() {
return "codebuild";
}

@Override
protected String getCiFullName() {
return "AWS CodeBuild";
}

@Parameter(
names = "--account-id",
required = true,
description = AwsCodeBuildCommandProperties.ACCOUNT_ID_DESCRIPTION)
private String accountId;

@Parameter(
names = "--assume-role",
required = true,
description = AwsCodeBuildCommandProperties.ASSUME_ROLE_DESCRIPTION)
private String assumeRole;

@Parameter(
names = "--region",
required = true,
description = AwsCodeBuildCommandProperties.REGION_DESCRIPTION)
private String region;

@Override
protected AwsCodeBuildAccount buildAccount(String accountName) {
return new AwsCodeBuildAccount()
.setName(accountName)
.setAccountId(accountId)
.setAssumeRole(assumeRole)
.setRegion(region);
}
}
Loading

0 comments on commit e21b588

Please sign in to comment.