-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from KingAkeem/improving_codebase
Improving codebase
- Loading branch information
Showing
7 changed files
with
182 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM golang:1.19 | ||
|
||
WORKDIR /app | ||
|
||
# Downloading dependencies | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
# Copying over source code | ||
COPY . /app | ||
|
||
# Compiling code | ||
RUN CGO_ENABLED=0 GOOS=linux go build -o shadowguard cmd/main.go | ||
CMD ["./shadowguard"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,72 @@ | ||
#! /bin/bash | ||
#!/bin/bash | ||
|
||
psql -U postgres -f sql/initialize_database.sql | ||
psql -U postgres -d gorm -c "GRANT USAGE ON SCHEMA public TO gorm;" | ||
# Variables | ||
DB_USER="gorm" | ||
DB_PASSWORD="gorm" | ||
DB_NAME="gorm" | ||
|
||
# Check if PostgreSQL is installed; if not, install it | ||
if ! command -v psql &> /dev/null; then | ||
echo "PostgreSQL is not installed. Installing..." | ||
sudo apt update | ||
sudo apt install -y postgresql postgresql-contrib | ||
else | ||
echo "PostgreSQL is already installed." | ||
fi | ||
|
||
# Start PostgreSQL service | ||
sudo systemctl start postgresql | ||
sudo systemctl enable postgresql | ||
|
||
# Switch to the postgres user and run SQL commands to create user and database | ||
sudo -u postgres psql <<EOF | ||
-- Create a new PostgreSQL user with password | ||
DO \$$ | ||
BEGIN | ||
IF NOT EXISTS ( | ||
SELECT FROM pg_catalog.pg_roles | ||
WHERE rolname = '${DB_USER}' | ||
) THEN | ||
CREATE USER ${DB_USER} WITH PASSWORD '${DB_PASSWORD}'; | ||
END IF; | ||
END | ||
\$$; | ||
-- Create a new PostgreSQL database owned by the new user | ||
DO \$$ | ||
BEGIN | ||
IF NOT EXISTS ( | ||
SELECT FROM pg_catalog.pg_database | ||
WHERE datname = '${DB_NAME}' | ||
) THEN | ||
CREATE DATABASE ${DB_NAME} OWNER ${DB_USER}; | ||
END IF; | ||
END | ||
\$$; | ||
EOF | ||
|
||
# Variables | ||
PG_HBA_PATH="/var/lib/pgsql/data/pg_hba.conf" | ||
BACKUP_PATH="/var/lib/pgsql/backups/pg_hba.conf.bak" | ||
|
||
# Backup the original pg_hba.conf file | ||
if [ ! -f "$BACKUP_PATH" ]; then | ||
echo "Backing up the original pg_hba.conf to $BACKUP_PATH" | ||
sudo cp "$PG_HBA_PATH" "$BACKUP_PATH" | ||
else | ||
echo "Backup already exists at $BACKUP_PATH" | ||
fi | ||
|
||
# Update authentication method to md5 | ||
echo "Updating authentication method to md5 in $PG_HBA_PATH" | ||
sudo sed -i 's/^\(local\s\+all\s\+all\s\+\)peer/\1md5/' "$PG_HBA_PATH" | ||
sudo sed -i 's/^\(host\s\+all\s\+all\s\+127.0.0.1\/32\s\+\)ident/\1md5/' "$PG_HBA_PATH" | ||
sudo sed -i 's/^\(host\s\+all\s\+all\s\+::1\/128\s\+\)ident/\1md5/' "$PG_HBA_PATH" | ||
|
||
# Restart PostgreSQL to apply changes | ||
echo "Restarting PostgreSQL service to apply changes..." | ||
sudo systemctl restart postgresql | ||
|
||
echo "Authentication method updated to md5. Please test your connection." | ||
|
||
echo "User and database setup complete." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#! /bin/bash | ||
go run cmd/main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
|
||
# Default values for flags | ||
VERBOSE=false | ||
COVERAGE=false | ||
PACKAGE="" | ||
RACE=false | ||
TIMEOUT="" | ||
|
||
# Help message | ||
usage() { | ||
echo "Usage: $0 [options]" | ||
echo "Options:" | ||
echo " -v Enable verbose output for each test" | ||
echo " -c Generate a coverage report" | ||
echo " -p <package> Specify package to test (default is all packages)" | ||
echo " -r Enable race condition detection" | ||
echo " -t <time> Set a custom timeout (e.g., 2m, 1h)" | ||
echo " -h Display this help message" | ||
} | ||
|
||
# Parse command-line options | ||
while getopts "vcp:rt:h" opt; do | ||
case ${opt} in | ||
v ) VERBOSE=true ;; | ||
c ) COVERAGE=true ;; | ||
p ) PACKAGE=$OPTARG ;; | ||
r ) RACE=true ;; | ||
t ) TIMEOUT=$OPTARG ;; | ||
h ) usage; exit 0 ;; | ||
* ) usage; exit 1 ;; | ||
esac | ||
done | ||
|
||
# Base command | ||
CMD="go test" | ||
|
||
# Add flags based on options | ||
[ "$VERBOSE" = true ] && CMD+=" -v" | ||
[ "$RACE" = true ] && CMD+=" -race" | ||
[ -n "$TIMEOUT" ] && CMD+=" -timeout $TIMEOUT" | ||
[ -n "$PACKAGE" ] && CMD+=" $PACKAGE" || CMD+=" ./..." | ||
|
||
# Coverage option | ||
if [ "$COVERAGE" = true ]; then | ||
COVERAGE_FILE="coverage.out" | ||
CMD+=" -coverprofile=$COVERAGE_FILE" | ||
fi | ||
|
||
# Run the command | ||
echo "Running command: $CMD" | ||
$CMD | ||
|
||
# Show coverage report if generated | ||
if [ "$COVERAGE" = true ]; then | ||
echo "Coverage report:" | ||
go tool cover -func=$COVERAGE_FILE | ||
|
||
# Optional: Display HTML report | ||
# go tool cover -html=$COVERAGE_FILE | ||
fi |
This file was deleted.
Oops, something went wrong.