Last active
May 25, 2022 10:30
-
-
Save HokieGeek/a9d9759e60732e9d4169d40e6279345e to your computer and use it in GitHub Desktop.
Nexus Repo provisioning examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blobStore.createFileBlobStore('foo', 'bar') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blobStore.delete('testname') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def youSaid = args | |
return 'Hello. You said: ' + youSaid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blobStoreApi.createBlobStoreGroup('grpname', ['f1','f2','f3',], 'writeToFirst') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks.