forked from Skill17-WebTechnologies/competition-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_pat.sh
More file actions
executable file
·34 lines (28 loc) · 952 Bytes
/
create_pat.sh
File metadata and controls
executable file
·34 lines (28 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Check if the correct number of arguments are provided
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <GITEA_URL> <USERNAME> <PASSWORD>"
exit 1
fi
# Set variables from script arguments
GITEA_URL="$1"
USERNAME="$2"
PASSWORD="$3"
TOKEN_NAME="CreateOrganizationScript"
# Create a new personal access token
response=$(curl -s -k -X POST -H "Content-Type: application/json" \
-u "$USERNAME:$PASSWORD" \
-d '{
"name": "'"$TOKEN_NAME"'",
"scopes": ["read:admin","write:organization,write:repository,write:user"]
}' \
"$GITEA_URL/api/v1/users/$USERNAME/tokens")
# Extract the token from the response
# new_token=$(echo $response | jq -r '.sha1')
new_token=$(echo "$response" | grep -o '"sha1":"[^"]*"' | sed 's/"sha1":"//;s/"//g')
# Check if the token was successfully created
if [ "$new_token" == "null" ]; then
echo "Failed to create token. Response: $response"
exit 1
fi
echo "$new_token"