-
Notifications
You must be signed in to change notification settings - Fork 702
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(codebuild): Add support for static credentials (#1554)
1. Add an AbstractEditCiCommand class that could be inherited from. For now only codebuild account command extends this class. There could be more in the future. 2. Mark assume-role and account-id as not required so that the static credentials could be used directly 3. Add an API in halyard daemon to set custom fields for CI providers Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
4ba334a
commit b0d31ce
Showing
12 changed files
with
221 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...in/java/com/netflix/spinnaker/halyard/cli/command/v1/config/ci/AbstractEditCiCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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; | ||
|
||
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.AnsiUi; | ||
import com.netflix.spinnaker.halyard.config.model.v1.node.CIAccount; | ||
import com.netflix.spinnaker.halyard.config.model.v1.node.Ci; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
@Data | ||
@Parameters(separators = "=") | ||
@EqualsAndHashCode(callSuper = false) | ||
public abstract class AbstractEditCiCommand<A extends CIAccount, C extends Ci<A>> | ||
extends AbstractCiCommand { | ||
String commandName = "edit"; | ||
|
||
@Override | ||
protected void executeThis() { | ||
String ciName = getCiName(); | ||
String currentDeployment = getCurrentDeployment(); | ||
|
||
Ci ci = | ||
new OperationHandler<Ci>() | ||
.setFailureMesssage("Failed to get ci provider " + ciName + ".") | ||
.setOperation(Daemon.getCi(currentDeployment, ciName, false)) | ||
.get(); | ||
|
||
int originalHash = ci.hashCode(); | ||
|
||
ci = editCi((C) ci); | ||
|
||
if (originalHash == ci.hashCode()) { | ||
AnsiUi.failure("No changes supplied."); | ||
return; | ||
} | ||
|
||
new OperationHandler<Void>() | ||
.setFailureMesssage("Failed to edit ci provider " + ci + ".") | ||
.setSuccessMessage("Successfully edited ci provider " + ci + ".") | ||
.setOperation(Daemon.setCi(currentDeployment, ciName, !noValidate, ci)) | ||
.get(); | ||
} | ||
|
||
protected abstract Ci editCi(C ci); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...tflix/spinnaker/halyard/cli/command/v1/config/ci/codebuild/AwsCodeBuildEditCiCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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.AbstractEditCiCommand; | ||
import com.netflix.spinnaker.halyard.config.model.v1.ci.codebuild.AwsCodeBuild; | ||
import com.netflix.spinnaker.halyard.config.model.v1.ci.codebuild.AwsCodeBuildAccount; | ||
import com.netflix.spinnaker.halyard.config.model.v1.node.Ci; | ||
import lombok.Getter; | ||
|
||
@Parameters(separators = "=") | ||
public class AwsCodeBuildEditCiCommand | ||
extends AbstractEditCiCommand<AwsCodeBuildAccount, AwsCodeBuild> { | ||
protected String getCiName() { | ||
return "codebuild"; | ||
} | ||
|
||
@Override | ||
protected String getCiFullName() { | ||
return "AWS CodeBuild"; | ||
} | ||
|
||
@Getter String shortDescription = "Set CI provider-wide properties for " + getCiFullName(); | ||
|
||
@Parameter( | ||
names = "--access-key-id", | ||
description = AwsCodeBuildCommandProperties.ACCESS_KEY_ID_DESCRIPTION) | ||
private String accessKeyId; | ||
|
||
@Parameter( | ||
names = "--secret-access-key", | ||
description = AwsCodeBuildCommandProperties.SECRET_KEY_DESCRIPTION, | ||
password = true) | ||
private String secretAccessKey; | ||
|
||
@Override | ||
protected Ci editCi(AwsCodeBuild ci) { | ||
ci.setAccessKeyId(isSet(accessKeyId) ? accessKeyId : ci.getAccessKeyId()); | ||
ci.setSecretAccessKey(isSet(secretAccessKey) ? secretAccessKey : ci.getSecretAccessKey()); | ||
return ci; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters