Search in sources :

Example 1 with DCOSAccount

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;
}
Also used : DockerRegistryReference(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference) DockerRegistryReference(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference) Parameters(com.beust.jcommander.Parameters) DCOSAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount) List(java.util.List) Parameter(com.beust.jcommander.Parameter) AbstractEditAccountCommand(com.netflix.spinnaker.halyard.cli.command.v1.config.providers.account.AbstractEditAccountCommand) Account(com.netflix.spinnaker.halyard.config.model.v1.node.Account) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) DCOSAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount)

Example 2 with DCOSAccount

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);
}
Also used : Node(com.netflix.spinnaker.halyard.config.model.v1.node.Node) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)

Example 3 with DCOSAccount

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;
}
Also used : DockerRegistryReference(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference) ClusterCredential(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount.ClusterCredential) DCOSAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount)

Example 4 with DCOSAccount

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.");
            }
        }
    });
}
Also used : NodeIterator(com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator) DockerRegistryReference(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference) NodeIterator(com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator) Set(java.util.Set) ERROR(com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.ERROR) Lists(com.beust.jcommander.internal.Lists) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration) ConfigProblemSetBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) DCOSAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount) Component(org.springframework.stereotype.Component) List(java.util.List) WARNING(com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.WARNING) Strings(com.beust.jcommander.Strings) Validator(com.netflix.spinnaker.halyard.config.model.v1.node.Validator) DockerRegistryReferenceValidation.validateDockerRegistries(com.netflix.spinnaker.halyard.config.validate.v1.providers.dockerRegistry.DockerRegistryReferenceValidation.validateDockerRegistries) DCOSCluster(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster) ValidatingFileReader(com.netflix.spinnaker.halyard.config.validate.v1.util.ValidatingFileReader) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider) Node(com.netflix.spinnaker.halyard.config.model.v1.node.Node) Node(com.netflix.spinnaker.halyard.config.model.v1.node.Node) List(java.util.List) DCOSCluster(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster) HashSet(java.util.HashSet)

Aggregations

DockerRegistryReference (com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference)3 DCOSAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount)3 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)2 Node (com.netflix.spinnaker.halyard.config.model.v1.node.Node)2 Provider (com.netflix.spinnaker.halyard.config.model.v1.node.Provider)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Parameter (com.beust.jcommander.Parameter)1 Parameters (com.beust.jcommander.Parameters)1 Strings (com.beust.jcommander.Strings)1 Lists (com.beust.jcommander.internal.Lists)1 AbstractEditAccountCommand (com.netflix.spinnaker.halyard.cli.command.v1.config.providers.account.AbstractEditAccountCommand)1 Account (com.netflix.spinnaker.halyard.config.model.v1.node.Account)1 NodeIterator (com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator)1 Validator (com.netflix.spinnaker.halyard.config.model.v1.node.Validator)1 ClusterCredential (com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount.ClusterCredential)1 DCOSCluster (com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster)1 ConfigProblemSetBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder)1 DockerRegistryReferenceValidation.validateDockerRegistries (com.netflix.spinnaker.halyard.config.validate.v1.providers.dockerRegistry.DockerRegistryReferenceValidation.validateDockerRegistries)1 ValidatingFileReader (com.netflix.spinnaker.halyard.config.validate.v1.util.ValidatingFileReader)1