Skip to content

Commit d8970d1

Browse files
authored
Merge pull request #260139 from wchigit/doc-fix
Fix sample code docs
2 parents 9c20299 + 94ed826 commit d8970d1

13 files changed

+355
-80
lines changed

articles/service-connector/how-to-integrate-cosmos-cassandra.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Supported authentication and clients for App Service, Azure Functions, Container
3131
| Java - Spring Boot | | | ![yes icon](./media/green-check.png) | |
3232
| Node.js | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
3333
| Python | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
34+
| None | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
3435

3536
---
3637

articles/service-connector/how-to-integrate-cosmos-db.md

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: maud-lv
55
ms.author: malev
66
ms.service: service-connector
77
ms.topic: how-to
8-
ms.date: 10/31/2023
8+
ms.date: 12/04/2023
99
ms.custom: event-tier1-build-2022, ignite-2022
1010
---
1111
# Integrate Azure Cosmos DB for MongoDB with Service Connector
@@ -23,45 +23,16 @@ This page shows supported authentication methods and clients, and shows sample c
2323

2424
Supported authentication and clients for App Service, Azure Functions, Container Apps, and Azure Spring Apps:
2525

26-
### [Azure App Service](#tab/app-service)
2726

2827
| Client type | System-assigned managed identity | User-assigned managed identity | Secret / connection string | Service principal |
2928
| ------------------ | ---------------------------------- | ---------------------------------- | ---------------------------------- | ---------------------------------- |
3029
| .NET | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
3130
| Java | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
3231
| Java - Spring Boot | | | ![yes icon](./media/green-check.png) | |
3332
| Node.js | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
33+
| Python | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
3434
| Go | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
35-
36-
### [Azure Functions](#tab/azure-functions)
37-
38-
| Client type | System-assigned managed identity | User-assigned managed identity | Secret / connection string | Service principal |
39-
| ------------------ | ---------------------------------- | ---------------------------------- | ---------------------------------- | ---------------------------------- |
40-
| .NET | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
41-
| Java | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
42-
| Java - Spring Boot | | | ![yes icon](./media/green-check.png) | |
43-
| Node.js | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
44-
| Go | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
45-
46-
### [Azure Container Apps](#tab/container-apps)
47-
48-
| Client type | System-assigned managed identity | User-assigned managed identity | Secret / connection string | Service principal |
49-
| ------------------ | ---------------------------------- | ---------------------------------- | ---------------------------------- | ---------------------------------- |
50-
| .NET | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
51-
| Java | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
52-
| Java - Spring Boot | | | ![yes icon](./media/green-check.png) | |
53-
| Node.js | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
54-
| Go | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
55-
56-
### [Azure Spring Apps](#tab/spring-apps)
57-
58-
| Client type | System-assigned managed identity | User-assigned managed identity | Secret / connection string | Service principal |
59-
| ------------------ | ---------------------------------- | ------------------------------ | ---------------------------------- | ---------------------------------- |
60-
| .NET | ![yes icon](./media/green-check.png) | | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
61-
| Java | ![yes icon](./media/green-check.png) | | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
62-
| Java - Spring Boot | | | ![yes icon](./media/green-check.png) | |
63-
| Node.js | ![yes icon](./media/green-check.png) | | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
64-
| Go | ![yes icon](./media/green-check.png) | | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
35+
| None | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
6536

6637
---
6738

@@ -84,6 +55,8 @@ Use the connection details below to connect compute services to Azure Cosmos DB.
8455
|-----------------------------------|-------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
8556
| AZURE_COSMOS_CONNECTIONSTRING | MongoDB API connection string | `mongodb://<mongo-db-admin-user>:<password>@<mongo-db-server>.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@<mongo-db-server>@` |
8657

58+
#### Sample code
59+
8760
Refer to the steps and code below to connect to Azure Cosmos DB for MongoDB using a connection string.
8861
[!INCLUDE [code sample for mongo](./includes/code-cosmosmongo-secret.md)]
8962

@@ -95,6 +68,8 @@ Refer to the steps and code below to connect to Azure Cosmos DB for MongoDB usin
9568
| AZURE_COSMOS_SCOPE | Your managed identity scope | `https://management.azure.com/.default` |
9669
| AZURE_COSMOS_RESOURCEENDPOINT | Your resource endpoint | `https://<Azure-Cosmos-DB-API-for-MongoDB-account>.documents.azure.com:443/` |
9770

71+
#### Sample code
72+
9873
Refer to the steps and code below to connect to Azure Cosmos DB for MongoDB using a system-assigned managed identity.
9974
[!INCLUDE [code sample for mongo](./includes/code-cosmosmongo-me-id.md)]
10075

@@ -107,6 +82,8 @@ Refer to the steps and code below to connect to Azure Cosmos DB for MongoDB usin
10782
| AZURE_COSMOS_CLIENTID | Your client ID | `<client-ID>` |
10883
| AZURE_COSMOS_RESOURCEENDPOINT | Your resource endpoint | `https://<Azure-Cosmos-DB-API-for-MongoDB-account>.documents.azure.com:443/` |
10984

85+
#### Sample code
86+
11087
Refer to the steps and code below to connect to Azure Cosmos DB for MongoDB using a user-assigned managed identity.
11188
[!INCLUDE [code sample for mongo](./includes/code-cosmosmongo-me-id.md)]
11289

@@ -121,6 +98,8 @@ Refer to the steps and code below to connect to Azure Cosmos DB for MongoDB usin
12198
| AZURE_COSMOS_TENANTID | Your tenant ID | `<tenant-ID>` |
12299
| AZURE_COSMOS_RESOURCEENDPOINT | Your resource endpoint | `https://<Azure-Cosmos-DB-API-for-MongoDB-account>.documents.azure.com:443/` |
123100

101+
#### Sample code
102+
124103
Refer to the steps and code below to connect to Azure Cosmos DB for MongoDB using a service principal.
125104
[!INCLUDE [code sample for mongo](./includes/code-cosmosmongo-me-id.md)]
126105

articles/service-connector/how-to-integrate-cosmos-gremlin.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: maud-lv
55
ms.author: malev
66
ms.service: service-connector
77
ms.topic: how-to
8-
ms.date: 10/31/2023
8+
ms.date: 12/04/2023
99
ms.custom: event-tier1-build-2022, ignite-2022
1010
---
1111
# Integrate the Azure Cosmos DB for Gremlin with Service Connector
@@ -30,6 +30,8 @@ Supported authentication and clients for App Service, Azure Functions, Container
3030
| Node.js | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
3131
| PHP | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
3232
| Python | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
33+
| Go | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
34+
| None | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
3335

3436
---
3537

articles/service-connector/how-to-integrate-cosmos-sql.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: maud-lv
55
ms.author: malev
66
ms.service: service-connector
77
ms.topic: how-to
8-
ms.date: 10/24/2023
8+
ms.date: 12/04/2023
99
ms.custom: event-tier1-build-2022, ignite-2022
1010
---
1111
# Integrate the Azure Cosmos DB for NoSQL with Service Connector
@@ -30,6 +30,8 @@ Supported authentication and clients for App Service, Azure Functions, Container
3030
| Java - Spring Boot | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
3131
| Node.js | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
3232
| Python | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
33+
| Go | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
34+
| None | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
3335

3436

3537
## Default environment variable names or application properties and Sample code

articles/service-connector/how-to-integrate-cosmos-table.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: maud-lv
55
ms.author: malev
66
ms.service: service-connector
77
ms.topic: how-to
8-
ms.date: 11/01/2023
8+
ms.date: 12/04/2023
99
ms.custom: event-tier1-build-2022, ignite-2022
1010
---
1111
# Integrate the Azure Cosmos DB for Table with Service Connector
@@ -29,6 +29,8 @@ Supported authentication and clients for App Service, Azure Functions, Container
2929
| Java | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
3030
| Node.js | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
3131
| Python | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
32+
| Go | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
33+
| None | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
3234

3335
---
3436

articles/service-connector/includes/code-cosmosgremlin-me-id.md

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ author: wchigit
33
description: managed identity, code sample
44
ms.service: service-connector
55
ms.topic: include
6-
ms.date: 10/31/2023
6+
ms.date: 12/04/2023
77
ms.author: wchi
88
---
99

