From 15274f9aeb04c6549833146b4d49557d7552d7e2 Mon Sep 17 00:00:00 2001 From: aguestuser <aguestuser@riseup.net> Date: Sat, 21 Sep 2019 15:54:41 -0400 Subject: [PATCH] [ns] add trust boost command --- cli/boost | 4 +++- cli/boost-commands/help | 3 +++ cli/boost-commands/trust | 43 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 cli/boost-commands/trust diff --git a/cli/boost b/cli/boost index 2823d4c..f15d990 100755 --- a/cli/boost +++ b/cli/boost @@ -22,6 +22,7 @@ print_usage(){ echo " list-channels" echo " list-numbers" echo " release-numbers" + echo " trust" echo "" echo "To learn what these commands do, run:" echo "" @@ -34,7 +35,8 @@ if [[ $command != "help" ]] && [[ $command != "create-number" ]] && [[ $command != "list-channels" ]] && [[ $command != "list-numbers" ]] && - [[ $command != "release-numbers" ]] + [[ $command != "release-numbers" ]] && + [[ $command != "trust" ]] then print_usage exit 1 diff --git a/cli/boost-commands/help b/cli/boost-commands/help index da55caf..237f16d 100755 --- a/cli/boost-commands/help +++ b/cli/boost-commands/help @@ -21,6 +21,9 @@ boost cli supports the following commands: release-numbers <path> - releases all phone numbers with twilio ids listed at given path + trust <user phone number> + - trusts all safety numbers associated with a user's phone number + for more detailed instructions on any command, run: boost <command> -h diff --git a/cli/boost-commands/trust b/cli/boost-commands/trust new file mode 100755 index 0000000..7227c43 --- /dev/null +++ b/cli/boost-commands/trust @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +if [[ $1 == "-h" ]] || [[ $1 == "--help" ]];then + echo "this command trusts all safety numbers associated with a user's phone number. valid options are:" + echo "" + echo "-p : user phone number"; + echo "-u : url to target (in dev, use signalboost.ngrok.io)"; + echo "" + exit 1 +fi + +echo "--- checking environment and args..." + +if [ -z $SIGNALBOOST_API_TOKEN ];then + echo "--- ERROR: no SIGNALBOOST_API_TOKEN found. try \`\$ set -a && source .env && set +a\`" + exit 1 +fi + +while getopts ":p:n:s:u:" opt; do + case "$opt" in + p) + phone_number="$OPTARG" + ;; + u) + url="$OPTARG" + ;; + esac +done + +if [[ ! $phone_number =~ ^\+(1|52)[0-9]{10}$ ]];then + echo "> ERROR: -p must be a 10 digit phone number prefixed by a country code (+1 or +52)" + exit 1 +fi + +if [ -z $url ];then url=${SIGNALBOOST_HOST_URL}; fi + +echo "--- trusting all safety numbers for user phone number ${phone_number} at url ${url}" + +curl -s -X POST \ + -H "Content-Type: application/json" \ + -H "Token: $SIGNALBOOST_API_TOKEN" \ + -d "{ \"memberPhoneNumber\": \"$phone_number\" }" \ + https://${url}/channels | jq -- GitLab