use of com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount in project halyard by spinnaker.
the class DCOSEditAccountCommand method editAccount.
@Override
protected Account editAccount(DCOSAccount account) {
if (!removeCredential.isEmpty()) {
account.removeCredential(removeCredential.get(0), removeCredential.get(1));
}
if (!updateUserCredential.isEmpty()) {
validateCredential(updateUserCredential);
final String clusterName = updateUserCredential.get(0);
final String uid = updateUserCredential.get(1);
final String password = updateUserCredential.get(2);
account.removeCredential(clusterName, uid);
final DCOSAccount.ClusterCredential credential = new DCOSAccount.ClusterCredential(clusterName, uid, password, null);
account.getClusters().add(credential);
}
if (!updateServiceCredential.isEmpty()) {
validateCredential(updateServiceCredential);
final String clusterName = updateServiceCredential.get(0);
final String uid = updateServiceCredential.get(1);
final String serviceKeyFile = updateServiceCredential.get(2);
account.removeCredential(clusterName, uid);
final DCOSAccount.ClusterCredential credential = new DCOSAccount.ClusterCredential(clusterName, uid, null, serviceKeyFile);
account.getClusters().add(credential);
}
try {
List<String> oldRegistries = account.getDockerRegistries().stream().map(DockerRegistryReference::getAccountName).collect(Collectors.toList());
List<DockerRegistryReference> newRegistries = updateStringList(oldRegistries, dockerRegistries, addDockerRegistry, removeDockerRegistry).stream().map(s -> new DockerRegistryReference().setAccountName(s)).collect(Collectors.toList());
account.setDockerRegistries(newRegistries);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Set either --docker-registries or --[add/remove]-docker-registry");
}
return account;
}
use of com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount in project halyard by spinnaker.
the class DCOSAccountValidator method validate.
@Override
public void validate(final ConfigProblemSetBuilder problems, final DCOSAccount account) {
DeploymentConfiguration deploymentConfiguration;
/**
* I have copied
* the code
* that was in
* the KubernetesAccountValidator
*
* and which
* you were planning
* to refactor
* with filters
*
* Forgive me
* It did the job
* And I was lazy
* so very lazy
*/
// TODO(lwander) this is still a little messy - I should use the filters to get the necessary docker account
Node parent = account.getParent();
while (!(parent instanceof DeploymentConfiguration)) {
// Note this will crash in the above check if the halconfig representation is corrupted
// (that's ok, because it indicates a more serious error than we want to validate).
parent = parent.getParent();
}
deploymentConfiguration = (DeploymentConfiguration) parent;
validateClusters(problems, account);
if (account.getClusters().isEmpty()) {
problems.addProblem(ERROR, "Account does not have any clusters configured").setRemediation("Edit the account with either --update-user-credential or --update-service-credential");
}
final List<String> dockerRegistryNames = account.getDockerRegistries().stream().map(DockerRegistryReference::getAccountName).collect(Collectors.toList());
validateDockerRegistries(problems, deploymentConfiguration, dockerRegistryNames, Provider.ProviderType.DCOS);
}
use of com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount in project halyard by spinnaker.
the class DCOSAddAccountCommand method buildAccount.
@Override
protected Account buildAccount(String accountName) {
DCOSAccount account = (DCOSAccount) new DCOSAccount().setName(accountName);
dockerRegistries.forEach(registryName -> account.getDockerRegistries().add(new DockerRegistryReference().setAccountName(registryName)));
if (!isNull(serviceKeyFile) && !isNull(password)) {
throw new IllegalArgumentException("Only one of --service-key-file or --password may be set");
}
account.setClusters(Lists.newArrayList(new ClusterCredential(cluster, uid, password, serviceKeyFile)));
return account;
}
use of com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount in project halyard by spinnaker.
the class DCOSAccountValidator method validateClusters.
private void validateClusters(final ConfigProblemSetBuilder problems, final DCOSAccount account) {
final NodeIterator children = account.getParent().getChildren();
Node n = children.getNext();
Set<String> definedClusters = new HashSet<>();
while (n != null) {
if (n instanceof DCOSCluster) {
definedClusters.add(((DCOSCluster) n).getName());
}
n = children.getNext();
}
final Set<String> accountClusters = account.getClusters().stream().map(c -> c.getName()).collect(Collectors.toSet());
accountClusters.removeAll(definedClusters);
accountClusters.forEach(c -> problems.addProblem(ERROR, "Cluster \"" + c.toString() + "\" not defined for provider").setRemediation("Add cluster to the provider or remove from the account").setOptions(Lists.newArrayList(definedClusters)));
Set<List<String>> credentials = new HashSet<>();
account.getClusters().forEach(c -> {
final List<String> key = Lists.newArrayList(c.getName(), c.getUid());
if (credentials.contains(key)) {
problems.addProblem(ERROR, "Account contains duplicate credentials for cluster \"" + c.getName() + "\" and user id \"" + c.getUid() + "\".").setRemediation("Remove the duplicate credentials");
} else {
credentials.add(key);
}
// we can connect without a password
if (Strings.isStringEmpty(c.getPassword()) && Strings.isStringEmpty(c.getServiceKeyFile())) {
problems.addProblem(WARNING, "Account has no password or service key. Unless the cluster has security disabled this may be an error").setRemediation("Add a password or service key.");
}
if (!Strings.isStringEmpty(c.getPassword()) && !Strings.isStringEmpty(c.getServiceKeyFile())) {
problems.addProblem(ERROR, "Account has both a password and service key").setRemediation("Remove either the password or service key.");
}
if (!Strings.isStringEmpty(c.getServiceKeyFile())) {
String resolvedServiceKey = ValidatingFileReader.contents(problems, c.getServiceKeyFile());
if (Strings.isStringEmpty(resolvedServiceKey)) {
problems.addProblem(ERROR, "The supplied service key file does not exist or is empty.").setRemediation("Supply a valid service key file.");
}
}
});
}
Aggregations