Skip to content

Commit

Permalink
Fix CORS domains from multiple app-config fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
tgeens committed Sep 21, 2023
1 parent 926a96d commit b1ef660
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.contentgrid.gateway.runtime.config;

import static com.contentgrid.gateway.runtime.config.ApplicationConfiguration.Keys.DELIMITER_REGEX;

import com.contentgrid.gateway.runtime.application.ApplicationId;
import java.util.Arrays;
import java.util.Map.Entry;
Expand Down Expand Up @@ -34,6 +32,10 @@ class Keys {

Optional<String> getProperty(@NonNull String property);

default Stream<String> getProperties(@NonNull String property) {
return this.getProperty(property).stream();
}

Stream<String> keys();

Stream<Entry<String, String>> stream();
Expand All @@ -51,14 +53,15 @@ default String getIssuerUri() {
}

default Set<String> getDomains() {
return Arrays.stream(this.getProperty(Keys.ROUTING_DOMAINS).orElse("").split(DELIMITER_REGEX))
return Arrays.stream(this.getProperty(Keys.ROUTING_DOMAINS).orElse("").split(Keys.DELIMITER_REGEX))
.map(String::trim)
.filter(str -> !str.isBlank())
.collect(Collectors.toSet());
}

default Set<String> getCorsOrigins() {
return Arrays.stream(this.getProperty(Keys.CORS_ORIGINS).orElse("").split(DELIMITER_REGEX))
return this.getProperties(Keys.CORS_ORIGINS)
.flatMap(value -> Stream.of(value.split(Keys.DELIMITER_REGEX)))
.map(String::trim)
.filter(str -> !str.isBlank())
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ public String getConfigurationId() {

@Override
public Optional<String> getProperty(@NonNull String property) {
return this.getProperties(property).findFirst();
}

@Override
public Stream<String> getProperties(@NonNull String property) {
return this.fragments.values().stream()
.flatMap(frag -> frag.getProperty(property).stream())
.findFirst();
.flatMap(frag -> frag.getProperty(property).stream());
}



public Stream<Entry<String, String>> stream() {
return this.keys().flatMap(key -> this.getProperty(key).stream().map(prop -> Map.entry(key, prop)));
}
Expand Down

0 comments on commit b1ef660

Please sign in to comment.