Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions hack/bin/create_team.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash
#
# consider using create_team.py

set -o pipefail
set -o errexit

BRIG_HOST="http://localhost:8080"
OWNER_NAME="owner name n/a"
OWNER_EMAIL="owner email n/a"
OWNER_PASSWORD="owner pass n/a"
EMAIL_CODE="email code n/a"
TEAM_NAME="team name n/a"
TEAM_CURRENCY="USD"

USAGE="
Request a code to create a team. Call ./create_test_team_members.sh
first, then use the code you will receive by email to call this script.

USAGE: $0 -h <host> -o <owner_name> -e <owner_email> -p <owner_password> -v <email_code> -t <team_name> -c <team_currency>
-h <host>: Base URI of brig. default: ${BRIG_HOST}
-o <owner_name>: user display name of the owner of the team to be created. default: ${OWNER_NAME}
-e <owner_email>: email address of the owner of the team to be created. default: ${OWNER_EMAIL}
-p <owner_password>: owner password. default: ${OWNER_PASSWORD}
-v <email_code>: validation code received by email. default: ${EMAIL_CODE}
-t <team_name>: default: ${TEAM_NAME}
-c <team_currency>: default: ${TEAM_CURRENCY}

"

# Option parsing:
# https://sookocheff.com/post/bash/parsing-bash-script-arguments-with-shopts/
while getopts ":o:e:p:v:t:c:h:" opt; do
case ${opt} in
o ) OWNER_NAME="$OPTARG"
;;
e ) OWNER_EMAIL="$OPTARG"
;;
p ) OWNER_PASSWORD="$OPTARG"
;;
v ) EMAIL_CODE="$OPTARG"
;;
t ) TEAM_NAME="$OPTARG"
;;
c ) TEAM_CURRENCY="$OPTARG"
;;
h ) BRIG_HOST="$OPTARG"
;;
: ) 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

curl -i -s --show-error \
-XPOST "$BRIG_HOST/register" \
-H'Content-type: application/json' \
-d'{"name":"'"$OWNER_NAME"'","email":"'"$OWNER_EMAIL"'","password":"'"$OWNER_PASSWORD"'","email_code":"'"$EMAIL_CODE"'","team":{"currency":"'"$TEAM_CURRENCY"'","icon":"default","name":"'"$TEAM_NAME"'"}}'
101 changes: 101 additions & 0 deletions hack/bin/create_team_members.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env bash
#
# consider using create_team.py

set -e

ADMIN_UUID="n/a"
TEAM_UUID="n/a"
BRIG_HOST="http://localhost:8080"
CSV_FILE="n/a"

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>: file containing info on the invitees in format 'Email,UserName,Role'. default: ${CSV_FILE}

If role is specified, it must be one of owner, admin, member, partner.
If it is missing, default is member.

If you tee(1) stdout, stderr of this script into a log file, you can
grep that log file for errors like this:

$ grep code out.log | grep email-exists # the most common case
$ grep code out.log | grep -v email-exists

If you are in a hurry, you may want to change the sleep(1) at the end
of the invite loop to less than a second. If you want to give up on
the first error, add an exit(1) where we check the $INVIDATION_ID.

"

# 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 ) CSV_FILE="$OPTARG"
;;
: ) 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

if [ ! -e "$CSV_FILE" ]; then
echo -e "\n\n*** I need the name of an existing csv file.\n\n"
echo "$USAGE" 1>&2
exit 1
fi

# Generate users
while IFS=, read -r EMAIL USER_NAME ROLE
do
if ( echo "$ROLE" | grep -vq "\(owner\|admin\|member\|partner\)" ); then
export ROLE=member
fi

echo "inviting $USER_NAME <$EMAIL> with role $ROLE..." 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"'","role":"'"$ROLE"'"}')

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

if ( ( echo "$INVITATION_ID" | grep -q '"code"' ) &&
( echo "$INVITATION_ID" | grep -q '"label"' ) ) ; then
echo "failed inviting $USER_NAME <$EMAIL>: $INVITATION_ID"
fi

echo "Sleeping 1 second..." 1>&2
sleep 1
done < "$CSV_FILE"
46 changes: 46 additions & 0 deletions hack/bin/create_team_request_code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
#
# consider using create_team.py

set -o pipefail
set -o errexit

BRIG_HOST="http://localhost:8080"
OWNER_EMAIL="owner email n/a"

USAGE="
Request a code to create a team. Call this script first, then use the
code you will receive by email to call ./create_team.sh

USAGE: $0 -h <host> -e <email>
-h <host>: Base URI of brig. default: ${BRIG_HOST}
-e <email>: email address of the owner of the team to be created. default: ${OWNER_EMAIL}

"

# Option parsing:
while getopts ":e:h:" opt; do
case ${opt} in
e ) OWNER_EMAIL="$OPTARG"
;;
h ) BRIG_HOST="$OPTARG"
;;
: ) 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

curl -i -s --show-error \
-XPOST "$BRIG_HOST/activate/send" \
-H'Content-type: application/json' \
-d'{"email":"'"$OWNER_EMAIL"'"}'
68 changes: 68 additions & 0 deletions hack/bin/create_test_team_admins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash
#
# consider using create_team.py

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
Loading