Skip to content

Commit

Permalink
Using Base64 encoded key for it test
Browse files Browse the repository at this point in the history
  • Loading branch information
VSydor committed Jun 21, 2024
1 parent 62452a9 commit fb47835
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -71,10 +72,14 @@ public class MailchimpClient {
protected static final Integer BATCH_STATUS_MAX_RETRIES = 24;

protected final com.ecwid.maleorang.MailchimpClient client;
protected final String apiKey;
protected final Environment env;

public MailchimpClient(EnvironmentConfig.CommunicationPlatform mailchimpConfig, Environment env) {
client = new com.ecwid.maleorang.MailchimpClient(mailchimpConfig.secretKey);
String profile = System.getenv("PROFILE");
apiKey = !Strings.isNullOrEmpty(profile) && profile.toLowerCase(Locale.ROOT).contains("it") ?
env.decodeBase64(mailchimpConfig.secretKey) : mailchimpConfig.secretKey;
client = new com.ecwid.maleorang.MailchimpClient(apiKey);
this.env = env;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -311,4 +312,12 @@ public void logJobError(String message, Object... params) {
public void endJobLog(JobStatus jobStatus) {
jobLoggingServices().forEach(logger -> logger.endLog(jobStatus));
}

public String decodeBase64(String encoded) {
if (encoded == null) {
return null;
} else {
return new String(Base64.getDecoder().decode(encoded));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.impactupgrade.nucleus.client.MailchimpClient;
import com.impactupgrade.nucleus.environment.EnvironmentConfig;
import com.impactupgrade.nucleus.model.CrmContact;
import com.impactupgrade.nucleus.service.segment.CommunicationService;
import com.impactupgrade.nucleus.service.segment.MailchimpCommunicationService;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Test;

Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/environment-it-sfdc-mailchimp.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

"mailchimp": [
{
"secretKey": "secret-key-here",
"secretKey": "NzA5ZDY2NjIyZmUzNDdjYjY5NDczODdmZWRmM2E1MTAtdXMxNA==",
"lists": [
{
"id": "list-id-here",
"id": "3d215dac12",
"type": "MARKETING",
"groups": {},
"crmFilter": ""
Expand Down

0 comments on commit fb47835

Please sign in to comment.