This Flask API generates Behavior-Driven Development (BDD) scenarios in Gherkin syntax for cloud infrastructure security. The API leverages Gemini 1.5 Flash for natural language generation and a pre-built vector index for document querying.
- Generates Gherkin-based BDD scenarios for Terraform configurations.
- Accepts cloud
providerandserviceas inputs. - Uses a pre-persisted vector index and Gemini 1.5 Flash LLM for responses.
- Python 3.8+
- A
GOOGLE_API_KEYenvironment variable with access to Gemini 1.5 Flash. - Pre-built index stored in the
./storagedirectory.
Ensure you have the following installed:
-
Clone the Repository:
git clone https://github.com/your-repository/terraform-bdd-api.git cd terraform-bdd-api -
Install Dependencies:
pip install -r requirements.txt
-
Set the Environment Variable: Create a
.envfile in the root directory:echo "GOOGLE_API_KEY=your_google_api_key" > .env
Replace
your_google_api_keywith your valid API key. -
Ensure the Persisted Index: Place the pre-built index files in the
./storagedirectory.
This API relies on a vector index created using llama-index. Make sure your ./storage directory contains the persisted index files (docstore.json, index_store.json, etc.). Use StorageContext.from_defaults(persist_dir="./storage") during indexing.
Start the Flask app:
python app.pyThe API will run locally at http://127.0.0.1:5000.
Generate BDD scenarios for a specified cloud provider and service.
-
Request:
{ "provider": "GCP", "service": "Storage Bucket" } -
Response: Returns a string containing the Gherkin-based BDD scenario.
Example:
Scenario: Mitigating public access vulnerability in Storage Bucket Given a configuration for Storage Bucket on GCP When permissions are set to allow public access Then restrict bucket access to authorized users only to prevent unauthorized access
curl -X POST http://127.0.0.1:5000/generate_scenario -H "Content-Type: application/json" -d '{"provider": "AWS", "service": "S3 Bucket"}'├── app.py # Flask API implementation
├── storage/ # Persisted index files (pre-built)
├── requirements.txt # Python dependencies
├── README.md # Project documentation
└── .env # Environment variables
GOOGLE_API_KEY: Required for Gemini 1.5 Flash API access.
-
Missing API Key: Ensure the
.envfile contains the correctGOOGLE_API_KEY. -
Index Not Found: Verify the
./storagedirectory contains the persisted index files. -
Flask Errors:
- Ensure all dependencies are installed.
- Check for typos in the request payload.
This project is licensed under the MIT License.