Skip to content

Commit

Permalink
Updates for compatibility with EU Frankfurt AWS Region (#49)
Browse files Browse the repository at this point in the history
* Fixing s3 url construction for both us and eu
* Fix to us-east-1 region resolving as null
  • Loading branch information
jgavin authored and laughedelic committed Jun 14, 2017
1 parent 12cf6f6 commit 2ed29c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ bucketSuffix := "era7.com"

libraryDependencies += "ohnosequences" % "ivy-s3-resolver" % "0.9.0"

wartremoverErrors in (Compile, compile) --= Seq(Wart.Any, Wart.NonUnitStatements)
wartremoverErrors in (Compile, compile) --= Seq(Wart.Any, Wart.NonUnitStatements, Wart.Null)
24 changes: 21 additions & 3 deletions src/main/scala/SBTS3Resolver.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package ohnosequences.sbt

import sbt._, Keys._
import com.amazonaws.auth._, profile._
import sbt._
import Keys._
import com.amazonaws.auth._
import com.amazonaws.services.s3.model.Region
import profile._

object SbtS3Resolver extends AutoPlugin {

Expand Down Expand Up @@ -79,7 +82,22 @@ object SbtS3Resolver extends AutoPlugin {

// convenience method, to use normal bucket addresses with `at`
// without this resolver: "foo" at s3("maven.bucket.com").toHttps(s3region.value)
def toHttps(region: String): String = s"""https://s3-${region}.amazonaws.com/${url.stripPrefix("s3://")}"""
def toHttps(region: String): String = {
val bucketPath = url.stripPrefix("s3://")
val euCentral = Region.EU_Frankfurt.toString

//Correcting for fact that region enum resolves to null when provided US_STANDARD (us-east-1)
val correctedRegion = if(region == null) "us-east-1" else region

/*
Constructing host name based on region name. Frankfurt host name must be constructed using s3.{region}
for java sdk to sign its request using the v4 signature method (Frankfurt only supports v4 signing)
*/
region match {
case euCentral => s"""https://s3.${correctedRegion}.amazonaws.com/${bucketPath}"""
case _ => s"""https://s3-${correctedRegion}.amazonaws.com/${bucketPath}"""
}
}
}
}
import autoImport._
Expand Down

0 comments on commit 2ed29c3

Please sign in to comment.