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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations