From 1f405e6ceee7e1522c7dbda26302f6566839457c Mon Sep 17 00:00:00 2001 From: Tsuyoshi Yoshizawa Date: Sun, 15 Oct 2017 04:49:44 +0900 Subject: [PATCH 1/8] Fix to pass awsProfile to AwsRegionProviderChain --- src/main/scala/SBTS3Resolver.scala | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/scala/SBTS3Resolver.scala b/src/main/scala/SBTS3Resolver.scala index 6f0116e..cb01f78 100644 --- a/src/main/scala/SBTS3Resolver.scala +++ b/src/main/scala/SBTS3Resolver.scala @@ -3,8 +3,11 @@ 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.internal.AwsProfileNameLoader +import profile._ +import com.amazonaws.regions._ import com.amazonaws.services.s3.AmazonS3 @@ -129,12 +132,12 @@ object SbtS3Resolver extends AutoPlugin { // Default settings override def projectSettings: Seq[Setting[_]] = Seq( - awsProfile := "default", + awsProfile := AwsProfileNameLoader.DEFAULT_PROFILE_NAME, s3credentials := new ProfileCredentialsProvider(awsProfile.value) | new EnvironmentVariableCredentialsProvider() | InstanceProfileCredentialsProvider.getInstance(), - s3region := new com.amazonaws.regions.DefaultAwsRegionProviderChain(), + s3region := new SbtS3ResolverAwsRegionProviderChain(awsProfile.value), s3overwrite := isSnapshot.value, s3sse := false, s3acl := Some(com.amazonaws.services.s3.model.CannedAccessControlList.PublicRead), @@ -157,4 +160,11 @@ object SbtS3Resolver extends AutoPlugin { } ) + class SbtS3ResolverAwsRegionProviderChain(profile: String) extends AwsRegionProviderChain( + new AwsEnvVarOverrideRegionProvider(), + new AwsSystemPropertyRegionProvider(), + new AwsProfileRegionProvider(profile), + new InstanceMetadataRegionProvider() + ) + } From 9f5494d0e84fb28c5d160e6afbc56b84946c3249 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Yoshizawa Date: Mon, 16 Oct 2017 14:19:42 +0900 Subject: [PATCH 2/8] Optional for awsProfile --- src/main/scala/SBTS3Resolver.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/scala/SBTS3Resolver.scala b/src/main/scala/SBTS3Resolver.scala index cb01f78..54b41eb 100644 --- a/src/main/scala/SBTS3Resolver.scala +++ b/src/main/scala/SBTS3Resolver.scala @@ -88,7 +88,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") @@ -132,12 +132,12 @@ object SbtS3Resolver extends AutoPlugin { // Default settings override def projectSettings: Seq[Setting[_]] = Seq( - awsProfile := AwsProfileNameLoader.DEFAULT_PROFILE_NAME, + awsProfile := None, s3credentials := - new ProfileCredentialsProvider(awsProfile.value) | + new ProfileCredentialsProvider(awsProfile.value.orNull) | new EnvironmentVariableCredentialsProvider() | InstanceProfileCredentialsProvider.getInstance(), - s3region := new SbtS3ResolverAwsRegionProviderChain(awsProfile.value), + s3region := awsProfile.value.map(profile => new AwsProfileRegionProvider(profile)).getOrElse(new DefaultAwsRegionProviderChain), s3overwrite := isSnapshot.value, s3sse := false, s3acl := Some(com.amazonaws.services.s3.model.CannedAccessControlList.PublicRead), From bdc1cc4ccc30f54607f0ad1d3f18472d5d46cc60 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Yoshizawa Date: Mon, 16 Oct 2017 14:24:55 +0900 Subject: [PATCH 3/8] update Readme.md --- Readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Readme.md b/Readme.md index 8a0e3d8..7277c79 100644 --- a/Readme.md +++ b/Readme.md @@ -46,7 +46,7 @@ addSbtPlugin("ohnosequences" % "sbt-s3-resolver" % "") | Key | Type | Default | |:-----------------|:---------------------------:|:--------------------------------| | `s3credentials` | [`AWSCredentialsProvider`] | see [below](#credentials) | -| `awsProfile` | `String` | `"default"` | +| `awsProfile` | `Option[String]` | `None` | | `s3region` | [`Region`] | `DefaultAwsRegionProviderChain` | | `s3acl` | [`CannedAccessControlList`] | `PublicRead` | | `s3storageClass` | [`StorageClass`] | `Standard` | @@ -115,10 +115,10 @@ 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 ProfileCredentialsProvider(awsProfile.value.orNull) | new EnvironmentVariableCredentialsProvider() | new InstanceProfileCredentialsProvider() ``` @@ -132,14 +132,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() ``` From 1464b299f76dbce89daeb6bacca196c645c8ace4 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Yoshizawa Date: Mon, 16 Oct 2017 14:28:21 +0900 Subject: [PATCH 4/8] fix import --- src/main/scala/SBTS3Resolver.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/scala/SBTS3Resolver.scala b/src/main/scala/SBTS3Resolver.scala index 54b41eb..7b13aaf 100644 --- a/src/main/scala/SBTS3Resolver.scala +++ b/src/main/scala/SBTS3Resolver.scala @@ -5,8 +5,7 @@ import Keys._ import java.util.Optional import com.amazonaws.auth._ -import com.amazonaws.auth.profile.internal.AwsProfileNameLoader -import profile._ +import com.amazonaws.auth.profile.ProfileCredentialsProvider import com.amazonaws.regions._ import com.amazonaws.services.s3.AmazonS3 From 37d5adb69e2705d0db58ec338978fa1423388ef1 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Yoshizawa Date: Mon, 16 Oct 2017 14:49:48 +0900 Subject: [PATCH 5/8] use match for ignore compile error --- src/main/scala/SBTS3Resolver.scala | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/scala/SBTS3Resolver.scala b/src/main/scala/SBTS3Resolver.scala index 7b13aaf..eb11ddc 100644 --- a/src/main/scala/SBTS3Resolver.scala +++ b/src/main/scala/SBTS3Resolver.scala @@ -136,7 +136,10 @@ object SbtS3Resolver extends AutoPlugin { new ProfileCredentialsProvider(awsProfile.value.orNull) | new EnvironmentVariableCredentialsProvider() | InstanceProfileCredentialsProvider.getInstance(), - s3region := awsProfile.value.map(profile => new AwsProfileRegionProvider(profile)).getOrElse(new DefaultAwsRegionProviderChain), + 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), @@ -159,11 +162,4 @@ object SbtS3Resolver extends AutoPlugin { } ) - class SbtS3ResolverAwsRegionProviderChain(profile: String) extends AwsRegionProviderChain( - new AwsEnvVarOverrideRegionProvider(), - new AwsSystemPropertyRegionProvider(), - new AwsProfileRegionProvider(profile), - new InstanceMetadataRegionProvider() - ) - } From ab23fb533ef7f66fea7045ee575a2419ec390801 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Yoshizawa Date: Mon, 16 Oct 2017 22:32:32 +0900 Subject: [PATCH 6/8] support awsProfile to not Option --- src/main/scala/SBTS3Resolver.scala | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/scala/SBTS3Resolver.scala b/src/main/scala/SBTS3Resolver.scala index eb11ddc..10ef827 100644 --- a/src/main/scala/SBTS3Resolver.scala +++ b/src/main/scala/SBTS3Resolver.scala @@ -23,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(...) or None if you wish to inherit the bucket default.", "0.19.0") + implicit def awsProfile2Option(profile: String): Option[String] = Some(profile) + case class S3Resolver( credentialsProvider: AWSCredentialsProvider, overwrite: Boolean, @@ -133,9 +136,13 @@ object SbtS3Resolver extends AutoPlugin { override def projectSettings: Seq[Setting[_]] = Seq( awsProfile := None, s3credentials := - new ProfileCredentialsProvider(awsProfile.value.orNull) | - new EnvironmentVariableCredentialsProvider() | - InstanceProfileCredentialsProvider.getInstance(), + (awsProfile.value match { + case Some(profile) => new ProfileCredentialsProvider(profile) + case _ => + new ProfileCredentialsProvider() | + new EnvironmentVariableCredentialsProvider() | + InstanceProfileCredentialsProvider.getInstance() + }), s3region := (awsProfile.value match { case Some(profile) => new AwsProfileRegionProvider(profile) case _ => new DefaultAwsRegionProviderChain() From 4fc7f7cdb4763eedee5eda52981df606f784a028 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Yoshizawa Date: Mon, 16 Oct 2017 22:43:17 +0900 Subject: [PATCH 7/8] updated Readme.md --- Readme.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Readme.md b/Readme.md index 7277c79..04299fe 100644 --- a/Readme.md +++ b/Readme.md @@ -118,9 +118,13 @@ The **default credentials** chain in this plugin is awsProfile := Some("default") s3credentials := - new ProfileCredentialsProvider(awsProfile.value.orNull) | - new EnvironmentVariableCredentialsProvider() | - new InstanceProfileCredentialsProvider() + (awsProfile.value match { + case Some(profile) => new ProfileCredentialsProvider(profile) + case _ => + new ProfileCredentialsProvider() | + new EnvironmentVariableCredentialsProvider() | + InstanceProfileCredentialsProvider.getInstance() + }) ``` * [`new ProfileCredentialsProvider(...)`](http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/ProfileCredentialsProvider.html) which loads credentials for an AWS profile config file From e1e8e45d912785356ca68cb7260ee096c663625e Mon Sep 17 00:00:00 2001 From: Tsuyoshi Yoshizawa Date: Tue, 17 Oct 2017 09:49:06 +0900 Subject: [PATCH 8/8] fix deprecated message and s3credentials --- Readme.md | 5 +---- src/main/scala/SBTS3Resolver.scala | 7 ++----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/Readme.md b/Readme.md index 04299fe..4dc9eab 100644 --- a/Readme.md +++ b/Readme.md @@ -120,10 +120,7 @@ awsProfile := Some("default") s3credentials := (awsProfile.value match { case Some(profile) => new ProfileCredentialsProvider(profile) - case _ => - new ProfileCredentialsProvider() | - new EnvironmentVariableCredentialsProvider() | - InstanceProfileCredentialsProvider.getInstance() + case _ => new DefaultAWSCredentialsProviderChain() }) ``` diff --git a/src/main/scala/SBTS3Resolver.scala b/src/main/scala/SBTS3Resolver.scala index 10ef827..d0601e6 100644 --- a/src/main/scala/SBTS3Resolver.scala +++ b/src/main/scala/SBTS3Resolver.scala @@ -23,7 +23,7 @@ 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(...) or None if you wish to inherit the bucket default.", "0.19.0") + @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( @@ -138,10 +138,7 @@ object SbtS3Resolver extends AutoPlugin { s3credentials := (awsProfile.value match { case Some(profile) => new ProfileCredentialsProvider(profile) - case _ => - new ProfileCredentialsProvider() | - new EnvironmentVariableCredentialsProvider() | - InstanceProfileCredentialsProvider.getInstance() + case _ => new DefaultAWSCredentialsProviderChain() }), s3region := (awsProfile.value match { case Some(profile) => new AwsProfileRegionProvider(profile)