Skip to content

Commit

Permalink
initial prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
ndeloof committed Dec 16, 2015
0 parents commit 43b32f0
Show file tree
Hide file tree
Showing 13 changed files with 846 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .gitignore
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)
8 changes: 8 additions & 0 deletions README.md
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.
89 changes: 89 additions & 0 deletions pom.xml
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>
38 changes: 38 additions & 0 deletions src/main/java/com/amazonaws/services/ecs/AmazonECR.java
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 src/main/java/com/amazonaws/services/ecs/AmazonECRClient.java
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;
}
}
Loading

0 comments on commit 43b32f0

Please sign in to comment.