From 1ba28f459e1c5804432f7da7ad394895155f5a2a Mon Sep 17 00:00:00 2001
From: Mark <mark@openappstack.net>
Date: Tue, 1 Oct 2019 16:34:19 +0200
Subject: [PATCH] Add util scripts to manage roles

---
 utils/assign-role.sh | 23 +++++++++++++++++++++++
 utils/create-role.sh | 22 ++++++++++++++++++++++
 2 files changed, 45 insertions(+)
 create mode 100644 utils/assign-role.sh
 create mode 100644 utils/create-role.sh

diff --git a/utils/assign-role.sh b/utils/assign-role.sh
new file mode 100644
index 0000000..6988f3b
--- /dev/null
+++ b/utils/assign-role.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+USERNAME=$1
+ROLE=$2
+SERVER=$3
+PORT=$4
+
+if [[ $USERNAME == "" ]] || [[ $ROLE == "" ]]; then
+    echo "Please specify username and role"
+    exit 1
+fi
+if [[ $SERVER == "" ]]; then
+    SERVER=localhost
+fi
+if [[ $PORT == "" ]]; then
+    PORT=5000
+fi
+
+echo "Assigning role $ROLE to User $USERNAME"
+curl --header "Content-Type: application/json" \
+     --request POST \
+     --data "{\"query\": \"mutation {addRoleToUser(username: \\\"$USERNAME\\\", role: \\\"$ROLE\\\"){user{username, roles{edges{node{name}}}}}}\" }" \
+     http://$SERVER:$PORT/graphql
diff --git a/utils/create-role.sh b/utils/create-role.sh
new file mode 100644
index 0000000..77aa4d0
--- /dev/null
+++ b/utils/create-role.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+ROLE=$1
+SERVER=$2
+PORT=$3
+
+if [[ $ROLE == "" ]]; then
+    echo "Please specify a role name"
+    exit 1
+fi
+if [[ $SERVER == "" ]]; then
+    SERVER=localhost
+fi
+if [[ $PORT == "" ]]; then
+    PORT=5000
+fi
+
+echo "Creating role $ROLE"
+curl --header "Content-Type: application/json" \
+     --request POST \
+     --data "{\"query\": \"mutation {createRole(name: \\\"$ROLE\\\"){role{name}}}\" }" \
+     http://$SERVER:$PORT/graphql
-- 
GitLab