-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implement initial CosmosClient, DatabaseClient and "read database" API * updates after rebase * fix some warnings and test issues * rename "adhoc" sample to "connect" * add CODEOWNERS for CosmosDB * use 'cosmosdb' as example prefix * fix spacing * a few more tidy-ups * switch to a team in the cosmos CODEOWNERS * clippy and lint fixes * spelling updates * auth policy test updates * doc comment updates * switch to using Model derive macro * a couple build fixes * ok that one was my bad * fix conditional imports * omit CODEOWNERS from cspell check * use direct mentions in CODEOWNERS for now * pr feedback * fix derive macro broken during refactoring * use dictionary file and update Cosmos to "Cosmos DB"
- Loading branch information
1 parent
dfb354d
commit 1fbc5dd
Showing
17 changed files
with
977 additions
and
7 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
colls | ||
pkranges | ||
sprocs | ||
udfs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[package] | ||
name = "azure_data_cosmos" | ||
version = "0.19.0" | ||
description = "Rust wrappers around Microsoft Azure REST APIs - Azure Cosmos DB" | ||
readme = "README.md" | ||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
homepage = "https://github.com/azure/azure-sdk-for-rust" | ||
documentation = "https://docs.rs/azure_data_cosmos" | ||
keywords = ["sdk", "azure", "rest", "cloud", "cosmos", "database"] | ||
categories = ["api-bindings"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
async-trait.workspace = true | ||
azure_core.workspace = true | ||
typespec_client_core = { workspace = true, features = ["derive"] } | ||
tracing.workspace = true | ||
url.workspace = true | ||
serde.workspace = true | ||
|
||
[dev-dependencies] | ||
tokio.workspace = true | ||
serde_json.workspace = true | ||
azure_identity.workspace = true | ||
clap.workspace = true | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[features] | ||
default = ["hmac_rust"] | ||
hmac_rust = ["azure_core/hmac_rust"] | ||
hmac_openssl = ["azure_core/hmac_openssl"] | ||
key_auth = [] # Enables support for key-based authentication (Primary Keys and Resource Tokens) | ||
|
||
[package.metadata.docs.rs] | ||
features = ["key_auth"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Azure Cosmos DB SDK for Rust. | ||
|
||
## Introduction | ||
|
||
This client library enables client applications to connect to [Azure Cosmos DB](https://azure.microsoft.com/en-us/products/cosmos-db) via the NoSQL API. Azure Cosmos DB is a globally distributed, multi-model database service. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use azure_data_cosmos::{clients::DatabaseClientMethods, CosmosClient, CosmosClientMethods}; | ||
use clap::Parser; | ||
|
||
/// A simple example to show connecting to a Cosmos DB Account and retrieving the properties of a database. | ||
#[derive(Parser)] | ||
pub struct Args { | ||
/// The Cosmos DB endpoint to connect to. | ||
endpoint: String, | ||
|
||
/// The database to fetch information for. | ||
database: String, | ||
|
||
/// An authentication key to use when connecting to the Cosmos DB account. If omitted, the connection will use Entra ID. | ||
#[clap(long)] | ||
#[cfg(feature = "key_auth")] | ||
key: Option<String>, | ||
} | ||
|
||
#[tokio::main] | ||
pub async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let args = Args::parse(); | ||
|
||
let client = create_client(&args); | ||
|
||
let db_client = client.database_client(&args.database); | ||
let response = db_client.read(None).await?.deserialize_body().await?; | ||
println!("{:?}", response); | ||
Ok(()) | ||
} | ||
|
||
#[cfg(feature = "key_auth")] | ||
fn create_client(args: &Args) -> CosmosClient { | ||
if let Some(key) = args.key.as_ref() { | ||
CosmosClient::with_key(&args.endpoint, key.clone(), None).unwrap() | ||
} else { | ||
let cred = azure_identity::create_default_credential().unwrap(); | ||
CosmosClient::new(&args.endpoint, cred, None).unwrap() | ||
} | ||
} | ||
|
||
#[cfg(not(feature = "key_auth"))] | ||
fn create_client(args: &Args) -> CosmosClient { | ||
let cred = azure_identity::create_default_credential().unwrap(); | ||
CosmosClient::new(&args.endpoint, cred, None).unwrap() | ||
} |
Oops, something went wrong.