Search in sources :

Example 1 with DockerRegistryReference

use of com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference 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 DockerRegistryReference

use of com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference in project halyard by spinnaker.

the class KubernetesAddAccountCommand method buildAccount.

@Override
protected Account buildAccount(String accountName) {
    KubernetesAccount account = (KubernetesAccount) new KubernetesAccount().setName(accountName);
    account.setContext(context);
    account.setKubeconfigFile(kubeconfigFile);
    account.setNamespaces(namespaces);
    account.setOmitNamespaces(omitNamespaces);
    account.setKinds(namespaces);
    account.setOmitKinds(omitKinds);
    account.setConfigureImagePullSecrets(configureImagePullSecrets);
    account.setServiceAccount(serviceAccount);
    dockerRegistries.forEach(registryName -> account.getDockerRegistries().add(new DockerRegistryReference().setAccountName(registryName)));
    account.setOAuthServiceAccount(oAuthServiceAccount);
    account.setOAuthScopes(oAuthScopes);
    account.setNamingStrategy(namingStrategy);
    account.setSkin(skin);
    return account;
}
Also used : DockerRegistryReference(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference) KubernetesAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount)

Example 3 with DockerRegistryReference

use of com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference 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 4 with DockerRegistryReference

use of com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference 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 5 with DockerRegistryReference

use of com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference in project halyard by spinnaker.

the class KubernetesEditAccountCommand method editAccount.

@Override
protected Account editAccount(KubernetesAccount account) {
    boolean contextSet = context != null && !context.isEmpty();
    if (contextSet && !clearContext) {
        account.setContext(context);
    } else if (!contextSet && clearContext) {
        account.setContext(null);
    } else if (contextSet && clearContext) {
        throw new IllegalArgumentException("Set either --context or --clear-context");
    }
    account.setKubeconfigFile(isSet(kubeconfigFile) ? kubeconfigFile : account.getKubeconfigFile());
    account.setConfigureImagePullSecrets(isSet(configureImagePullSecrets) ? configureImagePullSecrets : account.getConfigureImagePullSecrets());
    account.setServiceAccount(isSet(serviceAccount) ? serviceAccount : account.getServiceAccount());
    try {
        account.setNamespaces(updateStringList(account.getNamespaces(), namespaces, addNamespace, removeNamespace));
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Set either --namespaces or --[add/remove]-namespace");
    }
    try {
        account.setOmitNamespaces(updateStringList(account.getOmitNamespaces(), omitNamespaces, addOmitNamespace, removeOmitNamespace));
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Set either --omit-namespaces or --[add/remove]-omit-namespace");
    }
    try {
        account.setKinds(updateStringList(account.getKinds(), kinds, addKind, removeKind));
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Set either --kinds or --[add/remove]-kind");
    }
    try {
        account.setOmitKinds(updateStringList(account.getOmitKinds(), omitKinds, addOmitKind, removeOmitKind));
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Set either --omit-kinds or --[add/remove]-omit-kind");
    }
    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");
    }
    try {
        account.setOAuthScopes(updateStringList(account.getOAuthScopes(), oAuthScopes, addOAuthScope, removeOAuthScope));
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Set either --oauth-scopes or --[add/remove]-oauth-scope");
    }
    account.setOAuthServiceAccount(isSet(oAuthServiceAccount) ? oAuthServiceAccount : account.getOAuthServiceAccount());
    account.setNamingStrategy(isSet(namingStrategy) ? namingStrategy : account.getNamingStrategy());
    account.setSkin(isSet(skin) ? skin : account.getSkin());
    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) LocalFileConverter(com.netflix.spinnaker.halyard.cli.command.v1.converter.LocalFileConverter) Parameters(com.beust.jcommander.Parameters) 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) KubernetesAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList)

Aggregations

DockerRegistryReference (com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference)4 Parameter (com.beust.jcommander.Parameter)2 Parameters (com.beust.jcommander.Parameters)2 AbstractEditAccountCommand (com.netflix.spinnaker.halyard.cli.command.v1.config.providers.account.AbstractEditAccountCommand)2 Account (com.netflix.spinnaker.halyard.config.model.v1.node.Account)2 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)2 Node (com.netflix.spinnaker.halyard.config.model.v1.node.Node)2 DCOSAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount)2 KubernetesAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 LocalFileConverter (com.netflix.spinnaker.halyard.cli.command.v1.converter.LocalFileConverter)1 Provider (com.netflix.spinnaker.halyard.config.model.v1.node.Provider)1 ClusterCredential (com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount.ClusterCredential)1