Automatic config of S3 repo using API + groovy scripts

Hi,

I have been automating configuration of Nexus Repos using a combination of POST / PUT curl + groovy scripts as below triggered from Puppet. We are interested in using the new Blobstore S3 functionality and would appreciate help with the syntax of a groovy script to create the s3 blob store + repo similar to what we are doing below as we cant find reference to the classes etc via the documentation. Thanks

{
“name”: “test-docker”,
“type”: “groovy”,
“content”: “import org.sonatype.nexus.repository.storage.WritePolicy; blobStore.createFileBlobStore(‘docker_hosted_blob’, ‘docker_hosted_blob’); repository.createDockerHosted(‘test-docker-production’, 5000, 5001, ‘docker_hosted_blob’, true, true, WritePolicy.ALLOW_ONCE)”
}

thanks
Andy

You can use a script like this:

Where blobStore.createS3BlobStore is:

blobStore.createS3BlobStore(String name Map<String,String> config)

String name --> Name of Blobstore

Map<String><String> config --> contains values for the following configuration keys:
“bucket” : required Field
“accessKeyId”
“secretAccessKey”
“sessionToken”
“assumeRole”
“region”
“endpoint”
“expiration” : required field
“signertype”

Hi Rich,

Thank you for this, Im just attempting to add this as a script to run via POST but Im having issues with the parameters on creation of the blob store. Do you see where Im going wrong ? Im just adding the values as string at the moment just as a quick test:

{

“name”: “d-docker-s3”,

“type”: “groovy”,

“content”: “import org.sonatype.nexus.repository.storage.WritePolicy; import groovy.json.JsonSlurper; blobStore.createS3BlobStore(‘docker_s3_hosted_blob’, ‘docker_s3_hosted_blob’, ‘accessKeyID’, ‘secretKeyId’, ‘sessionToken’, ‘assumeRole’, ‘region’, ‘endpoint’, ‘expiration’, ‘signertype’); repository.createDockerHosted(‘d-docker-s3-production’, 5000, 5001, ‘docker_s3_hosted_blob’, true, true, WritePolicy.ALLOW_ONCE)”

}

Thanks

Andrew