Skip to content

Commit

Permalink
Merge pull request #290 from sbernauer/sessioToken
Browse files Browse the repository at this point in the history
Added support for STS session token
  • Loading branch information
gilv authored Dec 13, 2021
2 parents 08243e6 + 449b22e commit 6f29f55
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ The following is the list of the configuration keys. `<service>` can be any valu
| --- | ------------ | ------------- |
|fs.cos.`<service>`.access.key | Access key | mandatory
|fs.cos.`<service>`.secret.key | Secret key | mandatory
|fs.cos.`<service>`.session.token | Session token | optional
|fs.cos.`<service>`.endpoint | COS endpoint | mandatory
|fs.cos.`<service>`.v2.signer.type | Signer type | optional

Expand All @@ -224,6 +225,10 @@ Example, configure `<service>` as `myCOS`:
<name>fs.cos.myCos.secret.key</name>
<value>SECRET KEY</value>
</property>
<property>
<name>fs.cos.myCos.session.token</name>
<value>SESSION TOKEN</value>
</property>
<property>
<name>fs.cos.myCos.v2.signer.type</name>
<value>false</value>
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/ibm/stocator/fs/cos/COSAPIClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.BasicSessionCredentials;
import com.amazonaws.event.ProgressEvent;
import com.amazonaws.event.ProgressListener;
import com.amazonaws.services.s3.S3ClientOptions;
Expand Down Expand Up @@ -138,6 +140,7 @@
import static com.ibm.stocator.fs.cos.COSConstants.AUTO_BUCKET_CREATE_COS_PROPERTY;
import static com.ibm.stocator.fs.cos.COSConstants.ACCESS_KEY_COS_PROPERTY;
import static com.ibm.stocator.fs.cos.COSConstants.SECRET_KEY_COS_PROPERTY;
import static com.ibm.stocator.fs.cos.COSConstants.SESSION_TOKEN_COS_PROPERTY;
import static com.ibm.stocator.fs.cos.COSConstants.BLOCK_SIZE_COS_PROPERTY;
import static com.ibm.stocator.fs.cos.COSConstants.COS_BUCKET_PROPERTY;
import static com.ibm.stocator.fs.cos.COSConstants.ENDPOINT_URL_COS_PROPERTY;
Expand Down Expand Up @@ -278,16 +281,21 @@ public void initiate(String scheme) throws IOException, ConfigurationParseExcept
// Define COS client
String accessKey = props.getProperty(ACCESS_KEY_COS_PROPERTY);
String secretKey = props.getProperty(SECRET_KEY_COS_PROPERTY);
String sessionToken = props.getProperty(SESSION_TOKEN_COS_PROPERTY);

if (accessKey == null) {
throw new ConfigurationParseException("Access KEY is empty. Please provide valid access key");
}
if (secretKey == null) {
throw new ConfigurationParseException("Secret KEY is empty. Please provide valid secret key");
}
AWSCredentials creds;
if (sessionToken == null) {
creds = new BasicAWSCredentials(accessKey, secretKey);
} else {
creds = new BasicSessionCredentials(accessKey, secretKey, sessionToken);
}

BasicAWSCredentials creds =
new BasicAWSCredentials(accessKey, secretKey);
ClientConfiguration clientConf = new ClientConfiguration();

int maxThreads = Utils.getInt(conf, FS_COS, FS_ALT_KEYS, MAX_THREADS,
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/ibm/stocator/fs/cos/COSConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class COSConstants {
public static final String SECRET_KEY = ".secret.key";
public static final String SECRET_KEY_COS_PROPERTY = FS_COS + SECRET_KEY;

public static final String SESSION_TOKEN = ".session.token";
public static final String SESSION_TOKEN_COS_PROPERTY = FS_COS + SESSION_TOKEN;

public static final String ENDPOINT_URL = ".endpoint";
public static final String ENDPOINT_URL_COS_PROPERTY = FS_COS + ENDPOINT_URL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import static com.ibm.stocator.fs.cos.COSConstants.ACCESS_KEY_COS_PROPERTY;
import static com.ibm.stocator.fs.cos.COSConstants.SECRET_KEY;
import static com.ibm.stocator.fs.cos.COSConstants.SECRET_KEY_COS_PROPERTY;
import static com.ibm.stocator.fs.cos.COSConstants.SESSION_TOKEN;
import static com.ibm.stocator.fs.cos.COSConstants.SESSION_TOKEN_COS_PROPERTY;
import static com.ibm.stocator.fs.cos.COSConstants.ENDPOINT_URL;
import static com.ibm.stocator.fs.cos.COSConstants.ENDPOINT_URL_COS_PROPERTY;
import static com.ibm.stocator.fs.cos.COSConstants.AUTO_BUCKET_CREATE;
Expand Down Expand Up @@ -90,6 +92,8 @@ public static Properties initialize(URI uri, Configuration conf,
ACCESS_KEY_COS_PROPERTY, false);
Utils.updateProperty(conf, prefix, altPrefix, SECRET_KEY, props,
SECRET_KEY_COS_PROPERTY, false);
Utils.updateProperty(conf, prefix, altPrefix, SESSION_TOKEN, props,
SESSION_TOKEN_COS_PROPERTY, false);
Utils.updateProperty(conf, prefix, altPrefix, ENDPOINT_URL, props,
ENDPOINT_URL_COS_PROPERTY, false);
Utils.updateProperty(conf, prefix, altPrefix, AUTO_BUCKET_CREATE, props,
Expand Down

0 comments on commit 6f29f55

Please sign in to comment.