@@ -204,13 +204,79 @@ ms.author: wchi
204204
)
205205
```
206206
207-
### [NodeJS](#tab/node)
207+
### [Go](#tab/go)
208+
1. Install dependencies.
209+
```bash
210+
go get github.com/Azure/azure-sdk-for-go/sdk/azidentity
211+
go get github.com/go-gremlin/gremlin
212+
```
213+
214+
1. In code, get the access token using `azidentity`, then use it to acquire the password. Get connection information from the environment variable added by Service Connector and connect to Azure Cosmos DB for Apache Gremlin. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
215+
216+
```go
217+
import (
218+
"fmt"
219+
"os"
220+
"context"
221+
"log"
222+
"io/ioutil"
223+
"encoding/json"
224+
225+
"github.com/go-gremlin/gremlin"
226+
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
227+
)
228+
229+
func main() {
230+
username = os.Getenv("AZURE_COSMOS_USERNAME")
231+
endpoint = os.getenv("AZURE_COSMOS_RESOURCEENDPOINT")
232+
port = os.getenv("AZURE_COSMOS_PORT")
233+
listKeyUrl = os.Getenv("AZURE_COSMOS_LISTKEYURL")
234+
scope = os.Getenv("AZUE_COSMOS_SCOPE")
235+
236+
// Uncomment the following lines according to the authentication type.
237+
// For system-assigned identity.
238+
// cred, err := azidentity.NewDefaultAzureCredential(nil)
239+
240+
// For user-assigned identity.
241+
// clientid := os.Getenv("AZURE_COSMOS_CLIENTID")
242+
// azidentity.ManagedIdentityCredentialOptions.ID := clientid
243+
// options := &azidentity.ManagedIdentityCredentialOptions{ID: clientid}
244+
// cred, err := azidentity.NewManagedIdentityCredential(options)
245+
246+
// For service principal.
247+
// clientid := os.Getenv("AZURE_COSMOS_CLIENTID")
248+
// tenantid := os.Getenv("AZURE_COSMOS_TENANTID")
249+
// clientsecret := os.Getenv("AZURE_COSMOS_CLIENTSECRET")
250+
// cred, err := azidentity.NewClientSecretCredential(tenantid, clientid, clientsecret, &azidentity.ClientSecretCredentialOptions{})
251+
252+
// Acquire the access token.
253+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
254+
token, err := cred.GetToken(ctx, policy.TokenRequestOptions{
255+
Scopes: []string{scope},
256+
})
257+
258+
// Acquire the connection string.
259+
client := &http.Client{}
260+
req, err := http.NewRequest("POST", listKeyUrl, nil)
261+
req.Header.Add("Authorization", "Bearer " + token.Token)
262+
resp, err := client.Do(req)
263+
body, err := ioutil.ReadAll(resp.Body)
264+
var result map[string]interface{}
265+
json.Unmarshal(body, &result)
266+
password, err := result["primaryMasterKey"];
267+
268+
auth := gremlin.OptAuthUserPass(username, password)
269+
client, err := gremlin.NewClient(endpoint, auth)
270+
}
271+
```
272+
273+
### [NodeJS](#tab/nodejs)
208274
1. Install dependencies.
209275
```bash
210276
npm install gremlin
211277
npm install --save @azure/identity
212278
```
213-
2. In code, get the access token using `@azure/identity`, then use it to acquire the password. Get connection information from the environment variable added by Service Connector and connect to Azure Cosmos DB for Apache Gremlin. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
279+
1. In code, get the access token using `@azure/identity`, then use it to acquire the password. Get connection information from the environment variable added by Service Connector and connect to Azure Cosmos DB for Apache Gremlin. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
214280
215281
```javascript
216282
import { DefaultAzureCredential,ClientSecretCredential } from "@azure/identity";

articles/service-connector/includes/code-cosmosgremlin-secret.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ author: wchigit
33
description: code sample
44
ms.service: service-connector
55
ms.topic: include
6-
ms.date: 10/31/2023
6+
ms.date: 12/04/2023
77
ms.author: wchi
88
---
99

1010

1111
### [.NET](#tab/dotnet)
1212

13-
1. Install dependencies.
13+
1. Install dependency.
1414
```bash
1515
dotnet add package Gremlin.Net
1616
```
@@ -41,7 +41,7 @@ ms.author: wchi
4141

4242
### [Java](#tab/java)
4343

44-
1. Add the following dependencies in your *pom.xml* file:
44+
1. Add the following dependency in your *pom.xml* file:
4545
```xml
4646
<dependency>
4747
<groupId>org.apache.tinkerpop</groupId>
@@ -70,7 +70,7 @@ ms.author: wchi
7070
```
7171
7272
### [Python](#tab/python)
73-
1. Install dependencies.
73+
1. Install dependency.
7474
```bash
7575
pip install gremlinpython
7676
```
@@ -94,8 +94,25 @@ ms.author: wchi
9494
)
9595
```
9696
97-
### [NodeJS](#tab/node)
98-
1. Install dependencies
97+
### [Go](#tab/go)
98+
1. Install dependency.
99+
```bash
100+
go get github.com/go-gremlin/gremlin
101+
```
102+
2. Get the connection information from the environment variables added by Service Connector and connect to Azure Cosmos DB for Apache Gremlin.
103+
```go
104+
username = os.Getenv("AZURE_COSMOS_USERNAME")
105+
password = os.getenv("AZURE_COSMOS_PASSWORD")
106+
endpoint = os.getenv("AZURE_COSMOS_RESOURCEENDPOINT")
107+
port = os.getenv("AZURE_COSMOS_PORT")
108+
109+
auth := gremlin.OptAuthUserPass(username, password)
110+
client, err := gremlin.NewClient(endpoint, auth)
111+
```
112+
113+
114+
### [NodeJS](#tab/nodejs)
115+
1. Install dependency.
99116
```bash
100117
npm install gremlin
101118
```

0 commit comments

Comments
 (0)