Skip to content

Commit

Permalink
Merge pull request #1 from navya35/master
Browse files Browse the repository at this point in the history
Add possibility to use V2 signature
  • Loading branch information
gschueler authored Dec 19, 2018
2 parents 3205d1a + b6bd496 commit 0c03f91
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
44 changes: 37 additions & 7 deletions src/main/java/com/rundeck/plugins/aws/S3Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@
package com.rundeck.plugins.aws;


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;

import org.apache.log4j.Logger;

import com.amazonaws.AmazonClientException;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.RegionUtils;
Expand All @@ -35,10 +46,6 @@
import com.dtolabs.rundeck.core.resources.format.ResourceFormatParserException;
import com.dtolabs.rundeck.core.resources.format.UnsupportedFormatException;
import com.dtolabs.utils.Streams;
import org.apache.log4j.Logger;

import java.io.*;
import java.nio.file.Files;

public class S3Base implements AWSCredentials,ResourceModelSource, WriteableModelSource {

Expand All @@ -57,6 +64,7 @@ public class S3Base implements AWSCredentials,ResourceModelSource, WriteableMode
private boolean useRegion = false;
private String endpoint;
private boolean useEndpoint = false;
private boolean useSigV2 = false;

private String bucket;
private String filePath;
Expand Down Expand Up @@ -111,6 +119,10 @@ public void setS3ClientOptions(S3ClientOptions clientOptions){
this.useClientOptions = true;
}

public void setUseSigV2() {
this.useSigV2=true;
}

@Override
public INodeSet getNodes() throws ResourceModelSourceException {
InputStream remoteFile;
Expand Down Expand Up @@ -211,11 +223,29 @@ public long writeData(InputStream data) throws IOException, ResourceModelSourceE
private AmazonS3 getAmazonS3(){
if(null == amazonS3){
if(useKey) {
amazonS3 = new AmazonS3Client(this);
if (useSigV2) {
ClientConfiguration config = new ClientConfiguration();
config.setSignerOverride("S3SignerType");
amazonS3 = new AmazonS3Client(new BasicAWSCredentials(this.AWSAccessKeyId, this.AWSSecretKey), config);
} else {
amazonS3 = new AmazonS3Client(this);
}
}else if(useFile){
amazonS3 = new AmazonS3Client(cred);
if (useSigV2) {
ClientConfiguration opts = new ClientConfiguration();
opts.setSignerOverride("S3SignerType");
amazonS3 = new AmazonS3Client(cred, opts);
} else {
amazonS3 = new AmazonS3Client(cred);
}
}else{
amazonS3 = new AmazonS3Client();
if (useSigV2) {
ClientConfiguration opts = new ClientConfiguration();
opts.setSignerOverride("S3SignerType");
amazonS3 = new AmazonS3Client(opts);
} else {
amazonS3 = new AmazonS3Client();
}
}
if(useRegion) {
Region region = RegionUtils.getRegion(regionName);
Expand Down
30 changes: 22 additions & 8 deletions src/main/java/com/rundeck/plugins/aws/S3ResourceModelSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,30 @@
*/
package com.rundeck.plugins.aws;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import com.amazonaws.SDKGlobalConfiguration;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.s3.S3ClientOptions;
import com.dtolabs.rundeck.core.plugins.Plugin;
import com.dtolabs.rundeck.core.common.Framework;
import com.dtolabs.rundeck.core.plugins.configuration.*;
import com.dtolabs.rundeck.core.plugins.Plugin;
import com.dtolabs.rundeck.core.plugins.configuration.ConfigurationException;
import com.dtolabs.rundeck.core.plugins.configuration.Describable;
import com.dtolabs.rundeck.core.plugins.configuration.Description;
import com.dtolabs.rundeck.core.plugins.configuration.PropertyUtil;
import com.dtolabs.rundeck.core.plugins.configuration.StringRenderingConstants;
import com.dtolabs.rundeck.core.resources.ResourceModelSource;
import com.dtolabs.rundeck.core.resources.ResourceModelSourceFactory;
import com.dtolabs.rundeck.plugins.ServiceNameConstants;
import com.dtolabs.rundeck.plugins.util.DescriptionBuilder;


import java.io.File;
import java.io.IOException;
import java.util.*;

@Plugin(name = "aws-s3-source", service = ServiceNameConstants.ResourceModelSource)
public class S3ResourceModelSource implements ResourceModelSourceFactory,Describable {
public static final String PROVIDER_NAME = "aws-s3-source";
Expand All @@ -45,6 +53,7 @@ public class S3ResourceModelSource implements ResourceModelSourceFactory,Describ
public static final String REGION = "region";
public static final String ENDPOINT = "endpoint";
public static final String FORCEV4 = "forcev4";
public static final String USESIGV2 = "useSigV2";
public static final String PATHSTYLE = "pathstyle";

public static final String FILE = "file";
Expand Down Expand Up @@ -114,6 +123,9 @@ protected static Map<String, Object> getRenderOpt(String value, boolean secondar
.property(PropertyUtil.bool(FORCEV4, "Force Signature v4",
"Whether to force use of Signature Version 4 authentication. Default: false",
false,"false",null,renderingOptionsConnection))
.property(PropertyUtil.bool(USESIGV2, "Use Signature v2",
"Use of Signature Version 2 authentication for old container. Default: false",
false,"false",null,renderingOptionsConnection))
.property(PropertyUtil.bool(PATHSTYLE, "Use Path Style",
"Whether to access the Endpoint using `endpoint/bucket` style, default: false. The default will " +
"use DNS style `bucket.endpoint`, which may be incompatible with non-AWS S3-compatible services",
Expand Down Expand Up @@ -173,7 +185,9 @@ public ResourceModelSource createResourceModelSource(final Properties properties
if (Boolean.valueOf(properties.getProperty(WRITABLE))) {
s3.setWritable();
}

if (Boolean.valueOf(properties.getProperty(USESIGV2))) {
s3.setUseSigV2();
}

if(Boolean.valueOf(properties.getProperty(PATHSTYLE))) {
S3ClientOptions clientOptions = new S3ClientOptions();
Expand Down

0 comments on commit 0c03f91

Please sign in to comment.