Skip to content

Commit

Permalink
Add OciRegistries.exclusiveContent and OciRegistry.content
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Jul 28, 2024
1 parent 1e26cbc commit 0165304
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package io.github.sgtsilvio.gradle.oci.dsl
import org.gradle.api.Action
import org.gradle.api.Named
import org.gradle.api.NamedDomainObjectList
import org.gradle.api.artifacts.repositories.InclusiveRepositoryContentDescriptor
import org.gradle.api.artifacts.repositories.IvyArtifactRepository
import org.gradle.api.artifacts.repositories.RepositoryContentDescriptor
import org.gradle.api.credentials.PasswordCredentials
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
Expand All @@ -19,6 +21,8 @@ interface OciRegistries {
fun registry(name: String, configuration: Action<in OciRegistry>): OciRegistry
fun dockerHub(configuration: Action<in OciRegistry>): OciRegistry
fun gitHubContainerRegistry(configuration: Action<in OciRegistry>): OciRegistry

fun OciRegistry.exclusiveContent(configuration: Action<in InclusiveRepositoryContentDescriptor>)
}

interface OciRegistry : Named {
Expand All @@ -29,4 +33,5 @@ interface OciRegistry : Named {

fun credentials()
fun optionalCredentials()
fun content(configuration: Action<in RepositoryContentDescriptor>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import org.gradle.api.Project
import org.gradle.api.artifacts.ConfigurationContainer
import org.gradle.api.artifacts.ResolvableDependencies
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.artifacts.repositories.InclusiveRepositoryContentDescriptor
import org.gradle.api.artifacts.repositories.RepositoryContentDescriptor
import org.gradle.api.credentials.HttpHeaderCredentials
import org.gradle.api.credentials.PasswordCredentials
import org.gradle.api.model.ObjectFactory
Expand Down Expand Up @@ -47,6 +49,7 @@ import javax.inject.Inject
internal abstract class OciRegistriesImpl @Inject constructor(
private val imageMapping: OciImageMappingImpl,
private val objectFactory: ObjectFactory,
private val repositoryHandler: RepositoryHandler,
configurationContainer: ConfigurationContainer,
buildServiceRegistry: BuildServiceRegistry,
project: Project,
Expand Down Expand Up @@ -101,6 +104,13 @@ internal abstract class OciRegistriesImpl @Inject constructor(
return registry
}

final override fun OciRegistry.exclusiveContent(configuration: Action<in InclusiveRepositoryContentDescriptor>) {
repositoryHandler.exclusiveContent {
forRepository { repository }
filter(configuration)
}
}

private fun ResolvableDependencies.resolvesOciImages() =
attributes.getAttribute(DISTRIBUTION_TYPE_ATTRIBUTE) == OCI_IMAGE_DISTRIBUTION_TYPE

Expand Down Expand Up @@ -150,6 +160,9 @@ internal abstract class OciRegistryImpl @Inject constructor(
final override fun credentials() = credentials.set(providerFactory.passwordCredentials(name))

final override fun optionalCredentials() = credentials.set(providerFactory.optionalPasswordCredentials(name))

final override fun content(configuration: Action<in RepositoryContentDescriptor>) =
repository.content(configuration)
}

private const val PORT_HTTP_HEADER_NAME = "port"
Expand Down

0 comments on commit 0165304

Please sign in to comment.