Skip to content

Commit 310155b

Browse files
committed
More meaningful credential names
They apply to kubernetes, not just openshift OpenShiftTokenCredentialImpl is not needed as there is StringCredentialsImpl
1 parent 1c89b78 commit 310155b

File tree

4 files changed

+34
-54
lines changed

4 files changed

+34
-54
lines changed

pom.xml

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<groupId>org.jenkinsci.plugins</groupId>
1010
<artifactId>kubernetes-credentials</artifactId>
11-
<version>0.2.1-SNAPSHOT</version>
11+
<version>0.3.0-SNAPSHOT</version>
1212
<name>Kubernetes Credentials Plugin</name>
1313
<description>Common classes for Kubernetes credentials</description>
1414
<packaging>hpi</packaging>
@@ -47,6 +47,7 @@
4747

4848
<!-- jenkins plugins versions -->
4949
<jenkins-credentials.version>2.1.7</jenkins-credentials.version>
50+
<jenkins-plain-credentials.version>1.3</jenkins-plain-credentials.version>
5051

5152
</properties>
5253

@@ -70,6 +71,11 @@
7071
<artifactId>credentials</artifactId>
7172
<version>${jenkins-credentials.version}</version>
7273
</dependency>
74+
<dependency>
75+
<groupId>org.jenkins-ci.plugins</groupId>
76+
<artifactId>plain-credentials</artifactId>
77+
<version>${jenkins-plain-credentials.version}</version>
78+
</dependency>
7379
</dependencies>
7480

7581
<!-- just to fix enforcer RequireUpperBoundDeps -->
+3-3
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
/**
4444
* @author <a href="mailto:[email protected]">Nicolas De Loof</a>
4545
*/
46-
public class OpenShiftBearerTokenCredentialImpl extends UsernamePasswordCredentialsImpl implements TokenProducer {
46+
public class BearerTokenCredentialImpl extends UsernamePasswordCredentialsImpl implements TokenProducer {
4747

4848
private static final long serialVersionUID = 6031616605797622926L;
4949

5050
private transient AtomicReference<Token> token = new AtomicReference<Token>();
5151

5252
@DataBoundConstructor
53-
public OpenShiftBearerTokenCredentialImpl(CredentialsScope scope, String id, String description, String username, String password) {
53+
public BearerTokenCredentialImpl(CredentialsScope scope, String id, String description, String username, String password) {
5454
super(scope, id, description, username, password);
5555
}
5656

@@ -143,7 +143,7 @@ public static class DescriptorImpl extends BaseStandardCredentialsDescriptor {
143143

144144
@Override
145145
public String getDisplayName() {
146-
return "OpenShift Username and Password";
146+
return "Kubernetes Username and Password";
147147
}
148148
}
149149

Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package org.jenkinsci.plugins.kubernetes.credentials;
22

3+
import java.io.File;
4+
import java.io.IOException;
5+
6+
import org.apache.commons.io.FileUtils;
7+
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
8+
import org.kohsuke.stapler.DataBoundConstructor;
9+
310
import com.cloudbees.plugins.credentials.CredentialsScope;
411
import com.cloudbees.plugins.credentials.impl.BaseStandardCredentials;
512

613
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
714
import hudson.Extension;
8-
import org.apache.commons.io.FileUtils;
9-
import org.kohsuke.stapler.DataBoundConstructor;
10-
11-
import java.io.File;
12-
import java.io.IOException;
15+
import hudson.util.Secret;
1316

1417
/**
1518
* Read the OAuth bearer token from service account file provisioned by kubernetes
@@ -18,25 +21,35 @@
1821
*
1922
* @author <a href="mailto:[email protected]">Nicolas De Loof</a>
2023
*/
21-
public class ServiceAccountCredential extends BaseStandardCredentials implements TokenProducer {
24+
public class FileSystemServiceAccountCredential extends BaseStandardCredentials
25+
implements TokenProducer, StringCredentials {
26+
27+
private static final long serialVersionUID = -2222994164073756041L;
2228

2329
private static final String SERVICEACCOUNT_TOKEN_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/token";
2430

2531
@DataBoundConstructor
26-
public ServiceAccountCredential(CredentialsScope scope, String id, String description) {
32+
public FileSystemServiceAccountCredential(CredentialsScope scope, String id, String description) {
2733
super(scope, id, description);
2834
}
2935

3036
@Override
3137
@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
32-
public String getToken(String serviceAddress, String caCertData, boolean skipTlsVerify) {
38+
public Secret getSecret() {
3339
try {
34-
return FileUtils.readFileToString(new File(SERVICEACCOUNT_TOKEN_PATH));
40+
return Secret.fromString(FileUtils.readFileToString(new File(SERVICEACCOUNT_TOKEN_PATH)));
3541
} catch (IOException e) {
36-
return null;
42+
return Secret.fromString(null);
3743
}
3844
}
3945

46+
@Override
47+
@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
48+
@Deprecated
49+
public String getToken(String serviceAddress, String caCertData, boolean skipTlsVerify) {
50+
return getSecret().getPlainText();
51+
}
52+
4053
@Extension(optional = true)
4154
public static class DescriptorImpl extends BaseStandardCredentialsDescriptor {
4255

@@ -52,4 +65,5 @@ public String getDisplayName() {
5265
return "Kubernetes Service Account";
5366
}
5467
}
68+
5569
}

src/main/java/org/jenkinsci/plugins/kubernetes/credentials/OpenShiftTokenCredentialImpl.java

-40
This file was deleted.

0 commit comments

Comments
 (0)