Skip to content

Commit

Permalink
Merge pull request #50 from andresrc/JENKINS-53101
Browse files Browse the repository at this point in the history
[JENKINS-53101] Add Declarative credentials handler for AWS creds
  • Loading branch information
andresrc committed Feb 24, 2019
2 parents 294c62f + 5e667f5 commit 7016341
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 5 deletions.
58 changes: 53 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.25</version>
<version>3.37</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -57,16 +57,36 @@
<properties>
<revision>1.25</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>1.625.1</jenkins.version>
<java.level>7</java.level>
<jenkins.version>2.73.3</jenkins.version>
<java.level>8</java.level>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.14</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.16</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- plugin dependencies -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>2.1.16</version>
<version>2.1.18</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -76,7 +96,35 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials-binding</artifactId>
<version>1.7</version>
<version>1.16</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jackson2-api</artifactId>
<version>2.8.11.3</version>
</dependency>
<dependency>
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-model-extensions</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<version>1.53</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.17</version>
</dependency>
<!-- jenkins dependencies -->
<!-- test dependencies -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* The MIT License
*
* Copyright (c) 2018, 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.cloudbees.jenkins.plugins.awscredentials;

import com.cloudbees.plugins.credentials.common.StandardCredentials;
import hudson.Extension;
import org.jenkinsci.plugins.credentialsbinding.MultiBinding;
import org.jenkinsci.plugins.pipeline.modeldefinition.model.CredentialsBindingHandler;

import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Extension
public class AWSDeclarativeCredentialsHandler extends CredentialsBindingHandler<AmazonWebServicesCredentials> {

@Nonnull
@Override
public List<MultiBinding<AmazonWebServicesCredentials>> toBindings(String varName, String credentialsId) {
return Collections.singletonList(new AmazonWebServicesCredentialsBinding(varName + "_AWS_KEY_ID",
varName + "_AWS_SECRET",
credentialsId));
}

@Nonnull
@Override
public Class<? extends StandardCredentials> type() {
return AmazonWebServicesCredentials.class;
}

@Nonnull
@Override
public List<Map<String, Object>> getWithCredentialsParameters(String credentialsId) {
Map<String, Object> map = new HashMap<>();
map.put("$class", AmazonWebServicesCredentialsBinding.class.getName());
map.put("keyIdVariable", new EnvVarResolver("%s_AWS_KEY_ID"));
map.put("secretVariable", new EnvVarResolver("%s_AWS_SECRET"));
map.put("credentialsId", credentialsId);
return Collections.singletonList(map);
}
}

0 comments on commit 7016341

Please sign in to comment.