1 package org.kuali.common.devops.logic;
2
3 import static com.google.common.collect.Sets.newHashSet;
4 import static org.kuali.common.devops.dnsme.EncryptedDNSMECredentials.ENCRYPTED_DNSME_CREDENTIALS_PRODUCTION;
5 import static org.kuali.common.util.base.Exceptions.illegalArgument;
6 import static org.kuali.common.util.encrypt.Encryption.getDefaultEncryptor;
7
8 import java.util.Set;
9
10 import org.kuali.common.aws.model.ImmutableAWSCredentials;
11 import org.kuali.common.core.ssh.KeyPair;
12 import org.kuali.common.devops.aws.EncryptedAWSCredentials;
13 import org.kuali.common.devops.aws.EncryptedKeyPairs;
14 import org.kuali.common.dns.dnsme.model.DNSMadeEasyCredentials;
15 import org.kuali.common.util.encrypt.Encryptor;
16
17 import com.amazonaws.auth.AWSCredentials;
18
19
20
21
22 @Deprecated
23 public class Auth {
24
25 public static KeyPair getKeyPair(String account) {
26 for (EncryptedKeyPairs keyPair : EncryptedKeyPairs.values()) {
27 if (keyPair.name().equalsIgnoreCase(account)) {
28 return getKeyPair(keyPair);
29 }
30 }
31 throw illegalArgument("unknown account -> %s", account);
32 }
33
34 public static KeyPair getKeyPair(EncryptedKeyPairs encrypted) {
35 Encryptor encryptor = getDefaultEncryptor();
36 KeyPair keyPair = encrypted.getPair();
37 String publicKey = encryptor.decrypt(keyPair.getPublicKey());
38 String privateKey = encryptor.decrypt(keyPair.getPrivateKey());
39 return KeyPair.builder(keyPair.getName()).withPublicKey(publicKey).withPrivateKey(privateKey).build();
40 }
41
42 public static DNSMadeEasyCredentials getDNSMECredentials() {
43 DNSMadeEasyCredentials creds = ENCRYPTED_DNSME_CREDENTIALS_PRODUCTION.getCredentials();
44 Encryptor encryptor = getDefaultEncryptor();
45 String apiKey = encryptor.decrypt(creds.getApiKey());
46 String secretKey = encryptor.decrypt(creds.getSecretKey());
47 return DNSMadeEasyCredentials.builder().withApiKey(apiKey).withSecretKey(secretKey).build();
48 }
49
50 public static Set<String> getAwsAccountNames() {
51 Set<String> names = newHashSet();
52 for (EncryptedAWSCredentials credentials : EncryptedAWSCredentials.values()) {
53 names.add(credentials.name().toLowerCase());
54 }
55 return names;
56 }
57
58 public static AWSCredentials fromEncrypted(AWSCredentials encrypted) {
59 Encryptor encryptor = getDefaultEncryptor();
60 String accessKey = encryptor.decrypt(encrypted.getAWSAccessKeyId());
61 String secretKey = encryptor.decrypt(encrypted.getAWSSecretKey());
62 return ImmutableAWSCredentials.build(accessKey, secretKey);
63 }
64
65 public static AWSCredentials getAwsCredentials(String account) {
66 for (EncryptedAWSCredentials credentials : EncryptedAWSCredentials.values()) {
67 if (credentials.name().equalsIgnoreCase(account)) {
68 return getAwsCredentials(credentials);
69 }
70 }
71 throw illegalArgument("unknown account -> %s", account);
72 }
73
74 public static AWSCredentials getAwsCredentials(AWSCredentials encrypted) {
75 return fromEncrypted(encrypted);
76 }
77
78 }