|
1 | | -## Azure NetworkManagementClient SDK for JavaScript |
| 1 | +# Azure NetworkManagement client library for JavaScript |
2 | 2 |
|
3 | | -This package contains an isomorphic SDK for NetworkManagementClient. |
| 3 | +This package contains an isomorphic SDK (runs both in Node.js and in browsers) for Azure NetworkManagement client. |
| 4 | + |
| 5 | +Network Client |
| 6 | + |
| 7 | +[Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/network/arm-network-profile-2020-09-01-hybrid) | |
| 8 | +[Package (NPM)](https://www.npmjs.com/package/@azure/arm-network-profile-2020-09-01-hybrid) | |
| 9 | +[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/arm-network-profile-2020-09-01-hybrid) | |
| 10 | +[Samples](https://github.com/Azure-Samples/azure-samples-js-management) |
| 11 | + |
| 12 | +## Getting started |
4 | 13 |
|
5 | 14 | ### Currently supported environments |
6 | 15 |
|
7 | 16 | - [LTS versions of Node.js](https://nodejs.org/about/releases/) |
8 | | -- Latest versions of Safari, Chrome, Edge, and Firefox. |
| 17 | +- Latest versions of Safari, Chrome, Edge and Firefox. |
| 18 | + |
| 19 | +See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details. |
| 20 | + |
| 21 | +### Prerequisites |
| 22 | + |
| 23 | +- An [Azure subscription][azure_sub]. |
| 24 | + |
| 25 | +### Install the `@azure/arm-network-profile-2020-09-01-hybrid` package |
9 | 26 |
|
10 | | -### How to Install |
| 27 | +Install the Azure NetworkManagement client library for JavaScript with `npm`: |
11 | 28 |
|
12 | 29 | ```bash |
13 | 30 | npm install @azure/arm-network-profile-2020-09-01-hybrid |
14 | 31 | ``` |
15 | 32 |
|
16 | | -### How to use |
| 33 | +### Create and authenticate a `NetworkManagementClient` |
17 | 34 |
|
18 | | -#### nodejs - Authentication, client creation and get virtualNetworkGateways as an example written in TypeScript. |
| 35 | +To create a client object to access the Azure NetworkManagement API, you will need the `endpoint` of your Azure NetworkManagement resource and a `credential`. The Azure NetworkManagement client can use Azure Active Directory credentials to authenticate. |
| 36 | +You can find the endpoint for your Azure NetworkManagement resource in the [Azure Portal][azure_portal]. |
19 | 37 |
|
20 | | -##### Install @azure/ms-rest-nodeauth |
| 38 | +You can authenticate with Azure Active Directory using a credential from the [@azure/identity][azure_identity] library or [an existing AAD Token](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token). |
| 39 | + |
| 40 | +To use the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with the Azure SDK, please install the `@azure/identity` package: |
21 | 41 |
|
22 | | -- Please install minimum version of `"@azure/ms-rest-nodeauth": "^3.0.0"`. |
23 | 42 | ```bash |
24 | | -npm install @azure/ms-rest-nodeauth@"^3.0.0" |
| 43 | +npm install @azure/identity |
25 | 44 | ``` |
26 | 45 |
|
27 | | -##### Sample code |
28 | | - |
29 | | -```typescript |
30 | | -import * as msRest from "@azure/ms-rest-js"; |
31 | | -import * as msRestAzure from "@azure/ms-rest-azure-js"; |
32 | | -import * as msRestNodeAuth from "@azure/ms-rest-nodeauth"; |
33 | | -import { NetworkManagementClient, NetworkManagementModels, NetworkManagementMappers } from "@azure/arm-network-profile-2020-09-01-hybrid"; |
34 | | -const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; |
35 | | - |
36 | | -msRestNodeAuth.interactiveLogin().then((creds) => { |
37 | | - const client = new NetworkManagementClient(creds, subscriptionId); |
38 | | - const resourceGroupName = "testresourceGroupName"; |
39 | | - const virtualNetworkGatewayName = "testvirtualNetworkGatewayName"; |
40 | | - client.virtualNetworkGateways.get(resourceGroupName, virtualNetworkGatewayName).then((result) => { |
41 | | - console.log("The result is:"); |
42 | | - console.log(result); |
43 | | - }); |
44 | | -}).catch((err) => { |
45 | | - console.error(err); |
46 | | -}); |
47 | | -``` |
| 46 | +You will also need to **register a new AAD application and grant access to Azure NetworkManagement** by assigning the suitable role to your service principal (note: roles such as `"Owner"` will not grant the necessary permissions). |
| 47 | +Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`. |
48 | 48 |
|
49 | | -#### browser - Authentication, client creation and get virtualNetworkGateways as an example written in JavaScript. |
| 49 | +For more information about how to create an Azure AD Application check out [this guide](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal). |
50 | 50 |
|
51 | | -##### Install @azure/ms-rest-browserauth |
| 51 | +```javascript |
| 52 | +const { NetworkManagementClient } = require("@azure/arm-network-profile-2020-09-01-hybrid"); |
| 53 | +const { DefaultAzureCredential } = require("@azure/identity"); |
| 54 | +// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details. |
52 | 55 |
|
53 | | -```bash |
54 | | -npm install @azure/ms-rest-browserauth |
| 56 | +const subscriptionId = "00000000-0000-0000-0000-000000000000"; |
| 57 | +const client = new NetworkManagementClient(new DefaultAzureCredential(), subscriptionId); |
| 58 | + |
| 59 | +// For client-side applications running in the browser, use this code instead: |
| 60 | +// const credential = new InteractiveBrowserCredential({ |
| 61 | +// tenantId: "<YOUR_TENANT_ID>", |
| 62 | +// clientId: "<YOUR_CLIENT_ID>" |
| 63 | +// }); |
| 64 | +// const client = new NetworkManagementClient(credential, subscriptionId); |
55 | 65 | ``` |
56 | 66 |
|
57 | | -##### Sample code |
58 | | - |
59 | | -See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser. |
60 | | - |
61 | | -- index.html |
62 | | -```html |
63 | | -<!DOCTYPE html> |
64 | | -<html lang="en"> |
65 | | - <head> |
66 | | - <title>@azure/arm-network-profile-2020-09-01-hybrid sample</title> |
67 | | - <script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script> |
68 | | - <script src="node_modules/@azure/ms-rest-azure-js/dist/msRestAzure.js"></script> |
69 | | - <script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script> |
70 | | - <script src="node_modules/@azure/arm-network-profile-2020-09-01-hybrid/dist/arm-network-profile-2020-09-01-hybrid.js"></script> |
71 | | - <script type="text/javascript"> |
72 | | - const subscriptionId = "<Subscription_Id>"; |
73 | | - const authManager = new msAuth.AuthManager({ |
74 | | - clientId: "<client id for your Azure AD app>", |
75 | | - tenant: "<optional tenant for your organization>" |
76 | | - }); |
77 | | - authManager.finalizeLogin().then((res) => { |
78 | | - if (!res.isLoggedIn) { |
79 | | - // may cause redirects |
80 | | - authManager.login(); |
81 | | - } |
82 | | - const client = new Azure.ArmNetworkProfile20200901Hybrid.NetworkManagementClient(res.creds, subscriptionId); |
83 | | - const resourceGroupName = "testresourceGroupName"; |
84 | | - const virtualNetworkGatewayName = "testvirtualNetworkGatewayName"; |
85 | | - client.virtualNetworkGateways.get(resourceGroupName, virtualNetworkGatewayName).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 | | - }); |
92 | | - }); |
93 | | - </script> |
94 | | - </head> |
95 | | - <body></body> |
96 | | -</html> |
| 67 | + |
| 68 | +### JavaScript Bundle |
| 69 | +To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our [bundling documentation](https://aka.ms/AzureSDKBundling). |
| 70 | + |
| 71 | +## Key concepts |
| 72 | + |
| 73 | +### NetworkManagementClient |
| 74 | + |
| 75 | +`NetworkManagementClient` is the primary interface for developers using the Azure NetworkManagement client library. Explore the methods on this client object to understand the different features of the Azure NetworkManagement service that you can access. |
| 76 | + |
| 77 | +## Troubleshooting |
| 78 | + |
| 79 | +### Logging |
| 80 | + |
| 81 | +Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`: |
| 82 | + |
| 83 | +```javascript |
| 84 | +const { setLogLevel } = require("@azure/logger"); |
| 85 | +setLogLevel("info"); |
97 | 86 | ``` |
98 | 87 |
|
| 88 | +For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger). |
| 89 | + |
| 90 | +## Next steps |
| 91 | + |
| 92 | +Please take a look at the [samples](https://github.com/Azure-Samples/azure-samples-js-management) directory for detailed examples on how to use this library. |
| 93 | + |
| 94 | +## Contributing |
| 95 | + |
| 96 | +If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code. |
| 97 | + |
99 | 98 | ## Related projects |
100 | 99 |
|
101 | | -- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js) |
| 100 | +- [Microsoft Azure SDK for JavaScript](https://github.com/Azure/azure-sdk-for-js) |
| 101 | + |
| 102 | + |
102 | 103 |
|
103 | | - |
| 104 | +[azure_cli]: https://docs.microsoft.com/cli/azure |
| 105 | +[azure_sub]: https://azure.microsoft.com/free/ |
| 106 | +[azure_sub]: https://azure.microsoft.com/free/ |
| 107 | +[azure_portal]: https://portal.azure.com |
| 108 | +[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity |
| 109 | +[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential |
0 commit comments