use of org.eclipse.jkube.kit.build.api.auth.AuthConfig in project jkube by eclipse.
the class KubernetesConfigAuthUtilTest method readKubeConfigAuth_withNoKubeConfig.
@Test
public void readKubeConfigAuth_withNoKubeConfig() {
executeWithTempSystemUserHome(() -> {
final AuthConfig result = readKubeConfigAuth();
assertThat(result).isNull();
});
}
use of org.eclipse.jkube.kit.build.api.auth.AuthConfig in project jkube by eclipse.
the class KubernetesConfigAuthUtilTest method readKubeConfigAuth_withValidKubeConfig.
@Test
public void readKubeConfigAuth_withValidKubeConfig() throws IOException {
withKubeConfig("kube-config.yaml");
executeWithTempSystemUserHome(() -> {
final AuthConfig result = readKubeConfigAuth();
assertThat(result).hasFieldOrPropertyWithValue("username", "user").hasFieldOrPropertyWithValue("password", "the-token");
});
}
use of org.eclipse.jkube.kit.build.api.auth.AuthConfig in project jkube by eclipse.
the class JibBuildService method getRegistryCredentials.
static Credential getRegistryCredentials(RegistryConfig registryConfig, boolean isPush, ImageConfiguration imageConfiguration, KitLogger log) throws IOException {
String registry;
if (isPush) {
registry = EnvUtil.firstRegistryOf(new ImageName(imageConfiguration.getName()).getRegistry(), imageConfiguration.getRegistry(), registryConfig.getRegistry());
} else {
registry = EnvUtil.firstRegistryOf(new ImageName(getBaseImage(imageConfiguration)).getRegistry(), registryConfig.getRegistry());
}
if (registry == null || DEFAULT_DOCKER_REGISTRIES.contains(registry)) {
// Let's assume docker is default registry.
registry = DOCKER_LOGIN_DEFAULT_REGISTRY;
}
AuthConfigFactory authConfigFactory = new AuthConfigFactory(log);
AuthConfig standardAuthConfig = authConfigFactory.createAuthConfig(isPush, registryConfig.isSkipExtendedAuth(), registryConfig.getAuthConfig(), registryConfig.getSettings(), null, registry, registryConfig.getPasswordDecryptionMethod());
Credential credentials = null;
if (standardAuthConfig != null) {
credentials = Credential.from(standardAuthConfig.getUsername(), standardAuthConfig.getPassword());
}
return credentials;
}
use of org.eclipse.jkube.kit.build.api.auth.AuthConfig in project jkube by eclipse.
the class OpenshiftBuildService method checkOrCreatePullSecret.
private boolean checkOrCreatePullSecret(OpenShiftClient client, KubernetesListBuilder builder, String pullSecretName, ImageConfiguration imageConfig) throws Exception {
BuildConfiguration buildConfig = imageConfig.getBuildConfiguration();
String fromImage;
if (buildConfig.isDockerFileMode()) {
fromImage = extractBaseFromDockerfile(jKubeConfiguration, buildConfig);
} else {
fromImage = extractBaseFromConfiguration(buildConfig);
}
String pullRegistry = EnvUtil.firstRegistryOf(new ImageName(fromImage).getRegistry(), jKubeConfiguration.getRegistryConfig().getRegistry(), jKubeConfiguration.getRegistryConfig().getRegistry());
if (pullRegistry != null) {
RegistryConfig registryConfig = jKubeConfiguration.getRegistryConfig();
final AuthConfig authConfig = new AuthConfigFactory(log).createAuthConfig(false, registryConfig.isSkipExtendedAuth(), registryConfig.getAuthConfig(), registryConfig.getSettings(), null, pullRegistry, registryConfig.getPasswordDecryptionMethod());
final Secret secret = Optional.ofNullable(pullSecretName).map(psn -> client.secrets().inNamespace(applicableOpenShiftNamespace).withName(psn).get()).orElse(null);
if (secret != null) {
log.info("Adding to Secret %s", pullSecretName);
return updateSecret(client, pullSecretName, secret.getData());
}
if (authConfig != null) {
JsonObject auths = new JsonObject();
JsonObject auth = new JsonObject();
JsonObject item = new JsonObject();
String authString = authConfig.getUsername() + ":" + authConfig.getPassword();
item.add("auth", new JsonPrimitive(Base64.encodeBase64String(authString.getBytes(StandardCharsets.UTF_8))));
auth.add(pullRegistry, item);
auths.add("auths", auth);
String credentials = Base64.encodeBase64String(auths.toString().getBytes(StandardCharsets.UTF_8));
Map<String, String> data = new HashMap<>();
data.put(".dockerconfigjson", credentials);
log.info("Creating Secret");
builder.addNewSecretItem().withNewMetadata().withName(pullSecretName).endMetadata().withData(data).withType("kubernetes.io/dockerconfigjson").endSecretItem();
return true;
}
}
return false;
}
use of org.eclipse.jkube.kit.build.api.auth.AuthConfig in project jkube by eclipse.
the class AwsSdkAuthConfigFactoryTest method reflectionWorksForSessionCredentials.
@Test
public void reflectionWorksForSessionCredentials() throws Exception {
String accessKey = randomUUID().toString();
String secretKey = randomUUID().toString();
String sessionToken = randomUUID().toString();
Object credentials = new Object();
new Expectations() {
{
awsSdkHelper.getCredentialsFromDefaultAWSCredentialsProviderChain();
result = credentials;
awsSdkHelper.getAWSAccessKeyIdFromCredentials(any);
result = accessKey;
awsSdkHelper.getAwsSecretKeyFromCredentials(any);
result = secretKey;
awsSdkHelper.getSessionTokenFromCrendentials(any);
result = sessionToken;
}
};
AuthConfig authConfig = objectUnderTest.createAuthConfig();
assertNotNull(authConfig);
assertEquals(accessKey, authConfig.getUsername());
assertEquals(secretKey, authConfig.getPassword());
assertEquals(sessionToken, authConfig.getAuth());
assertNull(authConfig.getIdentityToken());
}
Aggregations