forked from jenkinsci/amazon-ecr-plugin
-
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
0 parents
commit 43b32f0
Showing
13 changed files
with
846 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
### Maven template | ||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
pom.xml.next | ||
release.properties | ||
dependency-reduced-pom.xml | ||
buildNumber.properties | ||
.mvn/timing.properties | ||
### JetBrains template | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio | ||
|
||
*.iml | ||
|
||
## Directory-based project format: | ||
.idea/ | ||
# if you remove the above rule, at least ignore the following: | ||
|
||
# User-specific stuff: | ||
# .idea/workspace.xml | ||
# .idea/tasks.xml | ||
# .idea/dictionaries | ||
|
||
# Sensitive or high-churn files: | ||
# .idea/dataSources.ids | ||
# .idea/dataSources.xml | ||
# .idea/sqlDataSources.xml | ||
# .idea/dynamic.xml | ||
# .idea/uiDesigner.xml | ||
|
||
# Gradle: | ||
# .idea/gradle.xml | ||
# .idea/libraries | ||
|
||
# Mongo Explorer plugin: | ||
# .idea/mongoSettings.xml | ||
|
||
## File-based project format: | ||
*.ipr | ||
*.iws | ||
|
||
## Jenkins | ||
work/ | ||
|
||
# IntelliJ | ||
/out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
|
||
# Created by .ignore support plugin (hsz.mobi) |
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,8 @@ | ||
## Amazon ECR Plugin | ||
|
||
This plugin offer integration with Amazon ECR (Docker refistry) as a DockerRegistryToken source to convert | ||
Amazon Credentials into a Docker CLI Authentication Token. | ||
|
||
It uses ECR GetAuthorizationToken API to generate such a token | ||
|
||
As aws-java-sdk does not provide ECR support, a basic client has been implemented in com.amazonaws.services.ecs package. |
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,89 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ The MIT License | ||
~ | ||
~ Copyright (c) 2015, CloudBees, Inc. | ||
~ | ||
~ Permission is hereby granted, free of charge, to any person obtaining a copy | ||
~ of this software and associated documentation files (the "Software"), to deal | ||
~ in the Software without restriction, including without limitation the rights | ||
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
~ copies of the Software, and to permit persons to whom the Software is | ||
~ furnished to do so, subject to the following conditions: | ||
~ | ||
~ The above copyright notice and this permission notice shall be included in | ||
~ all copies or substantial portions of the Software. | ||
~ | ||
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
~ THE SOFTWARE. | ||
~ | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.cloudbees.jenkins.plugins</groupId> | ||
<artifactId>jenkins-plugins</artifactId> | ||
<version>39</version> | ||
</parent> | ||
|
||
<groupId>com.cloudbees.jenkins.plugins</groupId> | ||
<artifactId>amazon-ecr</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>hpi</packaging> | ||
|
||
<name>Amazon ECR Plugin</name> | ||
<description>Integrate Jenkin with Amazon ECR </description> | ||
|
||
|
||
<properties> | ||
<jenkins.version>1.609</jenkins.version> | ||
</properties> | ||
|
||
|
||
<licenses> | ||
<license> | ||
<name>MIT License</name> | ||
<url>http://opensource.org/licenses/MIT</url> | ||
</license> | ||
</licenses> | ||
|
||
<repositories> | ||
<repository> | ||
<id>repo.jenkins-ci.org</id> | ||
<url>http://repo.jenkins-ci.org/public/</url> | ||
</repository> | ||
</repositories> | ||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>repo.jenkins-ci.org</id> | ||
<url>http://repo.jenkins-ci.org/public/</url> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>credentials</artifactId> | ||
<version>1.24</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>aws-credentials</artifactId> | ||
<version>1.10</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>docker-commons</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
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 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2015, CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
package com.amazonaws.services.ecs; | ||
|
||
import com.amazonaws.AmazonClientException; | ||
import com.amazonaws.AmazonServiceException; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Nicolas De Loof</a> | ||
*/ | ||
public interface AmazonECR { | ||
|
||
GetAuthorizationTokenResult getAuthorizationToken(GetAuthorizationTokenRequest request) | ||
throws AmazonServiceException, AmazonClientException;; | ||
} |
155 changes: 155 additions & 0 deletions
155
src/main/java/com/amazonaws/services/ecs/AmazonECRClient.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,155 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2015, CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
package com.amazonaws.services.ecs; | ||
|
||
import com.amazonaws.AmazonClientException; | ||
import com.amazonaws.AmazonServiceException; | ||
import com.amazonaws.AmazonWebServiceClient; | ||
import com.amazonaws.AmazonWebServiceRequest; | ||
import com.amazonaws.AmazonWebServiceResponse; | ||
import com.amazonaws.ClientConfiguration; | ||
import com.amazonaws.Request; | ||
import com.amazonaws.Response; | ||
import com.amazonaws.auth.AWSCredentials; | ||
import com.amazonaws.auth.AWSCredentialsProvider; | ||
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; | ||
import com.amazonaws.handlers.HandlerChainFactory; | ||
import com.amazonaws.http.ExecutionContext; | ||
import com.amazonaws.http.HttpResponseHandler; | ||
import com.amazonaws.http.JsonErrorResponseHandler; | ||
import com.amazonaws.http.JsonResponseHandler; | ||
import com.amazonaws.internal.StaticCredentialsProvider; | ||
import com.amazonaws.services.ecs.model.DeleteClusterRequest; | ||
import com.amazonaws.services.ecs.model.DeleteClusterResult; | ||
import com.amazonaws.services.ecs.model.transform.ClientExceptionUnmarshaller; | ||
import com.amazonaws.services.ecs.model.transform.ClusterContainsContainerInstancesExceptionUnmarshaller; | ||
import com.amazonaws.services.ecs.model.transform.ClusterContainsServicesExceptionUnmarshaller; | ||
import com.amazonaws.services.ecs.model.transform.ClusterNotFoundExceptionUnmarshaller; | ||
import com.amazonaws.services.ecs.model.transform.DeleteClusterRequestMarshaller; | ||
import com.amazonaws.services.ecs.model.transform.DeleteClusterResultJsonUnmarshaller; | ||
import com.amazonaws.services.ecs.model.transform.InvalidParameterExceptionUnmarshaller; | ||
import com.amazonaws.services.ecs.model.transform.MissingVersionExceptionUnmarshaller; | ||
import com.amazonaws.services.ecs.model.transform.NoUpdateAvailableExceptionUnmarshaller; | ||
import com.amazonaws.services.ecs.model.transform.ServerExceptionUnmarshaller; | ||
import com.amazonaws.services.ecs.model.transform.ServiceNotActiveExceptionUnmarshaller; | ||
import com.amazonaws.services.ecs.model.transform.ServiceNotFoundExceptionUnmarshaller; | ||
import com.amazonaws.services.ecs.model.transform.UpdateInProgressExceptionUnmarshaller; | ||
import com.amazonaws.transform.JsonErrorUnmarshaller; | ||
import com.amazonaws.transform.JsonUnmarshallerContext; | ||
import com.amazonaws.transform.Unmarshaller; | ||
import com.amazonaws.util.AWSRequestMetrics; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Nicolas De Loof</a> | ||
*/ | ||
public class AmazonECRClient extends AmazonWebServiceClient implements AmazonECR { | ||
|
||
/** Provider for AWS credentials. */ | ||
private AWSCredentialsProvider awsCredentialsProvider; | ||
|
||
private static final Log log = LogFactory.getLog(AmazonECS.class); | ||
|
||
/** | ||
* List of exception unmarshallers for all AmazonECS exceptions. | ||
*/ | ||
protected List<JsonErrorUnmarshaller> jsonErrorUnmarshallers; | ||
|
||
public AmazonECRClient(AWSCredentials awsCredentials, ClientConfiguration clientConfiguration) { | ||
super(clientConfiguration); | ||
|
||
this.awsCredentialsProvider = new StaticCredentialsProvider(awsCredentials); | ||
|
||
init(); | ||
} | ||
|
||
private void init() { | ||
jsonErrorUnmarshallers = new ArrayList<JsonErrorUnmarshaller>(); | ||
jsonErrorUnmarshallers.add(new ClusterContainsContainerInstancesExceptionUnmarshaller()); | ||
jsonErrorUnmarshallers.add(new ServerExceptionUnmarshaller()); | ||
jsonErrorUnmarshallers.add(new MissingVersionExceptionUnmarshaller()); | ||
jsonErrorUnmarshallers.add(new ClusterContainsServicesExceptionUnmarshaller()); | ||
jsonErrorUnmarshallers.add(new ServiceNotActiveExceptionUnmarshaller()); | ||
jsonErrorUnmarshallers.add(new ClientExceptionUnmarshaller()); | ||
jsonErrorUnmarshallers.add(new UpdateInProgressExceptionUnmarshaller()); | ||
jsonErrorUnmarshallers.add(new ClusterNotFoundExceptionUnmarshaller()); | ||
jsonErrorUnmarshallers.add(new InvalidParameterExceptionUnmarshaller()); | ||
jsonErrorUnmarshallers.add(new NoUpdateAvailableExceptionUnmarshaller()); | ||
jsonErrorUnmarshallers.add(new ServiceNotFoundExceptionUnmarshaller()); | ||
|
||
jsonErrorUnmarshallers.add(new JsonErrorUnmarshaller()); | ||
|
||
// calling this.setEndPoint(...) will also modify the signer accordingly | ||
this.setEndpoint("ecr.us-east-1.amazonaws.com"); | ||
|
||
HandlerChainFactory chainFactory = new HandlerChainFactory(); | ||
requestHandler2s.addAll(chainFactory.newRequestHandlerChain( | ||
"/com/amazonaws/services/ecr/request.handlers")); | ||
requestHandler2s.addAll(chainFactory.newRequestHandler2Chain( | ||
"/com/amazonaws/services/ecr/request.handler2s")); | ||
} | ||
|
||
@Override | ||
public GetAuthorizationTokenResult getAuthorizationToken(GetAuthorizationTokenRequest getAuthorizationTokenRequest) throws AmazonServiceException, AmazonClientException { | ||
ExecutionContext executionContext = createExecutionContext(getAuthorizationTokenRequest); | ||
Request<GetAuthorizationTokenRequest> request = null; | ||
Response<GetAuthorizationTokenResult> response = null; | ||
|
||
request = new GetAuthorizationTokenRequestMarshaller().marshall(super.beforeMarshalling(getAuthorizationTokenRequest)); | ||
|
||
Unmarshaller<GetAuthorizationTokenResult, JsonUnmarshallerContext> unmarshaller = | ||
new GetAuthorizationTokenResultJsonUnmarshaller(); | ||
JsonResponseHandler<GetAuthorizationTokenResult> responseHandler = | ||
new JsonResponseHandler<GetAuthorizationTokenResult>(unmarshaller); | ||
|
||
response = invoke(request, responseHandler, executionContext); | ||
|
||
return response.getAwsResponse(); | ||
} | ||
|
||
private <X, Y extends AmazonWebServiceRequest> Response<X> invoke(Request<Y> request, | ||
HttpResponseHandler<AmazonWebServiceResponse<X>> responseHandler, | ||
ExecutionContext executionContext) { | ||
request.setEndpoint(endpoint); | ||
request.setTimeOffset(timeOffset); | ||
|
||
AWSCredentials credentials = awsCredentialsProvider.getCredentials(); | ||
|
||
AmazonWebServiceRequest originalRequest = request.getOriginalRequest(); | ||
if (originalRequest != null && originalRequest.getRequestCredentials() != null) { | ||
credentials = originalRequest.getRequestCredentials(); | ||
} | ||
|
||
executionContext.setCredentials(credentials); | ||
JsonErrorResponseHandler errorResponseHandler = new JsonErrorResponseHandler(jsonErrorUnmarshallers); | ||
Response<X> result = client.execute(request, responseHandler, errorResponseHandler, executionContext); | ||
return result; | ||
} | ||
} |
Oops, something went wrong.