Skip to content

Commit

Permalink
Add back auth feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasthomsen committed Aug 12, 2024
1 parent 6feb636 commit 6ee8d85
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ThisBuild / organizationHomepage := Some(url("https://iterable.com"))
ThisBuild / description := "A plugin for authenticating with AWS CodeArtifact"
ThisBuild / licenses := Seq("MIT" -> url("https://opensource.org/licenses/MIT"))
ThisBuild / homepage := Some(url("https://github.com/Iterable/sbt-codeartifact"))
ThisBuild / version := "0.1.0"
ThisBuild / version := "0.2.0"

ThisBuild / developers := List(
Developer(
Expand Down
8 changes: 6 additions & 2 deletions core/src/main/scala/codeartifact/CodeArtifact.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ object CodeArtifact {
.getAuthorizationToken(req)
.authorizationToken()

def getAuthToken(repo: CodeArtifactRepo): String =
getAuthTokenFromRequest(getAuthorizationTokenRequest(repo.domain, repo.owner))
def getAuthToken(repo: CodeArtifactRepo): Option[String] =
try {
Some(getAuthTokenFromRequest(getAuthorizationTokenRequest(repo.domain, repo.owner)))
} catch {
case _: Throwable => None
}

object Defaults {
val READ_TIMEOUT: Int = 1.minutes.toMillis.toInt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ object CodeArtifactPlugin extends AutoPlugin {
def buildPublishSettings: Seq[Setting[_]] = Seq(
ThisBuild / codeArtifactUrl := "",
ThisBuild / codeArtifactResolvers := Nil,
ThisBuild / codeArtifactToken := getCodeArtifactAuthToken.value
codeArtifactRepo := CodeArtifactRepo.fromUrl(codeArtifactUrl.value),
codeArtifactToken := getCodeArtifactAuthToken.value
)

def codeArtifactSettings: Seq[Setting[_]] = Seq(
codeArtifactPublish := dynamicallyPublish.value,
codeArtifactRepo := CodeArtifactRepo.fromUrl(codeArtifactUrl.value),
codeArtifactConnectTimeout := CodeArtifact.Defaults.CONNECT_TIMEOUT,
codeArtifactReadTimeout := CodeArtifact.Defaults.READ_TIMEOUT,
codeArtifactPackage := CodeArtifactPackage(
Expand All @@ -51,7 +51,7 @@ object CodeArtifactPlugin extends AutoPlugin {
.map(_.resolver)
)

lazy val getCodeArtifactAuthToken: Def.Initialize[Task[Option[String]]] = Def.task {
def getCodeArtifactAuthToken: Def.Initialize[Task[Option[String]]] = Def.task {
sys.env
.get("CODEARTIFACT_AUTH_TOKEN")
.orElse(
Expand All @@ -61,6 +61,7 @@ object CodeArtifactPlugin extends AutoPlugin {
.map(_.passwd)
)
.orElse {
CodeArtifact.getAuthToken(codeArtifactRepo.value)
streams.value.log.warn("Unable to get AWS CodeArtifact auth token.")
None
}
Expand Down

0 comments on commit 6ee8d85

Please sign in to comment.