Skip to content

Commit

Permalink
Parsing of bucket tags from env vars added (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillston committed Feb 25, 2021
1 parent 03d5724 commit 98a37e0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -91,7 +92,7 @@ private List<PlanProxy> parsePlanCollection(String planCollectionJson) throws IO
return thesePlans.stream().map(p -> {
// TODO include cost amounts, displayname, and properties
PlanMetadataProxy planMetadata = new PlanMetadataProxy(p.getBullets(), p.getCosts(), null, null);
PlanProxy plan = new PlanProxy(p.getGuid(), p.getName(), p.getDescription(), planMetadata, p.getFree(), p.getServiceSettings());
PlanProxy plan = new PlanProxy(p.getGuid(), p.getName(), p.getDescription(), planMetadata, p.getFree(), parseBucketTags(p.getServiceSettings()));
plan.setRepositoryPlan(p.getRepositoryPlan());
return plan;
}).collect(Collectors.toList());
Expand Down Expand Up @@ -123,6 +124,7 @@ private Map<String, Object> parseServiceSettings(String settingsJson, int servic

if (selector.getValue().equals("Bucket")) {
settings.put(SERVICE_TYPE, ServiceType.BUCKET.getAlias());
settings = parseBucketTags(settings);
} else if (selector.getValue().equals("Namespace")) {
settings.put(SERVICE_TYPE, ServiceType.NAMESPACE.getAlias());
} else {
Expand Down Expand Up @@ -160,6 +162,37 @@ private Map<String, Object> parseServiceSettings(String settingsJson, int servic
return settings;
}

private Map<String, Object> parseBucketTags(Map<String, Object> settings) {
List<Map<String, String>> bucketTags = new ArrayList<>();

String bucketTagsString = (String) settings.get(BUCKET_TAGS);

if (bucketTagsString == null) {
return settings;
}

String[] tagsPairs = bucketTagsString.split(BUCKET_TAG_PAIRS_DELIMITER);

for(String tagPair: tagsPairs) {
String[] tag = tagPair.split(BUCKET_TAG_PAIR_KEY_VALUE_DELIMITER);
if (tag.length != 2) {
throw new ServiceBrokerException("Invalid bucket tag passed. Enable to split '" + tagPair +
"' on key and value. '" + BUCKET_TAG_PAIR_KEY_VALUE_DELIMITER + "' as key-value delimiter expected");
}

Map<String, String> tagMap = new HashMap<>();
tagMap.put(KEY, tag[0]);
tagMap.put(VALUE, tag[1]);

bucketTags.add(tagMap);
}

settings.remove(BUCKET_TAGS);
settings.put(TAGS, bucketTags);

return settings;
}

public void setServices(List<ServiceDefinitionProxy> services) {
this.services = services;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/emc/ecs/servicebroker/model/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public class Constants {
public static final String S3_URL = "s3Url";

public static final String TAGS = "tags";
public static final String KEY = "key";
public static final String VALUE = "value";
public static final String BUCKET_TAGS = "bucket_tags";
public static final String BUCKET_TAG_PAIRS_DELIMITER = ",";
public static final String BUCKET_TAG_PAIR_KEY_VALUE_DELIMITER = "=";

public static final String SEARCH_METADATA = "search-metadata";
public static final String SEARCH_METADATA_TYPE = "type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public class PlanCollectionInstance {
@JsonProperty("base_url")
private String baseUrl;

@JsonProperty("bucket_tags")
private String bucketTags;

public void setBullet1(String bullet1) {
this.bullet1 = bullet1;
}
Expand Down Expand Up @@ -176,6 +179,14 @@ public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}

public String getBucketTags() {
return bucketTags;
}

public void setBucketTags(String bucketTags) {
this.bucketTags = bucketTags;
}

public List<CostProxy> getCosts() {
Map<String, Double> val = new HashMap<>();
val.put(costCurrency != null ? costCurrency.toLowerCase() : Currency.getInstance("USD").getCurrencyCode().toLowerCase(), Double.valueOf(costValue));
Expand Down Expand Up @@ -224,6 +235,10 @@ public Map<String, Object> getServiceSettings() {
serviceSettings.put(QUOTA, quota);
}

if (bucketTags != null) {
serviceSettings.put(BUCKET_TAGS, bucketTags);
}

return serviceSettings;
}
}

0 comments on commit 98a37e0

Please sign in to comment.