Skip to content

Commit 2dcdc39

Browse files
author
SDKAuto
committed
CodeGen from PR 15007 in Azure/azure-rest-api-specs
Merge e98221e59c3b1b8f6ec54a662d3c735bd2eeee00 into 3cf8aa90fbdf15379f62a1e8e0c3dcbd9c4d46af
1 parent b8da289 commit 2dcdc39

File tree

8 files changed

+446
-428
lines changed

8 files changed

+446
-428
lines changed

sdk/reservations/arm-reservations/README.md

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,99 @@
11
## Azure AzureReservationAPI SDK for JavaScript
22

3-
This package contains an isomorphic SDK for AzureReservationAPI.
3+
This package contains an isomorphic SDK (runs both in node.js and in browsers) for AzureReservationAPI.
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
1111

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+
- `@azure/arm-reservations` that contains the client.
18+
- `@azure/identity` that provides different mechanisms for the client to authenticate your requests using Azure Active Directory.
19+
20+
Install both packages using the below command:
1221
```bash
13-
npm install @azure/arm-reservations
22+
npm install --save @azure/arm-reservations @azure/identity
1423
```
24+
> **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.
25+
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.
1526

1627
### How to use
1728

18-
#### nodejs - Authentication, client creation and get quota as an example written in TypeScript.
29+
- If you are writing a client side browser application,
30+
- 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.
31+
- 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.
32+
- If you are writing a server side application,
33+
- [Select a credential from `@azure/identity` based on the authentication method of your choice](https://aka.ms/azsdk/js/identity/examples)
34+
- Complete the set up steps required by the credential if any.
35+
- Use the credential you picked in the place of `DefaultAzureCredential` in the Node.js sample below.
1936

20-
##### Install @azure/ms-rest-nodeauth
21-
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-
```
37+
In the below samples, we pass the credential and the Azure subscription id to instantiate the client.
38+
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.
39+
#### nodejs - Authentication, client creation, and list reservation as an example written in JavaScript.
2640

2741
##### Sample code
2842

2943
```javascript
44+
const { DefaultAzureCredential } = require("@azure/identity");
3045
const { AzureReservationAPI } = require("@azure/arm-reservations");
31-
const { interactiveLogin } = require("@azure/ms-rest-nodeauth");
32-
33-
interactiveLogin().then((creds) => {
34-
const client = new AzureReservationAPI(creds);
35-
const subscriptionId = "testsubscriptionId";
36-
const providerId = "testproviderId";
37-
const location = "westus";
38-
const resourceName = "testresourceName";
39-
client.quota.get(subscriptionId, providerId, location, resourceName).then((result) => {
40-
console.log("The result is:");
41-
console.log(result);
42-
});
46+
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
47+
48+
// Use `DefaultAzureCredential` or any other credential of your choice based on https://aka.ms/azsdk/js/identity/examples
49+
// Please note that you can also use credentials from the `@azure/ms-rest-nodeauth` package instead.
50+
const creds = new DefaultAzureCredential();
51+
const client = new AzureReservationAPI(creds, subscriptionId);
52+
const reservationOrderId = "testreservationOrderId";
53+
client.reservation.list(reservationOrderId).then((result) => {
54+
console.log("The result is:");
55+
console.log(result);
4356
}).catch((err) => {
57+
console.log("An error occurred:");
4458
console.error(err);
4559
});
4660
```
4761

48-
#### browser - Authentication, client creation and get quota as an example written in JavaScript.
62+
#### browser - Authentication, client creation, and list reservation as an example written in JavaScript.
4963

50-
##### Install @azure/ms-rest-browserauth
51-
52-
```bash
53-
npm install @azure/ms-rest-browserauth
54-
```
64+
In browser applications, we recommend using the `InteractiveBrowserCredential` that interactively authenticates using the default system browser.
65+
- 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.
66+
- Note down the client Id from the previous step and use it in the browser sample below.
5567

5668
##### Sample code
5769

58-
See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser.
59-
6070
- index.html
71+
6172
```html
6273
<!DOCTYPE html>
6374
<html lang="en">
6475
<head>
6576
<title>@azure/arm-reservations sample</title>
66-
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
6777
<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>
78+
<script src="node_modules/@azure/identity/dist/index.js"></script>
6979
<script src="node_modules/@azure/arm-reservations/dist/arm-reservations.js"></script>
7080
<script type="text/javascript">
71-
const authManager = new msAuth.AuthManager({
81+
const subscriptionId = "<Subscription_Id>";
82+
// Create credentials using the `@azure/identity` package.
83+
// Please note that you can also use credentials from the `@azure/ms-rest-browserauth` package instead.
84+
const credential = new InteractiveBrowserCredential(
85+
{
7286
clientId: "<client id for your Azure AD app>",
7387
tenant: "<optional tenant for your organization>"
7488
});
75-
authManager.finalizeLogin().then((res) => {
76-
if (!res.isLoggedIn) {
77-
// may cause redirects
78-
authManager.login();
79-
}
80-
const client = new Azure.ArmReservations.AzureReservationAPI(res.creds);
81-
const subscriptionId = "testsubscriptionId";
82-
const providerId = "testproviderId";
83-
const location = "westus";
84-
const resourceName = "testresourceName";
85-
client.quota.get(subscriptionId, providerId, location, resourceName).then((result) => {
86-
console.log("The result is:");
87-
console.log(result);
88-
}).catch((err) => {
89-
console.log("An error occurred:");
90-
console.error(err);
91-
});
89+
const client = new Azure.ArmReservations.AzureReservationAPI(creds, subscriptionId);
90+
const reservationOrderId = "testreservationOrderId";
91+
client.reservation.list(reservationOrderId).then((result) => {
92+
console.log("The result is:");
93+
console.log(result);
94+
}).catch((err) => {
95+
console.log("An error occurred:");
96+
console.error(err);
9297
});
9398
</script>
9499
</head>

sdk/reservations/arm-reservations/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"description": "AzureReservationAPI Library with typescript type definitions for node.js and browser.",
55
"version": "6.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,13 +21,13 @@
2021
"module": "./esm/azureReservationAPI.js",
2122
"types": "./esm/azureReservationAPI.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",
2728
"uglify-js": "^3.6.0"
2829
},
29-
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/reservations/arm-reservations",
30+
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/reservations/arm-reservations",
3031
"repository": {
3132
"type": "git",
3233
"url": "https://github.com/Azure/azure-sdk-for-js.git"

sdk/reservations/arm-reservations/src/azureReservationAPI.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
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";
1314
import * as Parameters from "./models/parameters";
@@ -27,10 +28,15 @@ class AzureReservationAPI extends AzureReservationAPIContext {
2728

2829
/**
2930
* Initializes a new instance of the AzureReservationAPI class.
30-
* @param credentials Credentials needed for the client to connect to Azure.
31+
* @param credentials Credentials needed for the client to connect to Azure. Credentials
32+
* implementing the TokenCredential interface from the @azure/identity package are recommended. For
33+
* more information about these credentials, see
34+
* {@link https://www.npmjs.com/package/@azure/identity}. Credentials implementing the
35+
* ServiceClientCredentials interface from the older packages @azure/ms-rest-nodeauth and
36+
* @azure/ms-rest-browserauth are also supported.
3137
* @param [options] The parameter options
3238
*/
33-
constructor(credentials: msRest.ServiceClientCredentials, options?: Models.AzureReservationAPIOptions) {
39+
constructor(credentials: msRest.ServiceClientCredentials | TokenCredential, options?: Models.AzureReservationAPIOptions) {
3440
super(credentials, options);
3541
this.reservation = new operations.Reservation(this);
3642
this.reservationOrder = new operations.ReservationOrder(this);

sdk/reservations/arm-reservations/src/azureReservationAPIContext.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,25 @@
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-reservations";
1516
const packageVersion = "6.0.0";
1617

1718
export class AzureReservationAPIContext extends msRestAzure.AzureServiceClient {
18-
credentials: msRest.ServiceClientCredentials;
19+
credentials: msRest.ServiceClientCredentials | TokenCredential;
1920

2021
/**
2122
* Initializes a new instance of the AzureReservationAPI class.
22-
* @param credentials Credentials needed for the client to connect to Azure.
23+
* @param credentials Credentials needed for the client to connect to Azure. Credentials
24+
* implementing the TokenCredential interface from the @azure/identity package are recommended. For
25+
* more information about these credentials, see
26+
* {@link https://www.npmjs.com/package/@azure/identity}. Credentials implementing the
27+
* ServiceClientCredentials interface from the older packages @azure/ms-rest-nodeauth and
28+
* @azure/ms-rest-browserauth are also supported.
2329
* @param [options] The parameter options
2430
*/
25-
constructor(credentials: msRest.ServiceClientCredentials, options?: Models.AzureReservationAPIOptions) {
31+
constructor(credentials: msRest.ServiceClientCredentials | TokenCredential, options?: Models.AzureReservationAPIOptions) {
2632
if (credentials == undefined) {
2733
throw new Error('\'credentials\' cannot be null.');
2834
}

0 commit comments

Comments
 (0)