Skip to content

Commit 31d3d1c

Browse files
authored
[appplatform] Update appplatform projects to use snippets extraction (#32501)
### Packages impacted by this PR - @azure/arm-appplatform ### Issues associated with this PR - #32416 ### Describe the problem that is addressed by this PR Updates all `appplatform` projects to use snippets extraction. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary)
1 parent d8fb4f6 commit 31d3d1c

File tree

4 files changed

+118
-73
lines changed

4 files changed

+118
-73
lines changed

sdk/appplatform/arm-appplatform/README.md

+21-12
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,28 @@ Set the values of the client ID, tenant ID, and client secret of the AAD applica
4848

4949
For more information about how to create an Azure AD Application check out [this guide](https://learn.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal).
5050

51-
```javascript
52-
const { AppPlatformManagementClient } = require("@azure/arm-appplatform");
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.
51+
Using Node.js and Node-like environments, you can use the `DefaultAzureCredential` class to authenticate the client.
52+
53+
```ts snippet:ReadmeSampleCreateClient_Node
54+
import { AppPlatformManagementClient } from "@azure/arm-appplatform";
55+
import { DefaultAzureCredential } from "@azure/identity";
5556

5657
const subscriptionId = "00000000-0000-0000-0000-000000000000";
5758
const client = new AppPlatformManagementClient(new DefaultAzureCredential(), subscriptionId);
59+
```
60+
61+
For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate.
5862

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 AppPlatformManagementClient(credential, subscriptionId);
63+
```ts snippet:ReadmeSampleCreateClient_Browser
64+
import { InteractiveBrowserCredential } from "@azure/identity";
65+
import { AppPlatformManagementClient } from "@azure/arm-appplatform";
66+
67+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
68+
const credential = new InteractiveBrowserCredential({
69+
tenantId: "<YOUR_TENANT_ID>",
70+
clientId: "<YOUR_CLIENT_ID>",
71+
});
72+
const client = new AppPlatformManagementClient(credential, subscriptionId);
6573
```
6674

6775
### JavaScript Bundle
@@ -80,8 +88,9 @@ To use this client library in the browser, first you need to use a bundler. For
8088

8189
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`:
8290

83-
```javascript
84-
const { setLogLevel } = require("@azure/logger");
91+
```ts snippet:SetLogLevel
92+
import { setLogLevel } from "@azure/logger";
93+
8594
setLogLevel("info");
8695
```
8796

sdk/appplatform/arm-appplatform/package.json

+12-14
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@
88
"node": ">=18.0.0"
99
},
1010
"dependencies": {
11-
"@azure/abort-controller": "^1.0.0",
12-
"@azure/core-auth": "^1.3.0",
13-
"@azure/core-client": "^1.7.0",
14-
"@azure/core-lro": "^2.5.4",
15-
"@azure/core-paging": "^1.2.0",
16-
"@azure/core-rest-pipeline": "^1.12.0",
17-
"tslib": "^2.2.0"
11+
"@azure/abort-controller": "^2.1.2",
12+
"@azure/core-auth": "^1.9.0",
13+
"@azure/core-client": "^1.9.2",
14+
"@azure/core-lro": "^2.7.2",
15+
"@azure/core-paging": "^1.6.2",
16+
"@azure/core-rest-pipeline": "^1.18.1",
17+
"tslib": "^2.8.1"
1818
},
1919
"keywords": [
2020
"node",
2121
"azure",
2222
"typescript",
2323
"browser",
24-
"isomorphic"
24+
"isomorphic",
25+
"cloud"
2526
],
2627
"license": "MIT",
2728
"main": "./dist/commonjs/index.js",
@@ -32,7 +33,7 @@
3233
"@azure-tools/test-recorder": "^4.1.0",
3334
"@azure-tools/test-utils-vitest": "^1.0.0",
3435
"@azure/dev-tool": "^1.0.0",
35-
"@azure/identity": "^4.0.1",
36+
"@azure/identity": "^4.5.0",
3637
"@types/node": "^18.0.0",
3738
"@vitest/browser": "^2.1.8",
3839
"@vitest/coverage-istanbul": "^2.1.8",
@@ -41,10 +42,7 @@
4142
"typescript": "~5.7.2",
4243
"vitest": "^2.1.8"
4344
},
44-
"repository": {
45-
"type": "git",
46-
"url": "https://github.com/Azure/azure-sdk-for-js.git"
47-
},
45+
"repository": "github:Azure/azure-sdk-for-js",
4846
"bugs": {
4947
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
5048
},
@@ -79,7 +77,7 @@
7977
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
8078
"unit-test:browser": "echo skipped",
8179
"unit-test:node": "dev-tool run test:vitest",
82-
"update-snippets": "echo skipped"
80+
"update-snippets": "dev-tool run update-snippets"
8381
},
8482
"sideEffects": false,
8583
"//metadata": {

sdk/appplatform/arm-appplatform/test/appplatform_examples.spec.ts

+58-47
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
*/
88

9-
import {
10-
env,
11-
Recorder,
12-
RecorderStartOptions,
13-
isPlaybackMode,
14-
} from "@azure-tools/test-recorder";
9+
import type { RecorderStartOptions } from "@azure-tools/test-recorder";
10+
import { env, Recorder, isPlaybackMode } from "@azure-tools/test-recorder";
1511
import { createTestCredential } from "@azure-tools/test-credential";
1612
import { AppPlatformManagementClient } from "../src/appPlatformManagementClient.js";
1713
import { afterEach, assert, beforeEach, describe, it } from "vitest";
@@ -20,7 +16,7 @@ const replaceableVariables: Record<string, string> = {
2016
AZURE_CLIENT_ID: "azure_client_id",
2117
AZURE_CLIENT_SECRET: "azure_client_secret",
2218
AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888",
23-
SUBSCRIPTION_ID: "azure_subscription_id"
19+
SUBSCRIPTION_ID: "azure_subscription_id",
2420
};
2521

2622
const recorderOptions: RecorderStartOptions = {
@@ -44,96 +40,111 @@ describe("AppPlatform test", () => {
4440
let serviceName: string;
4541
let appName: string;
4642

47-
beforeEach(async function (ctx) {
43+
beforeEach(async (ctx) => {
4844
recorder = new Recorder(ctx);
4945
await recorder.start(recorderOptions);
50-
subscriptionId = env.SUBSCRIPTION_ID || '';
46+
subscriptionId = env.SUBSCRIPTION_ID || "";
5147
// This is an example of how the environment variables are used
5248
const credential = createTestCredential();
53-
client = new AppPlatformManagementClient(credential, subscriptionId, recorder.configureClientOptions({}) as any);
49+
client = new AppPlatformManagementClient(
50+
credential,
51+
subscriptionId,
52+
recorder.configureClientOptions({}) as any,
53+
);
5454
location = "east us";
5555
resourceGroup = "myjstest";
5656
serviceName = "myservicexxx12";
5757
appName = "myappxxx";
5858
});
5959

60-
afterEach(async function () {
60+
afterEach(async () => {
6161
await recorder.stop();
6262
});
6363

64-
it("services create test", async function () {
65-
const res = await client.services.beginCreateOrUpdateAndWait(resourceGroup, serviceName, {
66-
sku: {
67-
name: "B0",
68-
tier: "Basic"
69-
},
70-
tags: {
71-
key1: "value1"
64+
it("services create test", async () => {
65+
const res = await client.services.beginCreateOrUpdateAndWait(
66+
resourceGroup,
67+
serviceName,
68+
{
69+
sku: {
70+
name: "B0",
71+
tier: "Basic",
72+
},
73+
tags: {
74+
key1: "value1",
75+
},
76+
location: location,
7277
},
73-
location: location
74-
}, testPollingOptions);
78+
testPollingOptions,
79+
);
7580
assert.equal(res.name, serviceName);
7681
});
7782

78-
it("apps create test", async function () {
79-
const res = await client.apps.beginCreateOrUpdateAndWait(resourceGroup, serviceName, appName, {
80-
properties: {
81-
public: true,
82-
// activeDeploymentName: "mydeployment1",
83-
fqdn: "myapp.mydomain.com",
84-
httpsOnly: false,
85-
temporaryDisk: {
86-
sizeInGB: 2,
87-
mountPath: "/mytemporarydisk"
83+
it("apps create test", async () => {
84+
const res = await client.apps.beginCreateOrUpdateAndWait(
85+
resourceGroup,
86+
serviceName,
87+
appName,
88+
{
89+
properties: {
90+
public: true,
91+
// activeDeploymentName: "mydeployment1",
92+
fqdn: "myapp.mydomain.com",
93+
httpsOnly: false,
94+
temporaryDisk: {
95+
sizeInGB: 2,
96+
mountPath: "/mytemporarydisk",
97+
},
98+
persistentDisk: {
99+
sizeInGB: 1,
100+
mountPath: "/mypersistentdisk",
101+
},
88102
},
89-
persistentDisk: {
90-
sizeInGB: 1,
91-
mountPath: "/mypersistentdisk"
92-
}
93-
}
94-
}, testPollingOptions);
103+
},
104+
testPollingOptions,
105+
);
95106
assert.equal(res.name, appName);
96107
});
97108

98-
it("services get test", async function () {
109+
it("services get test", async () => {
99110
const res = await client.services.get(resourceGroup, serviceName);
100111
assert.equal(res.name, serviceName);
101112
});
102113

103-
it("apps get test", async function () {
114+
it("apps get test", async () => {
104115
const res = await client.apps.get(resourceGroup, serviceName, appName);
105116
assert.equal(res.name, appName);
106117
});
107118

108-
it("apps list test", async function () {
119+
it("apps list test", async () => {
109120
const resArray = new Array();
110-
for await (let item of client.apps.list(resourceGroup, serviceName)) {
121+
for await (const item of client.apps.list(resourceGroup, serviceName)) {
111122
resArray.push(item);
112123
}
113124
assert.equal(resArray.length, 1);
114125
});
115126

116-
it("services list test", async function () {
127+
it("services list test", async () => {
117128
const resArray = new Array();
118-
for await (let item of client.services.list(resourceGroup)) {
129+
for await (const item of client.services.list(resourceGroup)) {
119130
resArray.push(item);
120131
}
121132
assert.isTrue(resArray.length >= 1);
122133
});
123134

124-
it("apps delete test", async function () {
135+
it("apps delete test", async () => {
125136
await client.apps.beginDeleteAndWait(resourceGroup, serviceName, appName, testPollingOptions);
126137
const resArray = new Array();
127-
for await (let item of client.apps.list(resourceGroup, serviceName)) {
138+
for await (const item of client.apps.list(resourceGroup, serviceName)) {
128139
resArray.push(item);
129140
}
130141
assert.equal(resArray.length, 0);
131142
});
132143

133-
it("services delete test", async function () {
144+
it("services delete test", async () => {
134145
await client.services.beginDeleteAndWait(resourceGroup, serviceName, testPollingOptions);
135146
const resArray = new Array();
136-
for await (let item of client.services.list(resourceGroup)) {
147+
for await (const item of client.services.list(resourceGroup)) {
137148
resArray.push(item);
138149
}
139150
assert.equal(resArray.length, 0);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { AppPlatformManagementClient } from "@azure/arm-appplatform";
5+
import { DefaultAzureCredential, InteractiveBrowserCredential } from "@azure/identity";
6+
import { setLogLevel } from "@azure/logger";
7+
import { describe, it } from "vitest";
8+
9+
describe("snippets", () => {
10+
it("ReadmeSampleCreateClient_Node", async () => {
11+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
12+
const client = new AppPlatformManagementClient(new DefaultAzureCredential(), subscriptionId);
13+
});
14+
15+
it("ReadmeSampleCreateClient_Browser", async () => {
16+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
17+
const credential = new InteractiveBrowserCredential({
18+
tenantId: "<YOUR_TENANT_ID>",
19+
clientId: "<YOUR_CLIENT_ID>",
20+
});
21+
const client = new AppPlatformManagementClient(credential, subscriptionId);
22+
});
23+
24+
it("SetLogLevel", async () => {
25+
setLogLevel("info");
26+
});
27+
});

0 commit comments

Comments
 (0)