-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More scripts #801
More scripts #801
Changes from 15 commits
adf7430
8f04127
ab11e51
4704746
051b5b0
be5eb1d
a93ef67
c957384
b4455bb
16adefb
83d58a1
6cf950d
79a719d
15d3192
91eecea
baa6726
f4bb36a
311c13c
4b1e752
b8b56fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
ADMIN_UUID="a09e9521-e14e-4285-ad71-47caa97f4a16" | ||
TEAM_UUID="9e57a378-0dca-468f-9661-7872f5f1c910" | ||
BRIG_HOST="http://localhost:8082" | ||
|
||
USAGE=" | ||
This bash script can be used to invite members to a given team. Input | ||
is a csv file with email addresses and suggested user names. | ||
|
||
Note that this uses internal brig endpoints. It is not exposed over | ||
nginz and can only be used if you have direct access to brig. | ||
|
||
USAGE: $0 | ||
-a <admin uuid>: User ID of the inviting admin. default: ${ADMIN_UUID} | ||
-t <team uuid>: ID of the inviting team. default: ${TEAM_UUID} | ||
-h <host>: Base URI of brig. default: ${BRIG_HOST} | ||
-c: input file containing info on the invitees in format 'Email,UserName'. | ||
" | ||
|
||
# Option parsing: | ||
# https://sookocheff.com/post/bash/parsing-bash-script-arguments-with-shopts/ | ||
while getopts ":a:t:h:c" opt; do | ||
case ${opt} in | ||
a ) ADMIN_UUID="$OPTARG" | ||
;; | ||
t ) TEAM_UUID="$OPTARG" | ||
;; | ||
h ) BRIG_HOST="$OPTARG" | ||
;; | ||
c ) if [ ! -e "$OPTARG" ]; then | ||
echo -e "\n\n*** I need the name of an existing cvs file.\n\n" | ||
fisx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
echo "$USAGE" 1>&2 | ||
exit 1 | ||
else | ||
CSV_FILE="$OPTARG" | ||
fi | ||
;; | ||
: ) echo "-$OPTARG" requires an argument 1>&2 | ||
exit 1 | ||
;; | ||
\? ) echo "$USAGE" 1>&2 | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND -1)) | ||
|
||
if [ "$#" -ne 0 ]; then | ||
echo "$USAGE" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
# Generate users | ||
while IFS=, read -r EMAIL USER_NAME | ||
do | ||
echo "inviting $USER_NAME <$EMAIL>..." 1>&2 | ||
|
||
# Generate the invitation | ||
CURL_OUT_INVITATION=$(curl -i -s --show-error \ | ||
-XPOST "$BRIG_HOST/teams/$TEAM_UUID/invitations" \ | ||
-H'Content-type: application/json' \ | ||
-H'Z-User: '"$ADMIN_UUID"'' \ | ||
-d'{"email":"'"$EMAIL"'","name":"'"$USER_NAME"'","inviter_name":"Team admin"}') | ||
|
||
INVITATION_ID=$(echo "$CURL_OUT_INVITATION" | tail -1 | sed 's/.*\"id\":\"\([a-z0-9-]*\)\".*/\1/') | ||
|
||
echo "Created the invitation, sleeping 1 second..." 1>&2 | ||
sleep 1 | ||
|
||
ERR='{"code":409,"message":"The given e-mail address is in use.","label":"email-exists"}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not the only error case; the team ID or the user ID could also be incorrect, or the permissions for that admin_userid could not be sufficient. Perhaps you could abort the script on any 4xx, not just this particular 409. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like this?: 311c13c |
||
if [[ "$INVITATION_ID" == "$ERR" ]]; then | ||
echo "User with the email $EMAIL already exists, aborting" | ||
exit 1 | ||
fi | ||
|
||
echo "Sleeping 1 second..." 1>&2 | ||
sleep 1 | ||
done < "$CSV_FILE" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
COUNT="1" | ||
BRIG_HOST="http://localhost:8082" | ||
CSV="false" | ||
|
||
USAGE=" | ||
This bash script can be used to create active team admin users and | ||
their teams. | ||
|
||
Note that this uses an internal brig endpoint. It is not exposed over | ||
nginz and can only be used if you have direct access to brig. | ||
|
||
USAGE: $0 | ||
-n <N>: Create <N> users. default: ${COUNT} | ||
-h <host>: Base URI of brig. default: ${BRIG_HOST} | ||
-c: Output as headerless CSV in format 'User-Id,Email,Password'. default: ${CSV} | ||
" | ||
|
||
# Option parsing: | ||
# https://sookocheff.com/post/bash/parsing-bash-script-arguments-with-shopts/ | ||
while getopts ":n:h:c" opt; do | ||
case ${opt} in | ||
n ) COUNT="$OPTARG" | ||
;; | ||
h ) BRIG_HOST="$OPTARG" | ||
;; | ||
c ) CSV="true" | ||
;; | ||
: ) echo "-$OPTARG" requires an argument 1>&2 | ||
exit 1 | ||
;; | ||
\? ) echo "$USAGE" 1>&2 | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND -1)) | ||
|
||
if [ "$#" -ne 0 ]; then | ||
echo "$USAGE" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
# Generate users | ||
|
||
for i in $(seq 1 "$COUNT") | ||
do | ||
EMAIL=$(cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 8)"@example.com" | ||
PASSWORD=$(cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 8) | ||
|
||
CURL_OUT=$(curl -i -s --show-error \ | ||
-XPOST "$BRIG_HOST/i/users" \ | ||
-H'Content-type: application/json' \ | ||
-d'{"email":"'"$EMAIL"'","password":"'"$PASSWORD"'","name":"demo","team":{"name":"Wire team","icon":"default"}}') | ||
|
||
UUID=$(echo "$CURL_OUT" | tail -1 | sed 's/.*\"id\":\"\([a-z0-9-]*\)\".*/\1/') | ||
TEAM=$(echo "$CURL_OUT" | tail -1 | sed 's/.*\"team\":\"\([a-z0-9-]*\)\".*/\1/') | ||
|
||
if [ "$CSV" == "false" ] | ||
then echo -e "Succesfully created a team admin user: $UUID on team: $TEAM with email: $EMAIL and password: $PASSWORD" | ||
else echo -e "$UUID,$EMAIL,$PASSWORD" | ||
fi | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
ADMIN_UUID="a09e9521-e14e-4285-ad71-47caa97f4a16" | ||
TEAM_UUID="9e57a378-0dca-468f-9661-7872f5f1c910" | ||
BRIG_HOST="http://localhost:8082" | ||
START="1" | ||
COUNT="1" | ||
CSV="false" | ||
|
||
USAGE=" | ||
This bash script can be used to create active members in a given team. | ||
|
||
Note that this uses internal brig endpoints. It is not exposed over | ||
nginz and can only be used if you have direct access to brig. | ||
|
||
USAGE: $0 | ||
-a <admin uuid>: User ID of the inviting admin. default: ${ADMIN_UUID} | ||
-t <team uuid>: ID of the inviting team. default: ${TEAM_UUID} | ||
-s <S>: Start at offset. default: ${START} | ||
-n <N>: Create <N> users. default: ${COUNT} | ||
-h <host>: Base URI of brig. default: ${BRIG_HOST} | ||
-c: Output as headerless CSV in format 'User-Id,Email,Password'. default: ${CSV} | ||
" | ||
|
||
# Option parsing: | ||
# https://sookocheff.com/post/bash/parsing-bash-script-arguments-with-shopts/ | ||
while getopts ":a:t:s:n:h:c" opt; do | ||
case ${opt} in | ||
a ) ADMIN_UUID="$OPTARG" | ||
;; | ||
t ) TEAM_UUID="$OPTARG" | ||
;; | ||
s ) START="$OPTARG" | ||
;; | ||
n ) COUNT="$OPTARG" | ||
;; | ||
h ) BRIG_HOST="$OPTARG" | ||
;; | ||
c ) CSV="true" | ||
;; | ||
: ) echo "-$OPTARG" requires an argument 1>&2 | ||
exit 1 | ||
;; | ||
\? ) echo "$USAGE" 1>&2 | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND -1)) | ||
|
||
if [ "$#" -ne 0 ]; then | ||
echo "$USAGE" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
# Generate users | ||
END=$((COUNT + START - 1)) | ||
for i in $(seq "$START" "$END") | ||
do | ||
EMAIL='w'$(printf "%03d" "$i")"@example.com" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps a comment or something to tell the user the emails start with 'w'? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing that we should be careful about is that we actually send out emails with this request. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, only saw that after I merged... I'll make another PR and ping you. |
||
PASSWORD=$(cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 8) | ||
|
||
# Generate the invitation | ||
|
||
CURL_OUT_INVITATION=$(curl -i -s --show-error \ | ||
-XPOST "$BRIG_HOST/teams/$TEAM_UUID/invitations" \ | ||
-H'Content-type: application/json' \ | ||
-H'Z-User: '"$ADMIN_UUID"'' \ | ||
-d'{"email":"'"$EMAIL"'","name":"Replace with name","inviter_name":"Team admin"}') | ||
|
||
INVITATION_ID=$(echo "$CURL_OUT_INVITATION" | tail -1 | sed 's/.*\"id\":\"\([a-z0-9-]*\)\".*/\1/') | ||
|
||
echo "Created the invitation, sleeping 1 second..." 1>&2 | ||
sleep 1 | ||
|
||
ERR='{"code":409,"message":"The given e-mail address is in use.","label":"email-exists"}' | ||
if [[ "$INVITATION_ID" == "$ERR" ]]; then | ||
echo "User with the email $EMAIL already exists, aborting" | ||
exit 1 | ||
fi | ||
|
||
# Get the code | ||
CURL_OUT_INVITATION_CODE=$(curl -i -s --show-error \ | ||
-XGET "$BRIG_HOST/i/teams/invitation-code?team=$TEAM_UUID&invitation_id=$INVITATION_ID") | ||
|
||
INVITATION_CODE=$(echo "$CURL_OUT_INVITATION_CODE" | tail -1 | sed -n -e '/"code":/ s/^.*"\(.*\)".*/\1/p') | ||
|
||
echo "Got the code, sleeping 1 second..." 1>&2 | ||
sleep 1 | ||
|
||
# Create the user using that code | ||
CURL_OUT=$(curl -i -s --show-error \ | ||
-XPOST "$BRIG_HOST/i/users" \ | ||
-H'Content-type: application/json' \ | ||
-d'{"email":"'"$EMAIL"'","password":"'"$PASSWORD"'","name":"demo","team_code":"'"$INVITATION_CODE"'"}') | ||
|
||
TEAM_MEMBER_UUID=$(echo "$CURL_OUT" | tail -1 | sed 's/.*\"id\":\"\([a-z0-9-]*\)\".*/\1/') | ||
TEAM=$(echo "$CURL_OUT" | tail -1 | sed 's/.*\"team\":\"\([a-z0-9-]*\)\".*/\1/') | ||
|
||
if [ "$TEAM" != "$TEAM_UUID" ]; then | ||
echo "unexpected error: user got assigned to no / the wrong team?!" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps dump the curl_out here? |
||
exit 1 | ||
fi | ||
|
||
if [ "$CSV" == "false" ] | ||
then echo -e "Succesfully created a team member: $TEAM_MEMBER_UUID on team: $TEAM_UUID with email: $EMAIL and password: $PASSWORD" | ||
else echo -e "$UUID,$EMAIL,$PASSWORD" | ||
fi | ||
|
||
echo "Sleeping 1 second..." 1>&2 | ||
sleep 1 | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is
-x
verbosity necessary?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it. If you don't let me know and I'll remove it.