admin registration script
All checks were successful
Test (production install and build) / production (20.16.0) (push) Successful in 1m28s
Publish Docker image / Build (push) Successful in 4m51s

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
ゆめ 2024-11-14 11:50:42 -06:00
parent 738877016c
commit 60eb7e1dc9
No known key found for this signature in database
2 changed files with 80 additions and 0 deletions

1
yume-mods/admin-scripts/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/secrets

View file

@ -0,0 +1,79 @@
#!/usr/bin/env fish
argparse --name batch_register 'n/number=' 'h/host=' 'm/mount=' -- $argv
set -l dir_name (dirname (realpath (status -f)))
echo "Running in $dir_name"
if [ -f $dir_name/.env ]
source $dir_name/.env
end
if [ -f $dir_name/secrets/.env ]
source $dir_name/secrets/.env
end
if ! set -q MISSKEY_TOKEN
echo "Please set MISSKEY_TOKEN in .env file."
exit 1
end
if ! set -q VAULT_MOUNT
echo "Please set VAULT_MOUNT in .env file."
exit 1
end
if set -q _flag_host
set HOST $_flag_host
else
set HOST "https://test0.mi.yumechi.jp"
end
if set -q _flag_number
set NUMBER $_flag_number
else
set NUMBER 1
end
if ! set -q ACCOUNT_PREFIX
set ACCOUNT_PREFIX test_automated_
end
for i in (seq 1 $NUMBER)
set -l USERNAME "$ACCOUNT_PREFIX"(openssl rand 8 | base64 | tr -d /+=)
set -l PASSWORD (openssl rand 16 | base64)
echo "[$i/$NUMBER]" \
"Registering $USERNAME"
echo "$PASSWORD" | vault kv put -mount=$VAULT_MOUNT $USERNAME username=$USERNAME password=-
or begin
echo "Failed to save password for $USERNAME"
exit 3
end
set -l start (date +%s%N)
jq -nr --arg username $USERNAME --arg password $PASSWORD '{
username: $username,
password: $password
}' | curl -f --tlsv1.2 -d@- \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $MISSKEY_TOKEN" \
"$HOST/api/admin/accounts/create" | \
jq --arg password $PASSWORD \
'{"id": .id, "username": .username, "password": $password, "success": true, "token": .token}' | \
tee /dev/stderr | \
vault kv put -mount=$VAULT_MOUNT $USERNAME @/dev/stdin
or begin
echo "Failed to register $USERNAME"
vault kv destroy -mount=$VAULT_MOUNT -versions=1 $USERNAME
exit 2
end
echo "[$i/$NUMBER]" \
"Registered $USERNAME" (math \((date +%s%N) - $start\) / 1000000) ms
end
echo "Done."