-
Notifications
You must be signed in to change notification settings - Fork 705
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jenkins config w/o validation (#187)
- Loading branch information
Showing
32 changed files
with
1,651 additions
and
5 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
66 changes: 66 additions & 0 deletions
66
...a/com/netflix/spinnaker/halyard/cli/command/v1/config/webhooks/AbstractMasterCommand.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,66 @@ | ||
/* | ||
* Copyright 2017 Google, 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.webhooks; | ||
|
||
import com.netflix.spinnaker.halyard.cli.command.v1.config.webhooks.master.AbstractHasMasterCommand; | ||
import com.netflix.spinnaker.halyard.cli.command.v1.config.webhooks.master.DeleteMasterCommandBuilder; | ||
import com.netflix.spinnaker.halyard.cli.command.v1.config.webhooks.master.GetMasterCommandBuilder; | ||
import com.netflix.spinnaker.halyard.cli.command.v1.config.webhooks.master.ListMastersCommandBuilder; | ||
import com.netflix.spinnaker.halyard.cli.services.v1.Daemon; | ||
import com.netflix.spinnaker.halyard.config.model.v1.node.Master; | ||
|
||
import static com.netflix.spinnaker.halyard.cli.services.v1.Daemon.getCurrentDeployment; | ||
|
||
public abstract class AbstractMasterCommand extends AbstractHasMasterCommand { | ||
@Override | ||
public String getCommandName() { | ||
return "master"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Manage and view Spinnaker configuration for the " + getWebhookName() + " webhook's master"; | ||
} | ||
|
||
protected AbstractMasterCommand() { | ||
registerSubcommand(new DeleteMasterCommandBuilder() | ||
.setWebhookName(getWebhookName()) | ||
.build() | ||
); | ||
|
||
registerSubcommand(new GetMasterCommandBuilder() | ||
.setWebhookName(getWebhookName()) | ||
.build() | ||
); | ||
|
||
registerSubcommand(new ListMastersCommandBuilder() | ||
.setWebhookName(getWebhookName()) | ||
.build() | ||
); | ||
} | ||
|
||
@Override | ||
protected void executeThis() { | ||
showHelp(); | ||
} | ||
|
||
private Master getMaster(String masterName) { | ||
String currentDeployment = getCurrentDeployment(); | ||
return Daemon.getMaster(currentDeployment, getWebhookName(), masterName, !noValidate); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...netflix/spinnaker/halyard/cli/command/v1/config/webhooks/AbstractNamedWebhookCommand.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 2017 Google, 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.webhooks; | ||
|
||
import com.netflix.spinnaker.halyard.cli.services.v1.Daemon; | ||
import com.netflix.spinnaker.halyard.cli.ui.v1.AnsiFormatUtils; | ||
import com.netflix.spinnaker.halyard.cli.ui.v1.AnsiUi; | ||
import com.netflix.spinnaker.halyard.config.model.v1.node.Webhook; | ||
|
||
public abstract class AbstractNamedWebhookCommand extends AbstractWebhookCommand { | ||
@Override | ||
public String getCommandName() { | ||
return getWebhookName(); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Manage and view Spinnaker configuration for the " + getWebhookName() + " webhook"; | ||
} | ||
|
||
protected AbstractNamedWebhookCommand() { | ||
registerSubcommand(new WebhookEnableDisableCommandBuilder() | ||
.setWebhookName(getWebhookName()) | ||
.setEnable(false) | ||
.build() | ||
); | ||
|
||
registerSubcommand(new WebhookEnableDisableCommandBuilder() | ||
.setWebhookName(getWebhookName()) | ||
.setEnable(true) | ||
.build() | ||
); | ||
} | ||
|
||
private Webhook getWebhook() { | ||
return Daemon.getWebhook(getCurrentDeployment(), getWebhookName(), !noValidate); | ||
} | ||
|
||
@Override | ||
protected void executeThis() { | ||
AnsiUi.success(getWebhook().toString()); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
.../com/netflix/spinnaker/halyard/cli/command/v1/config/webhooks/AbstractWebhookCommand.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,24 @@ | ||
/* | ||
* Copyright 2017 Google, 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.webhooks; | ||
|
||
import com.netflix.spinnaker.halyard.cli.command.v1.config.AbstractConfigCommand; | ||
|
||
public abstract class AbstractWebhookCommand extends AbstractConfigCommand { | ||
abstract protected String getWebhookName(); | ||
} |
63 changes: 63 additions & 0 deletions
63
...spinnaker/halyard/cli/command/v1/config/webhooks/AbstractWebhookEnableDisableCommand.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,63 @@ | ||
/* | ||
* Copyright 2017 Google, 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.webhooks; | ||
|
||
import com.netflix.spinnaker.halyard.cli.command.v1.NestableCommand; | ||
import com.netflix.spinnaker.halyard.cli.services.v1.Daemon; | ||
import com.netflix.spinnaker.halyard.cli.ui.v1.AnsiUi; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public abstract class AbstractWebhookEnableDisableCommand extends AbstractWebhookCommand { | ||
@Override | ||
public String getCommandName() { | ||
return isEnable() ? "enable" : "disable"; | ||
} | ||
|
||
private String subjunctivePerfectAction() { | ||
return isEnable() ? "enabled" : "disabled"; | ||
} | ||
|
||
private String indicativePastPerfectAction() { | ||
return isEnable() ? "enabled" : "disabled"; | ||
} | ||
|
||
protected abstract boolean isEnable(); | ||
|
||
@Getter(AccessLevel.PROTECTED) | ||
private Map<String, NestableCommand> subcommands = new HashMap<>(); | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Set the " + getWebhookName() + " webhook as " + subjunctivePerfectAction(); | ||
} | ||
|
||
private void setEnable() { | ||
String currentDeployment = Daemon.getCurrentDeployment(); | ||
Daemon.setWebhookEnableDisable(currentDeployment, getWebhookName(), !noValidate, isEnable()); | ||
} | ||
|
||
@Override | ||
protected void executeThis() { | ||
setEnable(); | ||
AnsiUi.success("Successfully " + indicativePastPerfectAction() + " " + getWebhookName()); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...ain/java/com/netflix/spinnaker/halyard/cli/command/v1/config/webhooks/WebhookCommand.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,47 @@ | ||
/* | ||
* Copyright 2017 Google, 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.webhooks; | ||
|
||
import com.beust.jcommander.Parameters; | ||
import com.netflix.spinnaker.halyard.cli.command.v1.NestableCommand; | ||
import com.netflix.spinnaker.halyard.cli.command.v1.config.webhooks.jenkins.JenkinsCommand; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
|
||
/** | ||
* This is a top-level command for dealing with your halconfig. | ||
* | ||
* Usage is `$ hal config webhook` | ||
*/ | ||
@Parameters() | ||
public class WebhookCommand extends NestableCommand { | ||
@Getter(AccessLevel.PUBLIC) | ||
private String commandName = "webhook"; | ||
|
||
@Getter(AccessLevel.PUBLIC) | ||
private String description = "Configure, validate, and view the specified webhook."; | ||
|
||
public WebhookCommand() { | ||
registerSubcommand(new JenkinsCommand()); | ||
} | ||
|
||
@Override | ||
protected void executeThis() { | ||
showHelp(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
.../spinnaker/halyard/cli/command/v1/config/webhooks/WebhookEnableDisableCommandBuilder.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,52 @@ | ||
/* | ||
* Copyright 2017 Google, 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.webhooks; | ||
|
||
import com.beust.jcommander.Parameters; | ||
import com.netflix.spinnaker.halyard.cli.command.v1.CommandBuilder; | ||
import com.netflix.spinnaker.halyard.cli.command.v1.NestableCommand; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
public class WebhookEnableDisableCommandBuilder implements CommandBuilder { | ||
@Setter | ||
String webhookName; | ||
|
||
@Setter | ||
boolean enable; | ||
|
||
@Override | ||
public NestableCommand build() { | ||
return new WebhookEnableDisableCommand(webhookName, enable); | ||
} | ||
|
||
@Parameters() | ||
private static class WebhookEnableDisableCommand extends AbstractWebhookEnableDisableCommand { | ||
private WebhookEnableDisableCommand(String webhookName, boolean enable) { | ||
this.webhookName = webhookName; | ||
this.enable = enable; | ||
} | ||
|
||
@Getter(AccessLevel.PROTECTED) | ||
boolean enable; | ||
|
||
@Getter(AccessLevel.PROTECTED) | ||
private String webhookName; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...lix/spinnaker/halyard/cli/command/v1/config/webhooks/jenkins/JenkinsAddMasterCommand.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,61 @@ | ||
/* | ||
* Copyright 2017 Google, 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.webhooks.jenkins; | ||
|
||
import com.beust.jcommander.Parameter; | ||
import com.beust.jcommander.Parameters; | ||
import com.netflix.spinnaker.halyard.cli.command.v1.config.webhooks.master.AbstractAddMasterCommand; | ||
import com.netflix.spinnaker.halyard.config.model.v1.node.Master; | ||
import com.netflix.spinnaker.halyard.config.model.v1.webhooks.jenkins.JenkinsMaster; | ||
|
||
@Parameters() | ||
public class JenkinsAddMasterCommand extends AbstractAddMasterCommand { | ||
protected String getWebhookName() { | ||
return "jenkins"; | ||
} | ||
|
||
@Parameter( | ||
names = "--address", | ||
required = true, | ||
description = JenkinsCommandProperties.ADDRESS_DESCRIPTION | ||
) | ||
private String address; | ||
|
||
@Parameter( | ||
names = "--username", | ||
description = JenkinsCommandProperties.USERNAME_DESCRIPTION | ||
) | ||
public String username; | ||
|
||
@Parameter( | ||
names = "--password", | ||
password = true, | ||
description = JenkinsCommandProperties.PASSWORD_DESCRIPTION | ||
) | ||
public String password; | ||
|
||
@Override | ||
protected Master buildMaster(String masterName) { | ||
JenkinsMaster master = (JenkinsMaster) new JenkinsMaster().setName(masterName); | ||
master.setAddress(address) | ||
.setPassword(password) | ||
.setUsername(username); | ||
|
||
return master; | ||
} | ||
} |
Oops, something went wrong.