Skip to content

Commit

Permalink
[containerinstance] Migrate containerinstance projects to use snippet…
Browse files Browse the repository at this point in the history
…s extraction (#32675)

### Packages impacted by this PR

- @azure/arm-containerinstance

### Issues associated with this PR

- #32416

### Describe the problem that is addressed by this PR

Updates all projects under `containerinstance` 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)
  • Loading branch information
mpodwysocki authored Jan 22, 2025
1 parent 34c8981 commit 7d5caf3
Show file tree
Hide file tree
Showing 76 changed files with 461 additions and 636 deletions.
33 changes: 21 additions & 12 deletions sdk/containerinstance/arm-containerinstance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,28 @@ Set the values of the client ID, tenant ID, and client secret of the AAD applica

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

```javascript
const { ContainerInstanceManagementClient } = require("@azure/arm-containerinstance");
const { DefaultAzureCredential } = require("@azure/identity");
// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details.
Using Node.js and Node-like environments, you can use the `DefaultAzureCredential` class to authenticate the client.

```ts snippet:ReadmeSampleCreateClient_Node
import { ContainerInstanceManagementClient } from "@azure/arm-containerinstance";
import { DefaultAzureCredential } from "@azure/identity";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new ContainerInstanceManagementClient(new DefaultAzureCredential(), subscriptionId);
```

For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate.

// For client-side applications running in the browser, use this code instead:
// const credential = new InteractiveBrowserCredential({
// tenantId: "<YOUR_TENANT_ID>",
// clientId: "<YOUR_CLIENT_ID>"
// });
// const client = new ContainerInstanceManagementClient(credential, subscriptionId);
```ts snippet:ReadmeSampleCreateClient_Browser
import { InteractiveBrowserCredential } from "@azure/identity";
import { ContainerInstanceManagementClient } from "@azure/arm-containerinstance";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const credential = new InteractiveBrowserCredential({
tenantId: "<YOUR_TENANT_ID>",
clientId: "<YOUR_CLIENT_ID>",
});
const client = new ContainerInstanceManagementClient(credential, subscriptionId);
```

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

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

```javascript
const { setLogLevel } = require("@azure/logger");
```ts snippet:SetLogLevel
import { setLogLevel } from "@azure/logger";

setLogLevel("info");
```

Expand Down
2 changes: 1 addition & 1 deletion sdk/containerinstance/arm-containerinstance/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"repository_url": "https://github.com/Azure/azure-rest-api-specs.git",
"release_tool": "@azure-tools/[email protected]",
"use": "@autorest/[email protected]"
}
}
25 changes: 12 additions & 13 deletions sdk/containerinstance/arm-containerinstance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
},
"dependencies": {
"@azure/abort-controller": "^2.1.2",
"@azure/core-auth": "^1.6.0",
"@azure/core-client": "^1.7.0",
"@azure/core-auth": "^1.9.0",
"@azure/core-client": "^1.9.2",
"@azure/core-lro": "^2.5.4",
"@azure/core-paging": "^1.2.0",
"@azure/core-rest-pipeline": "^1.14.0",
"tslib": "^2.2.0"
"@azure/core-paging": "^1.6.2",
"@azure/core-rest-pipeline": "^1.18.2",
"tslib": "^2.8.1"
},
"keywords": [
"node",
"azure",
"typescript",
"browser",
"isomorphic"
"isomorphic",
"cloud"
],
"license": "MIT",
"main": "./dist/commonjs/index.js",
Expand All @@ -32,20 +33,17 @@
"@azure-tools/test-recorder": "^4.1.0",
"@azure-tools/test-utils-vitest": "^1.0.0",
"@azure/dev-tool": "^1.0.0",
"@azure/identity": "^4.2.1",
"@azure/identity": "^4.6.0",
"@azure/logger": "^1.1.4",
"@types/node": "^18.0.0",
"@vitest/browser": "^3.0.3",
"@vitest/coverage-istanbul": "^3.0.3",
"dotenv": "^16.0.0",
"playwright": "^1.49.1",
"tsx": "^4.7.1",
"typescript": "~5.7.2",
"vitest": "^3.0.3"
},
"repository": {
"type": "git",
"url": "https://github.com/Azure/azure-sdk-for-js.git"
},
"repository": "github:Azure/azure-sdk-for-js",
"bugs": {
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
},
Expand Down Expand Up @@ -79,7 +77,8 @@
"test:node": "echo skipped",
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
"unit-test:browser": "echo skipped",
"unit-test:node": "dev-tool run test:vitest"
"unit-test:node": "dev-tool run test:vitest",
"update-snippets": "dev-tool run update-snippets"
},
"sideEffects": false,
"//metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,22 @@ import "dotenv/config";
*/
async function containerGroupProfileGetByRevisionNumber(): Promise<void> {
const subscriptionId =
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] ||
"00000000-0000-0000-0000-000000000000";
const resourceGroupName =
process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const resourceGroupName = process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
const containerGroupProfileName = "demo1";
const revisionNumber = "1";
const credential = new DefaultAzureCredential();
const client = new ContainerInstanceManagementClient(
credential,
subscriptionId,
const client = new ContainerInstanceManagementClient(credential, subscriptionId);
const result = await client.containerGroupProfileOperations.getByRevisionNumber(
resourceGroupName,
containerGroupProfileName,
revisionNumber,
);
const result =
await client.containerGroupProfileOperations.getByRevisionNumber(
resourceGroupName,
containerGroupProfileName,
revisionNumber,
);
console.log(result);
}

async function main(): Promise<void> {
containerGroupProfileGetByRevisionNumber();
await containerGroupProfileGetByRevisionNumber();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@ import "dotenv/config";
*/
async function containerGroupProfileListAllRevisions(): Promise<void> {
const subscriptionId =
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] ||
"00000000-0000-0000-0000-000000000000";
const resourceGroupName =
process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const resourceGroupName = process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
const containerGroupProfileName = "demo1";
const credential = new DefaultAzureCredential();
const client = new ContainerInstanceManagementClient(
credential,
subscriptionId,
);
const client = new ContainerInstanceManagementClient(credential, subscriptionId);
const resArray = new Array();
for await (let item of client.containerGroupProfileOperations.listAllRevisions(
for await (const item of client.containerGroupProfileOperations.listAllRevisions(
resourceGroupName,
containerGroupProfileName,
)) {
Expand All @@ -41,7 +36,7 @@ async function containerGroupProfileListAllRevisions(): Promise<void> {
}

async function main(): Promise<void> {
containerGroupProfileListAllRevisions();
await containerGroupProfileListAllRevisions();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import {
ContainerGroupProfile,
ContainerInstanceManagementClient,
} from "@azure/arm-containerinstance";
import type { ContainerGroupProfile } from "@azure/arm-containerinstance";
import { ContainerInstanceManagementClient } from "@azure/arm-containerinstance";
import { DefaultAzureCredential } from "@azure/identity";
import "dotenv/config";

Expand All @@ -23,10 +21,8 @@ import "dotenv/config";
*/
async function confidentialContainerGroupProfile(): Promise<void> {
const subscriptionId =
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] ||
"00000000-0000-0000-0000-000000000000";
const resourceGroupName =
process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const resourceGroupName = process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
const containerGroupProfileName = "demo1";
const containerGroupProfile: ContainerGroupProfile = {
confidentialComputeProperties: {
Expand Down Expand Up @@ -55,10 +51,7 @@ async function confidentialContainerGroupProfile(): Promise<void> {
zones: ["1"],
};
const credential = new DefaultAzureCredential();
const client = new ContainerInstanceManagementClient(
credential,
subscriptionId,
);
const client = new ContainerInstanceManagementClient(credential, subscriptionId);
const result = await client.containerGroupProfiles.createOrUpdate(
resourceGroupName,
containerGroupProfileName,
Expand All @@ -75,10 +68,8 @@ async function confidentialContainerGroupProfile(): Promise<void> {
*/
async function containerGroupProfileCreateWithExtensions(): Promise<void> {
const subscriptionId =
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] ||
"00000000-0000-0000-0000-000000000000";
const resourceGroupName =
process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const resourceGroupName = process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
const containerGroupProfileName = "demo1";
const containerGroupProfile: ContainerGroupProfile = {
containers: [
Expand Down Expand Up @@ -112,10 +103,7 @@ async function containerGroupProfileCreateWithExtensions(): Promise<void> {
],
};
const credential = new DefaultAzureCredential();
const client = new ContainerInstanceManagementClient(
credential,
subscriptionId,
);
const client = new ContainerInstanceManagementClient(credential, subscriptionId);
const result = await client.containerGroupProfiles.createOrUpdate(
resourceGroupName,
containerGroupProfileName,
Expand All @@ -132,10 +120,8 @@ async function containerGroupProfileCreateWithExtensions(): Promise<void> {
*/
async function containerGroupProfileWithEncryptionProperties(): Promise<void> {
const subscriptionId =
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] ||
"00000000-0000-0000-0000-000000000000";
const resourceGroupName =
process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const resourceGroupName = process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
const containerGroupProfileName = "demo1";
const containerGroupProfile: ContainerGroupProfile = {
containers: [
Expand All @@ -162,10 +148,7 @@ async function containerGroupProfileWithEncryptionProperties(): Promise<void> {
zones: ["1"],
};
const credential = new DefaultAzureCredential();
const client = new ContainerInstanceManagementClient(
credential,
subscriptionId,
);
const client = new ContainerInstanceManagementClient(credential, subscriptionId);
const result = await client.containerGroupProfiles.createOrUpdate(
resourceGroupName,
containerGroupProfileName,
Expand All @@ -182,10 +165,8 @@ async function containerGroupProfileWithEncryptionProperties(): Promise<void> {
*/
async function containerGroupProfilesCreateOrUpdate(): Promise<void> {
const subscriptionId =
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] ||
"00000000-0000-0000-0000-000000000000";
const resourceGroupName =
process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const resourceGroupName = process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
const containerGroupProfileName = "demo1";
const containerGroupProfile: ContainerGroupProfile = {
containers: [
Expand Down Expand Up @@ -240,10 +221,7 @@ async function containerGroupProfilesCreateOrUpdate(): Promise<void> {
zones: ["1"],
};
const credential = new DefaultAzureCredential();
const client = new ContainerInstanceManagementClient(
credential,
subscriptionId,
);
const client = new ContainerInstanceManagementClient(credential, subscriptionId);
const result = await client.containerGroupProfiles.createOrUpdate(
resourceGroupName,
containerGroupProfileName,
Expand All @@ -260,10 +238,8 @@ async function containerGroupProfilesCreateOrUpdate(): Promise<void> {
*/
async function containerGroupsCreateWithPriority(): Promise<void> {
const subscriptionId =
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] ||
"00000000-0000-0000-0000-000000000000";
const resourceGroupName =
process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const resourceGroupName = process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
const containerGroupProfileName = "demo1";
const containerGroupProfile: ContainerGroupProfile = {
containers: [
Expand All @@ -281,10 +257,7 @@ async function containerGroupsCreateWithPriority(): Promise<void> {
sku: "Standard",
};
const credential = new DefaultAzureCredential();
const client = new ContainerInstanceManagementClient(
credential,
subscriptionId,
);
const client = new ContainerInstanceManagementClient(credential, subscriptionId);
const result = await client.containerGroupProfiles.createOrUpdate(
resourceGroupName,
containerGroupProfileName,
Expand All @@ -294,11 +267,11 @@ async function containerGroupsCreateWithPriority(): Promise<void> {
}

async function main(): Promise<void> {
confidentialContainerGroupProfile();
containerGroupProfileCreateWithExtensions();
containerGroupProfileWithEncryptionProperties();
containerGroupProfilesCreateOrUpdate();
containerGroupsCreateWithPriority();
await confidentialContainerGroupProfile();
await containerGroupProfileCreateWithExtensions();
await containerGroupProfileWithEncryptionProperties();
await containerGroupProfilesCreateOrUpdate();
await containerGroupsCreateWithPriority();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,11 @@ import "dotenv/config";
*/
async function containerGroupProfilesDelete(): Promise<void> {
const subscriptionId =
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] ||
"00000000-0000-0000-0000-000000000000";
const resourceGroupName =
process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
process.env["CONTAINERINSTANCE_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const resourceGroupName = process.env["CONTAINERINSTANCE_RESOURCE_GROUP"] || "demo";
const containerGroupProfileName = "demo1";
const credential = new DefaultAzureCredential();
const client = new ContainerInstanceManagementClient(
credential,
subscriptionId,
);
const client = new ContainerInstanceManagementClient(credential, subscriptionId);
const result = await client.containerGroupProfiles.delete(
resourceGroupName,
containerGroupProfileName,
Expand All @@ -38,7 +33,7 @@ async function containerGroupProfilesDelete(): Promise<void> {
}

async function main(): Promise<void> {
containerGroupProfilesDelete();
await containerGroupProfilesDelete();
}

main().catch(console.error);
Loading

0 comments on commit 7d5caf3

Please sign in to comment.