From 2ce58f8a69cf2db069c8c9923a2fabb19b6c2cf6 Mon Sep 17 00:00:00 2001 From: Mark <mark@openappstack.net> Date: Tue, 29 Oct 2019 17:11:40 +0100 Subject: [PATCH] Refactor util scripts --- utils/assign-role.bash | 13 +++---------- utils/create-application.bash | 4 ++-- utils/create-role.bash | 4 ++-- utils/create-user.bash | 12 +++--------- utils/grant-access.bash | 12 +++--------- 5 files changed, 13 insertions(+), 32 deletions(-) diff --git a/utils/assign-role.bash b/utils/assign-role.bash index c8d8ee6..f782281 100755 --- a/utils/assign-role.bash +++ b/utils/assign-role.bash @@ -1,6 +1,6 @@ #!/bin/bash -if [[ $1 == "" ]] || [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then +if [[ $1 == "" ]] || [[ $1 == "-h" ]] || [[ $1 == "--help" ]] || [[ $2 == "" ]]; then echo "usage: $0 USERNAME ROLE [ SERVER ]"; exit 0; fi @@ -9,19 +9,12 @@ USERNAME=$1 ROLE=$2 SERVER=$3 - -if [[ $USERNAME == "" ]] || [[ $ROLE == "" ]]; then - echo "Please specify username and role" - echo "usage: $0 USERNAME ROLE [ SERVER ]"; - exit 1 -fi - if [[ $SERVER == "" ]]; then - SERVER=localhost:5000 + SERVER=http://localhost: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/graphql + $SERVER/graphql diff --git a/utils/create-application.bash b/utils/create-application.bash index fa29650..ad33e52 100755 --- a/utils/create-application.bash +++ b/utils/create-application.bash @@ -9,11 +9,11 @@ APPLICATION=$1 SERVER=$2 if [[ $SERVER == "" ]]; then - SERVER=localhost:5000 + SERVER=http://localhost:5000 fi echo "Creating application $APPLICATION" curl --header "Content-Type: application/json" \ --request POST \ --data "{\"query\": \"mutation {createApplication(name: \\\"$APPLICATION\\\"){application{name}}}\" }" \ - http://$SERVER/graphql + $SERVER/graphql diff --git a/utils/create-role.bash b/utils/create-role.bash index dc8e538..15c6209 100755 --- a/utils/create-role.bash +++ b/utils/create-role.bash @@ -9,11 +9,11 @@ ROLE=$1 SERVER=$2 if [[ $SERVER == "" ]]; then - SERVER=localhost:5000 + SERVER=http://localhost:5000 fi echo "Creating role $ROLE" curl --header "Content-Type: application/json" \ --request POST \ --data "{\"query\": \"mutation {createRole(name: \\\"$ROLE\\\"){role{name}}}\" }" \ - http://$SERVER/graphql + $SERVER/graphql diff --git a/utils/create-user.bash b/utils/create-user.bash index 9640041..0a24f49 100755 --- a/utils/create-user.bash +++ b/utils/create-user.bash @@ -1,6 +1,6 @@ #!/bin/bash -if [[ $1 == "" ]] || [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then +if [[ $1 == "" ]] || [[ $1 == "-h" ]] || [[ $1 == "--help" ]] || [[ $2 == "" ]] || [[ $3 == "" ]]; then echo "usage: $0 USERNAME PASSWORD EMAIL [ SERVER ]"; exit 0; fi @@ -10,18 +10,12 @@ PASSWORD=$2 EMAIL=$3 SERVER=$4 -if [[ $USERNAME == "" ]] || [[ $PASSWORD == "" ]] || [[ $EMAIL == "" ]]; then - echo "Please specify username, password and email address" - echo "usage: $0 USERNAME PASSWORD EMAIL [ SERVER ]"; - exit 1 -fi - if [[ $SERVER == "" ]]; then - SERVER=localhost:5000 + SERVER=http://localhost: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/graphql + $SERVER/graphql diff --git a/utils/grant-access.bash b/utils/grant-access.bash index 3b52d9d..0c14048 100755 --- a/utils/grant-access.bash +++ b/utils/grant-access.bash @@ -1,6 +1,6 @@ #!/bin/bash -if [[ $1 == "" ]] || [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then +if [[ $1 == "" ]] || [[ $1 == "-h" ]] || [[ $1 == "--help" ]] || [[ $2 == "" ]]; then echo "usage: $0 USERNAME APPLICATION [ SERVER ]"; exit 0; fi @@ -9,18 +9,12 @@ USERNAME=$1 APPLICATION=$2 SERVER=$3 -if [[ $USERNAME == "" ]] || [[ $APPLICATION == "" ]]; then - echo "Please specify username and application" - echo "usage: $0 USERNAME APPLICATION [ SERVER ]"; - exit 1 -fi - if [[ $SERVER == "" ]]; then - SERVER=localhost:5000 + SERVER=http://localhost: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/graphql + $SERVER/graphql -- GitLab