This project is designed to manage BlueBanquise Ansible inventories via a REST API.
.
├── README.md
├── controllers
│ └── nodeController.go # Handles the API routes
├── go.mod # Go module file
├── go.sum # Go dependency file
├── helpers
│ ├── hosts.go # Functions for fetching node details from the hosts section
│ ├── inventory.go # Functions to map inventory files and retrieve paths
│ └── yaml.go # Functions to load and parse YAML files
├── main.go # Application entry point
├── models
│ ├── groups.go # Data model for group variables
│ ├── inventory.go # Data model for the entire cluster inventory
│ ├── network.go # Data model for network configurations
│ └── nodes.go # Data model for nodes and hardware specifications
├── routes
│ └── routes.go # Route definitions
├── services
│ └── nodeService.go # Business logic for working with nodes
└── utils
└── mergeMaps.go # Utility to merge maps
- Controllers handle the HTTP requests and route them to the appropriate service. For example, the GetAllNodes controller retrieves all nodes for a specific role from the inventory.
- Services contain the business logic, handling the manipulation of nodes and interaction with YAML files. For example, UpdateNodeVars updates a node in the inventory.
- Helpers provide utility functions such as loading and parsing YAML files, mapping inventory files, and fetching node data from the inventory.
Make sure you have the following installed:
- Go (version 1.17 or higher)
- A BlueBanquise inventory file available at the location specified in your
.env
file
- Clone the repository:
git clone https://github.com/your-username/bb-api.git
cd bb-api
- Install the required Go dependencies:
go mod tidy
The project uses a .env
file to manage configuration, including API settings and the BlueBanquise inventory file path. A template of the .env
file can be found as .env.example
.
Here’s how you can configure the environment variables:
# API
GIN_APP_API_IP=localhost
GIN_APP_API_PORT=:8080
# BlueBanquise spec
BLUEBANQUISE_INVENTORY_FILE_PATH='/etc/bluebanquise/inventory'
GIN_APP_API_IP
: The IP address or hostname where the API will run.GIN_APP_API_PORT
: The port on which the API will be accessible.BLUEBANQUISE_INVENTORY_FILE_PATH
: Path to the BlueBanquise inventory directory, used to load the YAML files.
- Create a
.env
file in the root of your project by copying the.env.example
:
cp .env.example .env
- Modify the
.env
file according to your environment settings.
To start the API, run:
go run main.go
The API will be available at http://localhost:8080
(or the IP and port you specified).