Skip to content

Commit

Permalink
Updating warning and error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasthomsen committed May 29, 2024
1 parent 4d1fb77 commit 58abdcd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
20 changes: 20 additions & 0 deletions core/src/main/scala/codeartifact/CodeArtifact.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package codeartifact

import software.amazon.awssdk.services.codeartifact.CodeartifactClient
import software.amazon.awssdk.services.codeartifact.model.GetAuthorizationTokenRequest

import sbt._
import scala.concurrent.duration._

Expand All @@ -12,6 +15,23 @@ object CodeArtifact {
passwd = token
)

private def getAuthorizationTokenRequest(domain: String, owner: String) =
GetAuthorizationTokenRequest
.builder()
.domain(domain)
.domainOwner(owner)
.durationSeconds(15.minutes.toSeconds)
.build()

private def getAuthTokenFromRequest(req: GetAuthorizationTokenRequest): String =
CodeartifactClient
.create()
.getAuthorizationToken(req)
.authorizationToken()

def getAuthToken(repo: CodeArtifactRepo): String =
getAuthTokenFromRequest(getAuthorizationTokenRequest(repo.domain, repo.owner))

object Defaults {
val READ_TIMEOUT: Int = 1.minutes.toMillis.toInt
val CONNECT_TIMEOUT: Int = 5.seconds.toMillis.toInt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ object CodeArtifactPlugin extends AutoPlugin {
)

lazy val getCodeArtifactAuthToken: Def.Initialize[Task[Option[String]]] = Def.task {
sys.env.get("CODEARTIFACT_AUTH_TOKEN").orElse {
streams.value.log.warn(
"Unable to get AWS CodeArtifact auth token from the CODEARTIFACT_AUTH_TOKEN environment variable."
sys.env
.get("CODEARTIFACT_AUTH_TOKEN")
.orElse(
Credentials
.loadCredentials(Path.userHome / ".sbt" / "credentials")
.toOption
.map(_.passwd)
)
None
}
.orElse {
streams.value.log.warn("Unable to get AWS CodeArtifact auth token.")
None
}
}

// Uses taskDyn because it can return one of two potential tasks
Expand All @@ -79,7 +85,7 @@ object CodeArtifactPlugin extends AutoPlugin {
val logger = streams.value.log
val token = codeArtifactToken.value.getOrElse {
throw new RuntimeException(
"Failed to publish to AWS Codeartifact because the auth token was not set in the CODEARTIFACT_AUTH_TOKEN environment variable."
"Failed to publish to AWS Codeartifact because the auth token was not set."
)
}
val api = new CodeArtifactApi(
Expand Down

0 comments on commit 58abdcd

Please sign in to comment.