Created
July 12, 2024 15:44
-
-
Save bcdurden/fe0f5a1d8ad5c6daec694befa3fca807 to your computer and use it in GitHub Desktop.
Creating Harbor projects using Bash, curl, and jq
This file contains hidden or 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
| function create_project() { | |
| project_name=$1 | |
| URL=$2 | |
| PASSWORD=$3 | |
| code=$(curl -s -o /dev/null -w "%{http_code}" -u "admin:$PASSWORD" -X HEAD $URL/api/v2.0/projects?project_name=${project_name}) | |
| if [[ "$code" -eq 404 ]]; then | |
| # create project | |
| code=$(jq '.project_name = "'${project_name}'"' project_template.json | curl -s -o /tmp/result -w "%{http_code}" -u "admin:$PASSWORD" -H 'accept: application/json' -H 'Content-Type: application/json' --data-binary @- -X POST $URL/api/v2.0/projects) | |
| if [[ "$code" -eq 201 ]]; then | |
| echo "Created ${project_name} project" | |
| else | |
| echo "Failed to create ${project_name} project: HTTP code: $code" | |
| cat /tmp/result | |
| rm /tmp/result | |
| fi | |
| fi | |
| } | |
| # Usage | |
| create_project my_project harbor.myurl.com 'mypassword' |
This file contains hidden or 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
| { | |
| "project_name": "string", | |
| "public": true, | |
| "metadata": { | |
| "public": "true", | |
| "enable_content_trust": "false", | |
| "enable_content_trust_cosign": "false" | |
| }, | |
| "storage_limit": 0 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment