Skip to content

Commit

Permalink
Use awsProfile in s3region and s3credentials (#57)
Browse files Browse the repository at this point in the history
Use awsProfile in s3region and s3credentials
  • Loading branch information
tsuyoshizawa authored and laughedelic committed Oct 17, 2017
1 parent 8b65986 commit 19e8ef4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
15 changes: 8 additions & 7 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ addSbtPlugin("ohnosequences" % "sbt-s3-resolver" % "<version>")
| Key | Type | Default |
|:-----------------|:---------------------------:|:--------------------------------|
| `s3credentials` | [`AWSCredentialsProvider`] | see [below](#credentials) |
| `awsProfile` | `String` | `"default"` |
| `awsProfile` | `Option[String]` | `None` |
| `s3region` | [`Region`] | `DefaultAwsRegionProviderChain` |
| `s3acl` | [`CannedAccessControlList`] | `PublicRead` |
| `s3storageClass` | [`StorageClass`] | `Standard` |
Expand Down Expand Up @@ -115,12 +115,13 @@ i.e. without using this plugin. Or if you're using it anyway, you can write:
The **default credentials** chain in this plugin is

```scala
awsProfile := "default"
awsProfile := Some("default")

s3credentials :=
new ProfileCredentialsProvider(awsProfile.value) |
new EnvironmentVariableCredentialsProvider() |
new InstanceProfileCredentialsProvider()
(awsProfile.value match {
case Some(profile) => new ProfileCredentialsProvider(profile)
case _ => new DefaultAWSCredentialsProviderChain()
})
```

* [`new ProfileCredentialsProvider(...)`](http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/ProfileCredentialsProvider.html) which loads credentials for an AWS profile config file
Expand All @@ -132,14 +133,14 @@ You can find other types of credentials providers in the [AWS Java SDK docs][`AW
If you have [different profiles](http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/credentials.html#credentials-file-format) in your `~/.aws/credentials` file, you can choose the one you need by setting

```scala
awsProfile := "bob"
awsProfile := Some("bob")
```

Or if you would like to use profile credentials and have your env vars override if they exist. This is handy if you have both a local dev environment as well as a CI environment where you need to use env vars.

```scala
s3credentials :=
new ProfileCredentialsProvider(awsProfile.value) |
new ProfileCredentialsProvider(awsProfile.value.orNull) |
new EnvironmentVariableCredentialsProvider()
```

Expand Down
25 changes: 17 additions & 8 deletions src/main/scala/SBTS3Resolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package ohnosequences.sbt
import sbt._
import Keys._
import java.util.Optional
import com.amazonaws.auth._, profile._
import com.amazonaws.regions.{ Region, Regions, RegionUtils, AwsRegionProvider }

import com.amazonaws.auth._
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.regions._
import com.amazonaws.services.s3.AmazonS3


Expand All @@ -21,6 +23,9 @@ object SbtS3Resolver extends AutoPlugin {
@deprecated("s3acl is now an Option. Please define it either Some(...) or None if you wish to inherit the bucket default.", "0.18.0")
implicit def acl2Option(acl: S3ACL): Option[S3ACL] = Some(acl)

@deprecated("awsProfile is now an Option. Please define it either Some(...).", "0.19.0")
implicit def awsProfile2Option(profile: String): Option[String] = Some(profile)

case class S3Resolver(
credentialsProvider: AWSCredentialsProvider,
overwrite: Boolean,
Expand Down Expand Up @@ -85,7 +90,7 @@ object SbtS3Resolver extends AutoPlugin {
implicit def fromProviderToAWSRegion(provider: AwsRegionProvider): Region = regionFromString(provider.getRegion())

// Adding setting keys
lazy val awsProfile = settingKey[String]("AWS credentials profile")
lazy val awsProfile = settingKey[Option[String]]("AWS credentials profile")
lazy val s3credentials = settingKey[AWSCredentialsProvider]("AWS credentials provider to access S3")
lazy val s3region = settingKey[Region]("AWS Region for your S3 resolvers")
lazy val s3overwrite = settingKey[Boolean]("Controls whether publishing resolver can overwrite artifacts")
Expand Down Expand Up @@ -129,12 +134,16 @@ object SbtS3Resolver extends AutoPlugin {

// Default settings
override def projectSettings: Seq[Setting[_]] = Seq(
awsProfile := "default",
awsProfile := None,
s3credentials :=
new ProfileCredentialsProvider(awsProfile.value) |
new EnvironmentVariableCredentialsProvider() |
InstanceProfileCredentialsProvider.getInstance(),
s3region := new com.amazonaws.regions.DefaultAwsRegionProviderChain(),
(awsProfile.value match {
case Some(profile) => new ProfileCredentialsProvider(profile)
case _ => new DefaultAWSCredentialsProviderChain()
}),
s3region := (awsProfile.value match {
case Some(profile) => new AwsProfileRegionProvider(profile)
case _ => new DefaultAwsRegionProviderChain()
}),
s3overwrite := isSnapshot.value,
s3sse := false,
s3acl := Some(com.amazonaws.services.s3.model.CannedAccessControlList.PublicRead),
Expand Down

0 comments on commit 19e8ef4

Please sign in to comment.