src/main/scala/s3/website/model/Config.scala in s3_website-3.0.0 vs src/main/scala/s3/website/model/Config.scala in s3_website-3.1.0

- old
+ new

@@ -6,15 +6,16 @@ import scala.util.matching.Regex import scala.util.{Failure, Try} import scala.collection.JavaConversions._ import s3.website.Ruby.rubyRuntime import s3.website._ -import com.amazonaws.auth.{AWSCredentialsProvider, BasicAWSCredentials, DefaultAWSCredentialsProviderChain} +import com.amazonaws.auth.{AWSCredentialsProvider, BasicAWSCredentials, BasicSessionCredentials, DefaultAWSCredentialsProviderChain} case class Config( s3_id: Option[String], // If undefined, use IAM Roles (http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-roles.html) s3_secret: Option[String], // If undefined, use IAM Roles (http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-roles.html) + session_token: Option[String], // If defined, the AWS Security Token Service session token (http://docs.aws.amazon.com/STS/latest/APIReference/Welcome.html) s3_bucket: String, s3_endpoint: S3Endpoint, site: Option[String], max_age: Option[Either[Int, S3KeyGlob[Int]]], cache_control: Option[Either[String, S3KeyGlob[String]]], @@ -34,13 +35,22 @@ ) object Config { def awsCredentials(config: Config): AWSCredentialsProvider = { - val credentialsFromConfigFile = for { - s3_id <- config.s3_id - s3_secret <- config.s3_secret - } yield new BasicAWSCredentials(s3_id, s3_secret) + val credentialsFromConfigFile = + if (config.session_token.isEmpty) { + for { + s3_id <- config.s3_id + s3_secret <- config.s3_secret + } yield new BasicAWSCredentials(s3_id, s3_secret) + } else { + for { + s3_id <- config.s3_id + s3_secret <- config.s3_secret + session_token <- config.session_token + } yield new BasicSessionCredentials(s3_id, s3_secret, session_token) + } credentialsFromConfigFile.fold(new DefaultAWSCredentialsProviderChain: AWSCredentialsProvider)(credentials => new AWSCredentialsProvider { def getCredentials = credentials def refresh() = {} } \ No newline at end of file