diff --git a/README.md b/README.md index e361bf4a..a02699a1 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,7 @@ The following is the list of the configuration keys. `` can be any valu | --- | ------------ | ------------- | |fs.cos.``.access.key | Access key | mandatory |fs.cos.``.secret.key | Secret key | mandatory +|fs.cos.``.session.token | Session token | optional |fs.cos.``.endpoint | COS endpoint | mandatory |fs.cos.``.v2.signer.type | Signer type | optional @@ -224,6 +225,10 @@ Example, configure `` as `myCOS`: fs.cos.myCos.secret.key SECRET KEY + + fs.cos.myCos.session.token + SESSION TOKEN + fs.cos.myCos.v2.signer.type false diff --git a/src/main/java/com/ibm/stocator/fs/cos/COSAPIClient.java b/src/main/java/com/ibm/stocator/fs/cos/COSAPIClient.java index f74b24d6..dd1e8f97 100644 --- a/src/main/java/com/ibm/stocator/fs/cos/COSAPIClient.java +++ b/src/main/java/com/ibm/stocator/fs/cos/COSAPIClient.java @@ -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; @@ -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; @@ -278,6 +281,7 @@ 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"); @@ -285,9 +289,13 @@ public void initiate(String scheme) throws IOException, ConfigurationParseExcept 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, diff --git a/src/main/java/com/ibm/stocator/fs/cos/COSConstants.java b/src/main/java/com/ibm/stocator/fs/cos/COSConstants.java index 36455666..de6f8b4e 100644 --- a/src/main/java/com/ibm/stocator/fs/cos/COSConstants.java +++ b/src/main/java/com/ibm/stocator/fs/cos/COSConstants.java @@ -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; diff --git a/src/main/java/com/ibm/stocator/fs/cos/ConfigurationHandler.java b/src/main/java/com/ibm/stocator/fs/cos/ConfigurationHandler.java index 4ca3bb38..42daa566 100755 --- a/src/main/java/com/ibm/stocator/fs/cos/ConfigurationHandler.java +++ b/src/main/java/com/ibm/stocator/fs/cos/ConfigurationHandler.java @@ -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; @@ -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,