-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from iconoeugen/feature/gitlab-helm-publish
Publishing: Gitlab support
- Loading branch information
Showing
3 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...lin/org/unbrokendome/gradle/plugins/helm/publishing/dsl/GitlabHelmPublishingRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
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.internal.SerializableCredentials | ||
import org.unbrokendome.gradle.plugins.helm.dsl.credentials.internal.toSerializable | ||
import org.unbrokendome.gradle.plugins.helm.publishing.publishers.AbstractHttpHelmChartPublisher | ||
import org.unbrokendome.gradle.plugins.helm.publishing.publishers.HelmChartPublisher | ||
import org.unbrokendome.gradle.plugins.helm.publishing.publishers.PublisherParams | ||
import org.unbrokendome.gradle.plugins.helm.publishing.util.toMultipartBody | ||
import org.unbrokendome.gradle.pluginutils.property | ||
import java.io.File | ||
import java.net.URI | ||
import javax.inject.Inject | ||
|
||
|
||
interface GitlabHelmPublishingRepository : HelmPublishingRepository { | ||
/** | ||
* The ID of the Gitlab project. | ||
*/ | ||
val projectId: Property<Int> | ||
} | ||
|
||
|
||
private open class DefaultGitlabHelmPublishingRepository @Inject constructor( | ||
name: String, | ||
objects: ObjectFactory | ||
) : AbstractHelmPublishingRepository(objects, name), GitlabHelmPublishingRepository { | ||
|
||
override val projectId: Property<Int> = | ||
objects.property() | ||
|
||
override val publisherParams: PublisherParams | ||
get() = GitlabPublisherParams( | ||
url = requireNotNull(url.orNull) { "url is required for Gitlab publishing repository" }, | ||
credentials = configuredCredentials.orNull?.toSerializable(), | ||
projectId = requireNotNull(projectId.orNull) { "projectId is required for Gitlab publishing repository" } | ||
) | ||
|
||
|
||
private class GitlabPublisherParams( | ||
private val url: URI, | ||
private val credentials: SerializableCredentials?, | ||
private var projectId: Int | ||
) : PublisherParams { | ||
|
||
override fun createPublisher(): HelmChartPublisher = | ||
GitlabPublisher(url, credentials, projectId) | ||
} | ||
|
||
|
||
private class GitlabPublisher( | ||
url: URI, | ||
credentials: SerializableCredentials?, | ||
private val projectId: Int | ||
) : AbstractHttpHelmChartPublisher(url, credentials) { | ||
|
||
override val uploadMethod: String | ||
get() = "POST" | ||
|
||
override fun uploadPath(chartName: String, chartVersion: String): String = | ||
"/projects/$projectId/packages/helm/api/stable/charts" | ||
|
||
override fun requestBody(chartFile: File): RequestBody = | ||
MultipartBody.Builder().run { | ||
setType(MultipartBody.FORM) | ||
addFormDataPart("chart", chartFile.name, chartFile.asRequestBody(MEDIA_TYPE_GZIP)) | ||
build() | ||
} | ||
} | ||
} | ||
|
||
|
||
internal fun ObjectFactory.newGitlabHelmPublishingRepository(name: String): GitlabHelmPublishingRepository = | ||
newInstance(DefaultGitlabHelmPublishingRepository::class.java, name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters