Go-Bash is a REST API built with Go that allows you to run bash scripts. It provides a simple and efficient way to manage and execute bash scripts through a RESTful interface.
Topics:
- Get information about all commands.
- Insert a new command.
- Remove an existing command.
- Get information about specific commands by ID.
- Go: The backend is built entirely in Go.
- Gorilla Mux: A powerful HTTP router and URL matcher for building Go web servers.
- PostgreSQL: Used as the primary database for storing command information.
- Docker: Used to containerize the application.
- DATA-DOG/go-sqlmock: Used for testing the database layer.
- godotenv: Used for loading environment variables from a
.env
file.
To get a local copy up and running, follow these simple steps.
- Go (latest version)
- PostgreSQL
- Clone the repo
git clone https://github.com/Ki4EH/go-bash.git
- Install Go packages
go mod download
- Create a PostgreSQL database. With the following schema:
Or you can use init.sql file in the root directory to create the table.
CREATE TABLE IF NOT EXISTS "commands" ( "id" SERIAL PRIMARY KEY, "name" TEXT NOT NULL, "script" TEXT NOT NULL, "description" TEXT NOT NULL, "output" TEXT NOT NULL );
psql -U your_db_user -d your_db_name -a -f init.sql
- Create a
.env
file in the root directory and add the following environment variablesPOSTGRES_USER=your_db_user POSTGRES_PASSWORD=your_db_password POSTGRES_DB=your_db_name POSTGRES_HOST=your_db_host POSTGRES_PORT=your_db_port
- Run the application in directory where project cloned
go run ./cmd/app/main.go
- The application should now be running on default
http://localhost:8080
- You can now test the API using Postman or any other API testing tool
Before you start, make sure you have Docker and Docker Compose installed on your machine.
- Navigate to the project directory where project cloned and
docker-compose.yml
file is located.
cd /path/to/your/project
-
Change in
.env
POSTGRES_HOST=
toPOSTGRES_HOST=db
for saving data in the database container. -
Change ports in
docker-compose.yml
on your own if you need to use another port for the application or database -
Build the Docker image.
docker-compose build
- After the build is complete, run the Docker container.
docker-compose up
- Now the application should be running on default
http://localhost:8082
GET /info
: Get information about all commands.- returns a JSON array of all commands. Example:
[ { "id": 1, "name": "test" } ]
POST /new
: Insert a new command. The request body should be a JSON object representing the command.- body example:
{ "name": "test", "script": "echo 'Hello, World!'", "description": "test description" }
GET /remove?id={id}
: Remove an existing command by ID.GET /info-by-id?id={id}
: Get information about a specific command by ID.- returns a JSON object representing the command. Example:
{ "id": 1, "name": "test", "script": "echo 'Hello, World!'", "description": "test description", "output": "Hello, World!\n" }
- 🔒 Add authentication and authorization.
- 📝 Add support for running commands with arguments.
- 🌍 Add support for running commands with environment variables.
- 🔄 Add support for running commands with input/output redirection.
- ⏱️ Add support for running commands with a timeout.
- 👤 Add support for running commands with a specific user.
- 📂 Add support for running commands with a specific working directory.
- 🛡️ Add protection from SQL Injection Attacks and other security vulnerabilities.