-
Notifications
You must be signed in to change notification settings - Fork 140
/
VaultGCRLoginImpl.java
88 lines (69 loc) · 2.73 KB
/
VaultGCRLoginImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.datapipe.jenkins.vault.credentials.common;
import com.cloudbees.plugins.credentials.CredentialsScope;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Item;
import hudson.model.ItemGroup;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import hudson.util.Secret;
import java.util.Map;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import static com.datapipe.jenkins.vault.configuration.VaultConfiguration.engineVersions;
import static com.datapipe.jenkins.vault.credentials.common.VaultHelper.getVaultSecret;
public class VaultGCRLoginImpl extends AbstractVaultBaseStandardCredentials implements VaultGCRLogin {
private final static Logger LOGGER = Logger.getLogger(VaultGCRLoginImpl.class.getName());
@DataBoundConstructor
public VaultGCRLoginImpl(CredentialsScope scope, String id,
String description) {
super(scope, id, description);
}
@Override
public String getDisplayName() {
return "Vault Google Container Registry Login";
}
@NonNull
@Override
public Secret getPassword() {
Map<String, String> s = getVaultSecretValue();
String key = JSONObject.fromObject(s).toString();
return Secret.fromString(key);
}
@NonNull
@Override
public String getUsername() {
return "_json_key";
}
@Extension
public static class DescriptorImpl extends BaseStandardCredentialsDescriptor {
@Override
public String getDisplayName() {
return "Vault Google Container Registry Login";
}
public FormValidation doTestConnection(
@AncestorInPath ItemGroup<Item> context,
@QueryParameter("path") String path,
@QueryParameter("prefixPath") String prefixPath,
@QueryParameter("namespace") String namespace,
@QueryParameter("engineVersion") Integer engineVersion) {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
String okMessage = "Successfully retrieved secret " + path;
try {
getVaultSecret(path, prefixPath, namespace, engineVersion, context);
} catch (Exception e) {
return FormValidation.error("FAILED to retrieve Vault secret: \n" + e);
}
return FormValidation
.ok(okMessage);
}
@SuppressWarnings("unused") // used by stapler
public ListBoxModel doFillEngineVersionItems(@AncestorInPath Item context) {
return engineVersions(context);
}
}
}