Skip to content

Commit

Permalink
Merge pull request #103 from adferrand/master
Browse files Browse the repository at this point in the history
Fix Harbor chart POST requests
  • Loading branch information
tkrullmann authored Dec 5, 2020
2 parents bc40563 + 681ad3d commit 14274aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.unbrokendome.gradle.plugins.helm.publishing.dsl

import okhttp3.MultipartBody
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.asRequestBody
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.unbrokendome.gradle.plugins.helm.dsl.credentials.SerializableCredentials
Expand All @@ -8,6 +11,7 @@ import org.unbrokendome.gradle.plugins.helm.publishing.publishers.AbstractHttpHe
import org.unbrokendome.gradle.plugins.helm.publishing.publishers.HelmChartPublisher
import org.unbrokendome.gradle.plugins.helm.publishing.publishers.PublisherParams
import org.unbrokendome.gradle.plugins.helm.util.property
import java.io.File
import java.net.URI
import javax.inject.Inject

Expand Down Expand Up @@ -63,6 +67,13 @@ private open class DefaultHarborHelmPublishingRepository

override fun uploadPath(chartName: String, chartVersion: String): String =
"/api/chartrepo/$projectName/charts"

override fun requestBody(chartFile: File): RequestBody =
MultipartBody.Builder().run {
setType(MultipartBody.FORM)
addFormDataPart("chart", chartFile.name, chartFile.asRequestBody(MEDIA_TYPE_GZIP))
build()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package org.unbrokendome.gradle.plugins.helm.publishing.publishers

import okhttp3.Credentials
import okhttp3.*
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Interceptor
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.tls.HandshakeCertificates
import okhttp3.tls.HeldCertificate
Expand Down Expand Up @@ -42,8 +38,10 @@ internal abstract class AbstractHttpHelmChartPublisher(
): Map<String, String> =
emptyMap()

protected open fun requestBody(chartFile: File): RequestBody = chartFile.asRequestBody(MEDIA_TYPE_GZIP)

private companion object {

protected companion object {
val MEDIA_TYPE_GZIP: MediaType = "application/x-gzip".toMediaType()
}

Expand Down Expand Up @@ -73,7 +71,7 @@ internal abstract class AbstractHttpHelmChartPublisher(

val request = Request.Builder().run {
url(uploadUrl.toHttpUrl())
method(uploadMethod, chartFile.asRequestBody(MEDIA_TYPE_GZIP))
method(uploadMethod, requestBody(chartFile))
build()
}

Expand Down

0 comments on commit 14274aa

Please sign in to comment.