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

Commit

Permalink
Merge pull request #36 from tlisonbee/update-consul-config-additional…
Browse files Browse the repository at this point in the history
…-options

Adding option for user to supply tokens
  • Loading branch information
tlisonbee authored Apr 18, 2017
2 parents 6d55294 + ca4e506 commit 7bce320
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.nike.cerberus.command.consul;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.nike.cerberus.command.Command;
import com.nike.cerberus.operation.Operation;
Expand All @@ -12,6 +13,22 @@ public class UpdateConsulConfigCommand implements Command {

public static final String COMMAND_NAME = "update-consul-config";

@Parameter(names = {"--acl-master-token"}, description = "Overwrites the existing ACL Master Token with the value supplied."
+ " If not supplied, the existing token in secrets.json will be maintained (safer and generally preferred).")
private String aclMasterToken = null;

@Parameter(names = {"--gossip-encryption-token"}, description = "Overwrites the existing Gossip Encryption Token with the value supplied."
+ " If not supplied, the existing token in secrets.json will be maintained (safer and generally preferred).")
private String gossipEncryptionToken = null;

public String getAclMasterToken() {
return aclMasterToken;
}

public String getGossipEncryptionToken() {
return gossipEncryptionToken;
}

@Override
public String getCommandName() {
return COMMAND_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,23 @@ public UpdateConsulConfigOperation(final ConsulConfigGenerator consulConfigGener

@Override
public void run(final UpdateConsulConfigCommand command) {
logger.info("Regenerating the Consul configuration while maintaining values such as the AclMasterToken and GossipEncryptionToken.");
logger.info("Regenerating Consul configuration");

String aclMasterToken = command.getAclMasterToken();
if (aclMasterToken == null) {
logger.info("Regenerating Consul configuration: maintaining existing ACL Master Token");
aclMasterToken = configStore.getAclMasterToken();
}
String gossipEncryptionToken = command.getGossipEncryptionToken();
if (gossipEncryptionToken == null) {
logger.info("Regenerating Consul configuration: maintaining existing Gossip Encryption Token");
gossipEncryptionToken = configStore.getGossipEncryptionToken();
}

final ConsulConfiguration consulConfiguration = consulConfigGenerator.generate(
ConfigConstants.CONSUL_DATACENTER,
configStore.getAclMasterToken(),
configStore.getGossipEncryptionToken()
aclMasterToken,
gossipEncryptionToken
);

logger.info("Uploading Consul configuration to the configuration bucket.");
Expand Down

0 comments on commit 7bce320

Please sign in to comment.