add garage admin api with token, expose via garage.hantim.net
This commit is contained in:
@@ -105,6 +105,8 @@ echo "==> Fetching secrets from Bitwarden Secrets Manager..."
|
||||
GITEA_TOKEN=$(bws_get "hantim-new-app-script")
|
||||
VULTR_API_KEY=$(bws_get "hantim-vultr-api-key")
|
||||
DEPLOY_KEY=$(bws_get "hantim-deploy-ssh-private-key")
|
||||
GARAGE_ADMIN_TOKEN=$(bws_get "hantim-garage-admin-token")
|
||||
GARAGE_MEDIA_KEY_ID=$(bws_get "hantim-garage-media-key-id")
|
||||
|
||||
DEPLOY_KEY_FILE=$(mktemp)
|
||||
echo "$DEPLOY_KEY" > "$DEPLOY_KEY_FILE"
|
||||
@@ -328,6 +330,38 @@ NGINX
|
||||
echo "==> Issuing SSL certificate via deploy user..."
|
||||
ssh -o StrictHostKeyChecking=accept-new -i "$DEPLOY_KEY_FILE" deploy@"$SERVER_IP" "cert-$APP"
|
||||
|
||||
# --- Create Garage media bucket ---
|
||||
|
||||
GARAGE_API="https://garage.hantim.net"
|
||||
GARAGE_AUTH="Authorization: Bearer $GARAGE_ADMIN_TOKEN"
|
||||
|
||||
echo "==> Creating Garage media bucket for $APP..."
|
||||
BUCKET_RESP=$(curl -s -X POST "$GARAGE_API/v2/CreateBucket" \
|
||||
-H "$GARAGE_AUTH" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"globalAlias\": \"$APP\"}")
|
||||
|
||||
BUCKET_ID=$(echo "$BUCKET_RESP" | jq -r '.id')
|
||||
if [ -z "$BUCKET_ID" ] || [ "$BUCKET_ID" = "null" ]; then
|
||||
echo "Error: Failed to create bucket"
|
||||
echo "$BUCKET_RESP"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo " Allowing media-key access..."
|
||||
curl -sf -X POST "$GARAGE_API/v2/AllowBucketKey" \
|
||||
-H "$GARAGE_AUTH" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"bucketId\": \"$BUCKET_ID\", \"accessKeyId\": \"$GARAGE_MEDIA_KEY_ID\", \"permissions\": {\"read\": true, \"write\": true, \"owner\": false}}" > /dev/null
|
||||
|
||||
echo " Enabling website access..."
|
||||
curl -sf -X POST "$GARAGE_API/v2/UpdateBucket?id=$BUCKET_ID" \
|
||||
-H "$GARAGE_AUTH" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"websiteAccess": {"enabled": true, "indexDocument": "index.html"}}' > /dev/null
|
||||
|
||||
echo " Bucket '$APP' ready"
|
||||
|
||||
# --- Commit and push ---
|
||||
|
||||
echo "==> Committing and pushing hantim-server..."
|
||||
|
||||
Reference in New Issue
Block a user