andres
(Andrés Pérez)
January 10, 2020, 2:17pm
4
Absolutely. The following gist contains a few examples of single and multiline groovy scripts and a bash script which can upload them via the REST API.
createBlobstore.groovy
blobStore.createFileBlobStore('foo', 'bar')
createS3Blobstore.groovy
def config = [:]
config['bucket'] = 'bucket_name'
config['accessKeyId'] = 'aws_access_key'
config['secretAccessKey'] = 'aws_secret'
config['assumeRole'] = 'aws_iam_role'
config['region'] = 'aws_region'
blobStore.createS3BlobStore('repo_name', config)
createUserToken.groovy
import groovy.json.JsonSlurper
import org.apache.shiro.subject.PrincipalCollection
import org.apache.shiro.subject.SimplePrincipalMap
import com.sonatype.nexus.usertoken.plugin.*
def userId = new JsonSlurper().parseText(args)
PrincipalCollection principal = new SimplePrincipalMap(Collections.singletonMap('user', Collections.singletonMap('user', userId)))
This file has been truncated. show original
There are more than three files. show original
The pertinent part is line L33 in the bash script
"content": "$(sed '/^$/d; /^\/\//d; s/"/\\"/g' ${script} | tr '\n' ';')",
which is taking the multiline script and performing the following transformations:
Removes empty lines
Removes line comments
Escapes double quotes \\"
Replaces newlines with semicolons