Skip to content
/ go-bash Public

Go-Bash is a project with a focus on working with bash scripts, through RESTful API

License

Notifications You must be signed in to change notification settings

Ki4EH/go-bash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go-Bash

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:

Features

  • Get information about all commands.
  • Insert a new command.
  • Remove an existing command.
  • Get information about specific commands by ID.

Technologies Used

  • 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.

Getting Started

To get a local copy up and running, follow these simple steps.

Prerequisites

  • Go (latest version)
  • PostgreSQL

Installation

  1. Clone the repo
    git clone https://github.com/Ki4EH/go-bash.git
  2. Install Go packages
    go mod download
  3. Create a PostgreSQL database. With the following schema:
    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
    );
    Or you can use init.sql file in the root directory to create the table.
     psql -U your_db_user -d your_db_name -a -f init.sql
  4. Create a .env file in the root directory and add the following environment variables
    POSTGRES_USER=your_db_user
    POSTGRES_PASSWORD=your_db_password
    POSTGRES_DB=your_db_name
    POSTGRES_HOST=your_db_host
    POSTGRES_PORT=your_db_port
  5. Run the application in directory where project cloned
     go run ./cmd/app/main.go
  6. The application should now be running on default http://localhost:8080
  7. You can now test the API using Postman or any other API testing tool

Docker Build and Run Guide

Before you start, make sure you have Docker and Docker Compose installed on your machine.

Steps

  1. Navigate to the project directory where project cloned and docker-compose.yml file is located.
cd /path/to/your/project
  1. Change in .env POSTGRES_HOST= to POSTGRES_HOST=db for saving data in the database container.

  2. Change ports in docker-compose.yml on your own if you need to use another port for the application or database

  3. Build the Docker image.

docker-compose build
  1. After the build is complete, run the Docker container.
docker-compose up
  1. Now the application should be running on default http://localhost:8082

API Endpoints

  • 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"
    }

🚀 Roadmap

  1. 🔒 Add authentication and authorization.
  2. 📝 Add support for running commands with arguments.
  3. 🌍 Add support for running commands with environment variables.
  4. 🔄 Add support for running commands with input/output redirection.
  5. ⏱️ Add support for running commands with a timeout.
  6. 👤 Add support for running commands with a specific user.
  7. 📂 Add support for running commands with a specific working directory.
  8. 🛡️ Add protection from SQL Injection Attacks and other security vulnerabilities.

Contact

Kirill Aksenov - [email protected]

Telegram - @ki4eh

About

Go-Bash is a project with a focus on working with bash scripts, through RESTful API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published