๐ Rust Azure CLI Wrapper for Cosmos DB
A type-safe and ergonomic Rust wrapper for Azure CLI, with specific focus on Cosmos DB
๐ฏ About the Project
This project provides a type-safe and ergonomic Rust interface for Azure CLI operations related to Cosmos DB. Instead of dealing with command line commands and manual JSON parsing, you get:
- โ Typed structs for all Azure resources
- โ Automatic serialization/deserialization to/from JSON
- โ Robust error handling with specific types
- โ Asynchronous operations with Tokio
- โ Complete multi-subscription support
- โ Ergonomic API that abstracts Azure CLI complexity
โจ Features
- ๐ Complete abstractions for Azure CLI commands related to Cosmos DB
- ๐ฆ Serializable models for all resources (JSON in/out)
- ๐ก๏ธ Robust error handling with specific types
- โก Asynchronous operations with Tokio
- ๐ฏ Cosmos DB focused - SQL API, MongoDB, throughput, keys
- ๐ Multi-subscription support - work with specific subscriptions
- ๐ Resource Groups - complete management
- ๐งช Extensively tested with real Azure data
๐ Quick Start
โ๏ธ Prerequisites
- Rust 1.70+
- Azure CLI installed and configured (
az --version) - Valid Azure authentication (
az login)
# Check prerequisites
Basic Client
use ;
async
Working with Specific Subscriptions
use ;
async
Complete Example - Cosmos DB
use ;
async
๐๏ธ Project Architecture
rust_az_wrapper/
โโโ src/
โ โโโ lib.rs # ๐ Main API and public exports
โ โโโ client.rs # ๐ง Unified Azure client
โ โโโ commands/ # ๐ Azure CLI specific commands
โ โ โโโ account.rs # โโ Subscriptions and Resource Groups
โ โ โโโ cosmos.rs # โโ Cosmos DB specific
โ โโโ models.rs # ๐ Typed models for Azure resources
โ โโโ utils.rs # ๐ ๏ธ Utilities and command builder
โ โโโ error.rs # โ ๏ธ Typed error system
โโโ examples/ # ๐ฏ Practical examples
โ โโโ basic_usage.rs # โโ Basic wrapper usage
โ โโโ json_output.rs # โโ JSON conversion
โ โโโ subscription_usage.rs โโ Working with subscriptions
โโโ tests/ # ๐งช Integration tests
โโโ README.md, Cargo.toml # ๐ Documentation and configuration
๐ง Implemented Features
โ Subscriptions & Resource Groups
// List and manage subscriptions
let subs = client.list_subscriptions.await?;
let current = client.show_current_subscription.await?;
// Resource Groups with specific subscription
let rgs = client.list_resource_groups.await?;
let rg = client.show_resource_group.await?;
โ Cosmos DB Accounts
// Complete CRUD for accounts
let accounts = client.list_cosmos_accounts.await?;
let account = client.show_cosmos_account.await?;
let new_account = client.create_cosmos_account.await?;
โ Keys and Authentication
// Keys and connection strings
let keys = client.list_cosmos_keys.await?;
let readonly_keys = client.list_cosmos_read_only_keys.await?;
let conn_strings = client.list_cosmos_connection_strings.await?;
โ SQL API - Databases & Containers
// SQL Databases
let databases = client.list_sql_databases.await?;
let new_db = client.create_sql_database.await?;
// SQL Containers
let containers = client.list_sql_containers.await?;
let new_container = client.create_sql_container.await?;
โ MongoDB API
// MongoDB databases and collections
let mongo_dbs = client.list_mongodb_databases.await?;
let collections = client.list_mongodb_collections.await?;
โ Throughput Management
// Performance management
let db_throughput = client.get_database_throughput.await?;
let updated = client.update_database_throughput.await?;
Clone and Test
# Run tests (requires configured Azure CLI)
# Run examples
๐งช Test Status
The project has extensive test coverage with real Azure data:
# Unit and integration tests
# Functional examples
๐ Automatic JSON Conversion
All types implement Serialize and Deserialize:
use ;
async
๐ฏ Use Cases
DevOps & Automation
// Automate Cosmos DB deployment
let account = client.create_cosmos_account.await?;
let database = client.create_sql_database.await?;
let container = client.create_sql_container.await?;
Monitoring & Inventory
// Discover resources across multiple subscriptions
for sub in subscriptions
Migration & Backup
// Get configurations for migration
let account = client.show_cosmos_account.await?;
let databases = client.list_sql_databases.await?;
let keys = client.list_cosmos_keys.await?;
๐ค Contributing
- Fork the project
- Create a branch (
git checkout -b feature/new-feature) - Commit changes (
git commit -am 'Add new feature') - Push to branch (
git push origin feature/new-feature) - Open a Pull Request