Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cf): bump CD version add Space Filter to Halyard for CF #1824

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -8050,6 +8050,7 @@ hal config provider cloudfoundry account add ACCOUNT [parameters]
* `--read-permissions`: (*Default*: `[]`) A user must have at least one of these roles in order to view this account's cloud resources.
* `--required-group-membership`: (*Default*: `[]`) A user must be a member of at least one specified group in order to make changes to this account's cloud resources.
* `--skip-ssl-validation`: (*Default*: `false`) Skip SSL server certificate validation of the API endpoint
* `--space-filter, --spaceFilter`: Organization and Space filter applied to the Spinnaker CF account
* `--user`: (*Required*) User name for the account to use on for this CloudFoundry Foundation
* `--write-permissions`: (*Default*: `[]`) A user must have at least one of these roles in order to make changes to this account's cloud resources.

Expand Down Expand Up @@ -8098,6 +8099,7 @@ hal config provider cloudfoundry account edit ACCOUNT [parameters]
* `--remove-write-permission`: Remove this permission to from list of write permissions.
* `--required-group-membership`: A user must be a member of at least one specified group in order to make changes to this account's cloud resources.
* `--skip-ssl-validation`: (*Default*: `false`) Skip SSL server certificate validation of the API endpoint
* `--space-filter, --spaceFilter`: Organization and Space filter applied to the Spinnaker CF account
* `--user`: User name for the account to use on for this CloudFoundry Foundation
* `--write-permissions`: A user must have at least one of these roles in order to make changes to this account's cloud resources.

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
clouddriverVersion=5.69.0
clouddriverVersion=5.70.0
fiatVersion=1.26.0
front50Version=2.21.0
korkVersion=7.88.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.netflix.spinnaker.halyard.config.model.v1.node.Account;
import com.netflix.spinnaker.halyard.config.model.v1.providers.cloudfoundry.CloudFoundryAccount;
import java.net.URL;
import java.util.Map;
import java.util.Set;

@Parameters(separators = "=")
public class CloudFoundryAddAccountCommand extends AbstractAddAccountCommand {
Expand Down Expand Up @@ -59,6 +61,13 @@ public class CloudFoundryAddAccountCommand extends AbstractAddAccountCommand {
description = CloudFoundryCommandProperties.SKIP_SSL_VALIDATION_DESCRIPTION)
private Boolean skipSslValidation = false;

@Parameter(
names = {"--space-filter", "--spaceFilter"},
required = false,
converter = CloudFoundrySpaceFilterMapConverter.class,
description = CloudFoundryCommandProperties.SPACE_FILTER_DESCRIPTION)
private Map<String, Set<String>> spaceFilter;

@Override
protected Account buildAccount(String accountName) {
CloudFoundryAccount cloudFoundryAccount =
Expand All @@ -69,7 +78,8 @@ protected Account buildAccount(String accountName) {
.setMetricsUrl(metricsUrl)
.setPassword(password)
.setUser(user)
.setSkipSslValidation(skipSslValidation);
.setSkipSslValidation(skipSslValidation)
.setSpaceFilter(spaceFilter);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public class CloudFoundryCommandProperties {
"Password for the account to use on for this CloudFoundry Foundation";
public static final String SKIP_SSL_VALIDATION_DESCRIPTION =
"Skip SSL server certificate validation of the API endpoint";
public static final String SPACE_FILTER_DESCRIPTION =
"Organization and Space filter applied to the Spinnaker CF account";
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.netflix.spinnaker.halyard.config.model.v1.node.Account;
import com.netflix.spinnaker.halyard.config.model.v1.providers.cloudfoundry.CloudFoundryAccount;
import java.net.URL;
import java.util.Map;
import java.util.Set;

@Parameters(separators = "=")
public class CloudFoundryEditAccountCommand
Expand Down Expand Up @@ -58,6 +60,13 @@ protected String getProviderName() {
description = CloudFoundryCommandProperties.SKIP_SSL_VALIDATION_DESCRIPTION)
private Boolean skipSslValidation = false;

@Parameter(
names = {"--space-filter", "--spaceFilter"},
required = false,
converter = CloudFoundrySpaceFilterMapConverter.class,
description = CloudFoundryCommandProperties.SPACE_FILTER_DESCRIPTION)
private Map<String, Set<String>> spaceFilter;

@Override
protected Account editAccount(CloudFoundryAccount account) {
account.setApiHost(isSet(apiHost) ? apiHost : account.getApiHost());
Expand All @@ -67,6 +76,7 @@ protected Account editAccount(CloudFoundryAccount account) {
account.setUser(isSet(user) ? user : account.getUser());
account.setSkipSslValidation(
isSet(skipSslValidation) ? skipSslValidation : account.isSkipSslValidation());
account.setSpaceFilter(isSet(spaceFilter) ? spaceFilter : account.getSpaceFilter());

return account;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.netflix.spinnaker.halyard.cli.command.v1.config.providers.cloudfoundry;

import com.beust.jcommander.IStringConverter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class CloudFoundrySpaceFilterMapConverter
implements IStringConverter<Map<String, Set<String>>> {

@Override
public Map<String, Set<String>> convert(String filter) {
Map<String, Set<String>> spaceFilters = new HashMap<>();

String[] s = filter.split(",");
for (String pair : s) {
String[] p = pair.split(":");
if (p.length > 2) {
throw new IllegalArgumentException(
"Syntax must be one of the following: 'Organization1' or 'Organization1:Space1' or 'Organization1:Space1,Organization2:Space2'");
} else if (p.length == 2) {
spaceFilters.computeIfAbsent(p[0], k -> new HashSet<>()).add(p[1]);
} else if (p.length == 1) {
spaceFilters.computeIfAbsent(p[0], k -> new HashSet<>());
}
}
return spaceFilters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.netflix.spinnaker.halyard.config.model.v1.node.Account;
import com.netflix.spinnaker.halyard.config.model.v1.node.Secret;
import java.net.URL;
import java.util.Map;
import java.util.Set;
import lombok.Data;
import lombok.EqualsAndHashCode;

Expand All @@ -40,4 +42,7 @@ public class CloudFoundryAccount extends Account {
@Secret String password;
String user;
boolean skipSslValidation = false;

@JsonProperty("spaceFilter")
Map<String, Set<String>> spaceFilter;
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void validate(

try {
SpaceService spaceService = createSpaceService(apiHost, skipSslValidation, user, password);
int count = spaceService.all(null, null).getTotalResults();
int count = spaceService.all(null, null, null).getResources().size();
log.info("Retrieved {} spaces using account {}", count, accountName);
} catch (Exception e) {
problemSetBuilder.addProblem(
Expand Down