Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Config const and strings update
Browse files Browse the repository at this point in the history
  • Loading branch information
james-michael committed Jun 2, 2017
1 parent 6c54858 commit 1209662
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 14 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/nike/cerberus/ConfigConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,15 @@ public class ConfigConstants {
public static final String CONSUL_AMI_TAG_VALUE = "consul";

public static final String VAULT_AMI_TAG_VALUE = "vault";

public static final String SKIP_AMI_TAG_CHECK_ARG = "--skip-ami-tag-check";

public static final String SKIP_AMI_TAG_CHECK_DESCRIPTION = "Skip validation of 'cerberus_component' tag on AMI";

public static final String AMI_TAG_CHECK_ERROR_MESSAGE
= "FAIL: AMI tag check failed!\n"
+ "Given AMI ID either does not exist "
+ "or does not contain cerberus tag 'cerberus_component' with stack name "
+ "or cerberus tag does not match the stack that is being deployed.\n"
+ "Please refer documentation on AMI Tagging or use '"+ SKIP_AMI_TAG_CHECK_ARG +"' option to skip this check.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.nike.cerberus.operation.cms.CreateCmsClusterOperation;

import static com.nike.cerberus.command.cms.CreateCmsClusterCommand.COMMAND_NAME;
import static com.nike.cerberus.ConfigConstants.SKIP_AMI_TAG_CHECK_ARG;
import static com.nike.cerberus.ConfigConstants.SKIP_AMI_TAG_CHECK_DESCRIPTION;

/**
* Command to create the CMS cluster.
Expand All @@ -34,8 +36,6 @@ public class CreateCmsClusterCommand implements Command {

public static final String COMMAND_NAME = "create-cms-cluster";

public static final String SKIP_AMI_TAG_CHECK_ARG = "--skip-ami-tag-check";

@ParametersDelegate
private StackDelegate stackDelegate = new StackDelegate();

Expand All @@ -49,7 +49,7 @@ public String getCommandName() {
}

@Parameter(names = SKIP_AMI_TAG_CHECK_ARG,
description = "Flag for skipping validation of AMI with matching stackname tags")
description = SKIP_AMI_TAG_CHECK_DESCRIPTION)
private boolean skipAmiTagCheck;

public boolean isSkipAmiTagCheck() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.nike.cerberus.operation.consul.CreateConsulClusterOperation;

import static com.nike.cerberus.command.consul.CreateConsulClusterCommand.COMMAND_NAME;
import static com.nike.cerberus.ConfigConstants.SKIP_AMI_TAG_CHECK_ARG;
import static com.nike.cerberus.ConfigConstants.SKIP_AMI_TAG_CHECK_DESCRIPTION;

/**
* Command to create the consul cluster.
Expand All @@ -34,8 +36,6 @@ public class CreateConsulClusterCommand implements Command {

public static final String COMMAND_NAME = "create-consul-cluster";

public static final String SKIP_AMI_TAG_CHECK_ARG = "--skip-ami-tag-check";

@ParametersDelegate
private StackDelegate stackDelegate = new StackDelegate();

Expand All @@ -49,7 +49,7 @@ public String getCommandName() {
}

@Parameter(names = SKIP_AMI_TAG_CHECK_ARG,
description = "Flag for skipping validation of AMI with matching stackname tags")
description = SKIP_AMI_TAG_CHECK_DESCRIPTION)
private boolean skipAmiTagCheck;

public boolean isSkipAmiTagCheck() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import java.util.Map;

import static com.nike.cerberus.command.core.UpdateStackCommand.COMMAND_NAME;
import static com.nike.cerberus.ConfigConstants.SKIP_AMI_TAG_CHECK_ARG;
import static com.nike.cerberus.ConfigConstants.SKIP_AMI_TAG_CHECK_DESCRIPTION;


/**
* Command for updating the specified CloudFormation stack with the new parameters.
Expand All @@ -39,7 +42,6 @@ public class UpdateStackCommand implements Command {
public static final String COMMAND_NAME = "update-stack";
public static final String OVERWRITE_TEMPLATE_LONG_ARG = "--overwrite-template";
public static final String PARAMETER_SHORT_ARG = "-P";
public static final String SKIP_AMI_TAG_CHECK_ARG = "--skip-ami-tag-check";

@Parameter(names = {"--stack-name"}, required = true, description = "The stack name to update.")
private StackName stackName;
Expand Down Expand Up @@ -80,7 +82,7 @@ public class UpdateStackCommand implements Command {
private Integer minimumInstances;

@Parameter(names = SKIP_AMI_TAG_CHECK_ARG,
description = "Flag for skipping validation of AMI with matching stackname tags")
description = SKIP_AMI_TAG_CHECK_DESCRIPTION)
private boolean skipAmiTagCheck;

@DynamicParameter(names = PARAMETER_SHORT_ARG, description = "Dynamic parameters for overriding the values for specific parameters in the CloudFormation.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.nike.cerberus.operation.gateway.CreateGatewayClusterOperation;

import static com.nike.cerberus.command.gateway.CreateGatewayClusterCommand.COMMAND_NAME;
import static com.nike.cerberus.ConfigConstants.SKIP_AMI_TAG_CHECK_ARG;
import static com.nike.cerberus.ConfigConstants.SKIP_AMI_TAG_CHECK_DESCRIPTION;

/**
* Command to create the Gateway cluster.
Expand All @@ -35,7 +37,6 @@ public class CreateGatewayClusterCommand implements Command {
public static final String COMMAND_NAME = "create-gateway-cluster";
public static final String HOSTED_ZONE_ID_LONG_ARG = "--hosted-zone-id";
public static final String HOSTNAME_LONG_ARG = "--hostname";
public static final String SKIP_AMI_TAG_CHECK_ARG = "--skip-ami-tag-check";

@Parameter(names = HOSTED_ZONE_ID_LONG_ARG,
description = "The Route 53 hosted zone ID that will be used to create the CNAME record for Cerberus.",
Expand All @@ -48,7 +49,7 @@ public class CreateGatewayClusterCommand implements Command {
private String hostname;

@Parameter(names = SKIP_AMI_TAG_CHECK_ARG,
description = "Flag for skipping validation of AMI with matching stackname tags")
description = SKIP_AMI_TAG_CHECK_DESCRIPTION)
private boolean skipAmiTagCheck;

@ParametersDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.nike.cerberus.operation.vault.CreateVaultClusterOperation;

import static com.nike.cerberus.command.vault.CreateVaultClusterCommand.COMMAND_NAME;
import static com.nike.cerberus.ConfigConstants.SKIP_AMI_TAG_CHECK_ARG;
import static com.nike.cerberus.ConfigConstants.SKIP_AMI_TAG_CHECK_DESCRIPTION;

/**
* Command to create the Vault cluster.
Expand All @@ -34,8 +36,6 @@ public class CreateVaultClusterCommand implements Command {

public static final String COMMAND_NAME = "create-vault-cluster";

public static final String SKIP_AMI_TAG_CHECK_ARG = "--skip-ami-tag-check";

@ParametersDelegate
private StackDelegate stackDelegate = new StackDelegate();

Expand All @@ -49,7 +49,7 @@ public String getCommandName() {
}

@Parameter(names = SKIP_AMI_TAG_CHECK_ARG,
description = "Flag for skipping validation of AMI with matching stackname tags")
description = SKIP_AMI_TAG_CHECK_DESCRIPTION)
private boolean skipAmiTagCheck;

public boolean isSkipAmiTagCheck() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public boolean isAmiWithTagExist(final String amiId, final String tagName, final
*/
public void validateAmiTagForStack(final String amiId, final StackName stackName) {
if (!isAmiWithTagExist(amiId, ConfigConstants.CERBERUS_AMI_TAG_NAME, stackAmiTagValueMap.get(stackName) )) {
throw new IllegalStateException("AMI tag check failed!. Given AMI ID does not contain cerberus tag 'cerberus_component' with stack name");
throw new IllegalStateException(ConfigConstants.AMI_TAG_CHECK_ERROR_MESSAGE);
}
}
}

0 comments on commit 1209662

Please sign in to comment.