admin registration script
Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
parent
738877016c
commit
60eb7e1dc9
2 changed files with 80 additions and 0 deletions
1
yume-mods/admin-scripts/.gitignore
vendored
Normal file
1
yume-mods/admin-scripts/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/secrets
|
79
yume-mods/admin-scripts/batch_register.fish
Executable file
79
yume-mods/admin-scripts/batch_register.fish
Executable 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."
|
Loading…
Reference in a new issue