diff --git a/scripts/database/create-auth.sh b/scripts/database/create-auth.sh new file mode 100755 index 0000000..52e6f4f --- /dev/null +++ b/scripts/database/create-auth.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Database credentials +DATABASE="aerius_authorization" +USER="aerius" +PASSWORD="aerius" + +# Create a new user +echo "Creating user if not exists" +psql -q -U postgres postgres < /dev/null + echo "Added $HOST_LINE to your $HOSTS_FILE" +else + echo "$HOST_LINE already exists in your $HOSTS_FILE" +fi diff --git a/scripts/misc/create-user.sh b/scripts/misc/create-user.sh new file mode 100755 index 0000000..9c1182f --- /dev/null +++ b/scripts/misc/create-user.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# First, you need to ensure that you have received all the necessary arguments +if [ "$#" -ne 3 ]; then + echo "You must enter exactly 3 arguments: username, plaintext password, and role name" + exit 1 +fi + +# Assigning command line arguments to variables +DBNAME="aerius_authorization" +DBUSER="aerius" +DBPASS="aerius" +DBHOST="localhost" + +USERNAME=$1 +PLAIN_PASSWORD=$2 +ROLE=$3 + +# Create a temporary file for htpasswd output +TEMP_FILE=$(mktemp) + +# Generate bcrypt hash with htpasswd +# Here, -B means bcrypt, -bn means don't add a newline and username:password is the input +htpasswd -Bbn "$USERNAME" "$PLAIN_PASSWORD" > "$TEMP_FILE" + +# Extract just the hash from the output +# Cut -d: -f2 removes the username and colon at the start +BCRYPT_HASH=$(cut -d: -f2 "$TEMP_FILE") + +# Clean up the temporary file +rm "$TEMP_FILE" + +export PGPASSWORD=$DBPASS + +# SQL Command +SQL_COMMAND="SELECT auth.ae_create_local_user('$USERNAME', '$BCRYPT_HASH', '$ROLE');" + +# Execute SQL Command +psql -h $DBHOST -U $DBUSER -d $DBNAME -c "$SQL_COMMAND" + +# Unset the PGPASSWORD environment variable +unset PGPASSWORD diff --git a/scripts/misc/view-roles.sh b/scripts/misc/view-roles.sh new file mode 100755 index 0000000..f551140 --- /dev/null +++ b/scripts/misc/view-roles.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Database details +DBNAME="aerius_authorization" +DBUSER="aerius" +DBPASS="aerius" +DBHOST="localhost" + +export PGPASSWORD=$DBPASS + +# SQL Command to list roles from the auth.roles table +SQL_COMMAND="SELECT * FROM auth.roles;" + +# Execute SQL Command +psql -h $DBHOST -U $DBUSER -d $DBNAME -c "$SQL_COMMAND" + +# Unset the PGPASSWORD environment variable +unset PGPASSWORD diff --git a/scripts/misc/view-users.sh b/scripts/misc/view-users.sh new file mode 100755 index 0000000..b4cf287 --- /dev/null +++ b/scripts/misc/view-users.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Database details +DBNAME="aerius_authorization" +DBUSER="aerius" +DBPASS="aerius" +DBHOST="localhost" + +export PGPASSWORD=$DBPASS + +# SQL Command to list roles from the auth.roles table +SQL_COMMAND="SELECT * FROM auth.users;" + +# Execute SQL Command +psql -h $DBHOST -U $DBUSER -d $DBNAME -c "$SQL_COMMAND" + +# Unset the PGPASSWORD environment variable +unset PGPASSWORD diff --git a/source/.gitignore b/source/.gitignore index 82d968e..3d5378a 100644 --- a/source/.gitignore +++ b/source/.gitignore @@ -28,3 +28,5 @@ target/ build/ !**/src/main/**/build/ !**/src/test/**/build/ + +/config