From 1f388853b5a55306ff23fa3b00be8742b3a98ab4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 15:02:38 +0000 Subject: [PATCH 01/11] Initial plan From c727bb6311422647c4d033b065749b8bbe76b2c9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 15:22:37 +0000 Subject: [PATCH 02/11] Add three Azure Cosmos DB code samples (dotnet, python, go) - dotnet/001-connect-passwordless: .NET 8 passwordless auth via DefaultAzureCredential - python/002-connect-connection-string: Python connection string auth with python-dotenv - go/101-create-item: Go full CRUD sample with key-based auth Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../001-connect-passwordless/CosmosApp.csproj | 15 +++ dotnet/001-connect-passwordless/Program.cs | 33 +++++ dotnet/001-connect-passwordless/readme.md | 61 +++++++++ go/101-create-item/.env.example | 2 + go/101-create-item/go.mod | 5 + go/101-create-item/main.go | 126 ++++++++++++++++++ go/101-create-item/readme.md | 52 ++++++++ .../.env.example | 1 + python/002-connect-connection-string/app.py | 39 ++++++ .../002-connect-connection-string/readme.md | 45 +++++++ .../requirements.txt | 2 + 11 files changed, 381 insertions(+) create mode 100644 dotnet/001-connect-passwordless/CosmosApp.csproj create mode 100644 dotnet/001-connect-passwordless/Program.cs create mode 100644 dotnet/001-connect-passwordless/readme.md create mode 100644 go/101-create-item/.env.example create mode 100644 go/101-create-item/go.mod create mode 100644 go/101-create-item/main.go create mode 100644 go/101-create-item/readme.md create mode 100644 python/002-connect-connection-string/.env.example create mode 100644 python/002-connect-connection-string/app.py create mode 100644 python/002-connect-connection-string/readme.md create mode 100644 python/002-connect-connection-string/requirements.txt diff --git a/dotnet/001-connect-passwordless/CosmosApp.csproj b/dotnet/001-connect-passwordless/CosmosApp.csproj new file mode 100644 index 0000000..9d4321c --- /dev/null +++ b/dotnet/001-connect-passwordless/CosmosApp.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + diff --git a/dotnet/001-connect-passwordless/Program.cs b/dotnet/001-connect-passwordless/Program.cs new file mode 100644 index 0000000..87f7b81 --- /dev/null +++ b/dotnet/001-connect-passwordless/Program.cs @@ -0,0 +1,33 @@ +using Azure.Identity; +using Microsoft.Azure.Cosmos; + +string endpoint = Environment.GetEnvironmentVariable("COSMOS_ENDPOINT") + ?? throw new InvalidOperationException("COSMOS_ENDPOINT environment variable is not set."); + +var credential = new DefaultAzureCredential(); +var client = new CosmosClient(endpoint, credential); + +Database database = await client.CreateDatabaseIfNotExistsAsync("cosmicworks"); +Console.WriteLine($"Created/retrieved database: {database.Id}"); + +Container container = await database.CreateContainerIfNotExistsAsync("products", "/category"); +Console.WriteLine($"Created/retrieved container: {container.Id}"); + +Product newItem = new( + id: "70b63682-b93a-4c77-aad2-65501347265f", + category: "gear-surf-surfboards", + name: "Yamba Surfboard", + quantity: 12, + sale: false +); + +ItemResponse createResponse = await container.UpsertItemAsync(newItem, new PartitionKey(newItem.category)); +Console.WriteLine($"Upserted item: {createResponse.Resource.id} (status: {createResponse.StatusCode})"); + +ItemResponse readResponse = await container.ReadItemAsync( + newItem.id, + new PartitionKey(newItem.category) +); +Console.WriteLine($"Read item: {readResponse.Resource.name} | Quantity: {readResponse.Resource.quantity}"); + +record Product(string id, string category, string name, int quantity, bool sale); diff --git a/dotnet/001-connect-passwordless/readme.md b/dotnet/001-connect-passwordless/readme.md new file mode 100644 index 0000000..7cbeb9b --- /dev/null +++ b/dotnet/001-connect-passwordless/readme.md @@ -0,0 +1,61 @@ +# Connect to Azure Cosmos DB for NoSQL — Passwordless (.NET) + +This sample demonstrates how to authenticate to Azure Cosmos DB for NoSQL using **passwordless authentication** via `DefaultAzureCredential` from the Azure Identity library. No connection strings or keys are required. + +## Prerequisites + +- An [Azure subscription](https://azure.microsoft.com/free/) +- An Azure Cosmos DB for NoSQL account +- [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) +- [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli) (for local development login) + +## Setup + +### 1. Assign the required role + +Grant your Azure AD identity the **Cosmos DB Built-in Data Contributor** role on your Cosmos DB account: + +```bash +az cosmosdb sql role assignment create \ + --account-name \ + --resource-group \ + --role-definition-name "Cosmos DB Built-in Data Contributor" \ + --principal-id $(az ad signed-in-user show --query id -o tsv) \ + --scope "/" +``` + +### 2. Set the environment variable + +```bash +# Linux / macOS +export COSMOS_ENDPOINT="https://.documents.azure.com:443/" + +# Windows (Command Prompt) +set COSMOS_ENDPOINT=https://.documents.azure.com:443/ + +# Windows (PowerShell) +$env:COSMOS_ENDPOINT = "https://.documents.azure.com:443/" +``` + +### 3. Log in with Azure CLI (local development) + +```bash +az login +``` + +`DefaultAzureCredential` automatically uses your Azure CLI login locally. In production (Azure App Service, Azure Functions, Azure Container Apps, etc.) it uses the managed identity assigned to the resource — no code changes needed. + +## Run + +```bash +dotnet run +``` + +## What this sample does + +1. Reads the `COSMOS_ENDPOINT` environment variable +2. Authenticates using `DefaultAzureCredential` (Azure CLI / Managed Identity / etc.) +3. Creates (or retrieves) a database named `cosmicworks` +4. Creates (or retrieves) a container named `products` with partition key `/category` +5. Creates a product item +6. Reads the item back and prints its details diff --git a/go/101-create-item/.env.example b/go/101-create-item/.env.example new file mode 100644 index 0000000..fe52080 --- /dev/null +++ b/go/101-create-item/.env.example @@ -0,0 +1,2 @@ +COSMOS_ENDPOINT=https://.documents.azure.com:443/ +COSMOS_KEY= diff --git a/go/101-create-item/go.mod b/go/101-create-item/go.mod new file mode 100644 index 0000000..4ac8e93 --- /dev/null +++ b/go/101-create-item/go.mod @@ -0,0 +1,5 @@ +module github.com/AzureCosmosDB/samples/go/101-create-item + +go 1.21 + +require github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v0.4.0 diff --git a/go/101-create-item/main.go b/go/101-create-item/main.go new file mode 100644 index 0000000..31c9163 --- /dev/null +++ b/go/101-create-item/main.go @@ -0,0 +1,126 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "log" + "net/http" + "os" + + "github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos" +) + +type Product struct { + ID string `json:"id"` + Category string `json:"category"` + Name string `json:"name"` + Quantity int `json:"quantity"` + Sale bool `json:"sale"` +} + +func main() { + endpoint := os.Getenv("COSMOS_ENDPOINT") + if endpoint == "" { + log.Fatalf("COSMOS_ENDPOINT environment variable is not set") + } + key := os.Getenv("COSMOS_KEY") + if key == "" { + log.Fatalf("COSMOS_KEY environment variable is not set") + } + + cred, err := azcosmos.NewKeyCredential(key) + if err != nil { + log.Fatalf("failed to create key credential: %v", err) + } + + client, err := azcosmos.NewClientWithKey(endpoint, cred, nil) + if err != nil { + log.Fatalf("failed to create cosmos client: %v", err) + } + + ctx := context.Background() + + // Create database (ignore conflict if already exists) + _, err = client.CreateDatabase(ctx, azcosmos.DatabaseProperties{ID: "cosmicworks"}, nil) + if err != nil && !isConflict(err) { + log.Fatalf("failed to create database: %v", err) + } + fmt.Println("Created/retrieved database: cosmicworks") + + dbClient, err := client.NewDatabase("cosmicworks") + if err != nil { + log.Fatalf("failed to get database client: %v", err) + } + + // Create container (ignore conflict if already exists) + _, err = dbClient.CreateContainer(ctx, azcosmos.ContainerProperties{ + ID: "products", + PartitionKeyDefinition: azcosmos.PartitionKeyDefinition{ + Paths: []string{"/category"}, + }, + }, nil) + if err != nil && !isConflict(err) { + log.Fatalf("failed to create container: %v", err) + } + fmt.Println("Created/retrieved container: products") + + containerClient, err := client.NewContainer("cosmicworks", "products") + if err != nil { + log.Fatalf("failed to get container client: %v", err) + } + + product := Product{ + ID: "70b63682-b93a-4c77-aad2-65501347265f", + Category: "gear-surf-surfboards", + Name: "Yamba Surfboard", + Quantity: 12, + Sale: false, + } + pk := azcosmos.NewPartitionKeyString(product.Category) + + // CREATE + itemBytes, err := json.Marshal(product) + if err != nil { + log.Fatalf("failed to marshal product: %v", err) + } + _, err = containerClient.UpsertItem(ctx, pk, itemBytes, nil) + if err != nil { + log.Fatalf("failed to upsert item: %v", err) + } + fmt.Printf("Upserted item: %s\n", product.ID) + + // READ + readResp, err := containerClient.ReadItem(ctx, pk, product.ID, nil) + if err != nil { + log.Fatalf("failed to read item: %v", err) + } + var readProduct Product + if err = json.Unmarshal(readResp.Value, &readProduct); err != nil { + log.Fatalf("failed to unmarshal read response: %v", err) + } + fmt.Printf("Read item: %s | Quantity: %d\n", readProduct.Name, readProduct.Quantity) + + // UPDATE + readProduct.Quantity = 20 + updatedBytes, err := json.Marshal(readProduct) + if err != nil { + log.Fatalf("failed to marshal updated product: %v", err) + } + _, err = containerClient.ReplaceItem(ctx, pk, readProduct.ID, updatedBytes, nil) + if err != nil { + log.Fatalf("failed to replace item: %v", err) + } + fmt.Printf("Updated item: %s | New quantity: %d\n", readProduct.ID, readProduct.Quantity) + + // DELETE + _, err = containerClient.DeleteItem(ctx, pk, product.ID, nil) + if err != nil { + log.Fatalf("failed to delete item: %v", err) + } + fmt.Printf("Deleted item: %s\n", product.ID) +} + +func isConflict(err error) bool { + return azcosmos.IsErrorCode(err, http.StatusConflict) +} diff --git a/go/101-create-item/readme.md b/go/101-create-item/readme.md new file mode 100644 index 0000000..f169b84 --- /dev/null +++ b/go/101-create-item/readme.md @@ -0,0 +1,52 @@ +# CRUD Operations with Azure Cosmos DB for NoSQL (Go) + +This sample demonstrates the four fundamental **CRUD** operations (Create, Read, Update, Delete) against Azure Cosmos DB for NoSQL using the Azure SDK for Go. + +## Prerequisites + +- An [Azure subscription](https://azure.microsoft.com/free/) +- An Azure Cosmos DB for NoSQL account +- [Go 1.21+](https://go.dev/dl/) + +## Setup + +### Set environment variables + +```bash +# Linux / macOS +export COSMOS_ENDPOINT="https://.documents.azure.com:443/" +export COSMOS_KEY="" + +# Windows (Command Prompt) +set COSMOS_ENDPOINT=https://.documents.azure.com:443/ +set COSMOS_KEY= + +# Windows (PowerShell) +$env:COSMOS_ENDPOINT = "https://.documents.azure.com:443/" +$env:COSMOS_KEY = "" +``` + +You can find your endpoint and primary key in the Azure portal under your Cosmos DB account → **Keys**. + +### Install dependencies + +```bash +go mod tidy +``` + +## Run + +```bash +go run main.go +``` + +## Operations demonstrated + +| Operation | Description | +|-----------|-------------| +| **Create** | Inserts a new `Product` item into the `products` container | +| **Read** | Retrieves the item by ID and partition key, prints its name and quantity | +| **Update** | Modifies the `quantity` field to `20` and replaces the item | +| **Delete** | Removes the item from the container | + +The sample uses key-based authentication (`COSMOS_KEY`) and creates the `cosmicworks` database and `products` container (partitioned by `/category`) if they do not already exist. diff --git a/python/002-connect-connection-string/.env.example b/python/002-connect-connection-string/.env.example new file mode 100644 index 0000000..8f2614e --- /dev/null +++ b/python/002-connect-connection-string/.env.example @@ -0,0 +1 @@ +COSMOS_CONNECTION_STRING=AccountEndpoint=https://.documents.azure.com:443/;AccountKey===; diff --git a/python/002-connect-connection-string/app.py b/python/002-connect-connection-string/app.py new file mode 100644 index 0000000..b9abaec --- /dev/null +++ b/python/002-connect-connection-string/app.py @@ -0,0 +1,39 @@ +import os + +from dotenv import load_dotenv +from azure.cosmos import CosmosClient, PartitionKey + +load_dotenv() + +connection_string = os.environ.get("COSMOS_CONNECTION_STRING") +if not connection_string: + raise ValueError("COSMOS_CONNECTION_STRING environment variable is not set.") + +client = CosmosClient.from_connection_string(connection_string) + +database = client.create_database_if_not_exists("cosmicworks") +print(f"Created/retrieved database: {database.id}") + +container = database.create_container_if_not_exists( + id="products", + partition_key=PartitionKey(path="/category"), +) +print(f"Created/retrieved container: {container.id}") + +new_item = { + "id": "70b63682-b93a-4c77-aad2-65501347265f", + "category": "gear-surf-surfboards", + "name": "Yamba Surfboard", + "quantity": 12, + "sale": False, +} + +created = container.upsert_item(body=new_item) +print(f"Upserted item: {created['id']}") + +query = "SELECT * FROM products p WHERE p.category = @category" +parameters = [{"name": "@category", "value": "gear-surf-surfboards"}] + +items = list(container.query_items(query=query, parameters=parameters, enable_cross_partition_query=False)) +for item in items: + print(f"Read item: {item['name']} | Quantity: {item['quantity']} | Sale: {item['sale']}") diff --git a/python/002-connect-connection-string/readme.md b/python/002-connect-connection-string/readme.md new file mode 100644 index 0000000..26da0ce --- /dev/null +++ b/python/002-connect-connection-string/readme.md @@ -0,0 +1,45 @@ +# Connect to Azure Cosmos DB for NoSQL — Connection String (Python) + +This sample demonstrates how to authenticate to Azure Cosmos DB for NoSQL using a **connection string** (account endpoint + key). This is a quick way to get started, especially for local development and testing. + +## Prerequisites + +- An [Azure subscription](https://azure.microsoft.com/free/) +- An Azure Cosmos DB for NoSQL account +- [Python 3.8+](https://www.python.org/downloads/) + +## Setup + +### 1. Copy the example env file + +```bash +cp .env.example .env +``` + +### 2. Fill in your connection string + +Open `.env` and replace the placeholder with your actual connection string: + +``` +COSMOS_CONNECTION_STRING=AccountEndpoint=https://.documents.azure.com:443/;AccountKey===; +``` + +You can find the connection string in the Azure portal under your Cosmos DB account → **Keys** → **PRIMARY CONNECTION STRING**. + +> **Security note:** Never commit your `.env` file to source control. It is already listed in `.gitignore` by convention. + +## Run + +```bash +pip install -r requirements.txt && python app.py +``` + +## What this sample does + +1. Loads environment variables from a `.env` file (if present) using `python-dotenv` +2. Reads `COSMOS_CONNECTION_STRING` from the environment +3. Creates a `CosmosClient` using the connection string +4. Creates (or retrieves) a database named `cosmicworks` +5. Creates (or retrieves) a container named `products` with partition key `/category` +6. Creates a product item +7. Queries items filtered by category and prints the results diff --git a/python/002-connect-connection-string/requirements.txt b/python/002-connect-connection-string/requirements.txt new file mode 100644 index 0000000..c829d98 --- /dev/null +++ b/python/002-connect-connection-string/requirements.txt @@ -0,0 +1,2 @@ +azure-cosmos==4.9.0 +python-dotenv==1.0.1 From f4a2a92f6274b47743f3f588bec033470b1a5a0b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 15:28:27 +0000 Subject: [PATCH 03/11] Add .gitignore, go.sum, and updated go.mod for Go CRUD sample Co-authored-by: seesharprun <5067401+seesharprun@users.noreply.github.com> --- .gitignore | 27 +++++++++++++++++++++++++++ go/101-create-item/go.mod | 14 ++++++++++++-- go/101-create-item/go.sum | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 go/101-create-item/go.sum diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cb3452b --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# .NET build artifacts +bin/ +obj/ +*.user +*.suo +.vs/ + +# Python +__pycache__/ +*.py[cod] +*.pyo +.venv/ +venv/ +env/ +*.egg-info/ + +# Environment variables +.env + +# Go +# (go.sum should be committed) + +# macOS +.DS_Store + +# JetBrains +.idea/ diff --git a/go/101-create-item/go.mod b/go/101-create-item/go.mod index 4ac8e93..b02ab08 100644 --- a/go/101-create-item/go.mod +++ b/go/101-create-item/go.mod @@ -1,5 +1,15 @@ module github.com/AzureCosmosDB/samples/go/101-create-item -go 1.21 +go 1.23.0 -require github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v0.4.0 +toolchain go1.24.13 + +require github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v1.4.2 + +require ( + github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.1 // indirect + golang.org/x/net v0.38.0 // indirect + golang.org/x/text v0.23.0 // indirect +) diff --git a/go/101-create-item/go.sum b/go/101-create-item/go.sum new file mode 100644 index 0000000..ab69555 --- /dev/null +++ b/go/101-create-item/go.sum @@ -0,0 +1,36 @@ +github.com/Azure/azure-sdk-for-go v68.0.0+incompatible h1:fcYLmCpyNYRnvJbPerq7U0hS+6+I79yEDJBqVNcqUzU= +github.com/Azure/azure-sdk-for-go v68.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1 h1:DSDNVxqkoXJiko6x8a90zidoYqnYYa6c1MTzDKzKkTo= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1/go.mod h1:zGqV2R4Cr/k8Uye5w+dgQ06WJtEcbQG/8J7BB6hnCr4= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.2 h1:F0gBpfdPLGsw+nsgk6aqqkZS1jiixa5WwFe3fk/T3Ys= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.2/go.mod h1:SqINnQ9lVVdRlyC8cd1lCI0SdX4n2paeABd2K8ggfnE= +github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v1.4.2 h1:zqxnp53f5Jn5PFU5Av4mvyWEbZ7whg72AoOCEzlXFKc= +github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v1.4.2/go.mod h1:Krtog/7tz27z75TwM5cIS8bxEH4dcBUezcq+kGVeZEo= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.1 h1:FPKJS1T+clwv+OLGt13a8UjqeRuh0O4SJ3lUriThc+4= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.1/go.mod h1:j2chePtV91HrC22tGoRX3sGY42uF13WzmmV80/OdVAA= +github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2 h1:oygO0locgZJe7PpYPXT5A29ZkwJaPqcva7BVeemZOZs= +github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8= +github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= +github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= +golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= +golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= +golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= +golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= +golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From e176df5ec9c60a1a169ccd5445fcf006d336e68e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 15:41:44 +0000 Subject: [PATCH 04/11] Move language-specific .gitignores to language folders; slim root .gitignore Co-authored-by: seesharprun <5067401+seesharprun@users.noreply.github.com> --- .gitignore | 22 --- dotnet/.gitignore | 428 ++++++++++++++++++++++++++++++++++++++++++++++ go/.gitignore | 32 ++++ python/.gitignore | 216 +++++++++++++++++++++++ 4 files changed, 676 insertions(+), 22 deletions(-) create mode 100644 dotnet/.gitignore create mode 100644 go/.gitignore create mode 100644 python/.gitignore diff --git a/.gitignore b/.gitignore index cb3452b..5bb0edd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,25 +1,3 @@ -# .NET build artifacts -bin/ -obj/ -*.user -*.suo -.vs/ - -# Python -__pycache__/ -*.py[cod] -*.pyo -.venv/ -venv/ -env/ -*.egg-info/ - -# Environment variables -.env - -# Go -# (go.sum should be committed) - # macOS .DS_Store diff --git a/dotnet/.gitignore b/dotnet/.gitignore new file mode 100644 index 0000000..47a94ef --- /dev/null +++ b/dotnet/.gitignore @@ -0,0 +1,428 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates +*.env + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ + +[Dd]ebug/x64/ +[Dd]ebugPublic/x64/ +[Rr]elease/x64/ +[Rr]eleases/x64/ +bin/x64/ +obj/x64/ + +[Dd]ebug/x86/ +[Dd]ebugPublic/x86/ +[Rr]elease/x86/ +[Rr]eleases/x86/ +bin/x86/ +obj/x86/ + +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +[Aa][Rr][Mm]64[Ee][Cc]/ +bld/ +[Oo]bj/ +[Oo]ut/ +[Ll]og/ +[Ll]ogs/ + +# Build results on 'Bin' directories +**/[Bb]in/* +# Uncomment if you have tasks that rely on *.refresh files to move binaries +# (https://github.com/github/gitignore/pull/3736) +#!**/[Bb]in/*.refresh + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* +*.trx + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Approval Tests result files +*.received.* + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.idb +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +# but not Directory.Build.rsp, as it configures directory-level build defaults +!Directory.Build.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +**/.paket/paket.exe +paket-files/ + +# FAKE - F# Make +**/.fake/ + +# CodeRush personal settings +**/.cr/personal + +# Python Tools for Visual Studio (PTVS) +**/__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +#tools/** +#!tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog +MSBuild_Logs/ + +# AWS SAM Build and Temporary Artifacts folder +.aws-sam + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +**/.mfractor/ + +# Local History for Visual Studio +**/.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +**/.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp diff --git a/go/.gitignore b/go/.gitignore new file mode 100644 index 0000000..aaadf73 --- /dev/null +++ b/go/.gitignore @@ -0,0 +1,32 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Code coverage profiles and other test artifacts +*.out +coverage.* +*.coverprofile +profile.cov + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +go.work.sum + +# env file +.env + +# Editor/IDE +# .idea/ +# .vscode/ diff --git a/python/.gitignore b/python/.gitignore new file mode 100644 index 0000000..e15106e --- /dev/null +++ b/python/.gitignore @@ -0,0 +1,216 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[codz] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py.cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +# Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +# poetry.lock +# poetry.toml + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python. +# https://pdm-project.org/en/latest/usage/project/#working-with-version-control +# pdm.lock +# pdm.toml +.pdm-python +.pdm-build/ + +# pixi +# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control. +# pixi.lock +# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one +# in the .venv directory. It is recommended not to include this directory in version control. +.pixi + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# Redis +*.rdb +*.aof +*.pid + +# RabbitMQ +mnesia/ +rabbitmq/ +rabbitmq-data/ + +# ActiveMQ +activemq-data/ + +# SageMath parsed files +*.sage.py + +# Environments +.env +.envrc +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +# .idea/ + +# Abstra +# Abstra is an AI-powered process automation framework. +# Ignore directories containing user credentials, local state, and settings. +# Learn more at https://abstra.io/docs +.abstra/ + +# Visual Studio Code +# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore +# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore +# and can be added to the global gitignore or merged into this file. However, if you prefer, +# you could uncomment the following to ignore the entire vscode folder +# .vscode/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc + +# Marimo +marimo/_static/ +marimo/_lsp/ +__marimo__/ + +# Streamlit +.streamlit/secrets.toml From 975be289b789487a107e22028784be63ff1c6834 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 15:46:56 +0000 Subject: [PATCH 05/11] Convert .NET sample to file-based app (no .csproj, uses #:package directives) Co-authored-by: seesharprun <5067401+seesharprun@users.noreply.github.com> --- dotnet/001-connect-passwordless/CosmosApp.csproj | 15 --------------- dotnet/001-connect-passwordless/Program.cs | 3 +++ dotnet/001-connect-passwordless/readme.md | 4 ++-- 3 files changed, 5 insertions(+), 17 deletions(-) delete mode 100644 dotnet/001-connect-passwordless/CosmosApp.csproj diff --git a/dotnet/001-connect-passwordless/CosmosApp.csproj b/dotnet/001-connect-passwordless/CosmosApp.csproj deleted file mode 100644 index 9d4321c..0000000 --- a/dotnet/001-connect-passwordless/CosmosApp.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - Exe - net8.0 - enable - enable - - - - - - - - diff --git a/dotnet/001-connect-passwordless/Program.cs b/dotnet/001-connect-passwordless/Program.cs index 87f7b81..f718df9 100644 --- a/dotnet/001-connect-passwordless/Program.cs +++ b/dotnet/001-connect-passwordless/Program.cs @@ -1,3 +1,6 @@ +#:package Azure.Identity@1.13.2 +#:package Microsoft.Azure.Cosmos@3.47.0 + using Azure.Identity; using Microsoft.Azure.Cosmos; diff --git a/dotnet/001-connect-passwordless/readme.md b/dotnet/001-connect-passwordless/readme.md index 7cbeb9b..aaf8f8f 100644 --- a/dotnet/001-connect-passwordless/readme.md +++ b/dotnet/001-connect-passwordless/readme.md @@ -6,7 +6,7 @@ This sample demonstrates how to authenticate to Azure Cosmos DB for NoSQL using - An [Azure subscription](https://azure.microsoft.com/free/) - An Azure Cosmos DB for NoSQL account -- [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) +- [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0) - [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli) (for local development login) ## Setup @@ -48,7 +48,7 @@ az login ## Run ```bash -dotnet run +dotnet run Program.cs ``` ## What this sample does From 6bc5d87457efb4c18ec9f9df89050d78a8f4047a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 15:52:55 +0000 Subject: [PATCH 06/11] Standardize env vars: update Python sample to use COSMOS_ENDPOINT + COSMOS_KEY Co-authored-by: seesharprun <5067401+seesharprun@users.noreply.github.com> --- python/002-connect-connection-string/app.py | 12 ++++++++---- python/002-connect-connection-string/readme.md | 17 +++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/python/002-connect-connection-string/app.py b/python/002-connect-connection-string/app.py index b9abaec..49455f8 100644 --- a/python/002-connect-connection-string/app.py +++ b/python/002-connect-connection-string/app.py @@ -5,11 +5,15 @@ load_dotenv() -connection_string = os.environ.get("COSMOS_CONNECTION_STRING") -if not connection_string: - raise ValueError("COSMOS_CONNECTION_STRING environment variable is not set.") +endpoint = os.environ.get("COSMOS_ENDPOINT") +if not endpoint: + raise ValueError("COSMOS_ENDPOINT environment variable is not set.") -client = CosmosClient.from_connection_string(connection_string) +key = os.environ.get("COSMOS_KEY") +if not key: + raise ValueError("COSMOS_KEY environment variable is not set.") + +client = CosmosClient(url=endpoint, credential=key) database = client.create_database_if_not_exists("cosmicworks") print(f"Created/retrieved database: {database.id}") diff --git a/python/002-connect-connection-string/readme.md b/python/002-connect-connection-string/readme.md index 26da0ce..dfba82e 100644 --- a/python/002-connect-connection-string/readme.md +++ b/python/002-connect-connection-string/readme.md @@ -1,6 +1,6 @@ -# Connect to Azure Cosmos DB for NoSQL — Connection String (Python) +# Connect to Azure Cosmos DB for NoSQL — Key Auth (Python) -This sample demonstrates how to authenticate to Azure Cosmos DB for NoSQL using a **connection string** (account endpoint + key). This is a quick way to get started, especially for local development and testing. +This sample demonstrates how to authenticate to Azure Cosmos DB for NoSQL using an **account key**. This is a quick way to get started, especially for local development and testing. ## Prerequisites @@ -16,15 +16,16 @@ This sample demonstrates how to authenticate to Azure Cosmos DB for NoSQL using cp .env.example .env ``` -### 2. Fill in your connection string +### 2. Fill in your endpoint and key -Open `.env` and replace the placeholder with your actual connection string: +Open `.env` and replace the placeholders with your actual values: ``` -COSMOS_CONNECTION_STRING=AccountEndpoint=https://.documents.azure.com:443/;AccountKey===; +COSMOS_ENDPOINT=https://.documents.azure.com:443/ +COSMOS_KEY= ``` -You can find the connection string in the Azure portal under your Cosmos DB account → **Keys** → **PRIMARY CONNECTION STRING**. +You can find the endpoint and primary key in the Azure portal under your Cosmos DB account → **Keys**. > **Security note:** Never commit your `.env` file to source control. It is already listed in `.gitignore` by convention. @@ -37,8 +38,8 @@ pip install -r requirements.txt && python app.py ## What this sample does 1. Loads environment variables from a `.env` file (if present) using `python-dotenv` -2. Reads `COSMOS_CONNECTION_STRING` from the environment -3. Creates a `CosmosClient` using the connection string +2. Reads `COSMOS_ENDPOINT` and `COSMOS_KEY` from the environment +3. Creates a `CosmosClient` using the endpoint and key 4. Creates (or retrieves) a database named `cosmicworks` 5. Creates (or retrieves) a container named `products` with partition key `/category` 6. Creates a product item From a3735894459b2a82f00ef2b1f9ea3ddafb7c1d36 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 16:20:04 +0000 Subject: [PATCH 07/11] Fix CI failures: rename readme.md to README.md, fix Go IsErrorCode, update .NET workflow for file-based apps Co-authored-by: seesharprun <5067401+seesharprun@users.noreply.github.com> --- .github/workflows/validate.yml | 13 +++++++++++-- .../{readme.md => README.md} | 0 go/101-create-item/{readme.md => README.md} | 0 go/101-create-item/main.go | 5 ++++- python/002-connect-connection-string/.env.example | 3 ++- .../{readme.md => README.md} | 0 6 files changed, 17 insertions(+), 4 deletions(-) rename dotnet/001-connect-passwordless/{readme.md => README.md} (100%) rename go/101-create-item/{readme.md => README.md} (100%) rename python/002-connect-connection-string/{readme.md => README.md} (100%) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 55c3dbf..9fe7282 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -118,13 +118,22 @@ jobs: - name: Set up .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: '9.0' + dotnet-version: | + 9.0 + 10.0 - name: Build run: | [ -d dotnet ] || exit 0 for sample in dotnet/*/; do proj=$(find "$sample" -maxdepth 2 \( -name '*.sln' -o -name '*.csproj' \) | head -1) - [ -n "$proj" ] && dotnet build "$proj" --configuration Release -q + if [ -n "$proj" ]; then + dotnet build "$proj" --configuration Release -q + else + cs=$(find "$sample" -maxdepth 1 -name '*.cs' | head -1) + if [ -n "$cs" ]; then + dotnet publish "$cs" -o /tmp/dotnet-publish-output -q + fi + fi done validate-go: diff --git a/dotnet/001-connect-passwordless/readme.md b/dotnet/001-connect-passwordless/README.md similarity index 100% rename from dotnet/001-connect-passwordless/readme.md rename to dotnet/001-connect-passwordless/README.md diff --git a/go/101-create-item/readme.md b/go/101-create-item/README.md similarity index 100% rename from go/101-create-item/readme.md rename to go/101-create-item/README.md diff --git a/go/101-create-item/main.go b/go/101-create-item/main.go index 31c9163..d7ebd28 100644 --- a/go/101-create-item/main.go +++ b/go/101-create-item/main.go @@ -3,11 +3,13 @@ package main import ( "context" "encoding/json" + "errors" "fmt" "log" "net/http" "os" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos" ) @@ -122,5 +124,6 @@ func main() { } func isConflict(err error) bool { - return azcosmos.IsErrorCode(err, http.StatusConflict) + var responseErr *azcore.ResponseError + return errors.As(err, &responseErr) && responseErr.StatusCode == http.StatusConflict } diff --git a/python/002-connect-connection-string/.env.example b/python/002-connect-connection-string/.env.example index 8f2614e..5668c14 100644 --- a/python/002-connect-connection-string/.env.example +++ b/python/002-connect-connection-string/.env.example @@ -1 +1,2 @@ -COSMOS_CONNECTION_STRING=AccountEndpoint=https://.documents.azure.com:443/;AccountKey===; +COSMOS_ENDPOINT=https://.documents.azure.com:443/ +COSMOS_KEY= diff --git a/python/002-connect-connection-string/readme.md b/python/002-connect-connection-string/README.md similarity index 100% rename from python/002-connect-connection-string/readme.md rename to python/002-connect-connection-string/README.md From cfa42801f97c5b190b9be1806c8db24ff278cbd8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 16:36:57 +0000 Subject: [PATCH 08/11] Rename README.md to readme.md in all samples; revert .NET workflow changes; update structure check to readme.md Co-authored-by: seesharprun <5067401+seesharprun@users.noreply.github.com> --- .github/workflows/validate.yml | 17 ++++------------- .../{README.md => readme.md} | 0 go/101-create-item/{README.md => readme.md} | 0 .../{README.md => readme.md} | 0 4 files changed, 4 insertions(+), 13 deletions(-) rename dotnet/001-connect-passwordless/{README.md => readme.md} (100%) rename go/101-create-item/{README.md => readme.md} (100%) rename python/002-connect-connection-string/{README.md => readme.md} (100%) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 9fe7282..2a11c94 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -30,8 +30,8 @@ jobs: echo "::error::$name does not follow NNN-kebab-case naming" exit 1 fi - if [ ! -f "${sample}README.md" ]; then - echo "::error::$name is missing README.md" + if [ ! -f "${sample}readme.md" ]; then + echo "::error::$name is missing readme.md" exit 1 fi done @@ -118,22 +118,13 @@ jobs: - name: Set up .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: | - 9.0 - 10.0 + dotnet-version: '9.0' - name: Build run: | [ -d dotnet ] || exit 0 for sample in dotnet/*/; do proj=$(find "$sample" -maxdepth 2 \( -name '*.sln' -o -name '*.csproj' \) | head -1) - if [ -n "$proj" ]; then - dotnet build "$proj" --configuration Release -q - else - cs=$(find "$sample" -maxdepth 1 -name '*.cs' | head -1) - if [ -n "$cs" ]; then - dotnet publish "$cs" -o /tmp/dotnet-publish-output -q - fi - fi + [ -n "$proj" ] && dotnet build "$proj" --configuration Release -q done validate-go: diff --git a/dotnet/001-connect-passwordless/README.md b/dotnet/001-connect-passwordless/readme.md similarity index 100% rename from dotnet/001-connect-passwordless/README.md rename to dotnet/001-connect-passwordless/readme.md diff --git a/go/101-create-item/README.md b/go/101-create-item/readme.md similarity index 100% rename from go/101-create-item/README.md rename to go/101-create-item/readme.md diff --git a/python/002-connect-connection-string/README.md b/python/002-connect-connection-string/readme.md similarity index 100% rename from python/002-connect-connection-string/README.md rename to python/002-connect-connection-string/readme.md From a0da090701826111ed2b122ff9b43bae4428f401 Mon Sep 17 00:00:00 2001 From: Sidney Andrews Date: Wed, 18 Mar 2026 13:14:20 -0400 Subject: [PATCH 09/11] Apply suggestion from @seesharprun Signed-off-by: Sidney Andrews --- .github/workflows/validate.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 2a11c94..55c3dbf 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -30,8 +30,8 @@ jobs: echo "::error::$name does not follow NNN-kebab-case naming" exit 1 fi - if [ ! -f "${sample}readme.md" ]; then - echo "::error::$name is missing readme.md" + if [ ! -f "${sample}README.md" ]; then + echo "::error::$name is missing README.md" exit 1 fi done From ea3ff901d252cdbe46ab830a8d579f87c5e79318 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 17:26:24 +0000 Subject: [PATCH 10/11] Switch to inline env var setup: remove .env.example files, drop python-dotenv, update all readmes Co-authored-by: seesharprun <5067401+seesharprun@users.noreply.github.com> --- dotnet/001-connect-passwordless/readme.md | 28 +++++------- go/101-create-item/.env.example | 2 - go/101-create-item/readme.md | 35 ++++++--------- .../.env.example | 2 - python/002-connect-connection-string/app.py | 3 -- .../002-connect-connection-string/readme.md | 45 +++++++++---------- .../requirements.txt | 1 - 7 files changed, 45 insertions(+), 71 deletions(-) delete mode 100644 go/101-create-item/.env.example delete mode 100644 python/002-connect-connection-string/.env.example diff --git a/dotnet/001-connect-passwordless/readme.md b/dotnet/001-connect-passwordless/readme.md index aaf8f8f..e5e82ea 100644 --- a/dotnet/001-connect-passwordless/readme.md +++ b/dotnet/001-connect-passwordless/readme.md @@ -24,33 +24,29 @@ az cosmosdb sql role assignment create \ --scope "/" ``` -### 2. Set the environment variable - -```bash -# Linux / macOS -export COSMOS_ENDPOINT="https://.documents.azure.com:443/" - -# Windows (Command Prompt) -set COSMOS_ENDPOINT=https://.documents.azure.com:443/ +## Run -# Windows (PowerShell) -$env:COSMOS_ENDPOINT = "https://.documents.azure.com:443/" -``` +> [!IMPORTANT] +> The environment variable below is set **only for the current terminal session** and does **not persist** after you close the window. -### 3. Log in with Azure CLI (local development) +### macOS / Linux ```bash +export COSMOS_ENDPOINT="https://.documents.azure.com:443/" az login +dotnet run Program.cs ``` -`DefaultAzureCredential` automatically uses your Azure CLI login locally. In production (Azure App Service, Azure Functions, Azure Container Apps, etc.) it uses the managed identity assigned to the resource — no code changes needed. - -## Run +### Windows (PowerShell) -```bash +```powershell +$Env:COSMOS_ENDPOINT="https://.documents.azure.com:443/" +az login dotnet run Program.cs ``` +`DefaultAzureCredential` automatically uses your Azure CLI login locally. In production (Azure App Service, Azure Functions, Azure Container Apps, etc.) it uses the managed identity assigned to the resource — no code changes needed. + ## What this sample does 1. Reads the `COSMOS_ENDPOINT` environment variable diff --git a/go/101-create-item/.env.example b/go/101-create-item/.env.example deleted file mode 100644 index fe52080..0000000 --- a/go/101-create-item/.env.example +++ /dev/null @@ -1,2 +0,0 @@ -COSMOS_ENDPOINT=https://.documents.azure.com:443/ -COSMOS_KEY= diff --git a/go/101-create-item/readme.md b/go/101-create-item/readme.md index f169b84..20841e9 100644 --- a/go/101-create-item/readme.md +++ b/go/101-create-item/readme.md @@ -8,38 +8,29 @@ This sample demonstrates the four fundamental **CRUD** operations (Create, Read, - An Azure Cosmos DB for NoSQL account - [Go 1.21+](https://go.dev/dl/) -## Setup - -### Set environment variables - -```bash -# Linux / macOS -export COSMOS_ENDPOINT="https://.documents.azure.com:443/" -export COSMOS_KEY="" - -# Windows (Command Prompt) -set COSMOS_ENDPOINT=https://.documents.azure.com:443/ -set COSMOS_KEY= +## Run -# Windows (PowerShell) -$env:COSMOS_ENDPOINT = "https://.documents.azure.com:443/" -$env:COSMOS_KEY = "" -``` +> [!IMPORTANT] +> These environment variables are set **only for the current terminal session** and do **not persist** after you close the window. -You can find your endpoint and primary key in the Azure portal under your Cosmos DB account → **Keys**. - -### Install dependencies +### macOS / Linux ```bash -go mod tidy +export COSMOS_ENDPOINT="https://.documents.azure.com:443/" +export COSMOS_KEY="" +go run main.go ``` -## Run +### Windows (PowerShell) -```bash +```powershell +$Env:COSMOS_ENDPOINT="https://.documents.azure.com:443/" +$Env:COSMOS_KEY="" go run main.go ``` +You can find your endpoint and primary key in the Azure portal under your Cosmos DB account → **Keys**. + ## Operations demonstrated | Operation | Description | diff --git a/python/002-connect-connection-string/.env.example b/python/002-connect-connection-string/.env.example deleted file mode 100644 index 5668c14..0000000 --- a/python/002-connect-connection-string/.env.example +++ /dev/null @@ -1,2 +0,0 @@ -COSMOS_ENDPOINT=https://.documents.azure.com:443/ -COSMOS_KEY= diff --git a/python/002-connect-connection-string/app.py b/python/002-connect-connection-string/app.py index 49455f8..38570bb 100644 --- a/python/002-connect-connection-string/app.py +++ b/python/002-connect-connection-string/app.py @@ -1,10 +1,7 @@ import os -from dotenv import load_dotenv from azure.cosmos import CosmosClient, PartitionKey -load_dotenv() - endpoint = os.environ.get("COSMOS_ENDPOINT") if not endpoint: raise ValueError("COSMOS_ENDPOINT environment variable is not set.") diff --git a/python/002-connect-connection-string/readme.md b/python/002-connect-connection-string/readme.md index dfba82e..6a4d83b 100644 --- a/python/002-connect-connection-string/readme.md +++ b/python/002-connect-connection-string/readme.md @@ -8,39 +8,34 @@ This sample demonstrates how to authenticate to Azure Cosmos DB for NoSQL using - An Azure Cosmos DB for NoSQL account - [Python 3.8+](https://www.python.org/downloads/) -## Setup +## Run + +> [!IMPORTANT] +> These environment variables are set **only for the current terminal session** and do **not persist** after you close the window. -### 1. Copy the example env file +### macOS / Linux ```bash -cp .env.example .env +export COSMOS_ENDPOINT="https://.documents.azure.com:443/" +export COSMOS_KEY="" +pip install -r requirements.txt && python app.py ``` -### 2. Fill in your endpoint and key +### Windows (PowerShell) -Open `.env` and replace the placeholders with your actual values: - -``` -COSMOS_ENDPOINT=https://.documents.azure.com:443/ -COSMOS_KEY= +```powershell +$Env:COSMOS_ENDPOINT="https://.documents.azure.com:443/" +$Env:COSMOS_KEY="" +pip install -r requirements.txt; python app.py ``` -You can find the endpoint and primary key in the Azure portal under your Cosmos DB account → **Keys**. - -> **Security note:** Never commit your `.env` file to source control. It is already listed in `.gitignore` by convention. - -## Run - -```bash -pip install -r requirements.txt && python app.py -``` +You can find your endpoint and primary key in the Azure portal under your Cosmos DB account → **Keys**. ## What this sample does -1. Loads environment variables from a `.env` file (if present) using `python-dotenv` -2. Reads `COSMOS_ENDPOINT` and `COSMOS_KEY` from the environment -3. Creates a `CosmosClient` using the endpoint and key -4. Creates (or retrieves) a database named `cosmicworks` -5. Creates (or retrieves) a container named `products` with partition key `/category` -6. Creates a product item -7. Queries items filtered by category and prints the results +1. Reads `COSMOS_ENDPOINT` and `COSMOS_KEY` from the environment +2. Creates a `CosmosClient` using the endpoint and key +3. Creates (or retrieves) a database named `cosmicworks` +4. Creates (or retrieves) a container named `products` with partition key `/category` +5. Creates a product item +6. Queries items filtered by category and prints the results diff --git a/python/002-connect-connection-string/requirements.txt b/python/002-connect-connection-string/requirements.txt index c829d98..3623bed 100644 --- a/python/002-connect-connection-string/requirements.txt +++ b/python/002-connect-connection-string/requirements.txt @@ -1,2 +1 @@ azure-cosmos==4.9.0 -python-dotenv==1.0.1 From 43f87d85fb20cd47b5dfdcbfcc202a72c418538b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Mar 2026 17:49:31 +0000 Subject: [PATCH 11/11] Migrate .NET sample to dotnet user-secrets for COSMOS_ENDPOINT configuration Co-authored-by: seesharprun <5067401+seesharprun@users.noreply.github.com> --- dotnet/001-connect-passwordless/Program.cs | 11 +++++++++-- dotnet/001-connect-passwordless/readme.md | 21 ++++++++++----------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/dotnet/001-connect-passwordless/Program.cs b/dotnet/001-connect-passwordless/Program.cs index f718df9..186f8b4 100644 --- a/dotnet/001-connect-passwordless/Program.cs +++ b/dotnet/001-connect-passwordless/Program.cs @@ -1,11 +1,18 @@ #:package Azure.Identity@1.13.2 #:package Microsoft.Azure.Cosmos@3.47.0 +#:package Microsoft.Extensions.Configuration.UserSecrets@10.* +#:property UserSecretsId=azurecosmosdb-samples-dotnet-001-connect-passwordless using Azure.Identity; using Microsoft.Azure.Cosmos; +using Microsoft.Extensions.Configuration; -string endpoint = Environment.GetEnvironmentVariable("COSMOS_ENDPOINT") - ?? throw new InvalidOperationException("COSMOS_ENDPOINT environment variable is not set."); +IConfigurationRoot configuration = new ConfigurationBuilder() + .AddUserSecrets() + .Build(); + +string endpoint = configuration["COSMOS_ENDPOINT"] + ?? throw new InvalidOperationException("COSMOS_ENDPOINT is not configured. Run: dotnet user-secrets set --file Program.cs \"COSMOS_ENDPOINT\" \"\""); var credential = new DefaultAzureCredential(); var client = new CosmosClient(endpoint, credential); diff --git a/dotnet/001-connect-passwordless/readme.md b/dotnet/001-connect-passwordless/readme.md index e5e82ea..76c3a84 100644 --- a/dotnet/001-connect-passwordless/readme.md +++ b/dotnet/001-connect-passwordless/readme.md @@ -26,22 +26,21 @@ az cosmosdb sql role assignment create \ ## Run -> [!IMPORTANT] -> The environment variable below is set **only for the current terminal session** and does **not persist** after you close the window. +### 1. Set your endpoint using user secrets -### macOS / Linux +```shell +dotnet user-secrets set --file Program.cs "COSMOS_ENDPOINT" "https://.documents.azure.com:443/" +``` -```bash -export COSMOS_ENDPOINT="https://.documents.azure.com:443/" +### 2. Log in with Azure CLI + +```shell az login -dotnet run Program.cs ``` -### Windows (PowerShell) +### 3. Run the sample -```powershell -$Env:COSMOS_ENDPOINT="https://.documents.azure.com:443/" -az login +```shell dotnet run Program.cs ``` @@ -49,7 +48,7 @@ dotnet run Program.cs ## What this sample does -1. Reads the `COSMOS_ENDPOINT` environment variable +1. Reads `COSMOS_ENDPOINT` from user secrets (via `Microsoft.Extensions.Configuration.UserSecrets`) 2. Authenticates using `DefaultAzureCredential` (Azure CLI / Managed Identity / etc.) 3. Creates (or retrieves) a database named `cosmicworks` 4. Creates (or retrieves) a container named `products` with partition key `/category`