Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nexus Repo provisioning examples
blobStore.createFileBlobStore('foo', 'bar')
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)
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)))
UserTokenService userTokens = container.lookup(UserTokenService.class.name)
def token = userTokens.create(principal)
def name = token.getNameCode()
def pass = token.getPassCode()
return "${name}:${pass}"
import org.apache.shiro.subject.PrincipalCollection
import org.apache.shiro.subject.SimplePrincipalMap
import org.sonatype.nexus.security.*
import org.sonatype.nexus.security.user.*
import org.sonatype.nexus.security.role.*
import com.sonatype.nexus.usertoken.plugin.*
def userId = "testId"
User user = new User(userId: userId, firstName: 'First', lastName: 'Last', source: UserManager.DEFAULT_SOURCE, emailAddress: 'testUser@example.com', status: UserStatus.active, roles: [new RoleIdentifier(UserManager.DEFAULT_SOURCE, Roles.ADMIN_ROLE_ID)])
UserManager users = container.lookup(UserManager.class.name)
users.addUser(user, "password")
PrincipalCollection principal = new SimplePrincipalMap(Collections.singletonMap('user', Collections.singletonMap('user', userId)))
UserTokenService userTokens = container.lookup(UserTokenService.class.name)
def token = userTokens.create(principal)
def name = token.getNameCode()
def pass = token.getPassCode()
return "${name}:${pass}"
blobStore.delete('testname')
def youSaid = args
return 'Hello. You said: ' + youSaid
import groovy.json.JsonSlurper
import com.sonatype.nexus.usertoken.plugin.*
def userId = new JsonSlurper().parseText(args)
UserTokenService userTokens = container.lookup(UserTokenService.class.name)
def token = userTokens.lookup(userId)
def name = token.getNameCode()
def pass = token.getPassCode()
return "${name}:${pass}"
blobStoreApi.createBlobStoreGroup('grpname', ['f1','f2','f3',], 'writeToFirst')
#!/bin/bash
(( $# < 1 )) && {
echo "USAGE: <upload,run,delete> script [run_arguments]"
exit 1
}
cmd=$1
script=$2
data=${3}
scriptname=${script/.groovy/}
hostAndPort="localhost:8081"
auth="admin:admin123"
case $cmd in
l|ls|list)
echo "::>> listing scripts"
curl -v -u ${auth} -X GET \
http://${hostAndPort}/service/rest/v1/script || exit 1
;;
g|get)
echo "::>> retrieving script"
curl -v -u ${auth} -X GET \
http://${hostAndPort}/service/rest/v1/script/${scriptname} || exit 1
;;
u|up|upload)
json=$(mktemp)
cat << EOF > $json
{
"name": "${scriptname}",
"content": "$(sed '/^$/d; /^\/\//d; s/"/\\"/g' ${script} | tr '\n' ';')",
"type": "groovy"
}
EOF
echo "::>> uploading script"
curl -v -u ${auth} -X POST \
--header 'Content-Type: application/json' \
http://${hostAndPort}/service/rest/v1/script \
-d @$json || exit 1
;;
r|run)
set -x
header="application/json"
dataOpt="-d ${data}"
if [[ -z ${data} ]]; then
header="text/plain"
dataOpt=""
fi
echo "::>> running script"
curl -v -u ${auth} -X POST \
--header 'Content-Type: '${header} \
${dataOpt} \
http://${hostAndPort}/service/rest/v1/script/${scriptname}/run || exit 2
;;
d|del|delete)
echo "::>> deleting script"
curl -v -u ${auth} -X DELETE \
http://${hostAndPort}/service/rest/v1/script/${scriptname} || exit 3
;;
esac
@tuxillo
Copy link

tuxillo commented May 25, 2022

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment