Skip to content

Commit f440e06

Browse files
colawwjdw511214992ramya-rao-a
authored
ARM Cosmosdb (Azure#15482)
* cosmosdb-release * cosmosdb-release * arm-cosmosdb-v4 * arm-cosmosdb-v4 * readme update * Update sdk/cosmosdb/arm-cosmosdb/README.md Co-authored-by: Ramya Rao <[email protected]> Co-authored-by: Wei Dong <[email protected]> Co-authored-by: Ramya Rao <[email protected]>
1 parent e562127 commit f440e06

38 files changed

+1511
-8869
lines changed

sdk/cosmosdb/arm-cosmosdb/README.md

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,112 @@
11
## Azure CosmosDBManagementClient SDK for JavaScript
22

3-
This package contains an isomorphic SDK for CosmosDBManagementClient.
3+
This package contains an isomorphic SDK (runs both in Node.js and in browsers) for CosmosDBManagementClient.
44

55
### Currently supported environments
66

7-
- Node.js version 6.x.x or higher
8-
- Browser JavaScript
7+
- [LTS versions of Node.js](https://nodejs.org/about/releases/)
8+
- Latest versions of Safari, Chrome, Edge, and Firefox.
99

10-
### How to Install
10+
### Prerequisites
11+
12+
You must have an [Azure subscription](https://azure.microsoft.com/free/).
13+
14+
### How to install
15+
16+
To use this SDK in your project, you will need to install two packages.
17+
18+
- `@azure/arm-cosmosdb` that contains the client.
19+
- `@azure/identity` that provides different mechanisms for the client to authenticate your requests using Azure Active Directory.
20+
21+
Install both packages using the below command:
1122

1223
```bash
13-
npm install @azure/arm-cosmosdb
24+
npm install --save @azure/arm-cosmosdb @azure/identity
1425
```
1526

27+
> **Note**: You may have used either `@azure/ms-rest-nodeauth` or `@azure/ms-rest-browserauth` in the past. These packages are in maintenance mode receiving critical bug fixes, but no new features.
28+
> If you are on a [Node.js that has LTS status](https://nodejs.org/about/releases/), or are writing a client side browser application, we strongly encourage you to upgrade to `@azure/identity` which uses the latest versions of Azure Active Directory and MSAL APIs and provides more authentication options.
29+
1630
### How to use
1731

18-
#### nodejs - client creation and get databaseAccounts as an example written in TypeScript.
32+
- If you are writing a client side browser application,
33+
- Follow the instructions in the section on Authenticating client side browser applications in [Azure Identity examples](https://aka.ms/azsdk/js/identity/examples) to register your application in the Microsoft identity platform and set the right permissions.
34+
- Copy the client ID and tenant ID from the Overview section of your app registration in Azure portal and use it in the browser sample below.
35+
- If you are writing a server side application,
36+
- [Select a credential from `@azure/identity` based on the authentication method of your choice](https://aka.ms/azsdk/js/identity/examples)
37+
- Complete the set up steps required by the credential if any.
38+
- Use the credential you picked in the place of `DefaultAzureCredential` in the Node.js sample below.
1939

20-
##### Install @azure/ms-rest-nodeauth
40+
In the below samples, we pass the credential and the Azure subscription id to instantiate the client.
41+
Once the client is created, explore the operations on it either in your favorite editor or in our [API reference documentation](https://docs.microsoft.com/javascript/api) to get started.
2142

22-
- Please install minimum version of `"@azure/ms-rest-nodeauth": "^3.0.0"`.
23-
```bash
24-
npm install @azure/ms-rest-nodeauth@"^3.0.0"
25-
```
43+
#### nodejs - Authentication, client creation, and get databaseAccounts as an example written in JavaScript.
2644

2745
##### Sample code
2846

29-
While the below sample uses the interactive login, other authentication options can be found in the [README.md file of @azure/ms-rest-nodeauth](https://www.npmjs.com/package/@azure/ms-rest-nodeauth) package
30-
```typescript
31-
const msRestNodeAuth = require("@azure/ms-rest-nodeauth");
47+
```javascript
48+
const { DefaultAzureCredential } = require("@azure/identity");
3249
const { CosmosDBManagementClient } = require("@azure/arm-cosmosdb");
3350
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
3451

35-
msRestNodeAuth.interactiveLogin().then((creds) => {
36-
const client = new CosmosDBManagementClient(creds, subscriptionId);
37-
const resourceGroupName = "testresourceGroupName";
38-
const accountName = "testaccountName";
39-
client.databaseAccounts.get(resourceGroupName, accountName).then((result) => {
52+
// Use `DefaultAzureCredential` or any other credential of your choice based on https://aka.ms/azsdk/js/identity/examples
53+
// Please note that you can also use credentials from the `@azure/ms-rest-nodeauth` package instead.
54+
const creds = new DefaultAzureCredential();
55+
const client = new CosmosDBManagementClient(creds, subscriptionId);
56+
const resourceGroupName = "testresourceGroupName";
57+
const accountName = "testaccountName";
58+
client.databaseAccounts
59+
.get(resourceGroupName, accountName)
60+
.then((result) => {
4061
console.log("The result is:");
4162
console.log(result);
63+
})
64+
.catch((err) => {
65+
console.log("An error occurred:");
66+
console.error(err);
4267
});
43-
}).catch((err) => {
44-
console.error(err);
45-
});
4668
```
4769

48-
#### browser - Authentication, client creation and get databaseAccounts as an example written in JavaScript.
70+
#### browser - Authentication, client creation, and get databaseAccounts as an example written in JavaScript.
4971

50-
##### Install @azure/ms-rest-browserauth
72+
In browser applications, we recommend using the `InteractiveBrowserCredential` that interactively authenticates using the default system browser.
5173

52-
```bash
53-
npm install @azure/ms-rest-browserauth
54-
```
74+
- See [Single-page application: App registration guide](https://docs.microsoft.com/azure/active-directory/develop/scenario-spa-app-registration) to configure your app registration for the browser.
75+
- Note down the client Id from the previous step and use it in the browser sample below.
5576

5677
##### Sample code
5778

58-
See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser.
59-
6079
- index.html
80+
6181
```html
6282
<!DOCTYPE html>
6383
<html lang="en">
6484
<head>
6585
<title>@azure/arm-cosmosdb sample</title>
66-
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
6786
<script src="node_modules/@azure/ms-rest-azure-js/dist/msRestAzure.js"></script>
68-
<script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script>
87+
<script src="node_modules/@azure/identity/dist/index.js"></script>
6988
<script src="node_modules/@azure/arm-cosmosdb/dist/arm-cosmosdb.js"></script>
7089
<script type="text/javascript">
7190
const subscriptionId = "<Subscription_Id>";
72-
const authManager = new msAuth.AuthManager({
91+
// Create credentials using the `@azure/identity` package.
92+
// Please note that you can also use credentials from the `@azure/ms-rest-browserauth` package instead.
93+
const credential = new InteractiveBrowserCredential({
7394
clientId: "<client id for your Azure AD app>",
7495
tenant: "<optional tenant for your organization>"
7596
});
76-
authManager.finalizeLogin().then((res) => {
77-
if (!res.isLoggedIn) {
78-
// may cause redirects
79-
authManager.login();
80-
}
81-
const client = new Azure.ArmCosmosdb.CosmosDBManagementClient(res.creds, subscriptionId);
82-
const resourceGroupName = "testresourceGroupName";
83-
const accountName = "testaccountName";
84-
client.databaseAccounts.get(resourceGroupName, accountName).then((result) => {
97+
const client = new Azure.ArmCosmosdb.CosmosDBManagementClient(creds, subscriptionId);
98+
const resourceGroupName = "testresourceGroupName";
99+
const accountName = "testaccountName";
100+
client.databaseAccounts
101+
.get(resourceGroupName, accountName)
102+
.then((result) => {
85103
console.log("The result is:");
86104
console.log(result);
87-
}).catch((err) => {
105+
})
106+
.catch((err) => {
88107
console.log("An error occurred:");
89108
console.error(err);
90109
});
91-
});
92110
</script>
93111
</head>
94112
<body></body>

sdk/cosmosdb/arm-cosmosdb/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
"name": "@azure/arm-cosmosdb",
33
"author": "Microsoft Corporation",
44
"description": "CosmosDBManagementClient Library with typescript type definitions for node.js and browser.",
5-
"version": "13.0.0",
5+
"version": "14.0.0",
66
"dependencies": {
7-
"@azure/ms-rest-azure-js": "^2.0.1",
8-
"@azure/ms-rest-js": "^2.0.4",
7+
"@azure/ms-rest-azure-js": "^2.1.0",
8+
"@azure/ms-rest-js": "^2.2.0",
9+
"@azure/core-auth": "^1.1.4",
910
"tslib": "^1.10.0"
1011
},
1112
"keywords": [
@@ -20,7 +21,7 @@
2021
"module": "./esm/cosmosDBManagementClient.js",
2122
"types": "./esm/cosmosDBManagementClient.d.ts",
2223
"devDependencies": {
23-
"typescript": "^3.5.3",
24+
"typescript": "^3.6.0",
2425
"rollup": "^1.18.0",
2526
"rollup-plugin-node-resolve": "^5.2.0",
2627
"rollup-plugin-sourcemaps": "^0.4.2",

sdk/cosmosdb/arm-cosmosdb/src/cosmosDBManagementClient.ts

Lines changed: 8 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
*/
99

1010
import * as msRest from "@azure/ms-rest-js";
11+
import { TokenCredential } from "@azure/core-auth";
1112
import * as Models from "./models";
1213
import * as Mappers from "./models/mappers";
13-
import * as Parameters from "./models/parameters";
1414
import * as operations from "./operations";
1515
import { CosmosDBManagementClientContext } from "./cosmosDBManagementClientContext";
1616

@@ -34,28 +34,23 @@ class CosmosDBManagementClient extends CosmosDBManagementClientContext {
3434
tableResources: operations.TableResources;
3535
cassandraResources: operations.CassandraResources;
3636
gremlinResources: operations.GremlinResources;
37-
restorableDatabaseAccounts: operations.RestorableDatabaseAccounts;
3837
notebookWorkspaces: operations.NotebookWorkspaces;
39-
restorableSqlDatabases: operations.RestorableSqlDatabases;
40-
restorableSqlContainers: operations.RestorableSqlContainers;
41-
restorableSqlResources: operations.RestorableSqlResources;
42-
restorableMongodbDatabases: operations.RestorableMongodbDatabases;
43-
restorableMongodbCollections: operations.RestorableMongodbCollections;
44-
restorableMongodbResources: operations.RestorableMongodbResources;
45-
cassandraClusters: operations.CassandraClusters;
46-
cassandraDataCenters: operations.CassandraDataCenters;
4738
privateLinkResources: operations.PrivateLinkResources;
4839
privateEndpointConnections: operations.PrivateEndpointConnections;
49-
service: operations.Service;
5040

5141
/**
5242
* Initializes a new instance of the CosmosDBManagementClient class.
53-
* @param credentials Credentials needed for the client to connect to Azure.
43+
* @param credentials Credentials needed for the client to connect to Azure. Credentials
44+
* implementing the TokenCredential interface from the @azure/identity package are recommended. For
45+
* more information about these credentials, see
46+
* {@link https://www.npmjs.com/package/@azure/identity}. Credentials implementing the
47+
* ServiceClientCredentials interface from the older packages @azure/ms-rest-nodeauth and
48+
* @azure/ms-rest-browserauth are also supported.
5449
* @param subscriptionId The ID of the target subscription.
5550
* @param [options] The parameter options
5651
*/
5752
constructor(
58-
credentials: msRest.ServiceClientCredentials,
53+
credentials: msRest.ServiceClientCredentials | TokenCredential,
5954
subscriptionId: string,
6055
options?: Models.CosmosDBManagementClientOptions
6156
) {
@@ -78,128 +73,13 @@ class CosmosDBManagementClient extends CosmosDBManagementClientContext {
7873
this.tableResources = new operations.TableResources(this);
7974
this.cassandraResources = new operations.CassandraResources(this);
8075
this.gremlinResources = new operations.GremlinResources(this);
81-
this.restorableDatabaseAccounts = new operations.RestorableDatabaseAccounts(this);
8276
this.notebookWorkspaces = new operations.NotebookWorkspaces(this);
83-
this.restorableSqlDatabases = new operations.RestorableSqlDatabases(this);
84-
this.restorableSqlContainers = new operations.RestorableSqlContainers(this);
85-
this.restorableSqlResources = new operations.RestorableSqlResources(this);
86-
this.restorableMongodbDatabases = new operations.RestorableMongodbDatabases(this);
87-
this.restorableMongodbCollections = new operations.RestorableMongodbCollections(this);
88-
this.restorableMongodbResources = new operations.RestorableMongodbResources(this);
89-
this.cassandraClusters = new operations.CassandraClusters(this);
90-
this.cassandraDataCenters = new operations.CassandraDataCenters(this);
9177
this.privateLinkResources = new operations.PrivateLinkResources(this);
9278
this.privateEndpointConnections = new operations.PrivateEndpointConnections(this);
93-
this.service = new operations.Service(this);
94-
}
95-
96-
/**
97-
* List Cosmos DB locations and their properties
98-
* @param [options] The optional parameters
99-
* @returns Promise<Models.LocationListResponse>
100-
*/
101-
locationList(options?: msRest.RequestOptionsBase): Promise<Models.LocationListResponse>;
102-
/**
103-
* @param callback The callback
104-
*/
105-
locationList(callback: msRest.ServiceCallback<Models.LocationListResult>): void;
106-
/**
107-
* @param options The optional parameters
108-
* @param callback The callback
109-
*/
110-
locationList(
111-
options: msRest.RequestOptionsBase,
112-
callback: msRest.ServiceCallback<Models.LocationListResult>
113-
): void;
114-
locationList(
115-
options?: msRest.RequestOptionsBase | msRest.ServiceCallback<Models.LocationListResult>,
116-
callback?: msRest.ServiceCallback<Models.LocationListResult>
117-
): Promise<Models.LocationListResponse> {
118-
return this.sendOperationRequest(
119-
{
120-
options
121-
},
122-
locationListOperationSpec,
123-
callback
124-
) as Promise<Models.LocationListResponse>;
125-
}
126-
127-
/**
128-
* Get the properties of an existing Cosmos DB location
129-
* @param location Cosmos DB region, with spaces between words and each word capitalized.
130-
* @param [options] The optional parameters
131-
* @returns Promise<Models.LocationGetResponse>
132-
*/
133-
locationGet(
134-
location: string,
135-
options?: msRest.RequestOptionsBase
136-
): Promise<Models.LocationGetResponse>;
137-
/**
138-
* @param location Cosmos DB region, with spaces between words and each word capitalized.
139-
* @param callback The callback
140-
*/
141-
locationGet(location: string, callback: msRest.ServiceCallback<Models.LocationGetResult>): void;
142-
/**
143-
* @param location Cosmos DB region, with spaces between words and each word capitalized.
144-
* @param options The optional parameters
145-
* @param callback The callback
146-
*/
147-
locationGet(
148-
location: string,
149-
options: msRest.RequestOptionsBase,
150-
callback: msRest.ServiceCallback<Models.LocationGetResult>
151-
): void;
152-
locationGet(
153-
location: string,
154-
options?: msRest.RequestOptionsBase | msRest.ServiceCallback<Models.LocationGetResult>,
155-
callback?: msRest.ServiceCallback<Models.LocationGetResult>
156-
): Promise<Models.LocationGetResponse> {
157-
return this.sendOperationRequest(
158-
{
159-
location,
160-
options
161-
},
162-
locationGetOperationSpec,
163-
callback
164-
) as Promise<Models.LocationGetResponse>;
16579
}
16680
}
16781

16882
// Operation Specifications
169-
const serializer = new msRest.Serializer(Mappers);
170-
const locationListOperationSpec: msRest.OperationSpec = {
171-
httpMethod: "GET",
172-
path: "subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations",
173-
urlParameters: [Parameters.subscriptionId],
174-
queryParameters: [Parameters.apiVersion],
175-
headerParameters: [Parameters.acceptLanguage],
176-
responses: {
177-
200: {
178-
bodyMapper: Mappers.LocationListResult
179-
},
180-
default: {
181-
bodyMapper: Mappers.CloudError
182-
}
183-
},
184-
serializer
185-
};
186-
187-
const locationGetOperationSpec: msRest.OperationSpec = {
188-
httpMethod: "GET",
189-
path: "subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}",
190-
urlParameters: [Parameters.subscriptionId, Parameters.location],
191-
queryParameters: [Parameters.apiVersion],
192-
headerParameters: [Parameters.acceptLanguage],
193-
responses: {
194-
200: {
195-
bodyMapper: Mappers.LocationGetResult
196-
},
197-
default: {
198-
bodyMapper: Mappers.CloudError
199-
}
200-
},
201-
serializer
202-
};
20383

20484
export {
20585
CosmosDBManagementClient,

sdk/cosmosdb/arm-cosmosdb/src/cosmosDBManagementClientContext.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,29 @@
1010
import * as Models from "./models";
1111
import * as msRest from "@azure/ms-rest-js";
1212
import * as msRestAzure from "@azure/ms-rest-azure-js";
13+
import { TokenCredential } from "@azure/core-auth";
1314

1415
const packageName = "@azure/arm-cosmosdb";
15-
const packageVersion = "13.0.0";
16+
const packageVersion = "14.0.0";
1617

1718
export class CosmosDBManagementClientContext extends msRestAzure.AzureServiceClient {
18-
credentials: msRest.ServiceClientCredentials;
19+
credentials: msRest.ServiceClientCredentials | TokenCredential;
1920
apiVersion?: string;
2021
subscriptionId: string;
2122

2223
/**
2324
* Initializes a new instance of the CosmosDBManagementClient class.
24-
* @param credentials Credentials needed for the client to connect to Azure.
25+
* @param credentials Credentials needed for the client to connect to Azure. Credentials
26+
* implementing the TokenCredential interface from the @azure/identity package are recommended. For
27+
* more information about these credentials, see
28+
* {@link https://www.npmjs.com/package/@azure/identity}. Credentials implementing the
29+
* ServiceClientCredentials interface from the older packages @azure/ms-rest-nodeauth and
30+
* @azure/ms-rest-browserauth are also supported.
2531
* @param subscriptionId The ID of the target subscription.
2632
* @param [options] The parameter options
2733
*/
2834
constructor(
29-
credentials: msRest.ServiceClientCredentials,
35+
credentials: msRest.ServiceClientCredentials | TokenCredential,
3036
subscriptionId: string,
3137
options?: Models.CosmosDBManagementClientOptions
3238
) {
@@ -47,7 +53,7 @@ export class CosmosDBManagementClientContext extends msRestAzure.AzureServiceCli
4753

4854
super(credentials, options);
4955

50-
this.apiVersion = "2021-04-01-preview";
56+
this.apiVersion = "2021-05-15";
5157
this.acceptLanguage = "en-US";
5258
this.longRunningOperationRetryTimeout = 30;
5359
this.baseUri = options.baseUri || this.baseUri || "https://management.azure.com";

0 commit comments

Comments
 (0)