dsqlenv-Env
中文 | English
dsqlenv
is a SQL database operation tool designed to help developers quickly synchronize common variables, such as API keys, across different environments or hosts. All variables stored in the database are encrypted using AES for enhanced security.
Table of Contents
Features
- Environment Variable Management: Search and update environment variables using keywords or regular expressions.
- Database Operations: Perform basic SQL operations like get, insert, update, and delete records securely.
- AES Encryption: All variables stored in the database are encrypted to ensure sensitive information is protected.
Installation
To install dsqlenv
, follow these steps:
-
Clone the repository:
git clone https://gitee.com/iint/dsqlenv.git
cd dsqlenv
-
Install the required dependencies:
pip install -r requirements.txt
-
Create a .env
file in the root directory and define the necessary environment variables, as explained in the next section.
or
pip install dsqlenv
Configuration
Before using dsqlenv
, ensure that your environment variables contain the following database information:
DB_USER='<username>'
DB_PASSWORD='<password>'
DB_NAME='xxx'
DB_HOST='xxx'
DB_PORT='xxx'
AES_KEY='xxx'
TABLE_NAME='dagent_info'
ID_COLUMN='name'
INFO_COLUMN='data'
Make sure to replace the placeholder values with your actual database credentials.
Quick Usage
To get started with dsqlenv
, you can use the command-line interface (CLI) for quick database and environment variable operations.
Basic Commands
-
Get a Record:
dsqlenv db --action get --id <Record ID>
-
Insert a Record:
dsqlenv db --action insert --id <Record ID> --data <Record data>
-
Update a Record:
dsqlenv db --action update --id <Record ID> --data <Record data>
-
Delete a Record:
dsqlenv db --action delete --id <Record ID>
Python Usage Examples
You can also use the dsqlenv
library directly in your Python code.
from dsqlenv.core import SQL
from dsqlenv.config import load_config
config = load_config()
db = SQL(config)
db.insert_data("api_key", "your_api_key")
data = db.get_data_by_id("api_key")
print(data)
db.update_data("api_key", "new_api_key")
db.delete_data("api_key")
CLI Usage Examples
Here are some examples of how to use the CLI effectively:
-
Search for Environment Variables:
dsqlenv search-env --keyword SECRET
-
Update an Environment Variable:
dsqlenv update-env --key API_KEY --value new_value
-
Search using Regular Expressions:
dsqlenv re search '^SECRET'
-
Update using Regular Expressions:
dsqlenv re update '^API_' 'new_value'
License
This project is licensed under the MIT License. See the LICENSE file for details.