@azure-rest/arm-network 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Microsoft
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # Azure NetworkManagement REST client library for JavaScript
2
+
3
+ Network Management Rest Client
4
+
5
+ **If you are not familiar with our REST client, please spend 5 minutes to take a look at our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library, the REST client provides a light-weighted & developer friendly way to call azure rest api**
6
+
7
+ Key links:
8
+
9
+ - [Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/network/arm-network-rest)
10
+ - [Package (NPM)](https://www.npmjs.com/package/@azure-rest/arm-network)
11
+ - [API reference documentation](https://docs.microsoft.com/javascript/api/@azure-rest/arm-network?view=azure-node-preview)
12
+ - [Samples](https://github.com/Azure-Samples/azure-samples-js-management)
13
+
14
+ ## Getting started
15
+
16
+ ### Currently supported environments
17
+
18
+ - Node.js version 14.x.x or higher
19
+
20
+ ### Prerequisites
21
+
22
+ - You must have an [Azure subscription](https://azure.microsoft.com/free/) to use this package.
23
+
24
+ ### Install the `@azure-rest/arm-network` package
25
+
26
+ Install the Azure NetworkManagement client REST client library for JavaScript with `npm`:
27
+
28
+ ```bash
29
+ npm install @azure-rest/arm-network
30
+ ```
31
+
32
+ ### Create and authenticate a `NetworkManagementClient`
33
+
34
+ To use an [Azure Active Directory (AAD) token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token),
35
+ provide an instance of the desired credential type obtained from the
36
+ [@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library.
37
+
38
+ To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity)
39
+
40
+ After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from `@azure/identity` to use.
41
+ As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential)
42
+ can be used to authenticate the client.
43
+
44
+ Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
45
+ AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
46
+
47
+ Use the returned token credential to authenticate the client:
48
+
49
+ ```typescript
50
+ import NetworkManagementClient from "@azure-rest/arm-network";
51
+ import { DefaultAzureCredential } from "@azure/identity";
52
+ const credential = new DefaultAzureCredential();
53
+ const client = NetworkManagementClient(credential);
54
+ ```
55
+
56
+ ## Examples
57
+
58
+ The following section shows you how to initialize and authenticate your client, then list all of your Virtual Networks within a resource group.
59
+ ### List virtual networks within a resource group
60
+
61
+ ```typescript
62
+ import createNetworkManagementClient, {
63
+ VirtualNetworksListParameters,
64
+ paginate
65
+ } from "@azure-rest/arm-network";
66
+ import { DefaultAzureCredential } from "@azure/identity";
67
+ import * as dotenv from "dotenv";
68
+ dotenv.config();
69
+ async function listVirtualNetworksInResourceGroup() {
70
+ const credential = new DefaultAzureCredential();
71
+ const client = createNetworkManagementClient(credential);
72
+ const subscriptionId = "";
73
+ const resourceGroupName = "rg1";
74
+ const options: VirtualNetworksListParameters = {
75
+ queryParameters: { "api-version": "2022-05-01" }
76
+ };
77
+ const initialResponse = await client
78
+ .path(
79
+ "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks",
80
+ subscriptionId,
81
+ resourceGroupName
82
+ )
83
+ .get(options);
84
+ const pageData = paginate(client, initialResponse);
85
+ const result = [];
86
+ for await (const item of pageData) {
87
+ result.push(item);
88
+ }
89
+ console.log(result);
90
+ }
91
+
92
+ listVirtualNetworksInResourceGroup().catch(console.error);
93
+ ```
94
+
95
+ ## Troubleshooting
96
+
97
+ ### Logging
98
+
99
+ 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`:
100
+
101
+ ```javascript
102
+ import { setLogLevel } from "@azure/logger";
103
+
104
+ setLogLevel("info");
105
+ ```
106
+
107
+ 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).