All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mill.contrib.artifactory.ArtifactoryHttpApi.scala Maven / Gradle / Ivy

There is a newer version: 0.12.0-RC2-17-07e173
Show newest version
package mill.contrib.artifactory

import java.util.Base64

import scala.concurrent.duration._
import requests.Session

class ArtifactoryHttpApi(
    credentials: String,
    readTimeout: Int,
    connectTimeout: Int
) {
  val http: Session = requests.Session(
    readTimeout = readTimeout,
    connectTimeout = connectTimeout,
    maxRedirects = 0,
    check = false
  )

  private val base64Creds = base64(credentials)
  private val uploadTimeout = 5.minutes.toMillis.toInt

  // https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-DeployArtifact
  def upload(uri: String, data: Array[Byte]): requests.Response = {
    http.put(
      uri,
      readTimeout = uploadTimeout,
      headers = Seq(
        "Content-Type" -> "application/java-archive",
        "Authorization" -> s"Basic ${base64Creds}"
      ),
      data = data
    )
  }

  private def base64(s: String) =
    new String(Base64.getEncoder.encode(s.getBytes))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy