Skip to content
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

Script for registering IdPs in wire teams. #489

Merged
merged 3 commits into from
Oct 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 61 additions & 0 deletions deploy/services-demo/register_idp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash

set -e

#
# This bash script can be used to register an idp service with a team
# over the public backend API.
#
# Usage:
# register_idp.sh idp-metadata.xml
# WIRE_TRACE=1 WIRE_BACKEND=our-wire-backend.example.com register_idp.sh idp-metadata.xml
#
# the script will prompt you for your wire login and password. your
# user needs to be a team admin, and the idp will be registered with
# that team.
#

metadata_file=$1
if [ ! -e "$metadata_file" ]; then
echo "*** no metadata: '$1'"
exit 80
fi

if [ -n "$WIRE_BACKEND" ]; then
backend="$WIRE_BACKEND"
else
backend="localhost:8080"
fi

if [ "$WIRE_TRACE" == "1" ]; then
trace="1"
fi

which curl >/dev/null || ( echo "*** please install https://curl.haxx.se/ in your path."; exit 81 )
curl_exe=`which curl`

which jq >/dev/null || ( echo "*** please install https://stedolan.github.io/jq/ in your path."; exit 82 )
jq_exe=`which jq`

# login
if [ -n "$WIRE_LOGIN" ]; then
login="$WIRE_LOGIN"
else
echo -n "login email: "
read login
fi

if [ -n "$WIRE_PASSWORD" ]; then
password="$WIRE_PASSWORD"
else
echo -n "password: "
stty -echo; read password; stty echo; echo
fi

payload="{\"email\":\"$login\",\"password\":\"$password\"}"
test -n "$trace" && echo "$curl_exe -is --show-error -XPOST https://$backend/login -H'Content-type: application/json' -d$payload"
access_token=$($curl_exe -s --show-error -XPOST https://$backend/login -H'Content-type: application/json' -d$payload | $jq_exe -r .access_token)

# register idp
test -n "$trace" && echo "$curl_exe -is --show-error -XPOST https://$backend/identity-providers -H\"Authorization: Bearer $access_token\" -H'Content-type: application/xml' -d@\"$metadata_file\""
$curl_exe -is --show-error -XPOST https://$backend/identity-providers -H"Authorization: Bearer $access_token" -H'Content-type: application/xml' -d@"$metadata_file"