Create a strategy class to decide which sender id to use

The rules around selecting sender ids can get complicated with some
countries not supporting it and others requiring pre-registration that
may result in having a different sender id for that country than
others. This strategy class handles the logic of dealing with this
expanded configuration and applying the appropriate sender id or none
when it's not appropriate to do so at all.
This commit is contained in:
Ehren Kret
2020-07-13 23:25:06 -05:00
parent e3aecb2aa9
commit b7e0e5a356
7 changed files with 240 additions and 81 deletions

View File

@@ -1,31 +0,0 @@
package org.whispersystems.textsecuregcm.configuration;
import com.google.common.annotations.VisibleForTesting;
import javax.validation.constraints.NotEmpty;
public class TwilioAlphaIdConfiguration {
@NotEmpty
private String prefix;
@NotEmpty
private String value;
public String getPrefix() {
return prefix;
}
@VisibleForTesting
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public String getValue() {
return value;
}
@VisibleForTesting
public void setValue(String value) {
this.value = value;
}
}

View File

@@ -16,34 +16,27 @@
*/
package org.whispersystems.textsecuregcm.configuration;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.annotations.VisibleForTesting;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
public class TwilioConfiguration {
@NotEmpty
@JsonProperty
private String accountId;
@NotEmpty
@JsonProperty
private String accountToken;
@NotNull
@JsonProperty
private List<String> numbers;
@NotEmpty
@JsonProperty
private String localDomain;
@JsonProperty
private String messagingServicesId;
@NotNull
@@ -56,7 +49,7 @@ public class TwilioConfiguration {
@NotNull
@Valid
private List<TwilioAlphaIdConfiguration> alphaId = new ArrayList<>();
private TwilioSenderIdConfiguration senderId = new TwilioSenderIdConfiguration();
public String getAccountId() {
return accountId;
@@ -121,12 +114,12 @@ public class TwilioConfiguration {
this.retry = retry;
}
public List<TwilioAlphaIdConfiguration> getAlphaId() {
return alphaId;
public TwilioSenderIdConfiguration getSenderId() {
return senderId;
}
@VisibleForTesting
public void setAlphaId(List<TwilioAlphaIdConfiguration> alphaId) {
this.alphaId = alphaId;
public void setSenderId(TwilioSenderIdConfiguration senderId) {
this.senderId = senderId;
}
}

View File

@@ -0,0 +1,31 @@
package org.whispersystems.textsecuregcm.configuration;
import com.google.common.annotations.VisibleForTesting;
import javax.validation.constraints.NotEmpty;
public class TwilioCountrySenderIdConfiguration {
@NotEmpty
private String countryCode;
@NotEmpty
private String senderId;
public String getCountryCode() {
return countryCode;
}
@VisibleForTesting
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public String getSenderId() {
return senderId;
}
@VisibleForTesting
public void setSenderId(String senderId) {
this.senderId = senderId;
}
}

View File

@@ -0,0 +1,51 @@
package org.whispersystems.textsecuregcm.configuration;
import com.google.common.annotations.VisibleForTesting;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TwilioSenderIdConfiguration {
@NotEmpty
private String defaultSenderId;
@NotNull
@Valid
private List<TwilioCountrySenderIdConfiguration> countrySpecificSenderIds = new ArrayList<>();
@NotNull
@Valid
private Set<String> countryCodesWithoutSenderId = new HashSet<>();
public String getDefaultSenderId() {
return defaultSenderId;
}
@VisibleForTesting
public void setDefaultSenderId(String defaultSenderId) {
this.defaultSenderId = defaultSenderId;
}
public List<TwilioCountrySenderIdConfiguration> getCountrySpecificSenderIds() {
return countrySpecificSenderIds;
}
@VisibleForTesting
public void setCountrySpecificSenderIds(List<TwilioCountrySenderIdConfiguration> countrySpecificSenderIds) {
this.countrySpecificSenderIds = countrySpecificSenderIds;
}
public Set<String> getCountryCodesWithoutSenderId() {
return countryCodesWithoutSenderId;
}
@VisibleForTesting
public void setCountryCodesWithoutSenderId(Set<String> countryCodesWithoutSenderId) {
this.countryCodesWithoutSenderId = countryCodesWithoutSenderId;
}
}