Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use consistent credentials name for source secret #33

Merged
merged 1 commit into from
Nov 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static synchronized String updateSourceCredentials(BuildConfig buildConfi
Secret sourceSecret = getOpenShiftClient().secrets().inNamespace(buildConfig.getMetadata().getNamespace()).withName(buildConfig.getSpec().getSource().getSourceSecret().getName()).get();
if (sourceSecret != null) {
Credentials creds = secretToCredentials(sourceSecret);
id = buildConfig.getMetadata().getNamespace() + "-" + buildConfig.getSpec().getSource().getSourceSecret().getName();
id = secretName(buildConfig.getMetadata().getNamespace(), buildConfig.getSpec().getSource().getSourceSecret().getName());
Credentials existingCreds = lookupCredentials(id);
final SecurityContext previousContext = ACL.impersonate(ACL.SYSTEM);
try {
Expand Down Expand Up @@ -77,17 +77,22 @@ Collections.<DomainRequirement> emptyList()
);
}

private static String secretName(String namespace, String name) {
return namespace + "-" + name;
}

private static Credentials secretToCredentials(Secret secret) {
String namespace = secret.getMetadata().getNamespace();
String name = secret.getMetadata().getName();
final Map<String, String> data = secret.getData();
final String secretName = secretName(namespace, name);
switch (secret.getType()) {
case OPENSHIFT_SECRETS_TYPE_OPAQUE:
String usernameData = data.get(OPENSHIFT_SECRETS_DATA_USERNAME);
String passwordData = data.get(OPENSHIFT_SECRETS_DATA_PASSWORD);
if (isNotBlank(usernameData) && isNotBlank(passwordData)) {
return newUsernamePasswordCredentials(
namespace + "-" + name,
secretName,
usernameData,
passwordData
);
Expand All @@ -96,7 +101,7 @@ private static Credentials secretToCredentials(Secret secret) {
String sshKeyData = data.get(OPENSHIFT_SECRETS_DATA_SSHPRIVATEKEY);
if (isNotBlank(sshKeyData)) {
return newSSHUserCredential(
namespace + "-" + name,
secretName,
data.get(OPENSHIFT_SECRETS_DATA_USERNAME),
sshKeyData
);
Expand All @@ -110,13 +115,13 @@ private static Credentials secretToCredentials(Secret secret) {
return null;
case OPENSHIFT_SECRETS_TYPE_BASICAUTH:
return newUsernamePasswordCredentials(
name + "-" + namespace,
secretName,
data.get(OPENSHIFT_SECRETS_DATA_USERNAME),
data.get(OPENSHIFT_SECRETS_DATA_PASSWORD)
);
case OPENSHIFT_SECRETS_TYPE_SSH:
return newSSHUserCredential(
name + "-" + namespace,
secretName,
data.get(OPENSHIFT_SECRETS_DATA_USERNAME),
data.get(OPENSHIFT_SECRETS_DATA_SSHPRIVATEKEY));
default:
Expand Down