Skip to content

Commit

Permalink
Jenkins config w/o validation (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwander committed Mar 1, 2017
1 parent 07fcff4 commit 07b4158
Show file tree
Hide file tree
Showing 32 changed files with 1,651 additions and 5 deletions.
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.config.*;
import com.netflix.spinnaker.halyard.cli.command.v1.config.providers.ProviderCommand;
import com.netflix.spinnaker.halyard.cli.command.v1.config.webhooks.WebhookCommand;
import lombok.AccessLevel;
import lombok.Getter;

Expand All @@ -41,6 +42,7 @@ public class ConfigCommand extends NestableCommand {
registerSubcommand(new GenerateCommand());
registerSubcommand(new PersistentStorageCommand());
registerSubcommand(new ProviderCommand());
registerSubcommand(new WebhookCommand());
registerSubcommand(new SecurityCommand());
}

Expand Down
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);
}
}
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());
}
}
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();
}
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());
}
}
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();
}
}
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;
}
}
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;
}
}
Loading

0 comments on commit 07b4158

Please sign in to comment.