-
Notifications
You must be signed in to change notification settings - Fork 69
/
KubernetesCredentialsStore.java
128 lines (109 loc) · 4.49 KB
/
KubernetesCredentialsStore.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package com.cloudbees.jenkins.plugins.kubernetes_credentials_provider;
import java.util.Collections;
import java.util.List;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import org.acegisecurity.Authentication;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jenkins.ui.icon.IconType;
import org.kohsuke.stapler.export.ExportedBean;
import hudson.model.ModelObject;
import hudson.security.ACL;
import hudson.security.Permission;
import jenkins.model.Jenkins;
import com.cloudbees.plugins.credentials.Credentials;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsStore;
import com.cloudbees.plugins.credentials.CredentialsStoreAction;
import com.cloudbees.plugins.credentials.domains.Domain;
public class KubernetesCredentialsStore extends CredentialsStore {
private final KubernetesCredentialProvider provider;
private final KubernetesCredentialsStoreAction action = new KubernetesCredentialsStoreAction(this);
public KubernetesCredentialsStore(KubernetesCredentialProvider provider) {
super(KubernetesCredentialProvider.class);
this.provider = provider;
}
@NonNull
@Override
public ModelObject getContext() {
return Jenkins.getInstance();
}
@Override
public boolean hasPermission(@NonNull Authentication authentication, @NonNull Permission permission) {
return CredentialsProvider.VIEW.equals(permission) &&
Jenkins.getInstance().getACL().hasPermission(authentication, permission);
}
@NonNull
@Override
public List<Credentials> getCredentials(@NonNull Domain domain) {
// Only the global domain is supported
return Domain.global().equals(domain)
? provider.getCredentials(Credentials.class, Jenkins.getInstance(), ACL.SYSTEM)
: Collections.emptyList();
}
@Override
public boolean addCredentials(@NonNull Domain domain, @NonNull Credentials credentials) {
throw new UnsupportedOperationException();
}
@Override
public boolean removeCredentials(@NonNull Domain domain, @NonNull Credentials credentials) {
throw new UnsupportedOperationException();
}
@Override
public boolean updateCredentials(@NonNull Domain domain, @NonNull Credentials current,
@NonNull Credentials replacement) {
throw new UnsupportedOperationException();
}
@Nullable
@Override
public CredentialsStoreAction getStoreAction() {
return action;
}
/**
* Expose the store.
*/
@ExportedBean
public static class KubernetesCredentialsStoreAction extends CredentialsStoreAction {
private final KubernetesCredentialsStore store;
private KubernetesCredentialsStoreAction(KubernetesCredentialsStore store) {
this.store = store;
addIcons();
}
private void addIcons() {
IconSet.icons.addIcon(new Icon("icon-credentials-kubernetes-store icon-sm",
"kubernetes-credentials-provider/images/16x16/kubernetes-store.png",
Icon.ICON_SMALL_STYLE, IconType.PLUGIN));
IconSet.icons.addIcon(new Icon("icon-credentials-kubernetes-store icon-md",
"kubernetes-credentials-provider/images/24x24/kubernetes-store.png",
Icon.ICON_MEDIUM_STYLE, IconType.PLUGIN));
IconSet.icons.addIcon(new Icon("icon-credentials-kubernetes-store icon-lg",
"kubernetes-credentials-provider/images/32x32/kubernetes-store.png",
Icon.ICON_LARGE_STYLE, IconType.PLUGIN));
IconSet.icons.addIcon(new Icon("icon-credentials-kubernetes-store icon-xlg",
"kubernetes-credentials-provider/images/48x48/kubernetes-store.png",
Icon.ICON_XLARGE_STYLE, IconType.PLUGIN));
}
@Override
@NonNull
public CredentialsStore getStore() {
return store;
}
@Override
public String getIconFileName() {
return isVisible()
? "/plugin/kubernetes-credentials-provider/images/32x32/kubernetes-store.png"
: null;
}
@Override
public String getIconClassName() {
return isVisible()
? "icon-credentials-kubernetes-store"
: null;
}
@Override
public String getDisplayName() {
return "Kubernetes";
}
}
}