forked from kubernetes-client/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf764a4
commit ac7c1b5
Showing
7 changed files
with
121 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
util/src/main/java/io/kubernetes/client/util/credentials/ApiKeyCredentialProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.kubernetes.client.util.credentials; | ||
|
||
import io.kubernetes.client.ApiClient; | ||
|
||
public class ApiKeyCredentialProvider implements CredentialProvider { | ||
|
||
private String accessToken; | ||
|
||
public ApiKeyCredentialProvider(final String accessToken) { | ||
this.accessToken = accessToken; | ||
} | ||
|
||
@Override public void provide(ApiClient client) { | ||
client.setApiKeyPrefix("Bearer"); | ||
client.setApiKey(accessToken); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...in/java/io/kubernetes/client/util/credentials/CertificateAuthorityCredentialProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.kubernetes.client.util.credentials; | ||
|
||
import io.kubernetes.client.ApiClient; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.InputStream; | ||
import javax.net.ssl.KeyManager; | ||
import org.apache.commons.codec.binary.Base64; | ||
import org.apache.log4j.Logger; | ||
|
||
public class CertificateAuthorityCredentialProvider implements CredentialProvider { | ||
private static final Logger log = Logger.getLogger(CertificateAuthorityCredentialProvider.class); | ||
|
||
private KeyManager[] keyManagers; | ||
private InputStream inputStream; | ||
|
||
public CertificateAuthorityCredentialProvider(final KeyManager[] keyManagers, final File caFile) { | ||
this.keyManagers = keyManagers; | ||
try { | ||
this.inputStream = new FileInputStream(caFile); | ||
} catch(final FileNotFoundException e) { | ||
log.error("Unable to find Certificate Authority file", e); | ||
} | ||
} | ||
|
||
public CertificateAuthorityCredentialProvider(final KeyManager[] keyManagers, final String caData) { | ||
this.keyManagers = keyManagers; | ||
this.inputStream = new ByteArrayInputStream(Base64.decodeBase64(caData)); | ||
} | ||
|
||
@Override public void provide(ApiClient client) { | ||
client.setSslCaCert(inputStream); | ||
client.setKeyManagers(keyManagers); | ||
client.setVerifyingSsl(true); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
util/src/main/java/io/kubernetes/client/util/credentials/CredentialProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.kubernetes.client.util.credentials; | ||
|
||
import io.kubernetes.client.ApiClient; | ||
|
||
public interface CredentialProvider { | ||
|
||
void provide(final ApiClient client); | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
util/src/main/java/io/kubernetes/client/util/credentials/KeyManagerCredentialProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.kubernetes.client.util.credentials; | ||
|
||
import io.kubernetes.client.ApiClient; | ||
import javax.net.ssl.KeyManager; | ||
|
||
public class KeyManagerCredentialProvider implements CredentialProvider{ | ||
|
||
private KeyManager[] keyManagers; | ||
|
||
public KeyManagerCredentialProvider(final KeyManager[] keyManagers) { | ||
this.keyManagers = keyManagers; | ||
} | ||
|
||
@Override public void provide(ApiClient client) { | ||
client.setKeyManagers(keyManagers); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
util/src/main/java/io/kubernetes/client/util/credentials/UsernamePasswordProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.kubernetes.client.util.credentials; | ||
|
||
import io.kubernetes.client.ApiClient; | ||
import java.nio.charset.Charset; | ||
import okio.ByteString; | ||
|
||
public class UsernamePasswordProvider implements CredentialProvider { | ||
private final String username; | ||
private final String password; | ||
|
||
public UsernamePasswordProvider(final String username, final String password) { | ||
this.username = username; | ||
this.password = password; | ||
} | ||
|
||
@Override public void provide(ApiClient client) { | ||
final String usernameAndPassword = username + ":" + password; | ||
client.setApiKeyPrefix("Basic"); | ||
client.setApiKey(ByteString.of(usernameAndPassword.getBytes(Charset.forName("ISO-8859-1"))).base64()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters