Skip to content

Commit 9ce5139

Browse files
authored
[astro] Update astro projects to use snippets extraction (#32503)
### Packages impacted by this PR - @azure/arm-astro ### Issues associated with this PR - #32416 ### Describe the problem that is addressed by this PR Updates all projects under `astro` 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 897aecc commit 9ce5139

File tree

4 files changed

+75
-40
lines changed

4 files changed

+75
-40
lines changed

sdk/astro/arm-astro/README.md

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

4747
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).
4848

49-
```javascript
50-
const { AstroManagementClient } = require("@azure/arm-astro");
51-
const { DefaultAzureCredential } = require("@azure/identity");
52-
// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details.
49+
Using Node.js and Node-like environments, you can use the `DefaultAzureCredential` class to authenticate the client.
50+
51+
```ts snippet:ReadmeSampleCreateClient_Node
52+
import { AstroManagementClient } from "@azure/arm-astro";
53+
import { DefaultAzureCredential } from "@azure/identity";
5354

5455
const subscriptionId = "00000000-0000-0000-0000-000000000000";
5556
const client = new AstroManagementClient(new DefaultAzureCredential(), subscriptionId);
57+
```
58+
59+
For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate.
5660

57-
// For client-side applications running in the browser, use this code instead:
58-
// const credential = new InteractiveBrowserCredential({
59-
// tenantId: "<YOUR_TENANT_ID>",
60-
// clientId: "<YOUR_CLIENT_ID>"
61-
// });
62-
// const client = new AstroManagementClient(credential, subscriptionId);
61+
```ts snippet:ReadmeSampleCreateClient_Browser
62+
import { InteractiveBrowserCredential } from "@azure/identity";
63+
import { AstroManagementClient } from "@azure/arm-astro";
64+
65+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
66+
const credential = new InteractiveBrowserCredential({
67+
tenantId: "<YOUR_TENANT_ID>",
68+
clientId: "<YOUR_CLIENT_ID>",
69+
});
70+
const client = new AstroManagementClient(credential, subscriptionId);
6371
```
6472

6573
### JavaScript Bundle
@@ -78,8 +86,9 @@ To use this client library in the browser, first you need to use a bundler. For
7886

7987
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`:
8088

81-
```javascript
82-
const { setLogLevel } = require("@azure/logger");
89+
```ts snippet:SetLogLevel
90+
import { setLogLevel } from "@azure/logger";
91+
8392
setLogLevel("info");
8493
```
8594

sdk/astro/arm-astro/package.json

+13-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.6.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.14.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,8 @@
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",
37+
"@azure/logger": "^1.1.4",
3638
"@types/node": "^18.0.0",
3739
"@vitest/browser": "^2.1.8",
3840
"@vitest/coverage-istanbul": "^2.1.8",
@@ -41,10 +43,7 @@
4143
"typescript": "~5.7.2",
4244
"vitest": "^2.1.8"
4345
},
44-
"repository": {
45-
"type": "git",
46-
"url": "https://github.com/Azure/azure-sdk-for-js.git"
47-
},
46+
"repository": "github:Azure/azure-sdk-for-js",
4847
"bugs": {
4948
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
5049
},
@@ -79,7 +78,7 @@
7978
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
8079
"unit-test:browser": "echo skipped",
8180
"unit-test:node": "dev-tool run test:vitest",
82-
"update-snippets": "echo skipped"
81+
"update-snippets": "dev-tool run update-snippets"
8382
},
8483
"sideEffects": false,
8584
"//metadata": {

sdk/astro/arm-astro/test/astro_operations_test.spec.ts

+14-14
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 { AstroManagementClient } from "../src/astroManagementClient.js";
1713
import { describe, it, assert, beforeEach, afterEach } 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 = {
@@ -40,24 +36,28 @@ describe("Astro test", () => {
4036
let subscriptionId: string;
4137
let client: AstroManagementClient;
4238

43-
beforeEach(async function (ctx) {
39+
beforeEach(async (ctx) => {
4440
recorder = new Recorder(ctx);
4541
await recorder.start(recorderOptions);
46-
subscriptionId = env.SUBSCRIPTION_ID || '';
42+
subscriptionId = env.SUBSCRIPTION_ID || "";
4743
// This is an example of how the environment variables are used
4844
const credential = createTestCredential();
49-
client = new AstroManagementClient(credential, subscriptionId, recorder.configureClientOptions({}));
45+
client = new AstroManagementClient(
46+
credential,
47+
subscriptionId,
48+
recorder.configureClientOptions({}),
49+
);
5050
});
5151

52-
afterEach(async function () {
52+
afterEach(async () => {
5353
await recorder.stop();
5454
});
5555

56-
it("operations list test", async function () {
56+
it("operations list test", async () => {
5757
const resArray = new Array();
58-
for await (let item of client.operations.list()) {
58+
for await (const item of client.operations.list()) {
5959
resArray.push(item);
6060
}
6161
assert.notEqual(resArray.length, 0);
6262
});
63-
})
63+
});
+27
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 { AstroManagementClient } from "../src/index.js";
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 AstroManagementClient(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 AstroManagementClient(credential, subscriptionId);
22+
});
23+
24+
it("SetLogLevel", async () => {
25+
setLogLevel("info");
26+
});
27+
});

0 commit comments

Comments
 (0)