Allow authenticating via custom HTTP headers

This commit is contained in:
richardgilmore
2020-05-03 18:14:28 +02:00
committed by Alexandre Archambault
parent 8c2d660434
commit e2876fb23e
3 changed files with 18 additions and 2 deletions
@@ -75,6 +75,8 @@ import scala.concurrent.duration.Duration
withStrict(Some(strict))
def withTtl(ttl: Duration): CoursierConfiguration =
withTtl(Some(ttl))
def addRepositoryAuthentication(repositoryId: String, authentication: Authentication): CoursierConfiguration =
withAuthenticationByRepositoryId(authenticationByRepositoryId :+ (repositoryId, authentication))
}
object CoursierConfiguration {
@@ -1,15 +1,28 @@
package lmcoursier.definitions
import dataclass.data
import dataclass._
@data class Authentication(
user: String,
password: String,
optional: Boolean = false,
realmOpt: Option[String] = None
realmOpt: Option[String] = None,
@since
headers: Seq[(String,String)] = Nil
) {
override def toString(): String =
withPassword("****")
.withHeaders(
headers.map {
case (k, v) => (k, "****")
}
)
.productIterator
.mkString("Authentication(", ", ", ")")
}
object Authentication {
def apply(headers: Seq[(String, String)]): Authentication =
Authentication("", "", optional = false, None, headers)
}
@@ -27,6 +27,7 @@ object ToCoursier {
coursier.core.Authentication(authentication.user, authentication.password)
.withOptional(authentication.optional)
.withRealmOpt(authentication.realmOpt)
.withHttpHeaders(authentication.headers)
def module(module: Module): coursier.core.Module =
coursier.core.Module(