forked from eclipse-jkube/jkube
-
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.
Fetch AWS Credentials from AWS SDK/Environment variables
Add support in AuthConfigFactory to retrieve credentials from different mechanisms for AWS. Port of fabric8io/docker-maven-plugin#1311 Port of fabric8io/docker-maven-plugin#1310 Related to eclipse-jkube#702 Signed-off-by: Rohan Kumar <rohaan@redhat.com>
- Loading branch information
1 parent
32be156
commit f7ada40
Showing
8 changed files
with
633 additions
and
16 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
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
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
64 changes: 64 additions & 0 deletions
64
...ain/java/org/eclipse/jkube/kit/build/service/docker/auth/ecr/AwsSdkAuthConfigFactory.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,64 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.build.service.docker.auth.ecr; | ||
|
||
import org.eclipse.jkube.kit.build.api.auth.AuthConfig; | ||
import org.eclipse.jkube.kit.common.KitLogger; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.net.URLEncoder; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
public class AwsSdkAuthConfigFactory { | ||
|
||
private final KitLogger log; | ||
private AwsSdkHelper awsSdkHelper; | ||
|
||
public AwsSdkAuthConfigFactory(KitLogger log, AwsSdkHelper awsSdkHelper) { | ||
this.log = log; | ||
this.awsSdkHelper = awsSdkHelper; | ||
} | ||
|
||
public AuthConfig createAuthConfig() { | ||
try { | ||
Object credentials = awsSdkHelper.getCredentialsFromDefaultAWSCredentialsProviderChain(); | ||
if (credentials == null) { | ||
return null; | ||
} | ||
|
||
return new AuthConfig( | ||
awsSdkHelper.getAWSAccessKeyIdFromCredentials(credentials), | ||
awsSdkHelper.getAwsSecretKeyFromCredentials(credentials), | ||
"none", | ||
awsSdkHelper.getSessionTokenFromCrendentials(credentials) | ||
); | ||
} catch (Exception t) { | ||
String issueTitle = null; | ||
try { | ||
issueTitle = URLEncoder.encode("Failed calling AWS SDK: " + t.getMessage(), UTF_8.name()); | ||
} catch (UnsupportedEncodingException ignore) { | ||
} | ||
log.warn("Failed to fetch AWS credentials: %s", t.getMessage()); | ||
if (t.getCause() != null) { | ||
log.warn("Caused by: %s", t.getCause().getMessage()); | ||
} | ||
log.warn("Please report a bug at https://github.com/eclipse/jkube/issues/new?%s", | ||
issueTitle == null ? "" : "title=?" + issueTitle); | ||
log.warn("%s", t); | ||
return null; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.