Add a dynamically-configured list of allowed country codes for payments.

This commit is contained in:
Jon Chambers 2021-03-26 11:10:56 -04:00 committed by Jon Chambers
parent c3c46f2f74
commit 5965f0fd22
3 changed files with 52 additions and 0 deletions

View File

@ -30,6 +30,10 @@ public class DynamicConfiguration {
@Valid
private DynamicMessageRateConfiguration messageRate = new DynamicMessageRateConfiguration();
@JsonProperty
@Valid
private DynamicPaymentsConfiguration payments = new DynamicPaymentsConfiguration();
@JsonProperty
private Set<String> featureFlags = Collections.emptySet();
@ -59,6 +63,10 @@ public class DynamicConfiguration {
return messageRate;
}
public DynamicPaymentsConfiguration getPaymentsConfiguration() {
return payments;
}
public Set<String> getActiveFeatureFlags() {
return featureFlags;
}

View File

@ -0,0 +1,20 @@
/*
* Copyright 2021 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.configuration.dynamic;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Collections;
import java.util.Set;
public class DynamicPaymentsConfiguration {
@JsonProperty
private Set<String> allowedCountryCodes = Collections.emptySet();
public Set<String> getAllowedCountryCodes() {
return allowedCountryCodes;
}
}

View File

@ -252,4 +252,28 @@ class DynamicConfigurationTest {
assertEquals(List.of("2135551212", "2135551313"), config.getNumbers());
}
}
@Test
public void testParsePaymentsConfiguration() throws JsonProcessingException {
{
final String emptyConfigYaml = "test: true";
final DynamicConfiguration emptyConfig = DynamicConfigurationManager.OBJECT_MAPPER
.readValue(emptyConfigYaml, DynamicConfiguration.class);
assertTrue(emptyConfig.getPaymentsConfiguration().getAllowedCountryCodes().isEmpty());
}
{
final String paymentsConfigYaml =
"payments:\n"
+ " allowedCountryCodes:\n"
+ " - 44";
final DynamicPaymentsConfiguration config = DynamicConfigurationManager.OBJECT_MAPPER
.readValue(paymentsConfigYaml, DynamicConfiguration.class)
.getPaymentsConfiguration();
assertEquals(Set.of("44"), config.getAllowedCountryCodes());
}
}
}