From 5ee76d3dd010ff9893b9d61dbb7c9660758c8ddc Mon Sep 17 00:00:00 2001 From: Mark <mark@openappstack.net> Date: Tue, 17 Sep 2019 16:02:43 +0200 Subject: [PATCH] Add helper scripts to create users --- utils/create-application.sh | 22 ++++++++++++++++++++++ utils/create-user.sh | 24 ++++++++++++++++++++++++ utils/grant-access.sh | 23 +++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 utils/create-application.sh create mode 100644 utils/create-user.sh create mode 100644 utils/grant-access.sh diff --git a/utils/create-application.sh b/utils/create-application.sh new file mode 100644 index 0000000..5249d11 --- /dev/null +++ b/utils/create-application.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +APPLICATION=$1 +SERVER=$2 +PORT=$3 + +if [[ $APPLICATION == "" ]]; then + echo "Please specify an application name" + exit 1 +fi +if [[ $SERVER == "" ]]; then + SERVER=localhost +fi +if [[ $PORT == "" ]]; then + PORT=5000 +fi + +echo "Creating application $APPLICATION" +curl --header "Content-Type: application/json" \ + --request POST \ + --data "{\"query\": \"mutation {createApplication(name: \\\"$APPLICATION\\\"){application{name}}}\" }" \ + http://$SERVER:$PORT/graphql diff --git a/utils/create-user.sh b/utils/create-user.sh new file mode 100644 index 0000000..2f5e526 --- /dev/null +++ b/utils/create-user.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +USERNAME=$1 +PASSWORD=$2 +EMAIL=$3 +SERVER=$4 +PORT=$5 + +if [[ $USERNAME == "" ]] || [[ $PASSWORD == "" ]] || [[ $EMAIL == "" ]]; then + echo "Please specify username, password and email address" + exit 1 +fi +if [[ $SERVER == "" ]]; then + SERVER=localhost +fi +if [[ $PORT == "" ]]; then + PORT=5000 +fi + +echo "Creating admin user" +curl --header "Content-Type: application/json" \ + --request POST \ + --data "{\"query\": \"mutation {createUser(username: \\\"$USERNAME\\\", password: \\\"$PASSWORD\\\", email: \\\"$EMAIL\\\"){user{username}}}\" }" \ + http://$SERVER:$PORT/graphql diff --git a/utils/grant-access.sh b/utils/grant-access.sh new file mode 100644 index 0000000..dce4828 --- /dev/null +++ b/utils/grant-access.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +USERNAME=$1 +APPLICATION=$2 +SERVER=$3 +PORT=$4 + +if [[ $USERNAME == "" ]] || [[ $APPLICATION == "" ]]; then + echo "Please specify username and application" + exit 1 +fi +if [[ $SERVER == "" ]]; then + SERVER=localhost +fi +if [[ $PORT == "" ]]; then + PORT=5000 +fi + +echo "Granting access to application $APPLICATION to User $USERNAME" +curl --header "Content-Type: application/json" \ + --request POST \ + --data "{\"query\": \"mutation {addApplicationToUser(username: \\\"$USERNAME\\\", application: \\\"$APPLICATION\\\"){user{username, applications{edges{node{name}}}}}}\" }" \ + http://$SERVER:$PORT/graphql -- GitLab