aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Frank <b.frank@sap.com>2016-07-05 15:15:36 +0200
committerBenjamin Frank <b.frank@sap.com>2016-07-05 15:15:36 +0200
commit11342ecc8c6bd92e73b8ad9a2791f8d9462043a6 (patch)
tree6c37b019c3c23cbc7a03484bec003c7266c99e4b
parentb1b2195b13300d9b3057b96deebf24d9353a7344 (diff)
downloadcbt-11342ecc8c6bd92e73b8ad9a2791f8d9462043a6.tar.gz
cbt-11342ecc8c6bd92e73b8ad9a2791f8d9462043a6.tar.bz2
cbt-11342ecc8c6bd92e73b8ad9a2791f8d9462043a6.zip
Allow empty credentials for publishing.
This enables to publish into a repository where no credentials are required but and empty/wrong HTTP Auth header throws an HTTP 401 (not authorized) error
-rw-r--r--stage2/Lib.scala18
-rw-r--r--stage2/Publish.scala4
2 files changed, 13 insertions, 9 deletions
diff --git a/stage2/Lib.scala b/stage2/Lib.scala
index 620c009..a060ac6 100644
--- a/stage2/Lib.scala
+++ b/stage2/Lib.scala
@@ -361,20 +361,20 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{
else items.map(projection)
}
- def publishUnsigned( sourceFiles: Seq[File], artifacts: Seq[File], url: URL, credentials: String ): Unit = {
+ def publishUnsigned( sourceFiles: Seq[File], artifacts: Seq[File], url: URL, credentials: Option[String] = None ): Unit = {
if(sourceFiles.nonEmpty){
publish( artifacts, url, credentials )
}
}
- def publishSigned( sourceFiles: Seq[File], artifacts: Seq[File], url: URL, credentials: String ): Unit = {
+ def publishSigned( sourceFiles: Seq[File], artifacts: Seq[File], url: URL, credentials: Option[String] = None ): Unit = {
// TODO: make concurrency configurable here
if(sourceFiles.nonEmpty){
publish( artifacts ++ artifacts.map(sign), url, credentials )
}
}
- private def publish(artifacts: Seq[File], url: URL, credentials: String): Unit = {
+ private def publish(artifacts: Seq[File], url: URL, credentials: Option[String]): Unit = {
val files = artifacts.map(nameAndContents)
lazy val checksums = files.flatMap{
case (name, content) => Seq(
@@ -386,10 +386,10 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{
uploadAll(url, all, credentials)
}
- def uploadAll(url: URL, nameAndContents: Seq[(String, Array[Byte])], credentials: String ): Unit =
+ def uploadAll(url: URL, nameAndContents: Seq[(String, Array[Byte])], credentials: Option[String] = None ): Unit =
nameAndContents.map{ case(name, content) => upload(name, content, url, credentials ) }
- def upload(fileName: String, fileContents: Array[Byte], baseUrl: URL, credentials: String): Unit = {
+ def upload(fileName: String, fileContents: Array[Byte], baseUrl: URL, credentials: Option[String] = None): Unit = {
import java.net._
import java.io._
val url = baseUrl ++ fileName
@@ -397,8 +397,12 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{
val httpCon = url.openConnection.asInstanceOf[HttpURLConnection]
httpCon.setDoOutput(true)
httpCon.setRequestMethod("PUT")
- val encoding = new sun.misc.BASE64Encoder().encode(credentials.getBytes)
- httpCon.setRequestProperty("Authorization", "Basic " ++ encoding)
+ credentials.foreach(
+ c => {
+ val encoding = new sun.misc.BASE64Encoder().encode(c.getBytes)
+ httpCon.setRequestProperty("Authorization", "Basic " ++ encoding)
+ }
+ )
httpCon.setRequestProperty("Content-Type", "application/binary")
httpCon.getOutputStream.write(
fileContents
diff --git a/stage2/Publish.scala b/stage2/Publish.scala
index 8cdb65b..1cc3b70 100644
--- a/stage2/Publish.scala
+++ b/stage2/Publish.scala
@@ -41,9 +41,9 @@ trait Publish extends PackageJars{
def publishUrl = if(version.endsWith("-SNAPSHOT")) snapshotUrl else releaseUrl
override def copy(context: Context) = super.copy(context).asInstanceOf[Publish]
- protected def sonatypeCredentials = {
+ protected def sonatypeCredentials: Option[String] = {
// FIXME: this should probably not use cbtHome, but some reference to the system's host cbt
- new String(readAllBytes((context.cbtRootHome ++ "/sonatype.login").toPath)).trim
+ Some(new String(readAllBytes((context.cbtRootHome ++ "/sonatype.login").toPath)).trim)
}
def publishSnapshot: Unit = {