1 package org.kuali.common.dns.dnsme.spring; 2 3 import static org.kuali.common.util.encrypt.Encryption.getDefaultEncryptor; 4 import static org.kuali.common.util.nullify.NullUtils.trimToNull; 5 6 import org.kuali.common.dns.dnsme.model.DNSMadeEasyCredentials; 7 import org.kuali.common.dns.dnsme.model.DNSMadeEasyServiceContext; 8 import org.kuali.common.util.encrypt.Encryptor; 9 import org.kuali.common.util.spring.env.EnvironmentService; 10 11 public class DNSMadeEasyUtils { 12 13 private static final String API_KEY = "dnsme.apiKey"; 14 private static final String SECRET_KEY = "dnsme.secretKey"; 15 private static final String URL_KEY = "dnsme.url"; 16 private static final String DOMAIN_KEY = "dnsme.domain"; 17 18 public static DNSMadeEasyServiceContext getServiceContext(EnvironmentService env, String restApiUrl, String domain, DNSMadeEasyCredentials encrypted) { 19 Encryptor encryptor = getDefaultEncryptor(); 20 String url = trimToNull(env.getString(URL_KEY, restApiUrl)); 21 String domainName = trimToNull(env.getString(DOMAIN_KEY, domain)); 22 String apiKey = encryptor.decrypt(trimToNull(env.getString(API_KEY, encrypted.getApiKey()))); 23 String secretKey = encryptor.decrypt(trimToNull(env.getString(SECRET_KEY, encrypted.getSecretKey()))); 24 DNSMadeEasyCredentials credentials = DNSMadeEasyCredentials.builder().withApiKey(apiKey).withSecretKey(secretKey).build(); 25 return new DNSMadeEasyServiceContext(credentials, url, domainName); 26 } 27 }