Skip to content

Instantly share code, notes, and snippets.

@imtrinity94
Created August 17, 2023 08:17
Show Gist options
  • Save imtrinity94/a3586b37c0073c06872cab0cfb0fc79d to your computer and use it in GitHub Desktop.
Save imtrinity94/a3586b37c0073c06872cab0cfb0fc79d to your computer and use it in GitHub Desktop.
vro_deployment_script.sh
```
#!/bin/bash
## Variables ##
VROname=${VROserver}
VROuser=${VROuser}
VROpass=${VROpass}
GitLabPrivateToken=glpat-********
packages=("all.config.elements.package" "com.company.resources.package")
initWfID="14ad73ff-a606-40e6-9197-65063de29d28"
### REPOSITORY ###
## VRO ##
#GET Public Key
pubKey=$(curl -k --request GET "https://${VROname}/vco/api/content-repositories/public-keys" --header 'Content-Type: application/json' --user "$VROuser:$VROpass" | jq '.[] | .publicKey' | tr -d '"')
#CREATE
curl -k  --request POST "https://${VROname}/vco/api/content-repositories/" --header 'Content-Type: application/json' --user "$VROuser:$VROpass" --data '{"name":"private-cloud/private-cloud","remoteUrl":"git@gitlab-tpc.tsl.telus.com:private-cloud/private-cloud.git","active":true,"id":"create","publicKeyReference":{"id":"TEMP","publicKey":""}}'
#GET ID
id=$(curl -k --request GET "https://${VROname}/vco/api/content-repositories" --header 'Content-Type: application/json' --user "$VROuser:$VROpass" | jq 'first(.link[]|.attributes[]|.value)' | tr -d '"')
#PATCH (set branch to dev)
curl -k  --request PATCH "https://${VROname}/vco/api/content-repositories/$id" --header 'Content-Type: application/json' --user "$VROuser:$VROpass" --data '{"name":"private-cloud/private-cloud","remoteUrl":"git@gitlab-tpc.tsl.telus.com:private-cloud/private-cloud.git","remoteBranch":"dev","active":true,"publicKey":"","id":"6","href":"https://pclidcdvvro113.dv.pc.local:443/vco/api/content-repositories/6/","relations":{"link":[{"href":"/active/history/","rel":"down"},{"href":"/content-repositories/requests/pull/","rel":"down"}]}}'
## GitLab ##
#LIST Deploy keys
curl --request GET --header "PRIVATE-TOKEN: $GitLabPrivateToken" "https://gitlab-tpc.tsl.telus.com/api/v4/projects/108/deploy_keys"
#ADD Deploy keys
curl --request POST --header "PRIVATE-TOKEN: $GitLabPrivateToken"  --header "Content-Type: application/json" --data "{\"title\": \"$VROname\", \"key\": \"$pubKey\", \"can_push\": \"false\"}" "https://gitlab-tpc.tsl.telus.com/api/v4/projects/108/deploy_keys"
## VRO #
#Pull
curl -k --request POST "https://${VROname}/vco/api/content-repositories/requests/pull" --header 'Content-Type: application/json' --user "$VROuser:$VROpass" --data ''
### PACKAGES ###
for package_name in ${packages[@]}; do ##Loop through all packages
  echo "Package name "$str
#Accept certificate - get the certificate from the package that will be imported via 7zip ant import it
unzip -o $package_name
mv certificates/* ./$package_name.cer --force
rm -rf certificates/ dunes-meta-inf elements/ signatures/
curl -k --request POST "https://${VROname}/vco/api/certificates" --user "$VROuser:$VROpass" -H 'accept: application/json' -H 'Content-Type: multipart/form-data' -F "file=@$package_name.cer;type=application/x-x509-ca-cert"
#Import packages
curl -k --user "$VROuser:$VROpass" -X 'POST' "https://${VROname}/vco/api/content/packages?importConfigSecureStringAttributeValues=true&importConfigurationAttributeValues=true&overwrite=false&tagImportMode=ImportButPreserveExistingValue" -H 'accept: application/xml' -H 'Content-Type: multipart/form-data' -F "file=@./$package_name"
done
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment