diff --git a/build.sbt b/build.sbt index 829cc5a..6c819de 100644 --- a/build.sbt +++ b/build.sbt @@ -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( diff --git a/core/src/main/scala/codeartifact/CodeArtifact.scala b/core/src/main/scala/codeartifact/CodeArtifact.scala index 4b4c3a6..e08bd71 100644 --- a/core/src/main/scala/codeartifact/CodeArtifact.scala +++ b/core/src/main/scala/codeartifact/CodeArtifact.scala @@ -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 diff --git a/sbt-codeartifact/src/main/scala/codeartifact/CodeArtifactPlugin.scala b/sbt-codeartifact/src/main/scala/codeartifact/CodeArtifactPlugin.scala index ed9a761..effbc39 100644 --- a/sbt-codeartifact/src/main/scala/codeartifact/CodeArtifactPlugin.scala +++ b/sbt-codeartifact/src/main/scala/codeartifact/CodeArtifactPlugin.scala @@ -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( @@ -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( @@ -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 }