Module Cosmos_lwt.Databases

module type Auth_key = Cosmos.Databases_intf.Auth_key
module Credential : sig ... end
module type Credentials = Cosmos.Databases_intf.Credentials
val body_to_string : Cohttp_lwt.Body.t -> string Lwt.t
module Response_headers : sig ... end
type batch_validation_error = Cosmos.Databases_core.batch_validation_error =
  1. | Too_many_operations of int
  2. | Mixed_patch_operations
  3. | Empty_batch
type cosmos_error = Cosmos.Databases_core.Cosmos_error.t =
  1. | Timeout_error
  2. | Connection_error
  3. | Http_error of string
  4. | Azure_error of int * Response_headers.t
val string_of_cosmos_error : cosmos_error -> string

Human-readable description of a cosmos_error.

module type S = Database_intf.S

Database connects with master-key authentication.

module Database_as (C : Credentials) : S

Database_as connects with an arbitrary credential, e.g. a resource token minted through Permission. Master-key-only operations (list_databases, User, Permission, Offer) fail with Azure_error (401 | 403, _) under a resource token.

val credentials_of_token : endpoint:string -> string -> (module Credentials)

credentials_of_token ~endpoint token wraps a permission's _token as credentials suitable for Database_as.

val credentials_of_token_provider : endpoint:string -> (unit -> string) -> (module Credentials)

credentials_of_token_provider ~endpoint provider calls provider for every request, so callers can refresh expiring resource tokens.

val credentials_of_aad_token : endpoint:string -> string -> (module Credentials)

credentials_of_aad_token ~endpoint token wraps a Microsoft Entra ID access token (e.g. az account get-access-token --resource https://cosmos.azure.com) as credentials suitable for Database_as. Unlike a resource token, an Entra token authorizes every operation, including list_databases, User, Permission and Offer.

val credentials_of_aad_token_provider : endpoint:string -> (unit -> string) -> (module Credentials)

credentials_of_aad_token_provider ~endpoint provider calls provider for every request, so callers running their own refresh loop (managed identity, token broker) always supply a fresh Entra access token.

module type Aad = Cosmos.Databases_intf.Aad
module type Aad_client = Cosmos.Databases_intf.Aad_client
module Database_aad (A : Aad) : S

Database_aad connects with SDK-managed Microsoft Entra ID client credentials. The first request acquires a token from https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token; the token is cached and refreshed before expiry. The service principal needs a data-plane role assignment (e.g. Cosmos DB Built-in Data Contributor); control-plane roles do not apply.

val aad_client : ?scope:string -> ?authority_host:string -> ?now:(unit -> float) -> endpoint:string -> tenant_id:string -> client_id:string -> client_secret:string -> unit -> (module Aad_client)

aad_client builds a full Cosmos.Databases_intf.Aad_client module for sovereign clouds, a custom scope, or an injected clock; Database_aad covers the common case.