Use "global." instead of "g." as the prefix for global config options.

This commit is contained in:
Jon Chambers 2020-08-11 11:48:47 -04:00 committed by Jon Chambers
parent 9be6af8481
commit 31a215d4d6
2 changed files with 9 additions and 7 deletions

View File

@ -40,6 +40,8 @@ public class RemoteConfigController {
private final List<String> configAuthTokens; private final List<String> configAuthTokens;
private final Map<String, String> globalConfig; private final Map<String, String> globalConfig;
private static final String GLOBAL_CONFIG_PREFIX = "global.";
public RemoteConfigController(RemoteConfigsManager remoteConfigsManager, List<String> configAuthTokens, Map<String, String> globalConfig) { public RemoteConfigController(RemoteConfigsManager remoteConfigsManager, List<String> configAuthTokens, Map<String, String> globalConfig) {
this.remoteConfigsManager = remoteConfigsManager; this.remoteConfigsManager = remoteConfigsManager;
this.configAuthTokens = configAuthTokens; this.configAuthTokens = configAuthTokens;
@ -54,7 +56,7 @@ public class RemoteConfigController {
try { try {
MessageDigest digest = MessageDigest.getInstance("SHA1"); MessageDigest digest = MessageDigest.getInstance("SHA1");
final Stream<UserRemoteConfig> globalConfigStream = globalConfig.entrySet().stream().map(entry -> new UserRemoteConfig("g." + entry.getKey(), true, entry.getValue())); final Stream<UserRemoteConfig> globalConfigStream = globalConfig.entrySet().stream().map(entry -> new UserRemoteConfig(GLOBAL_CONFIG_PREFIX + entry.getKey(), true, entry.getValue()));
return new UserRemoteConfigList(Stream.concat(remoteConfigsManager.getAll().stream().map(config -> { return new UserRemoteConfigList(Stream.concat(remoteConfigsManager.getAll().stream().map(config -> {
final byte[] hashKey = config.getHashKey() != null ? config.getHashKey().getBytes(StandardCharsets.UTF_8) : config.getName().getBytes(StandardCharsets.UTF_8); final byte[] hashKey = config.getHashKey() != null ? config.getHashKey().getBytes(StandardCharsets.UTF_8) : config.getName().getBytes(StandardCharsets.UTF_8);
boolean inBucket = isInBucket(digest, account.getUuid(), hashKey, config.getPercentage(), config.getUuids()); boolean inBucket = isInBucket(digest, account.getUuid(), hashKey, config.getPercentage(), config.getUuids());
@ -74,7 +76,7 @@ public class RemoteConfigController {
throw new WebApplicationException(Response.Status.UNAUTHORIZED); throw new WebApplicationException(Response.Status.UNAUTHORIZED);
} }
if (config.getName().startsWith("g.")) { if (config.getName().startsWith(GLOBAL_CONFIG_PREFIX)) {
throw new WebApplicationException(Response.Status.FORBIDDEN); throw new WebApplicationException(Response.Status.FORBIDDEN);
} }
@ -89,7 +91,7 @@ public class RemoteConfigController {
throw new WebApplicationException(Response.Status.UNAUTHORIZED); throw new WebApplicationException(Response.Status.UNAUTHORIZED);
} }
if (name.startsWith("g.")) { if (name.startsWith(GLOBAL_CONFIG_PREFIX)) {
throw new WebApplicationException(Response.Status.FORBIDDEN); throw new WebApplicationException(Response.Status.FORBIDDEN);
} }

View File

@ -100,7 +100,7 @@ public class RemoteConfigControllerTest {
assertThat(configuration.getConfig().get(7).getName()).isEqualTo("linked.config.0"); assertThat(configuration.getConfig().get(7).getName()).isEqualTo("linked.config.0");
assertThat(configuration.getConfig().get(8).getName()).isEqualTo("linked.config.1"); assertThat(configuration.getConfig().get(8).getName()).isEqualTo("linked.config.1");
assertThat(configuration.getConfig().get(9).getName()).isEqualTo("unlinked.config"); assertThat(configuration.getConfig().get(9).getName()).isEqualTo("unlinked.config");
assertThat(configuration.getConfig().get(10).getName()).isEqualTo("g.maxGroupSize"); assertThat(configuration.getConfig().get(10).getName()).isEqualTo("global.maxGroupSize");
} }
@Test @Test
@ -134,7 +134,7 @@ public class RemoteConfigControllerTest {
assertThat(configuration.getConfig().get(7).getName()).isEqualTo("linked.config.0"); assertThat(configuration.getConfig().get(7).getName()).isEqualTo("linked.config.0");
assertThat(configuration.getConfig().get(8).getName()).isEqualTo("linked.config.1"); assertThat(configuration.getConfig().get(8).getName()).isEqualTo("linked.config.1");
assertThat(configuration.getConfig().get(9).getName()).isEqualTo("unlinked.config"); assertThat(configuration.getConfig().get(9).getName()).isEqualTo("unlinked.config");
assertThat(configuration.getConfig().get(10).getName()).isEqualTo("g.maxGroupSize"); assertThat(configuration.getConfig().get(10).getName()).isEqualTo("global.maxGroupSize");
} }
@Test @Test
@ -305,7 +305,7 @@ public class RemoteConfigControllerTest {
.target("/v1/config") .target("/v1/config")
.request() .request()
.header("Config-Token", "foo") .header("Config-Token", "foo")
.put(Entity.entity(new RemoteConfig("g.maxGroupSize", 88, Set.of(), "FALSE", "TRUE", null), MediaType.APPLICATION_JSON_TYPE)); .put(Entity.entity(new RemoteConfig("global.maxGroupSize", 88, Set.of(), "FALSE", "TRUE", null), MediaType.APPLICATION_JSON_TYPE));
assertThat(response.getStatus()).isEqualTo(403); assertThat(response.getStatus()).isEqualTo(403);
verifyNoMoreInteractions(remoteConfigsManager); verifyNoMoreInteractions(remoteConfigsManager);
} }
@ -340,7 +340,7 @@ public class RemoteConfigControllerTest {
@Test @Test
public void testDeleteGlobalConfig() { public void testDeleteGlobalConfig() {
Response response = resources.getJerseyTest() Response response = resources.getJerseyTest()
.target("/v1/config/g.maxGroupSize") .target("/v1/config/global.maxGroupSize")
.request() .request()
.header("Config-Token", "foo") .header("Config-Token", "foo")
.delete(); .delete();