From 4811051ea3602c043c294b9b0078a7132c111ae3 Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Mon, 9 Dec 2024 08:40:41 +0000 Subject: [PATCH] use the nexus api to create the powershell nuget repositories --- README.md | 2 +- provision/provision-nexus.sh | 82 +++++++++++++++++++ .../src/main/groovy/provision.groovy | 11 --- 3 files changed, 83 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1ca5837..bb9dccc 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ This will: * Create the `adhoc-package` repository. * Create the `apt-hosted` repository. * Create the `npm-group`, `npm-hosted` and `npmjs.org-proxy` repositories. + * Create the `powershell-group`, `powershell-hosted` and `powershellgallery.com-proxy` repositories. * Configure the NuGet `nuget-hosted` repository to accept pushing with an API key. * Configure Nexus through Groovy scripts. * Create the `chocolatey-group`, `chocolatey-hosted` and `chocolatey.org-proxy` repositories. - * Create the `powershell-group`, `powershell-hosted` and `powershellgallery.com-proxy` repositories. * Schedule a task to remove the old snapshots from the `maven-snapshots` repository. * Create users and a custom `deployer` role. * Setup an Active Directory LDAP user authentication source (when `config_authentication='ldap'` is set inside the `provision-nexus.sh` file). diff --git a/provision/provision-nexus.sh b/provision/provision-nexus.sh index 0c47cc1..2cebec5 100644 --- a/provision/provision-nexus.sh +++ b/provision/provision-nexus.sh @@ -324,6 +324,88 @@ http \ EOF +# create the powershell-hosted nuget hosted repository. +# see https://help.sonatype.com/en/nuget-repositories.html +http \ + --check-status \ + --auth "$api_auth" \ + POST \ + https://$nexus_domain/service/rest/v1/repositories/nuget/hosted \ + <<'EOF' +{ + "name": "powershell-hosted", + "online": true, + "storage": { + "blobStoreName": "default", + "strictContentTypeValidation": true, + "writePolicy": "allow_once" + }, + "component": { + "proprietaryComponents": true + } +} +EOF + + +# create a powershellgallery.com-proxy powershell proxy repository. +# see https://help.sonatype.com/en/nuget-repositories.html +http \ + --check-status \ + --auth "$api_auth" \ + POST \ + https://$nexus_domain/service/rest/v1/repositories/nuget/proxy \ + <<'EOF' +{ + "name": "powershellgallery.com-proxy", + "online": true, + "storage": { + "blobStoreName": "default", + "strictContentTypeValidation": true + }, + "proxy": { + "remoteUrl": "https://www.powershellgallery.com/api/v2/", + "contentMaxAge": 1440, + "metadataMaxAge": 1440 + }, + "nugetProxy": { + "queryCacheItemMaxAge": 3600, + "nugetVersion": "V2" + }, + "negativeCache": { + "enabled": true, + "timeToLive": 1440 + }, + "httpClient": { + "blocked": false, + "autoBlock": true + } +} +EOF + + +# create the powershell-group nuget group repository. +# see https://help.sonatype.com/en/nuget-repositories.html +http \ + --check-status \ + --auth "$api_auth" \ + POST \ + https://$nexus_domain/service/rest/v1/repositories/nuget/group \ + <<'EOF' +{ + "name": "powershell-group", + "online": true, + "storage": { + "blobStoreName": "default", + "strictContentTypeValidation": true + }, + "group": { + "memberNames": [ + "powershell-hosted", + "powershellgallery.com-proxy" + ] + } +} +EOF # configure nexus ldap with a groovy script. if [ "$config_authentication" = 'ldap' ]; then bash /vagrant/provision/execute-provision-ldap.groovy-script.sh diff --git a/provision/provision-nexus/src/main/groovy/provision.groovy b/provision/provision-nexus/src/main/groovy/provision.groovy index a3bc4e8..7997a01 100644 --- a/provision/provision-nexus/src/main/groovy/provision.groovy +++ b/provision/provision-nexus/src/main/groovy/provision.groovy @@ -26,17 +26,6 @@ capabilityRegistry.all.findAll {it.context().type().toString().startsWith("Outre //]) -// create a powershell repository backed by the default blob store. -repository.createNugetHosted("powershell-hosted", "default", true, WritePolicy.ALLOW_ONCE) -// create a powershell proxy repository backed by the default blob store. -// see https://help.sonatype.com/repomanager3/formats/nuget-repositories -config = repository.createNugetProxy("powershellgallery.com-proxy", "https://www.powershellgallery.com/api/v2/", "default").configuration.copy() -config.attributes.nugetProxy.nugetVersion = "V2" -repository.repositoryManager.update(config) -// create a powershell group repository that merges the powershell-host and powershellgallery.com-proxy together. -repository.createNugetGroup("powershell-group", ["powershell-hosted", "powershellgallery.com-proxy"], "default") - - // create a chocolatey repository backed by the default blob store. repository.createNugetHosted("chocolatey-hosted", "default", true, WritePolicy.ALLOW_ONCE) // create a chocolatey proxy repository backed by the default blob store.