diff --git a/kubernetesruntime/arm-containerorchestratorruntime/LICENSE b/kubernetesruntime/arm-containerorchestratorruntime/LICENSE new file mode 100644 index 000000000000..63447fd8bbbf --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/LICENSE @@ -0,0 +1,21 @@ +Copyright (c) Microsoft Corporation. + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/kubernetesruntime/arm-containerorchestratorruntime/README.md b/kubernetesruntime/arm-containerorchestratorruntime/README.md new file mode 100644 index 000000000000..3625bdd5f3f0 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/README.md @@ -0,0 +1,109 @@ +# Azure KubernetesRuntime client library for JavaScript + +This package contains an isomorphic SDK (runs both in Node.js and in browsers) for Azure KubernetesRuntime client. + + + +Key links: + +- [Package (NPM)](https://www.npmjs.com/package/@azure/arm-containerorchestratorruntime) +- [API reference documentation](https://learn.microsoft.com/javascript/api/@azure/arm-containerorchestratorruntime?view=azure-node-preview) + +## Getting started + +### Currently supported environments + +- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule) +- Latest versions of Safari, Chrome, Edge and Firefox. + +See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details. + +### Prerequisites + +- An [Azure subscription][azure_sub]. + +### Install the `@azure/arm-containerorchestratorruntime` package + +Install the Azure KubernetesRuntime client library for JavaScript with `npm`: + +```bash +npm install @azure/arm-containerorchestratorruntime +``` + +### Create and authenticate a `KubernetesRuntimeClient` + +To create a client object to access the Azure KubernetesRuntime API, you will need the `endpoint` of your Azure KubernetesRuntime resource and a `credential`. The Azure KubernetesRuntime client can use Azure Active Directory credentials to authenticate. +You can find the endpoint for your Azure KubernetesRuntime resource in the [Azure Portal][azure_portal]. + +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). + +To use the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with the Azure SDK, please install the `@azure/identity` package: + +```bash +npm install @azure/identity +``` + +You will also need to **register a new AAD application and grant access to Azure KubernetesRuntime** by assigning the suitable role to your service principal (note: roles such as `"Owner"` will not grant the necessary permissions). + +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). + +Using Node.js and Node-like environments, you can use the `DefaultAzureCredential` class to authenticate the client. + +```ts snippet:ReadmeSampleCreateClient_Node +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +const subscriptionId = "00000000-0000-0000-0000-000000000000"; +const client = new KubernetesRuntimeClient(new DefaultAzureCredential(), subscriptionId); +``` + +For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate. + +```ts snippet:ReadmeSampleCreateClient_Browser +import { InteractiveBrowserCredential } from "@azure/identity"; +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; + +const credential = new InteractiveBrowserCredential({ + tenantId: "", + clientId: "" + }); +const client = new KubernetesRuntimeClient(credential, subscriptionId); +``` + + +### JavaScript Bundle +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). + +## Key concepts + +### KubernetesRuntimeClient + +`KubernetesRuntimeClient` is the primary interface for developers using the Azure KubernetesRuntime client library. Explore the methods on this client object to understand the different features of the Azure KubernetesRuntime service that you can access. + +## Troubleshooting + +### Logging + +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`: + +```ts snippet:SetLogLevel +import { setLogLevel } from "@azure/logger"; + +setLogLevel("info"); +``` + +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). + + +## Contributing + +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. + +## Related projects + +- [Microsoft Azure SDK for JavaScript](https://github.com/Azure/azure-sdk-for-js) + +[azure_sub]: https://azure.microsoft.com/free/ +[azure_portal]: https://portal.azure.com +[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity +[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential diff --git a/kubernetesruntime/arm-containerorchestratorruntime/api-extractor.json b/kubernetesruntime/arm-containerorchestratorruntime/api-extractor.json new file mode 100644 index 000000000000..62a58e6e98ca --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/api-extractor.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", + "mainEntryPointFilePath": "./dist/esm/index.d.ts", + "docModel": { "enabled": true }, + "apiReport": { "enabled": true, "reportFolder": "./review" }, + "dtsRollup": { + "enabled": true, + "untrimmedFilePath": "", + "publicTrimmedFilePath": "./types/arm-containerorchestratorruntime.d.ts" + }, + "messages": { + "tsdocMessageReporting": { "default": { "logLevel": "none" } }, + "extractorMessageReporting": { + "ae-missing-release-tag": { "logLevel": "none" }, + "ae-unresolved-link": { "logLevel": "none" } + } + } +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/eslint.config.mjs b/kubernetesruntime/arm-containerorchestratorruntime/eslint.config.mjs new file mode 100644 index 000000000000..9396819633a9 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/eslint.config.mjs @@ -0,0 +1,14 @@ +import azsdkEslint from "@azure/eslint-plugin-azure-sdk"; + +export default azsdkEslint.config([ + { + rules: { + "@azure/azure-sdk/ts-modules-only-named": "warn", + "@azure/azure-sdk/ts-package-json-types": "warn", + "@azure/azure-sdk/ts-package-json-engine-is-present": "warn", + "@azure/azure-sdk/ts-package-json-files-required": "off", + "@azure/azure-sdk/ts-package-json-main-is-cjs": "off", + "tsdoc/syntax": "warn" + } + } +]); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/package.json b/kubernetesruntime/arm-containerorchestratorruntime/package.json new file mode 100644 index 000000000000..93d749a6312e --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/package.json @@ -0,0 +1,96 @@ +{ + "name": "@azure/arm-containerorchestratorruntime", + "version": "1.0.0-beta.1", + "description": "A generated SDK for KubernetesRuntimeClient.", + "engines": { + "node": ">=18.0.0" + }, + "sideEffects": false, + "autoPublish": false, + "tshy": { + "exports": { + "./package.json": "./package.json", + ".": "./src/index.ts", + "./models": "./src/models/index.ts" + }, + "dialects": ["esm", "commonjs"], + "esmDialects": ["browser", "react-native"], + "selfLink": false + }, + "type": "module", + "keywords": ["node", "azure", "cloud", "typescript", "browser", "isomorphic"], + "author": "Microsoft Corporation", + "license": "MIT", + "files": ["dist", "README.md", "LICENSE", "review/*", "CHANGELOG.md"], + "sdk-type": "mgmt", + "repository": "github:Azure/azure-sdk-for-js", + "bugs": { + "url": "https://github.com/Azure/azure-sdk-for-js/issues" + }, + "prettier": "@azure/eslint-plugin-azure-sdk/prettier.json", + "//metadata": { + "constantPaths": [ + { + "path": "src/api/kubernetesRuntimeContext.ts", + "prefix": "userAgentInfo" + } + ] + }, + "dependencies": { + "@azure/core-util": "^1.9.2", + "@azure-rest/core-client": "^2.3.1", + "@azure/core-auth": "^1.6.0", + "@azure/core-rest-pipeline": "^1.5.0", + "@azure/logger": "^1.0.0", + "tslib": "^2.6.2", + "@azure/core-lro": "^3.1.0", + "@azure/abort-controller": "^2.1.2" + }, + "devDependencies": { + "dotenv": "^16.0.0", + "@microsoft/api-extractor": "^7.40.3", + "@types/node": "^18.0.0", + "eslint": "^9.9.0", + "typescript": "~5.6.2", + "@azure/identity": "^4.2.1", + "@vitest/browser": "^3.0.3", + "@vitest/coverage-istanbul": "^3.0.3", + "playwright": "^1.41.2", + "vitest": "^3.0.3", + "@azure-tools/test-credential": "^2.0.0", + "@azure-tools/test-recorder": "^4.0.0", + "@azure/dev-tool": "^1.0.0", + "@azure/eslint-plugin-azure-sdk": "^3.0.0" + }, + "scripts": { + "clean": "dev-tool run vendored rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log", + "extract-api": "dev-tool run vendored rimraf review && dev-tool run extract-api", + "pack": "npm pack 2>&1", + "lint": "eslint package.json api-extractor.json src test", + "lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]", + "unit-test": "npm run unit-test:node && npm run unit-test:browser", + "unit-test:browser": "npm run build:test && dev-tool run test:vitest --browser", + "unit-test:node": "dev-tool run test:vitest", + "integration-test": "npm run integration-test:node && npm run integration-test:browser", + "integration-test:browser": "echo skipped", + "integration-test:node": "echo skipped", + "build:samples": "dev-tool run typecheck --paths samples-dev/*.ts && dev-tool samples publish -f", + "check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.{ts,cts,mts}\" \"test/**/*.{ts,cts,mts}\" \"*.{js,cjs,mjs,json}\" \"samples-dev/*.ts\"", + "execute:samples": "dev-tool samples run samples-dev", + "format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.{ts,cts,mts}\" \"test/**/*.{ts,cts,mts}\" \"*.{js,cjs,mjs,json}\" \"samples-dev/*.ts\"", + "generate:client": "echo skipped", + "test:browser": "npm run clean && npm run build:test && npm run unit-test:browser && npm run integration-test:browser", + "minify": "dev-tool run vendored uglifyjs -c -m --comments --source-map \"content='./dist/index.js.map'\" -o ./dist/index.min.js ./dist/index.js", + "build:test": "npm run clean && dev-tool run build-package && dev-tool run build-test", + "build": "npm run clean && dev-tool run build-package && dev-tool run extract-api", + "test:node": "npm run clean && dev-tool run build-package && npm run unit-test:node && npm run integration-test:node", + "test": "npm run clean && dev-tool run build-package && npm run unit-test:node && dev-tool run bundle && npm run unit-test:browser && npm run integration-test", + "update-snippets": "dev-tool run update-snippets" + }, + "//sampleConfiguration": { + "productName": "@azure/arm-containerorchestratorruntime", + "productSlugs": ["azure"], + "disableDocsMs": true, + "apiRefLink": "https://learn.microsoft.com/javascript/api/@azure/arm-containerorchestratorruntime?view=azure-node-preview" + } +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/sample.env b/kubernetesruntime/arm-containerorchestratorruntime/sample.env new file mode 100644 index 000000000000..508439fc7d62 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/sample.env @@ -0,0 +1 @@ +# Feel free to add your own environment variables. \ No newline at end of file diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/bgpPeersCreateOrUpdateSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/bgpPeersCreateOrUpdateSample.ts new file mode 100644 index 000000000000..83ed71af4459 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/bgpPeersCreateOrUpdateSample.ts @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to create a BgpPeer + * + * @summary create a BgpPeer + * x-ms-original-file: 2024-03-01/BgpPeers_CreateOrUpdate.json + */ +async function bgpPeersCreateOrUpdate(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + const result = await client.bgpPeers.createOrUpdate( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + "testpeer", + { properties: { myAsn: 64500, peerAsn: 64501, peerAddress: "10.0.0.1" } }, + ); + console.log(result); +} + +async function main(): Promise { + await bgpPeersCreateOrUpdate(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/bgpPeersDeleteSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/bgpPeersDeleteSample.ts new file mode 100644 index 000000000000..6cf31e10c4e9 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/bgpPeersDeleteSample.ts @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to delete a BgpPeer + * + * @summary delete a BgpPeer + * x-ms-original-file: 2024-03-01/BgpPeers_Delete.json + */ +async function bgpPeersDelete(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + await client.bgpPeers.delete( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + "testpeer", + ); +} + +async function main(): Promise { + await bgpPeersDelete(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/bgpPeersGetSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/bgpPeersGetSample.ts new file mode 100644 index 000000000000..083c11216edb --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/bgpPeersGetSample.ts @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to get a BgpPeer + * + * @summary get a BgpPeer + * x-ms-original-file: 2024-03-01/BgpPeers_Get.json + */ +async function bgpPeersGet(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + const result = await client.bgpPeers.get( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + "testpeer", + ); + console.log(result); +} + +async function main(): Promise { + await bgpPeersGet(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/bgpPeersListSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/bgpPeersListSample.ts new file mode 100644 index 000000000000..3aea7ac495b5 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/bgpPeersListSample.ts @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to list BgpPeer resources by parent + * + * @summary list BgpPeer resources by parent + * x-ms-original-file: 2024-03-01/BgpPeers_List.json + */ +async function bgpPeersList(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + const resArray = new Array(); + for await (let item of client.bgpPeers.list( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + )) { + resArray.push(item); + } + + console.log(resArray); +} + +async function main(): Promise { + await bgpPeersList(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/loadBalancersCreateOrUpdateSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/loadBalancersCreateOrUpdateSample.ts new file mode 100644 index 000000000000..f5d19f2e30c6 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/loadBalancersCreateOrUpdateSample.ts @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to create a LoadBalancer + * + * @summary create a LoadBalancer + * x-ms-original-file: 2024-03-01/LoadBalancers_CreateOrUpdate.json + */ +async function loadBalancersCreateOrUpdate(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + const result = await client.loadBalancers.createOrUpdate( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + "testlb", + { + properties: { + addresses: ["192.168.50.1/24", "192.168.51.2-192.168.51.10"], + serviceSelector: { app: "frontend" }, + advertiseMode: "ARP", + }, + }, + ); + console.log(result); +} + +async function main(): Promise { + await loadBalancersCreateOrUpdate(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/loadBalancersDeleteSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/loadBalancersDeleteSample.ts new file mode 100644 index 000000000000..0babde833144 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/loadBalancersDeleteSample.ts @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to delete a LoadBalancer + * + * @summary delete a LoadBalancer + * x-ms-original-file: 2024-03-01/LoadBalancers_Delete.json + */ +async function loadBalancersDelete(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + await client.loadBalancers.delete( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + "testlb", + ); +} + +async function main(): Promise { + await loadBalancersDelete(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/loadBalancersGetSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/loadBalancersGetSample.ts new file mode 100644 index 000000000000..ddd22a2463d0 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/loadBalancersGetSample.ts @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to get a LoadBalancer + * + * @summary get a LoadBalancer + * x-ms-original-file: 2024-03-01/LoadBalancers_Get.json + */ +async function loadBalancersGet(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + const result = await client.loadBalancers.get( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + "testlb", + ); + console.log(result); +} + +async function main(): Promise { + await loadBalancersGet(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/loadBalancersListSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/loadBalancersListSample.ts new file mode 100644 index 000000000000..a10a13e1728f --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/loadBalancersListSample.ts @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to list LoadBalancer resources by parent + * + * @summary list LoadBalancer resources by parent + * x-ms-original-file: 2024-03-01/LoadBalancers_List.json + */ +async function loadBalancersList(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + const resArray = new Array(); + for await (let item of client.loadBalancers.list( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + )) { + resArray.push(item); + } + + console.log(resArray); +} + +async function main(): Promise { + await loadBalancersList(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/operationsListSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/operationsListSample.ts new file mode 100644 index 000000000000..a14d8744601f --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/operationsListSample.ts @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to list the operations for the provider + * + * @summary list the operations for the provider + * x-ms-original-file: 2024-03-01/Operations_List.json + */ +async function operationsList0(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + const resArray = new Array(); + for await (let item of client.operations.list()) { + resArray.push(item); + } + + console.log(resArray); +} + +async function main(): Promise { + await operationsList0(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/servicesCreateOrUpdateSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/servicesCreateOrUpdateSample.ts new file mode 100644 index 000000000000..31b39eeb2cda --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/servicesCreateOrUpdateSample.ts @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to create a ServiceResource + * + * @summary create a ServiceResource + * x-ms-original-file: 2024-03-01/Services_CreateOrUpdate.json + */ +async function servicesCreateOrUpdate(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + const result = await client.services.createOrUpdate( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + "storageclass", + { properties: {} }, + ); + console.log(result); +} + +async function main(): Promise { + await servicesCreateOrUpdate(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/servicesDeleteSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/servicesDeleteSample.ts new file mode 100644 index 000000000000..0eb9248954f8 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/servicesDeleteSample.ts @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to delete a ServiceResource + * + * @summary delete a ServiceResource + * x-ms-original-file: 2024-03-01/Services_Delete.json + */ +async function servicesDelete(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + await client.services.delete( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + "storageclass", + ); +} + +async function main(): Promise { + await servicesDelete(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/servicesGetSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/servicesGetSample.ts new file mode 100644 index 000000000000..55ada7d6ba6d --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/servicesGetSample.ts @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to get a ServiceResource + * + * @summary get a ServiceResource + * x-ms-original-file: 2024-03-01/Services_Get.json + */ +async function servicesGet(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + const result = await client.services.get( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + "storageclass", + ); + console.log(result); +} + +async function main(): Promise { + await servicesGet(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/servicesListSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/servicesListSample.ts new file mode 100644 index 000000000000..dacc4d6b957b --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/servicesListSample.ts @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to list ServiceResource resources by parent + * + * @summary list ServiceResource resources by parent + * x-ms-original-file: 2024-03-01/Services_List.json + */ +async function servicesList(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + const resArray = new Array(); + for await (let item of client.services.list( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + )) { + resArray.push(item); + } + + console.log(resArray); +} + +async function main(): Promise { + await servicesList(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/storageClassCreateOrUpdateSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/storageClassCreateOrUpdateSample.ts new file mode 100644 index 000000000000..1d96c22ee20c --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/storageClassCreateOrUpdateSample.ts @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to create a StorageClassResource + * + * @summary create a StorageClassResource + * x-ms-original-file: 2024-03-01/StorageClass_CreateOrUpdate.json + */ +async function storageClassCreateOrUpdate0(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + const result = await client.storageClass.createOrUpdate( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + "testrwx", + { + properties: { + typeProperties: { type: "RWX", backingStorageClassName: "default" }, + }, + }, + ); + console.log(result); +} + +async function main(): Promise { + await storageClassCreateOrUpdate0(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/storageClassDeleteSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/storageClassDeleteSample.ts new file mode 100644 index 000000000000..727b5e97b26a --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/storageClassDeleteSample.ts @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to delete a StorageClassResource + * + * @summary delete a StorageClassResource + * x-ms-original-file: 2024-03-01/StorageClass_Delete.json + */ +async function storageClassDelete0(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + await client.storageClass.delete( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + "testrwx", + ); +} + +async function main(): Promise { + await storageClassDelete0(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/storageClassGetSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/storageClassGetSample.ts new file mode 100644 index 000000000000..a4e995bb64d9 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/storageClassGetSample.ts @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to get a StorageClassResource + * + * @summary get a StorageClassResource + * x-ms-original-file: 2024-03-01/StorageClass_Get.json + */ +async function storageClassGet0(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + const result = await client.storageClass.get( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + "testrwx", + ); + console.log(result); +} + +async function main(): Promise { + await storageClassGet0(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/storageClassListSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/storageClassListSample.ts new file mode 100644 index 000000000000..9fabc55765e4 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/storageClassListSample.ts @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to list StorageClassResource resources by parent + * + * @summary list StorageClassResource resources by parent + * x-ms-original-file: 2024-03-01/StorageClass_List.json + */ +async function storageClassList0(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + const resArray = new Array(); + for await (let item of client.storageClass.list( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + )) { + resArray.push(item); + } + + console.log(resArray); +} + +async function main(): Promise { + await storageClassList0(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/storageClassUpdateSample.ts b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/storageClassUpdateSample.ts new file mode 100644 index 000000000000..0c817593a972 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/samples-dev/storageClassUpdateSample.ts @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "@azure/arm-containerorchestratorruntime"; +import { DefaultAzureCredential } from "@azure/identity"; + +/** + * This sample demonstrates how to update a StorageClassResource + * + * @summary update a StorageClassResource + * x-ms-original-file: 2024-03-01/StorageClass_Update.json + */ +async function storageClassUpdate0(): Promise { + const credential = new DefaultAzureCredential(); + const subscriptionId = "00000000-0000-0000-0000-00000000000"; + const client = new KubernetesRuntimeClient(credential, subscriptionId); + const result = await client.storageClass.update( + "subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/example/providers/Microsoft.Kubernetes/connectedClusters/cluster1", + "testrwx", + { properties: { typeProperties: { backingStorageClassName: "default" } } }, + ); + console.log(result); +} + +async function main(): Promise { + await storageClassUpdate0(); +} + +main().catch(console.error); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/api/bgpPeers/index.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/api/bgpPeers/index.ts new file mode 100644 index 000000000000..d5fd3757939a --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/api/bgpPeers/index.ts @@ -0,0 +1,246 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + BgpPeersCreateOrUpdateOptionalParams, + BgpPeersDeleteOptionalParams, + BgpPeersGetOptionalParams, + BgpPeersListOptionalParams, + KubernetesRuntimeContext as Client, +} from "../index.js"; +import { + errorResponseDeserializer, + BgpPeer, + bgpPeerSerializer, + bgpPeerDeserializer, + _BgpPeerListResult, + _bgpPeerListResultDeserializer, +} from "../../models/models.js"; +import { + PagedAsyncIterableIterator, + buildPagedAsyncIterator, +} from "../../static-helpers/pagingHelpers.js"; +import { getLongRunningPoller } from "../../static-helpers/pollingHelpers.js"; +import { + StreamableMethod, + PathUncheckedResponse, + createRestError, + operationOptionsToRequestParameters, +} from "@azure-rest/core-client"; +import { PollerLike, OperationState } from "@azure/core-lro"; + +export function _bgpPeersListSend( + context: Client, + resourceUri: string, + options: BgpPeersListOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path("/{resourceUri}/providers/Microsoft.KubernetesRuntime/bgpPeers", { + value: resourceUri, + allowReserved: true, + }) + .get({ + ...operationOptionsToRequestParameters(options), + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + }); +} + +export async function _bgpPeersListDeserialize( + result: PathUncheckedResponse, +): Promise<_BgpPeerListResult> { + const expectedStatuses = ["200"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return _bgpPeerListResultDeserializer(result.body); +} + +/** List BgpPeer resources by parent */ +export function bgpPeersList( + context: Client, + resourceUri: string, + options: BgpPeersListOptionalParams = { requestOptions: {} }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => _bgpPeersListSend(context, resourceUri, options), + _bgpPeersListDeserialize, + ["200"], + { itemName: "value", nextLinkName: "nextLink" }, + ); +} + +export function _bgpPeersDeleteSend( + context: Client, + resourceUri: string, + bgpPeerName: string, + options: BgpPeersDeleteOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/{resourceUri}/providers/Microsoft.KubernetesRuntime/bgpPeers/{bgpPeerName}", + { value: resourceUri, allowReserved: true }, + bgpPeerName, + ) + .delete({ + ...operationOptionsToRequestParameters(options), + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + }); +} + +export async function _bgpPeersDeleteDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200", "204"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return; +} + +/** Delete a BgpPeer */ +export async function bgpPeersDelete( + context: Client, + resourceUri: string, + bgpPeerName: string, + options: BgpPeersDeleteOptionalParams = { requestOptions: {} }, +): Promise { + const result = await _bgpPeersDeleteSend( + context, + resourceUri, + bgpPeerName, + options, + ); + return _bgpPeersDeleteDeserialize(result); +} + +export function _bgpPeersCreateOrUpdateSend( + context: Client, + resourceUri: string, + bgpPeerName: string, + resource: BgpPeer, + options: BgpPeersCreateOrUpdateOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/{resourceUri}/providers/Microsoft.KubernetesRuntime/bgpPeers/{bgpPeerName}", + { value: resourceUri, allowReserved: true }, + bgpPeerName, + ) + .put({ + ...operationOptionsToRequestParameters(options), + contentType: "application/json", + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + body: bgpPeerSerializer(resource), + }); +} + +export async function _bgpPeersCreateOrUpdateDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200", "201"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return bgpPeerDeserializer(result.body); +} + +/** Create a BgpPeer */ +export function bgpPeersCreateOrUpdate( + context: Client, + resourceUri: string, + bgpPeerName: string, + resource: BgpPeer, + options: BgpPeersCreateOrUpdateOptionalParams = { requestOptions: {} }, +): PollerLike, BgpPeer> { + return getLongRunningPoller( + context, + _bgpPeersCreateOrUpdateDeserialize, + ["200", "201"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _bgpPeersCreateOrUpdateSend( + context, + resourceUri, + bgpPeerName, + resource, + options, + ), + resourceLocationConfig: "azure-async-operation", + }, + ) as PollerLike, BgpPeer>; +} + +export function _bgpPeersGetSend( + context: Client, + resourceUri: string, + bgpPeerName: string, + options: BgpPeersGetOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/{resourceUri}/providers/Microsoft.KubernetesRuntime/bgpPeers/{bgpPeerName}", + { value: resourceUri, allowReserved: true }, + bgpPeerName, + ) + .get({ + ...operationOptionsToRequestParameters(options), + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + }); +} + +export async function _bgpPeersGetDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return bgpPeerDeserializer(result.body); +} + +/** Get a BgpPeer */ +export async function bgpPeersGet( + context: Client, + resourceUri: string, + bgpPeerName: string, + options: BgpPeersGetOptionalParams = { requestOptions: {} }, +): Promise { + const result = await _bgpPeersGetSend( + context, + resourceUri, + bgpPeerName, + options, + ); + return _bgpPeersGetDeserialize(result); +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/api/index.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/api/index.ts new file mode 100644 index 000000000000..051948f3f8f1 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/api/index.ts @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +export { + createKubernetesRuntime, + KubernetesRuntimeContext, + KubernetesRuntimeClientOptionalParams, +} from "./kubernetesRuntimeContext.js"; +export { + ServicesListOptionalParams, + ServicesDeleteOptionalParams, + ServicesCreateOrUpdateOptionalParams, + ServicesGetOptionalParams, + BgpPeersListOptionalParams, + BgpPeersDeleteOptionalParams, + BgpPeersCreateOrUpdateOptionalParams, + BgpPeersGetOptionalParams, + LoadBalancersListOptionalParams, + LoadBalancersDeleteOptionalParams, + LoadBalancersCreateOrUpdateOptionalParams, + LoadBalancersGetOptionalParams, + OperationsListOptionalParams, + StorageClassListOptionalParams, + StorageClassDeleteOptionalParams, + StorageClassUpdateOptionalParams, + StorageClassCreateOrUpdateOptionalParams, + StorageClassGetOptionalParams, +} from "./options.js"; +export { + bgpPeersList, + bgpPeersDelete, + bgpPeersCreateOrUpdate, + bgpPeersGet, +} from "./bgpPeers/index.js"; +export { + loadBalancersList, + loadBalancersDelete, + loadBalancersCreateOrUpdate, + loadBalancersGet, +} from "./loadBalancers/index.js"; +export { operationsList } from "./operations/index.js"; +export { + servicesList, + servicesDelete, + servicesCreateOrUpdate, + servicesGet, +} from "./services/index.js"; +export { + storageClassList, + storageClassDelete, + storageClassUpdate, + storageClassCreateOrUpdate, + storageClassGet, +} from "./storageClass/index.js"; diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/api/kubernetesRuntimeContext.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/api/kubernetesRuntimeContext.ts new file mode 100644 index 000000000000..0d714211b420 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/api/kubernetesRuntimeContext.ts @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { logger } from "../logger.js"; +import { KnownVersions } from "../models/models.js"; +import { Client, ClientOptions, getClient } from "@azure-rest/core-client"; +import { TokenCredential } from "@azure/core-auth"; + +export interface KubernetesRuntimeContext extends Client { + /** The API version to use for this operation. */ + /** Known values of {@link KnownVersions} that the service accepts. */ + apiVersion: string; +} + +/** Optional parameters for the client. */ +export interface KubernetesRuntimeClientOptionalParams extends ClientOptions { + /** The API version to use for this operation. */ + /** Known values of {@link KnownVersions} that the service accepts. */ + apiVersion?: string; +} + +export function createKubernetesRuntime( + credential: TokenCredential, + options: KubernetesRuntimeClientOptionalParams = {}, +): KubernetesRuntimeContext { + const endpointUrl = + options.endpoint ?? options.baseUrl ?? "https://management.azure.com"; + const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; + const userAgentInfo = `azsdk-js-arm-containerorchestratorruntime/1.0.0-beta.1`; + const userAgentPrefix = prefixFromOptions + ? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}` + : `azsdk-js-api ${userAgentInfo}`; + const { apiVersion: _, ...updatedOptions } = { + ...options, + userAgentOptions: { userAgentPrefix }, + loggingOptions: { logger: options.loggingOptions?.logger ?? logger.info }, + credentials: { + scopes: options.credentials?.scopes ?? [`${endpointUrl}/.default`], + }, + }; + const clientContext = getClient(endpointUrl, credential, updatedOptions); + clientContext.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + const apiVersion = options.apiVersion ?? "2024-03-01"; + clientContext.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version")) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return { ...clientContext, apiVersion } as KubernetesRuntimeContext; +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/api/loadBalancers/index.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/api/loadBalancers/index.ts new file mode 100644 index 000000000000..bd692d78cabd --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/api/loadBalancers/index.ts @@ -0,0 +1,246 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + KubernetesRuntimeContext as Client, + LoadBalancersCreateOrUpdateOptionalParams, + LoadBalancersDeleteOptionalParams, + LoadBalancersGetOptionalParams, + LoadBalancersListOptionalParams, +} from "../index.js"; +import { + errorResponseDeserializer, + LoadBalancer, + loadBalancerSerializer, + loadBalancerDeserializer, + _LoadBalancerListResult, + _loadBalancerListResultDeserializer, +} from "../../models/models.js"; +import { + PagedAsyncIterableIterator, + buildPagedAsyncIterator, +} from "../../static-helpers/pagingHelpers.js"; +import { getLongRunningPoller } from "../../static-helpers/pollingHelpers.js"; +import { + StreamableMethod, + PathUncheckedResponse, + createRestError, + operationOptionsToRequestParameters, +} from "@azure-rest/core-client"; +import { PollerLike, OperationState } from "@azure/core-lro"; + +export function _loadBalancersListSend( + context: Client, + resourceUri: string, + options: LoadBalancersListOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/{resourceUri}/providers/Microsoft.KubernetesRuntime/loadBalancers", + { value: resourceUri, allowReserved: true }, + ) + .get({ + ...operationOptionsToRequestParameters(options), + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + }); +} + +export async function _loadBalancersListDeserialize( + result: PathUncheckedResponse, +): Promise<_LoadBalancerListResult> { + const expectedStatuses = ["200"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return _loadBalancerListResultDeserializer(result.body); +} + +/** List LoadBalancer resources by parent */ +export function loadBalancersList( + context: Client, + resourceUri: string, + options: LoadBalancersListOptionalParams = { requestOptions: {} }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => _loadBalancersListSend(context, resourceUri, options), + _loadBalancersListDeserialize, + ["200"], + { itemName: "value", nextLinkName: "nextLink" }, + ); +} + +export function _loadBalancersDeleteSend( + context: Client, + resourceUri: string, + loadBalancerName: string, + options: LoadBalancersDeleteOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/{resourceUri}/providers/Microsoft.KubernetesRuntime/loadBalancers/{loadBalancerName}", + { value: resourceUri, allowReserved: true }, + loadBalancerName, + ) + .delete({ + ...operationOptionsToRequestParameters(options), + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + }); +} + +export async function _loadBalancersDeleteDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200", "204"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return; +} + +/** Delete a LoadBalancer */ +export async function loadBalancersDelete( + context: Client, + resourceUri: string, + loadBalancerName: string, + options: LoadBalancersDeleteOptionalParams = { requestOptions: {} }, +): Promise { + const result = await _loadBalancersDeleteSend( + context, + resourceUri, + loadBalancerName, + options, + ); + return _loadBalancersDeleteDeserialize(result); +} + +export function _loadBalancersCreateOrUpdateSend( + context: Client, + resourceUri: string, + loadBalancerName: string, + resource: LoadBalancer, + options: LoadBalancersCreateOrUpdateOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/{resourceUri}/providers/Microsoft.KubernetesRuntime/loadBalancers/{loadBalancerName}", + { value: resourceUri, allowReserved: true }, + loadBalancerName, + ) + .put({ + ...operationOptionsToRequestParameters(options), + contentType: "application/json", + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + body: loadBalancerSerializer(resource), + }); +} + +export async function _loadBalancersCreateOrUpdateDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200", "201"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return loadBalancerDeserializer(result.body); +} + +/** Create a LoadBalancer */ +export function loadBalancersCreateOrUpdate( + context: Client, + resourceUri: string, + loadBalancerName: string, + resource: LoadBalancer, + options: LoadBalancersCreateOrUpdateOptionalParams = { requestOptions: {} }, +): PollerLike, LoadBalancer> { + return getLongRunningPoller( + context, + _loadBalancersCreateOrUpdateDeserialize, + ["200", "201"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _loadBalancersCreateOrUpdateSend( + context, + resourceUri, + loadBalancerName, + resource, + options, + ), + resourceLocationConfig: "azure-async-operation", + }, + ) as PollerLike, LoadBalancer>; +} + +export function _loadBalancersGetSend( + context: Client, + resourceUri: string, + loadBalancerName: string, + options: LoadBalancersGetOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/{resourceUri}/providers/Microsoft.KubernetesRuntime/loadBalancers/{loadBalancerName}", + { value: resourceUri, allowReserved: true }, + loadBalancerName, + ) + .get({ + ...operationOptionsToRequestParameters(options), + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + }); +} + +export async function _loadBalancersGetDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return loadBalancerDeserializer(result.body); +} + +/** Get a LoadBalancer */ +export async function loadBalancersGet( + context: Client, + resourceUri: string, + loadBalancerName: string, + options: LoadBalancersGetOptionalParams = { requestOptions: {} }, +): Promise { + const result = await _loadBalancersGetSend( + context, + resourceUri, + loadBalancerName, + options, + ); + return _loadBalancersGetDeserialize(result); +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/api/operations/index.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/api/operations/index.ts new file mode 100644 index 000000000000..565fe3c465ea --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/api/operations/index.ts @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + KubernetesRuntimeContext as Client, + OperationsListOptionalParams, +} from "../index.js"; +import { + errorResponseDeserializer, + _OperationListResult, + _operationListResultDeserializer, + Operation, +} from "../../models/models.js"; +import { + PagedAsyncIterableIterator, + buildPagedAsyncIterator, +} from "../../static-helpers/pagingHelpers.js"; +import { + StreamableMethod, + PathUncheckedResponse, + createRestError, + operationOptionsToRequestParameters, +} from "@azure-rest/core-client"; + +export function _operationsListSend( + context: Client, + options: OperationsListOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path("/providers/Microsoft.KubernetesRuntime/operations") + .get({ + ...operationOptionsToRequestParameters(options), + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + }); +} + +export async function _operationsListDeserialize( + result: PathUncheckedResponse, +): Promise<_OperationListResult> { + const expectedStatuses = ["200"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return _operationListResultDeserializer(result.body); +} + +/** List the operations for the provider */ +export function operationsList( + context: Client, + options: OperationsListOptionalParams = { requestOptions: {} }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => _operationsListSend(context, options), + _operationsListDeserialize, + ["200"], + { itemName: "value", nextLinkName: "nextLink" }, + ); +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/api/options.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/api/options.ts new file mode 100644 index 000000000000..80828d871f02 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/api/options.ts @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { OperationOptions } from "@azure-rest/core-client"; + +/** Optional parameters. */ +export interface ServicesListOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface ServicesDeleteOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface ServicesCreateOrUpdateOptionalParams + extends OperationOptions {} + +/** Optional parameters. */ +export interface ServicesGetOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface BgpPeersListOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface BgpPeersDeleteOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface BgpPeersCreateOrUpdateOptionalParams extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface BgpPeersGetOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface LoadBalancersListOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface LoadBalancersDeleteOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface LoadBalancersCreateOrUpdateOptionalParams + extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface LoadBalancersGetOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface OperationsListOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface StorageClassListOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface StorageClassDeleteOptionalParams extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface StorageClassUpdateOptionalParams extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface StorageClassCreateOrUpdateOptionalParams + extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface StorageClassGetOptionalParams extends OperationOptions {} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/api/services/index.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/api/services/index.ts new file mode 100644 index 000000000000..771c28fa8b32 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/api/services/index.ts @@ -0,0 +1,234 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + KubernetesRuntimeContext as Client, + ServicesCreateOrUpdateOptionalParams, + ServicesDeleteOptionalParams, + ServicesGetOptionalParams, + ServicesListOptionalParams, +} from "../index.js"; +import { + ServiceResource, + serviceResourceSerializer, + serviceResourceDeserializer, + errorResponseDeserializer, + _ServiceResourceListResult, + _serviceResourceListResultDeserializer, +} from "../../models/models.js"; +import { + PagedAsyncIterableIterator, + buildPagedAsyncIterator, +} from "../../static-helpers/pagingHelpers.js"; +import { + StreamableMethod, + PathUncheckedResponse, + createRestError, + operationOptionsToRequestParameters, +} from "@azure-rest/core-client"; + +export function _servicesListSend( + context: Client, + resourceUri: string, + options: ServicesListOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path("/{resourceUri}/providers/Microsoft.KubernetesRuntime/services", { + value: resourceUri, + allowReserved: true, + }) + .get({ + ...operationOptionsToRequestParameters(options), + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + }); +} + +export async function _servicesListDeserialize( + result: PathUncheckedResponse, +): Promise<_ServiceResourceListResult> { + const expectedStatuses = ["200"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return _serviceResourceListResultDeserializer(result.body); +} + +/** List ServiceResource resources by parent */ +export function servicesList( + context: Client, + resourceUri: string, + options: ServicesListOptionalParams = { requestOptions: {} }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => _servicesListSend(context, resourceUri, options), + _servicesListDeserialize, + ["200"], + { itemName: "value", nextLinkName: "nextLink" }, + ); +} + +export function _servicesDeleteSend( + context: Client, + resourceUri: string, + serviceName: string, + options: ServicesDeleteOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/{resourceUri}/providers/Microsoft.KubernetesRuntime/services/{serviceName}", + { value: resourceUri, allowReserved: true }, + serviceName, + ) + .delete({ + ...operationOptionsToRequestParameters(options), + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + }); +} + +export async function _servicesDeleteDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200", "204"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return; +} + +/** Delete a ServiceResource */ +export async function servicesDelete( + context: Client, + resourceUri: string, + serviceName: string, + options: ServicesDeleteOptionalParams = { requestOptions: {} }, +): Promise { + const result = await _servicesDeleteSend( + context, + resourceUri, + serviceName, + options, + ); + return _servicesDeleteDeserialize(result); +} + +export function _servicesCreateOrUpdateSend( + context: Client, + resourceUri: string, + serviceName: string, + resource: ServiceResource, + options: ServicesCreateOrUpdateOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/{resourceUri}/providers/Microsoft.KubernetesRuntime/services/{serviceName}", + { value: resourceUri, allowReserved: true }, + serviceName, + ) + .put({ + ...operationOptionsToRequestParameters(options), + contentType: "application/json", + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + body: serviceResourceSerializer(resource), + }); +} + +export async function _servicesCreateOrUpdateDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200", "201"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return serviceResourceDeserializer(result.body); +} + +/** Create a ServiceResource */ +export async function servicesCreateOrUpdate( + context: Client, + resourceUri: string, + serviceName: string, + resource: ServiceResource, + options: ServicesCreateOrUpdateOptionalParams = { requestOptions: {} }, +): Promise { + const result = await _servicesCreateOrUpdateSend( + context, + resourceUri, + serviceName, + resource, + options, + ); + return _servicesCreateOrUpdateDeserialize(result); +} + +export function _servicesGetSend( + context: Client, + resourceUri: string, + serviceName: string, + options: ServicesGetOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/{resourceUri}/providers/Microsoft.KubernetesRuntime/services/{serviceName}", + { value: resourceUri, allowReserved: true }, + serviceName, + ) + .get({ + ...operationOptionsToRequestParameters(options), + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + }); +} + +export async function _servicesGetDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return serviceResourceDeserializer(result.body); +} + +/** Get a ServiceResource */ +export async function servicesGet( + context: Client, + resourceUri: string, + serviceName: string, + options: ServicesGetOptionalParams = { requestOptions: {} }, +): Promise { + const result = await _servicesGetSend( + context, + resourceUri, + serviceName, + options, + ); + return _servicesGetDeserialize(result); +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/api/storageClass/index.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/api/storageClass/index.ts new file mode 100644 index 000000000000..3ff1c6a2c60e --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/api/storageClass/index.ts @@ -0,0 +1,325 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + KubernetesRuntimeContext as Client, + StorageClassCreateOrUpdateOptionalParams, + StorageClassDeleteOptionalParams, + StorageClassGetOptionalParams, + StorageClassListOptionalParams, + StorageClassUpdateOptionalParams, +} from "../index.js"; +import { + errorResponseDeserializer, + StorageClassResource, + storageClassResourceSerializer, + storageClassResourceDeserializer, + StorageClassResourceUpdate, + storageClassResourceUpdateSerializer, + _StorageClassResourceListResult, + _storageClassResourceListResultDeserializer, +} from "../../models/models.js"; +import { + PagedAsyncIterableIterator, + buildPagedAsyncIterator, +} from "../../static-helpers/pagingHelpers.js"; +import { getLongRunningPoller } from "../../static-helpers/pollingHelpers.js"; +import { + StreamableMethod, + PathUncheckedResponse, + createRestError, + operationOptionsToRequestParameters, +} from "@azure-rest/core-client"; +import { PollerLike, OperationState } from "@azure/core-lro"; + +export function _storageClassListSend( + context: Client, + resourceUri: string, + options: StorageClassListOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/{resourceUri}/providers/Microsoft.KubernetesRuntime/storageClasses", + { value: resourceUri, allowReserved: true }, + ) + .get({ + ...operationOptionsToRequestParameters(options), + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + }); +} + +export async function _storageClassListDeserialize( + result: PathUncheckedResponse, +): Promise<_StorageClassResourceListResult> { + const expectedStatuses = ["200"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return _storageClassResourceListResultDeserializer(result.body); +} + +/** List StorageClassResource resources by parent */ +export function storageClassList( + context: Client, + resourceUri: string, + options: StorageClassListOptionalParams = { requestOptions: {} }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => _storageClassListSend(context, resourceUri, options), + _storageClassListDeserialize, + ["200"], + { itemName: "value", nextLinkName: "nextLink" }, + ); +} + +export function _storageClassDeleteSend( + context: Client, + resourceUri: string, + storageClassName: string, + options: StorageClassDeleteOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/{resourceUri}/providers/Microsoft.KubernetesRuntime/storageClasses/{storageClassName}", + { value: resourceUri, allowReserved: true }, + storageClassName, + ) + .delete({ + ...operationOptionsToRequestParameters(options), + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + }); +} + +export async function _storageClassDeleteDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["202", "204", "200"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return; +} + +/** Delete a StorageClassResource */ +export function storageClassDelete( + context: Client, + resourceUri: string, + storageClassName: string, + options: StorageClassDeleteOptionalParams = { requestOptions: {} }, +): PollerLike, void> { + return getLongRunningPoller( + context, + _storageClassDeleteDeserialize, + ["202", "204", "200"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _storageClassDeleteSend( + context, + resourceUri, + storageClassName, + options, + ), + resourceLocationConfig: "location", + }, + ) as PollerLike, void>; +} + +export function _storageClassUpdateSend( + context: Client, + resourceUri: string, + storageClassName: string, + properties: StorageClassResourceUpdate, + options: StorageClassUpdateOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/{resourceUri}/providers/Microsoft.KubernetesRuntime/storageClasses/{storageClassName}", + { value: resourceUri, allowReserved: true }, + storageClassName, + ) + .patch({ + ...operationOptionsToRequestParameters(options), + contentType: "application/json", + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + body: storageClassResourceUpdateSerializer(properties), + }); +} + +export async function _storageClassUpdateDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200", "202"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return storageClassResourceDeserializer(result.body); +} + +/** Update a StorageClassResource */ +export function storageClassUpdate( + context: Client, + resourceUri: string, + storageClassName: string, + properties: StorageClassResourceUpdate, + options: StorageClassUpdateOptionalParams = { requestOptions: {} }, +): PollerLike, StorageClassResource> { + return getLongRunningPoller( + context, + _storageClassUpdateDeserialize, + ["200", "202"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _storageClassUpdateSend( + context, + resourceUri, + storageClassName, + properties, + options, + ), + resourceLocationConfig: "location", + }, + ) as PollerLike, StorageClassResource>; +} + +export function _storageClassCreateOrUpdateSend( + context: Client, + resourceUri: string, + storageClassName: string, + resource: StorageClassResource, + options: StorageClassCreateOrUpdateOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/{resourceUri}/providers/Microsoft.KubernetesRuntime/storageClasses/{storageClassName}", + { value: resourceUri, allowReserved: true }, + storageClassName, + ) + .put({ + ...operationOptionsToRequestParameters(options), + contentType: "application/json", + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + body: storageClassResourceSerializer(resource), + }); +} + +export async function _storageClassCreateOrUpdateDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200", "201"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return storageClassResourceDeserializer(result.body); +} + +/** Create a StorageClassResource */ +export function storageClassCreateOrUpdate( + context: Client, + resourceUri: string, + storageClassName: string, + resource: StorageClassResource, + options: StorageClassCreateOrUpdateOptionalParams = { requestOptions: {} }, +): PollerLike, StorageClassResource> { + return getLongRunningPoller( + context, + _storageClassCreateOrUpdateDeserialize, + ["200", "201"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _storageClassCreateOrUpdateSend( + context, + resourceUri, + storageClassName, + resource, + options, + ), + resourceLocationConfig: "azure-async-operation", + }, + ) as PollerLike, StorageClassResource>; +} + +export function _storageClassGetSend( + context: Client, + resourceUri: string, + storageClassName: string, + options: StorageClassGetOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/{resourceUri}/providers/Microsoft.KubernetesRuntime/storageClasses/{storageClassName}", + { value: resourceUri, allowReserved: true }, + storageClassName, + ) + .get({ + ...operationOptionsToRequestParameters(options), + headers: { + accept: "application/json", + ...options.requestOptions?.headers, + }, + queryParameters: { "api-version": context.apiVersion }, + }); +} + +export async function _storageClassGetDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200"]; + if (!expectedStatuses.includes(result.status)) { + const error = createRestError(result); + error.details = errorResponseDeserializer(result.body); + throw error; + } + + return storageClassResourceDeserializer(result.body); +} + +/** Get a StorageClassResource */ +export async function storageClassGet( + context: Client, + resourceUri: string, + storageClassName: string, + options: StorageClassGetOptionalParams = { requestOptions: {} }, +): Promise { + const result = await _storageClassGetSend( + context, + resourceUri, + storageClassName, + options, + ); + return _storageClassGetDeserialize(result); +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/classic/bgpPeers/index.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/classic/bgpPeers/index.ts new file mode 100644 index 000000000000..fc7cb8abfe37 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/classic/bgpPeers/index.ts @@ -0,0 +1,85 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeContext } from "../../api/kubernetesRuntimeContext.js"; +import { + bgpPeersList, + bgpPeersDelete, + bgpPeersCreateOrUpdate, + bgpPeersGet, +} from "../../api/bgpPeers/index.js"; +import { BgpPeer } from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.js"; +import { PollerLike, OperationState } from "@azure/core-lro"; +import { + BgpPeersListOptionalParams, + BgpPeersDeleteOptionalParams, + BgpPeersCreateOrUpdateOptionalParams, + BgpPeersGetOptionalParams, +} from "../../api/options.js"; + +/** Interface representing a BgpPeers operations. */ +export interface BgpPeersOperations { + /** List BgpPeer resources by parent */ + list: ( + resourceUri: string, + options?: BgpPeersListOptionalParams, + ) => PagedAsyncIterableIterator; + /** Delete a BgpPeer */ + delete: ( + resourceUri: string, + bgpPeerName: string, + options?: BgpPeersDeleteOptionalParams, + ) => Promise; + /** Create a BgpPeer */ + createOrUpdate: ( + resourceUri: string, + bgpPeerName: string, + resource: BgpPeer, + options?: BgpPeersCreateOrUpdateOptionalParams, + ) => PollerLike, BgpPeer>; + /** Get a BgpPeer */ + get: ( + resourceUri: string, + bgpPeerName: string, + options?: BgpPeersGetOptionalParams, + ) => Promise; +} + +function _getBgpPeers(context: KubernetesRuntimeContext) { + return { + list: (resourceUri: string, options?: BgpPeersListOptionalParams) => + bgpPeersList(context, resourceUri, options), + delete: ( + resourceUri: string, + bgpPeerName: string, + options?: BgpPeersDeleteOptionalParams, + ) => bgpPeersDelete(context, resourceUri, bgpPeerName, options), + createOrUpdate: ( + resourceUri: string, + bgpPeerName: string, + resource: BgpPeer, + options?: BgpPeersCreateOrUpdateOptionalParams, + ) => + bgpPeersCreateOrUpdate( + context, + resourceUri, + bgpPeerName, + resource, + options, + ), + get: ( + resourceUri: string, + bgpPeerName: string, + options?: BgpPeersGetOptionalParams, + ) => bgpPeersGet(context, resourceUri, bgpPeerName, options), + }; +} + +export function _getBgpPeersOperations( + context: KubernetesRuntimeContext, +): BgpPeersOperations { + return { + ..._getBgpPeers(context), + }; +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/classic/index.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/classic/index.ts new file mode 100644 index 000000000000..58e429a53bd1 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/classic/index.ts @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +export { BgpPeersOperations } from "./bgpPeers/index.js"; +export { LoadBalancersOperations } from "./loadBalancers/index.js"; +export { OperationsOperations } from "./operations/index.js"; +export { ServicesOperations } from "./services/index.js"; +export { StorageClassOperations } from "./storageClass/index.js"; diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/classic/loadBalancers/index.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/classic/loadBalancers/index.ts new file mode 100644 index 000000000000..92e0da312ee2 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/classic/loadBalancers/index.ts @@ -0,0 +1,85 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeContext } from "../../api/kubernetesRuntimeContext.js"; +import { + loadBalancersList, + loadBalancersDelete, + loadBalancersCreateOrUpdate, + loadBalancersGet, +} from "../../api/loadBalancers/index.js"; +import { + LoadBalancersListOptionalParams, + LoadBalancersDeleteOptionalParams, + LoadBalancersCreateOrUpdateOptionalParams, + LoadBalancersGetOptionalParams, +} from "../../api/options.js"; +import { LoadBalancer } from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.js"; +import { PollerLike, OperationState } from "@azure/core-lro"; + +/** Interface representing a LoadBalancers operations. */ +export interface LoadBalancersOperations { + /** List LoadBalancer resources by parent */ + list: ( + resourceUri: string, + options?: LoadBalancersListOptionalParams, + ) => PagedAsyncIterableIterator; + /** Delete a LoadBalancer */ + delete: ( + resourceUri: string, + loadBalancerName: string, + options?: LoadBalancersDeleteOptionalParams, + ) => Promise; + /** Create a LoadBalancer */ + createOrUpdate: ( + resourceUri: string, + loadBalancerName: string, + resource: LoadBalancer, + options?: LoadBalancersCreateOrUpdateOptionalParams, + ) => PollerLike, LoadBalancer>; + /** Get a LoadBalancer */ + get: ( + resourceUri: string, + loadBalancerName: string, + options?: LoadBalancersGetOptionalParams, + ) => Promise; +} + +function _getLoadBalancers(context: KubernetesRuntimeContext) { + return { + list: (resourceUri: string, options?: LoadBalancersListOptionalParams) => + loadBalancersList(context, resourceUri, options), + delete: ( + resourceUri: string, + loadBalancerName: string, + options?: LoadBalancersDeleteOptionalParams, + ) => loadBalancersDelete(context, resourceUri, loadBalancerName, options), + createOrUpdate: ( + resourceUri: string, + loadBalancerName: string, + resource: LoadBalancer, + options?: LoadBalancersCreateOrUpdateOptionalParams, + ) => + loadBalancersCreateOrUpdate( + context, + resourceUri, + loadBalancerName, + resource, + options, + ), + get: ( + resourceUri: string, + loadBalancerName: string, + options?: LoadBalancersGetOptionalParams, + ) => loadBalancersGet(context, resourceUri, loadBalancerName, options), + }; +} + +export function _getLoadBalancersOperations( + context: KubernetesRuntimeContext, +): LoadBalancersOperations { + return { + ..._getLoadBalancers(context), + }; +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/classic/operations/index.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/classic/operations/index.ts new file mode 100644 index 000000000000..186739aee8f1 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/classic/operations/index.ts @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeContext } from "../../api/kubernetesRuntimeContext.js"; +import { operationsList } from "../../api/operations/index.js"; +import { OperationsListOptionalParams } from "../../api/options.js"; +import { Operation } from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.js"; + +/** Interface representing a Operations operations. */ +export interface OperationsOperations { + /** List the operations for the provider */ + list: ( + options?: OperationsListOptionalParams, + ) => PagedAsyncIterableIterator; +} + +function _getOperations(context: KubernetesRuntimeContext) { + return { + list: (options?: OperationsListOptionalParams) => + operationsList(context, options), + }; +} + +export function _getOperationsOperations( + context: KubernetesRuntimeContext, +): OperationsOperations { + return { + ..._getOperations(context), + }; +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/classic/services/index.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/classic/services/index.ts new file mode 100644 index 000000000000..10a50d15a1d4 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/classic/services/index.ts @@ -0,0 +1,84 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeContext } from "../../api/kubernetesRuntimeContext.js"; +import { + ServicesListOptionalParams, + ServicesDeleteOptionalParams, + ServicesCreateOrUpdateOptionalParams, + ServicesGetOptionalParams, +} from "../../api/options.js"; +import { + servicesList, + servicesDelete, + servicesCreateOrUpdate, + servicesGet, +} from "../../api/services/index.js"; +import { ServiceResource } from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.js"; + +/** Interface representing a Services operations. */ +export interface ServicesOperations { + /** List ServiceResource resources by parent */ + list: ( + resourceUri: string, + options?: ServicesListOptionalParams, + ) => PagedAsyncIterableIterator; + /** Delete a ServiceResource */ + delete: ( + resourceUri: string, + serviceName: string, + options?: ServicesDeleteOptionalParams, + ) => Promise; + /** Create a ServiceResource */ + createOrUpdate: ( + resourceUri: string, + serviceName: string, + resource: ServiceResource, + options?: ServicesCreateOrUpdateOptionalParams, + ) => Promise; + /** Get a ServiceResource */ + get: ( + resourceUri: string, + serviceName: string, + options?: ServicesGetOptionalParams, + ) => Promise; +} + +function _getServices(context: KubernetesRuntimeContext) { + return { + list: (resourceUri: string, options?: ServicesListOptionalParams) => + servicesList(context, resourceUri, options), + delete: ( + resourceUri: string, + serviceName: string, + options?: ServicesDeleteOptionalParams, + ) => servicesDelete(context, resourceUri, serviceName, options), + createOrUpdate: ( + resourceUri: string, + serviceName: string, + resource: ServiceResource, + options?: ServicesCreateOrUpdateOptionalParams, + ) => + servicesCreateOrUpdate( + context, + resourceUri, + serviceName, + resource, + options, + ), + get: ( + resourceUri: string, + serviceName: string, + options?: ServicesGetOptionalParams, + ) => servicesGet(context, resourceUri, serviceName, options), + }; +} + +export function _getServicesOperations( + context: KubernetesRuntimeContext, +): ServicesOperations { + return { + ..._getServices(context), + }; +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/classic/storageClass/index.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/classic/storageClass/index.ts new file mode 100644 index 000000000000..4c8f58fa0dc5 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/classic/storageClass/index.ts @@ -0,0 +1,110 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeContext } from "../../api/kubernetesRuntimeContext.js"; +import { + StorageClassListOptionalParams, + StorageClassDeleteOptionalParams, + StorageClassUpdateOptionalParams, + StorageClassCreateOrUpdateOptionalParams, + StorageClassGetOptionalParams, +} from "../../api/options.js"; +import { + storageClassList, + storageClassDelete, + storageClassUpdate, + storageClassCreateOrUpdate, + storageClassGet, +} from "../../api/storageClass/index.js"; +import { + StorageClassResource, + StorageClassResourceUpdate, +} from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.js"; +import { PollerLike, OperationState } from "@azure/core-lro"; + +/** Interface representing a StorageClass operations. */ +export interface StorageClassOperations { + /** List StorageClassResource resources by parent */ + list: ( + resourceUri: string, + options?: StorageClassListOptionalParams, + ) => PagedAsyncIterableIterator; + /** Delete a StorageClassResource */ + delete: ( + resourceUri: string, + storageClassName: string, + options?: StorageClassDeleteOptionalParams, + ) => PollerLike, void>; + /** Update a StorageClassResource */ + update: ( + resourceUri: string, + storageClassName: string, + properties: StorageClassResourceUpdate, + options?: StorageClassUpdateOptionalParams, + ) => PollerLike, StorageClassResource>; + /** Create a StorageClassResource */ + createOrUpdate: ( + resourceUri: string, + storageClassName: string, + resource: StorageClassResource, + options?: StorageClassCreateOrUpdateOptionalParams, + ) => PollerLike, StorageClassResource>; + /** Get a StorageClassResource */ + get: ( + resourceUri: string, + storageClassName: string, + options?: StorageClassGetOptionalParams, + ) => Promise; +} + +function _getStorageClass(context: KubernetesRuntimeContext) { + return { + list: (resourceUri: string, options?: StorageClassListOptionalParams) => + storageClassList(context, resourceUri, options), + delete: ( + resourceUri: string, + storageClassName: string, + options?: StorageClassDeleteOptionalParams, + ) => storageClassDelete(context, resourceUri, storageClassName, options), + update: ( + resourceUri: string, + storageClassName: string, + properties: StorageClassResourceUpdate, + options?: StorageClassUpdateOptionalParams, + ) => + storageClassUpdate( + context, + resourceUri, + storageClassName, + properties, + options, + ), + createOrUpdate: ( + resourceUri: string, + storageClassName: string, + resource: StorageClassResource, + options?: StorageClassCreateOrUpdateOptionalParams, + ) => + storageClassCreateOrUpdate( + context, + resourceUri, + storageClassName, + resource, + options, + ), + get: ( + resourceUri: string, + storageClassName: string, + options?: StorageClassGetOptionalParams, + ) => storageClassGet(context, resourceUri, storageClassName, options), + }; +} + +export function _getStorageClassOperations( + context: KubernetesRuntimeContext, +): StorageClassOperations { + return { + ..._getStorageClass(context), + }; +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/index.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/index.ts new file mode 100644 index 000000000000..8b1697644187 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/index.ts @@ -0,0 +1,95 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + PageSettings, + ContinuablePage, + PagedAsyncIterableIterator, +} from "./static-helpers/pagingHelpers.js"; + +export { KubernetesRuntimeClient } from "./kubernetesRuntimeClient.js"; +export { restorePoller, RestorePollerOptions } from "./restorePollerHelpers.js"; +export { + ServiceResource, + ServiceProperties, + KnownProvisioningState, + ProvisioningState, + ExtensionResource, + Resource, + SystemData, + KnownCreatedByType, + CreatedByType, + ErrorResponse, + ErrorDetail, + ErrorAdditionalInfo, + BgpPeer, + BgpPeerProperties, + LoadBalancer, + LoadBalancerProperties, + KnownAdvertiseMode, + AdvertiseMode, + Operation, + OperationDisplay, + KnownOrigin, + Origin, + KnownActionType, + ActionType, + StorageClassResource, + StorageClassProperties, + KnownVolumeExpansion, + VolumeExpansion, + KnownVolumeBindingMode, + VolumeBindingMode, + KnownAccessMode, + AccessMode, + KnownDataResilienceTier, + DataResilienceTier, + KnownFailoverTier, + FailoverTier, + KnownPerformanceTier, + PerformanceTier, + StorageClassTypeProperties, + StorageClassTypePropertiesUnion, + KnownSCType, + SCType, + NativeStorageClassTypeProperties, + RwxStorageClassTypeProperties, + BlobStorageClassTypeProperties, + NfsStorageClassTypeProperties, + KnownNfsDirectoryActionOnVolumeDeletion, + NfsDirectoryActionOnVolumeDeletion, + SmbStorageClassTypeProperties, + StorageClassResourceUpdate, + StorageClassPropertiesUpdate, + StorageClassTypePropertiesUpdate, + KnownVersions, +} from "./models/index.js"; +export { + KubernetesRuntimeClientOptionalParams, + ServicesListOptionalParams, + ServicesDeleteOptionalParams, + ServicesCreateOrUpdateOptionalParams, + ServicesGetOptionalParams, + BgpPeersListOptionalParams, + BgpPeersDeleteOptionalParams, + BgpPeersCreateOrUpdateOptionalParams, + BgpPeersGetOptionalParams, + LoadBalancersListOptionalParams, + LoadBalancersDeleteOptionalParams, + LoadBalancersCreateOrUpdateOptionalParams, + LoadBalancersGetOptionalParams, + OperationsListOptionalParams, + StorageClassListOptionalParams, + StorageClassDeleteOptionalParams, + StorageClassUpdateOptionalParams, + StorageClassCreateOrUpdateOptionalParams, + StorageClassGetOptionalParams, +} from "./api/index.js"; +export { + BgpPeersOperations, + LoadBalancersOperations, + OperationsOperations, + ServicesOperations, + StorageClassOperations, +} from "./classic/index.js"; +export { PageSettings, ContinuablePage, PagedAsyncIterableIterator }; diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/kubernetesRuntimeClient.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/kubernetesRuntimeClient.ts new file mode 100644 index 000000000000..eb68da3775ac --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/kubernetesRuntimeClient.ts @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + _getServicesOperations, + ServicesOperations, +} from "./classic/services/index.js"; +import { + _getBgpPeersOperations, + BgpPeersOperations, +} from "./classic/bgpPeers/index.js"; +import { + _getLoadBalancersOperations, + LoadBalancersOperations, +} from "./classic/loadBalancers/index.js"; +import { + _getOperationsOperations, + OperationsOperations, +} from "./classic/operations/index.js"; +import { + _getStorageClassOperations, + StorageClassOperations, +} from "./classic/storageClass/index.js"; +import { + createKubernetesRuntime, + KubernetesRuntimeContext, + KubernetesRuntimeClientOptionalParams, +} from "./api/index.js"; +import { Pipeline } from "@azure/core-rest-pipeline"; +import { TokenCredential } from "@azure/core-auth"; + +export { KubernetesRuntimeClientOptionalParams } from "./api/kubernetesRuntimeContext.js"; + +export class KubernetesRuntimeClient { + private _client: KubernetesRuntimeContext; + /** The pipeline used by this client to make requests */ + public readonly pipeline: Pipeline; + + constructor( + credential: TokenCredential, + options: KubernetesRuntimeClientOptionalParams = {}, + ) { + const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; + const userAgentPrefix = prefixFromOptions + ? `${prefixFromOptions} azsdk-js-client` + : `azsdk-js-client`; + this._client = createKubernetesRuntime(credential, { + ...options, + userAgentOptions: { userAgentPrefix }, + }); + this.pipeline = this._client.pipeline; + this.services = _getServicesOperations(this._client); + this.bgpPeers = _getBgpPeersOperations(this._client); + this.loadBalancers = _getLoadBalancersOperations(this._client); + this.operations = _getOperationsOperations(this._client); + this.storageClass = _getStorageClassOperations(this._client); + } + + /** The operation groups for services */ + public readonly services: ServicesOperations; + /** The operation groups for bgpPeers */ + public readonly bgpPeers: BgpPeersOperations; + /** The operation groups for loadBalancers */ + public readonly loadBalancers: LoadBalancersOperations; + /** The operation groups for operations */ + public readonly operations: OperationsOperations; + /** The operation groups for storageClass */ + public readonly storageClass: StorageClassOperations; +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/logger.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/logger.ts new file mode 100644 index 000000000000..5e0f4080dcfa --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/logger.ts @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { createClientLogger } from "@azure/logger"; +export const logger = createClientLogger("arm-containerorchestratorruntime"); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/models/index.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/models/index.ts new file mode 100644 index 000000000000..5002a35dd558 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/models/index.ts @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +export { + ServiceResource, + ServiceProperties, + KnownProvisioningState, + ProvisioningState, + ExtensionResource, + Resource, + SystemData, + KnownCreatedByType, + CreatedByType, + ErrorResponse, + ErrorDetail, + ErrorAdditionalInfo, + BgpPeer, + BgpPeerProperties, + LoadBalancer, + LoadBalancerProperties, + KnownAdvertiseMode, + AdvertiseMode, + Operation, + OperationDisplay, + KnownOrigin, + Origin, + KnownActionType, + ActionType, + StorageClassResource, + StorageClassProperties, + KnownVolumeExpansion, + VolumeExpansion, + KnownVolumeBindingMode, + VolumeBindingMode, + KnownAccessMode, + AccessMode, + KnownDataResilienceTier, + DataResilienceTier, + KnownFailoverTier, + FailoverTier, + KnownPerformanceTier, + PerformanceTier, + StorageClassTypeProperties, + StorageClassTypePropertiesUnion, + KnownSCType, + SCType, + NativeStorageClassTypeProperties, + RwxStorageClassTypeProperties, + BlobStorageClassTypeProperties, + NfsStorageClassTypeProperties, + KnownNfsDirectoryActionOnVolumeDeletion, + NfsDirectoryActionOnVolumeDeletion, + SmbStorageClassTypeProperties, + StorageClassResourceUpdate, + StorageClassPropertiesUpdate, + StorageClassTypePropertiesUpdate, + KnownVersions, +} from "./models.js"; diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/models/models.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/models/models.ts new file mode 100644 index 000000000000..a0070fc4bf8c --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/models/models.ts @@ -0,0 +1,1332 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** A Service resource for an Arc connected cluster (Microsoft.Kubernetes/connectedClusters) */ +export interface ServiceResource extends ExtensionResource { + /** The resource-specific properties for this resource. */ + properties?: ServiceProperties; +} + +export function serviceResourceSerializer(item: ServiceResource): any { + return { + properties: !item["properties"] + ? item["properties"] + : servicePropertiesSerializer(item["properties"]), + }; +} + +export function serviceResourceDeserializer(item: any): ServiceResource { + return { + id: item["id"], + name: item["name"], + type: item["type"], + systemData: !item["systemData"] + ? item["systemData"] + : systemDataDeserializer(item["systemData"]), + properties: !item["properties"] + ? item["properties"] + : servicePropertiesDeserializer(item["properties"]), + }; +} + +/** Properties for the service resource */ +export interface ServiceProperties { + /** The object id of the service principal of the RP provisioned in the tenant */ + readonly rpObjectId?: string; + /** Resource provision state */ + readonly provisioningState?: ProvisioningState; +} + +export function servicePropertiesSerializer(item: ServiceProperties): any { + return item; +} + +export function servicePropertiesDeserializer(item: any): ServiceProperties { + return { + rpObjectId: item["rpObjectId"], + provisioningState: item["provisioningState"], + }; +} + +/** The status of the current operation. */ +export enum KnownProvisioningState { + /** Resource has been created. */ + Succeeded = "Succeeded", + /** Resource creation failed. */ + Failed = "Failed", + /** Resource creation was canceled. */ + Canceled = "Canceled", + /** Initial provisioning in progress */ + Provisioning = "Provisioning", + /** Update in progress */ + Updating = "Updating", + /** Deletion in progress */ + Deleting = "Deleting", + /** Change accepted for processing */ + Accepted = "Accepted", +} + +/** + * The status of the current operation. \ + * {@link KnownProvisioningState} can be used interchangeably with ProvisioningState, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Succeeded**: Resource has been created. \ + * **Failed**: Resource creation failed. \ + * **Canceled**: Resource creation was canceled. \ + * **Provisioning**: Initial provisioning in progress \ + * **Updating**: Update in progress \ + * **Deleting**: Deletion in progress \ + * **Accepted**: Change accepted for processing + */ +export type ProvisioningState = string; + +/** The base extension resource. */ +export interface ExtensionResource extends Resource {} + +export function extensionResourceSerializer(item: ExtensionResource): any { + return item; +} + +export function extensionResourceDeserializer(item: any): ExtensionResource { + return { + id: item["id"], + name: item["name"], + type: item["type"], + systemData: !item["systemData"] + ? item["systemData"] + : systemDataDeserializer(item["systemData"]), + }; +} + +/** Common fields that are returned in the response for all Azure Resource Manager resources */ +export interface Resource { + /** Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} */ + readonly id?: string; + /** The name of the resource */ + readonly name?: string; + /** The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" */ + readonly type?: string; + /** Azure Resource Manager metadata containing createdBy and modifiedBy information. */ + readonly systemData?: SystemData; +} + +export function resourceSerializer(item: Resource): any { + return item; +} + +export function resourceDeserializer(item: any): Resource { + return { + id: item["id"], + name: item["name"], + type: item["type"], + systemData: !item["systemData"] + ? item["systemData"] + : systemDataDeserializer(item["systemData"]), + }; +} + +/** Metadata pertaining to creation and last modification of the resource. */ +export interface SystemData { + /** The identity that created the resource. */ + createdBy?: string; + /** The type of identity that created the resource. */ + createdByType?: CreatedByType; + /** The timestamp of resource creation (UTC). */ + createdAt?: Date; + /** The identity that last modified the resource. */ + lastModifiedBy?: string; + /** The type of identity that last modified the resource. */ + lastModifiedByType?: CreatedByType; + /** The timestamp of resource last modification (UTC) */ + lastModifiedAt?: Date; +} + +export function systemDataDeserializer(item: any): SystemData { + return { + createdBy: item["createdBy"], + createdByType: item["createdByType"], + createdAt: !item["createdAt"] + ? item["createdAt"] + : new Date(item["createdAt"]), + lastModifiedBy: item["lastModifiedBy"], + lastModifiedByType: item["lastModifiedByType"], + lastModifiedAt: !item["lastModifiedAt"] + ? item["lastModifiedAt"] + : new Date(item["lastModifiedAt"]), + }; +} + +/** The kind of entity that created the resource. */ +export enum KnownCreatedByType { + /** The entity was created by a user. */ + User = "User", + /** The entity was created by an application. */ + Application = "Application", + /** The entity was created by a managed identity. */ + ManagedIdentity = "ManagedIdentity", + /** The entity was created by a key. */ + Key = "Key", +} + +/** + * The kind of entity that created the resource. \ + * {@link KnowncreatedByType} can be used interchangeably with createdByType, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **User**: The entity was created by a user. \ + * **Application**: The entity was created by an application. \ + * **ManagedIdentity**: The entity was created by a managed identity. \ + * **Key**: The entity was created by a key. + */ +export type CreatedByType = string; + +/** Common error response for all Azure Resource Manager APIs to return error details for failed operations. */ +export interface ErrorResponse { + /** The error object. */ + error?: ErrorDetail; +} + +export function errorResponseDeserializer(item: any): ErrorResponse { + return { + error: !item["error"] + ? item["error"] + : errorDetailDeserializer(item["error"]), + }; +} + +/** The error detail. */ +export interface ErrorDetail { + /** The error code. */ + readonly code?: string; + /** The error message. */ + readonly message?: string; + /** The error target. */ + readonly target?: string; + /** The error details. */ + readonly details?: ErrorDetail[]; + /** The error additional info. */ + readonly additionalInfo?: ErrorAdditionalInfo[]; +} + +export function errorDetailDeserializer(item: any): ErrorDetail { + return { + code: item["code"], + message: item["message"], + target: item["target"], + details: !item["details"] + ? item["details"] + : errorDetailArrayDeserializer(item["details"]), + additionalInfo: !item["additionalInfo"] + ? item["additionalInfo"] + : errorAdditionalInfoArrayDeserializer(item["additionalInfo"]), + }; +} + +export function errorDetailArrayDeserializer( + result: Array, +): any[] { + return result.map((item) => { + return errorDetailDeserializer(item); + }); +} + +export function errorAdditionalInfoArrayDeserializer( + result: Array, +): any[] { + return result.map((item) => { + return errorAdditionalInfoDeserializer(item); + }); +} + +/** The resource management error additional info. */ +export interface ErrorAdditionalInfo { + /** The additional info type. */ + readonly type?: string; + /** The additional info. */ + readonly info?: Record; +} + +export function errorAdditionalInfoDeserializer( + item: any, +): ErrorAdditionalInfo { + return { + type: item["type"], + info: !item["info"] + ? item["info"] + : _errorAdditionalInfoInfoDeserializer(item["info"]), + }; +} + +/** model interface _ErrorAdditionalInfoInfo */ +export interface _ErrorAdditionalInfoInfo {} + +export function _errorAdditionalInfoInfoDeserializer( + item: any, +): _ErrorAdditionalInfoInfo { + return item; +} + +/** The response of a ServiceResource list operation. */ +export interface _ServiceResourceListResult { + /** The ServiceResource items on this page */ + value: ServiceResource[]; + /** The link to the next page of items */ + nextLink?: string; +} + +export function _serviceResourceListResultDeserializer( + item: any, +): _ServiceResourceListResult { + return { + value: serviceResourceArrayDeserializer(item["value"]), + nextLink: item["nextLink"], + }; +} + +export function serviceResourceArraySerializer( + result: Array, +): any[] { + return result.map((item) => { + return serviceResourceSerializer(item); + }); +} + +export function serviceResourceArrayDeserializer( + result: Array, +): any[] { + return result.map((item) => { + return serviceResourceDeserializer(item); + }); +} + +/** A BgpPeer resource for an Arc connected cluster (Microsoft.Kubernetes/connectedClusters) */ +export interface BgpPeer extends ExtensionResource { + /** The resource-specific properties for this resource. */ + properties?: BgpPeerProperties; +} + +export function bgpPeerSerializer(item: BgpPeer): any { + return { + properties: !item["properties"] + ? item["properties"] + : bgpPeerPropertiesSerializer(item["properties"]), + }; +} + +export function bgpPeerDeserializer(item: any): BgpPeer { + return { + id: item["id"], + name: item["name"], + type: item["type"], + systemData: !item["systemData"] + ? item["systemData"] + : systemDataDeserializer(item["systemData"]), + properties: !item["properties"] + ? item["properties"] + : bgpPeerPropertiesDeserializer(item["properties"]), + }; +} + +/** Details of the BgpPeer. */ +export interface BgpPeerProperties { + /** My ASN */ + myAsn: number; + /** Peer ASN */ + peerAsn: number; + /** Peer Address */ + peerAddress: string; + /** Resource provision state */ + readonly provisioningState?: ProvisioningState; +} + +export function bgpPeerPropertiesSerializer(item: BgpPeerProperties): any { + return { + myAsn: item["myAsn"], + peerAsn: item["peerAsn"], + peerAddress: item["peerAddress"], + }; +} + +export function bgpPeerPropertiesDeserializer(item: any): BgpPeerProperties { + return { + myAsn: item["myAsn"], + peerAsn: item["peerAsn"], + peerAddress: item["peerAddress"], + provisioningState: item["provisioningState"], + }; +} + +/** The response of a BgpPeer list operation. */ +export interface _BgpPeerListResult { + /** The BgpPeer items on this page */ + value: BgpPeer[]; + /** The link to the next page of items */ + nextLink?: string; +} + +export function _bgpPeerListResultDeserializer(item: any): _BgpPeerListResult { + return { + value: bgpPeerArrayDeserializer(item["value"]), + nextLink: item["nextLink"], + }; +} + +export function bgpPeerArraySerializer(result: Array): any[] { + return result.map((item) => { + return bgpPeerSerializer(item); + }); +} + +export function bgpPeerArrayDeserializer(result: Array): any[] { + return result.map((item) => { + return bgpPeerDeserializer(item); + }); +} + +/** A LoadBalancer resource for an Arc connected cluster (Microsoft.Kubernetes/connectedClusters) */ +export interface LoadBalancer extends ExtensionResource { + /** The resource-specific properties for this resource. */ + properties?: LoadBalancerProperties; +} + +export function loadBalancerSerializer(item: LoadBalancer): any { + return { + properties: !item["properties"] + ? item["properties"] + : loadBalancerPropertiesSerializer(item["properties"]), + }; +} + +export function loadBalancerDeserializer(item: any): LoadBalancer { + return { + id: item["id"], + name: item["name"], + type: item["type"], + systemData: !item["systemData"] + ? item["systemData"] + : systemDataDeserializer(item["systemData"]), + properties: !item["properties"] + ? item["properties"] + : loadBalancerPropertiesDeserializer(item["properties"]), + }; +} + +/** Details of the LoadBalancer. */ +export interface LoadBalancerProperties { + /** IP Range */ + addresses: string[]; + /** A dynamic label mapping to select related services. For instance, if you want to create a load balancer only for services with label "a=b", then please specify {"a": "b"} in the field. */ + serviceSelector?: Record; + /** Advertise Mode */ + advertiseMode: AdvertiseMode; + /** The list of BGP peers it should advertise to. Null or empty means to advertise to all peers. */ + bgpPeers?: string[]; + /** Resource provision state */ + readonly provisioningState?: ProvisioningState; +} + +export function loadBalancerPropertiesSerializer( + item: LoadBalancerProperties, +): any { + return { + addresses: item["addresses"].map((p: any) => { + return p; + }), + serviceSelector: item["serviceSelector"], + advertiseMode: item["advertiseMode"], + bgpPeers: !item["bgpPeers"] + ? item["bgpPeers"] + : item["bgpPeers"].map((p: any) => { + return p; + }), + }; +} + +export function loadBalancerPropertiesDeserializer( + item: any, +): LoadBalancerProperties { + return { + addresses: item["addresses"].map((p: any) => { + return p; + }), + serviceSelector: item["serviceSelector"], + advertiseMode: item["advertiseMode"], + bgpPeers: !item["bgpPeers"] + ? item["bgpPeers"] + : item["bgpPeers"].map((p: any) => { + return p; + }), + provisioningState: item["provisioningState"], + }; +} + +/** Enum of advertise mode */ +export enum KnownAdvertiseMode { + /** ARP advertise mode */ + ARP = "ARP", + /** BGP advertise mode */ + BGP = "BGP", + /** both ARP and BGP advertise mode */ + Both = "Both", +} + +/** + * Enum of advertise mode \ + * {@link KnownAdvertiseMode} can be used interchangeably with AdvertiseMode, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **ARP**: ARP advertise mode \ + * **BGP**: BGP advertise mode \ + * **Both**: both ARP and BGP advertise mode + */ +export type AdvertiseMode = string; + +/** The response of a LoadBalancer list operation. */ +export interface _LoadBalancerListResult { + /** The LoadBalancer items on this page */ + value: LoadBalancer[]; + /** The link to the next page of items */ + nextLink?: string; +} + +export function _loadBalancerListResultDeserializer( + item: any, +): _LoadBalancerListResult { + return { + value: loadBalancerArrayDeserializer(item["value"]), + nextLink: item["nextLink"], + }; +} + +export function loadBalancerArraySerializer( + result: Array, +): any[] { + return result.map((item) => { + return loadBalancerSerializer(item); + }); +} + +export function loadBalancerArrayDeserializer( + result: Array, +): any[] { + return result.map((item) => { + return loadBalancerDeserializer(item); + }); +} + +/** A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to get the next set of results. */ +export interface _OperationListResult { + /** The Operation items on this page */ + value: Operation[]; + /** The link to the next page of items */ + nextLink?: string; +} + +export function _operationListResultDeserializer( + item: any, +): _OperationListResult { + return { + value: operationArrayDeserializer(item["value"]), + nextLink: item["nextLink"], + }; +} + +export function operationArrayDeserializer(result: Array): any[] { + return result.map((item) => { + return operationDeserializer(item); + }); +} + +/** Details of a REST API operation, returned from the Resource Provider Operations API */ +export interface Operation { + /** The name of the operation, as per Resource-Based Access Control (RBAC). Examples: "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action" */ + readonly name?: string; + /** Whether the operation applies to data-plane. This is "true" for data-plane operations and "false" for Azure Resource Manager/control-plane operations. */ + readonly isDataAction?: boolean; + /** Localized display information for this particular operation. */ + display?: OperationDisplay; + /** The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system" */ + readonly origin?: Origin; + /** Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. */ + readonly actionType?: ActionType; +} + +export function operationDeserializer(item: any): Operation { + return { + name: item["name"], + isDataAction: item["isDataAction"], + display: !item["display"] + ? item["display"] + : operationDisplayDeserializer(item["display"]), + origin: item["origin"], + actionType: item["actionType"], + }; +} + +/** Localized display information for and operation. */ +export interface OperationDisplay { + /** The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring Insights" or "Microsoft Compute". */ + readonly provider?: string; + /** The localized friendly name of the resource type related to this operation. E.g. "Virtual Machines" or "Job Schedule Collections". */ + readonly resource?: string; + /** The concise, localized friendly name for the operation; suitable for dropdowns. E.g. "Create or Update Virtual Machine", "Restart Virtual Machine". */ + readonly operation?: string; + /** The short, localized friendly description of the operation; suitable for tool tips and detailed views. */ + readonly description?: string; +} + +export function operationDisplayDeserializer(item: any): OperationDisplay { + return { + provider: item["provider"], + resource: item["resource"], + operation: item["operation"], + description: item["description"], + }; +} + +/** The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system" */ +export enum KnownOrigin { + /** Indicates the operation is initiated by a user. */ + user = "user", + /** Indicates the operation is initiated by a system. */ + system = "system", + /** Indicates the operation is initiated by a user or system. */ + "user,system" = "user,system", +} + +/** + * The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system" \ + * {@link KnownOrigin} can be used interchangeably with Origin, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **user**: Indicates the operation is initiated by a user. \ + * **system**: Indicates the operation is initiated by a system. \ + * **user,system**: Indicates the operation is initiated by a user or system. + */ +export type Origin = string; + +/** Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. */ +export enum KnownActionType { + /** Actions are for internal-only APIs. */ + Internal = "Internal", +} + +/** + * Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. \ + * {@link KnownActionType} can be used interchangeably with ActionType, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Internal**: Actions are for internal-only APIs. + */ +export type ActionType = string; + +/** A StorageClass resource for an Arc connected cluster (Microsoft.Kubernetes/connectedClusters) */ +export interface StorageClassResource extends ExtensionResource { + /** The resource-specific properties for this resource. */ + properties?: StorageClassProperties; +} + +export function storageClassResourceSerializer( + item: StorageClassResource, +): any { + return { + properties: !item["properties"] + ? item["properties"] + : storageClassPropertiesSerializer(item["properties"]), + }; +} + +export function storageClassResourceDeserializer( + item: any, +): StorageClassResource { + return { + id: item["id"], + name: item["name"], + type: item["type"], + systemData: !item["systemData"] + ? item["systemData"] + : systemDataDeserializer(item["systemData"]), + properties: !item["properties"] + ? item["properties"] + : storageClassPropertiesDeserializer(item["properties"]), + }; +} + +/** Details of the StorageClass StorageClass. */ +export interface StorageClassProperties { + /** Volume can be expanded or not */ + allowVolumeExpansion?: VolumeExpansion; + /** Additional mount options */ + mountOptions?: string[]; + /** Provisioner name */ + provisioner?: string; + /** Binding mode of volumes: Immediate, WaitForFirstConsumer */ + volumeBindingMode?: VolumeBindingMode; + /** The access mode: [ReadWriteOnce, ReadWriteMany] or [ReadWriteOnce] */ + accessModes?: AccessMode[]; + /** Allow single data node failure */ + dataResilience?: DataResilienceTier; + /** Failover speed: NA, Slow, Fast */ + failoverSpeed?: FailoverTier; + /** Limitations of the storage class */ + limitations?: string[]; + /** Performance tier */ + performance?: PerformanceTier; + /** Selection priority when multiple storage classes meet the criteria. 0: Highest, -1: Never use */ + priority?: number; + /** Properties of the StorageClass */ + typeProperties: StorageClassTypePropertiesUnion; + /** Resource provision state */ + readonly provisioningState?: ProvisioningState; +} + +export function storageClassPropertiesSerializer( + item: StorageClassProperties, +): any { + return { + allowVolumeExpansion: item["allowVolumeExpansion"], + mountOptions: !item["mountOptions"] + ? item["mountOptions"] + : item["mountOptions"].map((p: any) => { + return p; + }), + provisioner: item["provisioner"], + volumeBindingMode: item["volumeBindingMode"], + accessModes: !item["accessModes"] + ? item["accessModes"] + : item["accessModes"].map((p: any) => { + return p; + }), + dataResilience: item["dataResilience"], + failoverSpeed: item["failoverSpeed"], + limitations: !item["limitations"] + ? item["limitations"] + : item["limitations"].map((p: any) => { + return p; + }), + performance: item["performance"], + priority: item["priority"], + typeProperties: storageClassTypePropertiesUnionSerializer( + item["typeProperties"], + ), + }; +} + +export function storageClassPropertiesDeserializer( + item: any, +): StorageClassProperties { + return { + allowVolumeExpansion: item["allowVolumeExpansion"], + mountOptions: !item["mountOptions"] + ? item["mountOptions"] + : item["mountOptions"].map((p: any) => { + return p; + }), + provisioner: item["provisioner"], + volumeBindingMode: item["volumeBindingMode"], + accessModes: !item["accessModes"] + ? item["accessModes"] + : item["accessModes"].map((p: any) => { + return p; + }), + dataResilience: item["dataResilience"], + failoverSpeed: item["failoverSpeed"], + limitations: !item["limitations"] + ? item["limitations"] + : item["limitations"].map((p: any) => { + return p; + }), + performance: item["performance"], + priority: item["priority"], + typeProperties: storageClassTypePropertiesUnionDeserializer( + item["typeProperties"], + ), + provisioningState: item["provisioningState"], + }; +} + +/** Ability to expand volumes of a storage class */ +export enum KnownVolumeExpansion { + /** Allow volume expansion */ + Allow = "Allow", + /** Disallow volume expansion */ + Disallow = "Disallow", +} + +/** + * Ability to expand volumes of a storage class \ + * {@link KnownVolumeExpansion} can be used interchangeably with VolumeExpansion, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Allow**: Allow volume expansion \ + * **Disallow**: Disallow volume expansion + */ +export type VolumeExpansion = string; + +/** Storage class volume binding mode */ +export enum KnownVolumeBindingMode { + /** Immediate binding mode */ + Immediate = "Immediate", + /** Wait for first consumer binding mode */ + WaitForFirstConsumer = "WaitForFirstConsumer", +} + +/** + * Storage class volume binding mode \ + * {@link KnownVolumeBindingMode} can be used interchangeably with VolumeBindingMode, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Immediate**: Immediate binding mode \ + * **WaitForFirstConsumer**: Wait for first consumer binding mode + */ +export type VolumeBindingMode = string; + +/** Storage Class Access Mode */ +export enum KnownAccessMode { + /** Read Write Once (RWO) access mode */ + ReadWriteOnce = "ReadWriteOnce", + /** Read Write Many (RWX) access mode */ + ReadWriteMany = "ReadWriteMany", +} + +/** + * Storage Class Access Mode \ + * {@link KnownAccessMode} can be used interchangeably with AccessMode, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **ReadWriteOnce**: Read Write Once (RWO) access mode \ + * **ReadWriteMany**: Read Write Many (RWX) access mode + */ +export type AccessMode = string; + +/** Data resilience tier of a storage class */ +export enum KnownDataResilienceTier { + /** Not data resilient */ + NotDataResilient = "NotDataResilient", + /** Data resilient */ + DataResilient = "DataResilient", +} + +/** + * Data resilience tier of a storage class \ + * {@link KnownDataResilienceTier} can be used interchangeably with DataResilienceTier, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **NotDataResilient**: Not data resilient \ + * **DataResilient**: Data resilient + */ +export type DataResilienceTier = string; + +/** Failover tier of a storage class */ +export enum KnownFailoverTier { + /** Not available Failover Tier */ + NotAvailable = "NotAvailable", + /** Slow Failover Tier */ + Slow = "Slow", + /** Fast Failover Tier */ + Fast = "Fast", + /** Super Failover Tier */ + Super = "Super", +} + +/** + * Failover tier of a storage class \ + * {@link KnownFailoverTier} can be used interchangeably with FailoverTier, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **NotAvailable**: Not available Failover Tier \ + * **Slow**: Slow Failover Tier \ + * **Fast**: Fast Failover Tier \ + * **Super**: Super Failover Tier + */ +export type FailoverTier = string; + +/** Performance tier of a storage class */ +export enum KnownPerformanceTier { + /** Undefined Performance Tier */ + Undefined = "Undefined", + /** Basic Performance Tier */ + Basic = "Basic", + /** Standard Performance Tier */ + Standard = "Standard", + /** Premium Performance Tier */ + Premium = "Premium", + /** Ultra Performance Tier */ + Ultra = "Ultra", +} + +/** + * Performance tier of a storage class \ + * {@link KnownPerformanceTier} can be used interchangeably with PerformanceTier, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Undefined**: Undefined Performance Tier \ + * **Basic**: Basic Performance Tier \ + * **Standard**: Standard Performance Tier \ + * **Premium**: Premium Performance Tier \ + * **Ultra**: Ultra Performance Tier + */ +export type PerformanceTier = string; + +/** The properties of storage class of the StorageClass */ +export interface StorageClassTypeProperties { + /** Type of the storage class. */ + /** The discriminator possible values: Native, RWX, Blob, NFS, SMB */ + type: SCType; +} + +export function storageClassTypePropertiesSerializer( + item: StorageClassTypeProperties, +): any { + return { type: item["type"] }; +} + +export function storageClassTypePropertiesDeserializer( + item: any, +): StorageClassTypeProperties { + return { + type: item["type"], + }; +} + +/** Alias for StorageClassTypePropertiesUnion */ +export type StorageClassTypePropertiesUnion = + | NativeStorageClassTypeProperties + | RwxStorageClassTypeProperties + | BlobStorageClassTypeProperties + | NfsStorageClassTypeProperties + | SmbStorageClassTypeProperties + | StorageClassTypeProperties; + +export function storageClassTypePropertiesUnionSerializer( + item: StorageClassTypePropertiesUnion, +): any { + switch (item.type) { + case "Native": + return nativeStorageClassTypePropertiesSerializer( + item as NativeStorageClassTypeProperties, + ); + + case "RWX": + return rwxStorageClassTypePropertiesSerializer( + item as RwxStorageClassTypeProperties, + ); + + case "Blob": + return blobStorageClassTypePropertiesSerializer( + item as BlobStorageClassTypeProperties, + ); + + case "NFS": + return nfsStorageClassTypePropertiesSerializer( + item as NfsStorageClassTypeProperties, + ); + + case "SMB": + return smbStorageClassTypePropertiesSerializer( + item as SmbStorageClassTypeProperties, + ); + + default: + return storageClassTypePropertiesSerializer(item); + } +} + +export function storageClassTypePropertiesUnionDeserializer( + item: any, +): StorageClassTypePropertiesUnion { + switch (item.type) { + case "Native": + return nativeStorageClassTypePropertiesDeserializer( + item as NativeStorageClassTypeProperties, + ); + + case "RWX": + return rwxStorageClassTypePropertiesDeserializer( + item as RwxStorageClassTypeProperties, + ); + + case "Blob": + return blobStorageClassTypePropertiesDeserializer( + item as BlobStorageClassTypeProperties, + ); + + case "NFS": + return nfsStorageClassTypePropertiesDeserializer( + item as NfsStorageClassTypeProperties, + ); + + case "SMB": + return smbStorageClassTypePropertiesDeserializer( + item as SmbStorageClassTypeProperties, + ); + + default: + return storageClassTypePropertiesDeserializer(item); + } +} + +/** Type of a storage class */ +export enum KnownSCType { + /** Native storage class */ + Native = "Native", + /** RWX storage class */ + RWX = "RWX", + /** Blob storage class */ + Blob = "Blob", + /** NFS storage class */ + NFS = "NFS", + /** SMB storage class */ + SMB = "SMB", +} + +/** + * Type of a storage class \ + * {@link KnownSCType} can be used interchangeably with SCType, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Native**: Native storage class \ + * **RWX**: RWX storage class \ + * **Blob**: Blob storage class \ + * **NFS**: NFS storage class \ + * **SMB**: SMB storage class + */ +export type SCType = string; + +/** The properties of Native StorageClass */ +export interface NativeStorageClassTypeProperties + extends StorageClassTypeProperties { + /** Native StorageClass */ + type: "Native"; +} + +export function nativeStorageClassTypePropertiesSerializer( + item: NativeStorageClassTypeProperties, +): any { + return { type: item["type"] }; +} + +export function nativeStorageClassTypePropertiesDeserializer( + item: any, +): NativeStorageClassTypeProperties { + return { + type: item["type"], + }; +} + +/** The properties of RWX StorageClass */ +export interface RwxStorageClassTypeProperties + extends StorageClassTypeProperties { + /** RWX StorageClass */ + type: "RWX"; + /** The backing storageclass used to create new storageclass */ + backingStorageClassName: string; +} + +export function rwxStorageClassTypePropertiesSerializer( + item: RwxStorageClassTypeProperties, +): any { + return { + type: item["type"], + backingStorageClassName: item["backingStorageClassName"], + }; +} + +export function rwxStorageClassTypePropertiesDeserializer( + item: any, +): RwxStorageClassTypeProperties { + return { + type: item["type"], + backingStorageClassName: item["backingStorageClassName"], + }; +} + +/** The properties of Blob StorageClass */ +export interface BlobStorageClassTypeProperties + extends StorageClassTypeProperties { + /** Blob StorageClass */ + type: "Blob"; + /** Azure Storage Account Name */ + azureStorageAccountName: string; + /** Azure Storage Account Key */ + azureStorageAccountKey: string; +} + +export function blobStorageClassTypePropertiesSerializer( + item: BlobStorageClassTypeProperties, +): any { + return { + type: item["type"], + azureStorageAccountName: item["azureStorageAccountName"], + azureStorageAccountKey: item["azureStorageAccountKey"], + }; +} + +export function blobStorageClassTypePropertiesDeserializer( + item: any, +): BlobStorageClassTypeProperties { + return { + type: item["type"], + azureStorageAccountName: item["azureStorageAccountName"], + azureStorageAccountKey: item["azureStorageAccountKey"], + }; +} + +/** The properties of NFS StorageClass */ +export interface NfsStorageClassTypeProperties + extends StorageClassTypeProperties { + /** NFS StorageClass */ + type: "NFS"; + /** NFS Server */ + server: string; + /** NFS share */ + share: string; + /** Sub directory under share. If the sub directory doesn't exist, driver will create it */ + subDir?: string; + /** Mounted folder permissions. Default is 0. If set as non-zero, driver will perform `chmod` after mount */ + mountPermissions?: string; + /** The action to take when a NFS volume is deleted. Default is Delete */ + onDelete?: NfsDirectoryActionOnVolumeDeletion; +} + +export function nfsStorageClassTypePropertiesSerializer( + item: NfsStorageClassTypeProperties, +): any { + return { + type: item["type"], + server: item["server"], + share: item["share"], + subDir: item["subDir"], + mountPermissions: item["mountPermissions"], + onDelete: item["onDelete"], + }; +} + +export function nfsStorageClassTypePropertiesDeserializer( + item: any, +): NfsStorageClassTypeProperties { + return { + type: item["type"], + server: item["server"], + share: item["share"], + subDir: item["subDir"], + mountPermissions: item["mountPermissions"], + onDelete: item["onDelete"], + }; +} + +/** The action to take when a NFS volume is deleted */ +export enum KnownNfsDirectoryActionOnVolumeDeletion { + /** When the volume is deleted, delete the directory */ + Delete = "Delete", + /** When the volume is deleted, retain the directory */ + Retain = "Retain", +} + +/** + * The action to take when a NFS volume is deleted \ + * {@link KnownNfsDirectoryActionOnVolumeDeletion} can be used interchangeably with NfsDirectoryActionOnVolumeDeletion, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Delete**: When the volume is deleted, delete the directory \ + * **Retain**: When the volume is deleted, retain the directory + */ +export type NfsDirectoryActionOnVolumeDeletion = string; + +/** The properties of SMB StorageClass */ +export interface SmbStorageClassTypeProperties + extends StorageClassTypeProperties { + /** SMB StorageClass */ + type: "SMB"; + /** SMB Source */ + source: string; + /** Sub directory under share. If the sub directory doesn't exist, driver will create it */ + subDir?: string; + /** Server username */ + username?: string; + /** Server password */ + password?: string; + /** Server domain */ + domain?: string; +} + +export function smbStorageClassTypePropertiesSerializer( + item: SmbStorageClassTypeProperties, +): any { + return { + type: item["type"], + source: item["source"], + subDir: item["subDir"], + username: item["username"], + password: item["password"], + domain: item["domain"], + }; +} + +export function smbStorageClassTypePropertiesDeserializer( + item: any, +): SmbStorageClassTypeProperties { + return { + type: item["type"], + source: item["source"], + subDir: item["subDir"], + username: item["username"], + password: item["password"], + domain: item["domain"], + }; +} + +/** The model for updating a storageClass */ +export interface StorageClassResourceUpdate { + /** The properties of StorageClass */ + properties?: StorageClassPropertiesUpdate; +} + +export function storageClassResourceUpdateSerializer( + item: StorageClassResourceUpdate, +): any { + return { + properties: !item["properties"] + ? item["properties"] + : storageClassPropertiesUpdateSerializer(item["properties"]), + }; +} + +/** The model for updating storageClass properties */ +export interface StorageClassPropertiesUpdate { + /** Volume can be expanded or not */ + allowVolumeExpansion?: VolumeExpansion; + /** Additional mount options */ + mountOptions?: string[]; + /** The access mode: [ReadWriteOnce, ReadWriteMany] or [ReadWriteOnce] */ + accessModes?: AccessMode[]; + /** Allow single data node failure */ + dataResilience?: DataResilienceTier; + /** Failover speed: NA, Slow, Fast */ + failoverSpeed?: FailoverTier; + /** Limitations of the storage class */ + limitations?: string[]; + /** Performance tier */ + performance?: PerformanceTier; + /** Selection priority when multiple storage classes meet the criteria. 0: Highest, -1: Never use */ + priority?: number; + /** New storage class type of storageClass */ + typeProperties?: StorageClassTypePropertiesUpdate; +} + +export function storageClassPropertiesUpdateSerializer( + item: StorageClassPropertiesUpdate, +): any { + return { + allowVolumeExpansion: item["allowVolumeExpansion"], + mountOptions: !item["mountOptions"] + ? item["mountOptions"] + : item["mountOptions"].map((p: any) => { + return p; + }), + accessModes: !item["accessModes"] + ? item["accessModes"] + : item["accessModes"].map((p: any) => { + return p; + }), + dataResilience: item["dataResilience"], + failoverSpeed: item["failoverSpeed"], + limitations: !item["limitations"] + ? item["limitations"] + : item["limitations"].map((p: any) => { + return p; + }), + performance: item["performance"], + priority: item["priority"], + typeProperties: !item["typeProperties"] + ? item["typeProperties"] + : storageClassTypePropertiesUpdateSerializer(item["typeProperties"]), + }; +} + +/** The model for update a storageClass */ +export interface StorageClassTypePropertiesUpdate { + /** The backing storageclass used to create new storageclass */ + backingStorageClassName?: string; + /** Azure Storage Account Name */ + azureStorageAccountName?: string; + /** Azure Storage Account Key */ + azureStorageAccountKey?: string; + /** NFS Server */ + server?: string; + /** NFS share */ + share?: string; + /** Sub directory under share. If the sub directory doesn't exist, driver will create it */ + subDir?: string; + /** Mounted folder permissions. Default is 0. If set as non-zero, driver will perform `chmod` after mount */ + mountPermissions?: string; + /** The action to take when a NFS volume is deleted. Default is Delete */ + onDelete?: NfsDirectoryActionOnVolumeDeletion; + /** SMB Source */ + source?: string; + /** Server username */ + username?: string; + /** Server password */ + password?: string; + /** Server domain */ + domain?: string; +} + +export function storageClassTypePropertiesUpdateSerializer( + item: StorageClassTypePropertiesUpdate, +): any { + return { + backingStorageClassName: item["backingStorageClassName"], + azureStorageAccountName: item["azureStorageAccountName"], + azureStorageAccountKey: item["azureStorageAccountKey"], + server: item["server"], + share: item["share"], + subDir: item["subDir"], + mountPermissions: item["mountPermissions"], + onDelete: item["onDelete"], + source: item["source"], + username: item["username"], + password: item["password"], + domain: item["domain"], + }; +} + +/** The response of a StorageClassResource list operation. */ +export interface _StorageClassResourceListResult { + /** The StorageClassResource items on this page */ + value: StorageClassResource[]; + /** The link to the next page of items */ + nextLink?: string; +} + +export function _storageClassResourceListResultDeserializer( + item: any, +): _StorageClassResourceListResult { + return { + value: storageClassResourceArrayDeserializer(item["value"]), + nextLink: item["nextLink"], + }; +} + +export function storageClassResourceArraySerializer( + result: Array, +): any[] { + return result.map((item) => { + return storageClassResourceSerializer(item); + }); +} + +export function storageClassResourceArrayDeserializer( + result: Array, +): any[] { + return result.map((item) => { + return storageClassResourceDeserializer(item); + }); +} + +/** Versions of KubernetesRuntime service */ +export enum KnownVersions { + /** 2024-03-01, added bgpPeers field in LoadBalancer */ + v2024_03_01 = "2024-03-01", +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/restorePollerHelpers.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/restorePollerHelpers.ts new file mode 100644 index 000000000000..999500aa5ee2 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/restorePollerHelpers.ts @@ -0,0 +1,192 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "./kubernetesRuntimeClient.js"; +import { _bgpPeersCreateOrUpdateDeserialize } from "./api/bgpPeers/index.js"; +import { _loadBalancersCreateOrUpdateDeserialize } from "./api/loadBalancers/index.js"; +import { + _storageClassDeleteDeserialize, + _storageClassUpdateDeserialize, + _storageClassCreateOrUpdateDeserialize, +} from "./api/storageClass/index.js"; +import { getLongRunningPoller } from "./static-helpers/pollingHelpers.js"; +import { + OperationOptions, + PathUncheckedResponse, +} from "@azure-rest/core-client"; +import { AbortSignalLike } from "@azure/abort-controller"; +import { + PollerLike, + OperationState, + deserializeState, + ResourceLocationConfig, +} from "@azure/core-lro"; + +export interface RestorePollerOptions< + TResult, + TResponse extends PathUncheckedResponse = PathUncheckedResponse, +> extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; + /** + * The signal which can be used to abort requests. + */ + abortSignal?: AbortSignalLike; + /** Deserialization function for raw response body */ + processResponseBody?: (result: TResponse) => Promise; +} + +/** + * Creates a poller from the serialized state of another poller. This can be + * useful when you want to create pollers on a different host or a poller + * needs to be constructed after the original one is not in scope. + */ +export function restorePoller( + client: KubernetesRuntimeClient, + serializedState: string, + sourceOperation: ( + ...args: any[] + ) => PollerLike, TResult>, + options?: RestorePollerOptions, +): PollerLike, TResult> { + const pollerConfig = deserializeState(serializedState).config; + const { initialRequestUrl, requestMethod, metadata } = pollerConfig; + if (!initialRequestUrl || !requestMethod) { + throw new Error( + `Invalid serialized state: ${serializedState} for sourceOperation ${sourceOperation?.name}`, + ); + } + const resourceLocationConfig = metadata?.["resourceLocationConfig"] as + | ResourceLocationConfig + | undefined; + const { deserializer, expectedStatuses = [] } = + getDeserializationHelper(initialRequestUrl, requestMethod) ?? {}; + const deserializeHelper = options?.processResponseBody ?? deserializer; + if (!deserializeHelper) { + throw new Error( + `Please ensure the operation is in this client! We can't find its deserializeHelper for ${sourceOperation?.name}.`, + ); + } + return getLongRunningPoller( + (client as any)["_client"] ?? client, + deserializeHelper as (result: TResponse) => Promise, + expectedStatuses, + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + resourceLocationConfig, + restoreFrom: serializedState, + initialRequestUrl, + }, + ); +} + +interface DeserializationHelper { + deserializer: Function; + expectedStatuses: string[]; +} + +const deserializeMap: Record = { + "PUT /{resourceUri}/providers/Microsoft.KubernetesRuntime/bgpPeers/{bgpPeerName}": + { + deserializer: _bgpPeersCreateOrUpdateDeserialize, + expectedStatuses: ["200", "201"], + }, + "PUT /{resourceUri}/providers/Microsoft.KubernetesRuntime/loadBalancers/{loadBalancerName}": + { + deserializer: _loadBalancersCreateOrUpdateDeserialize, + expectedStatuses: ["200", "201"], + }, + "DELETE /{resourceUri}/providers/Microsoft.KubernetesRuntime/storageClasses/{storageClassName}": + { + deserializer: _storageClassDeleteDeserialize, + expectedStatuses: ["202", "204", "200"], + }, + "PATCH /{resourceUri}/providers/Microsoft.KubernetesRuntime/storageClasses/{storageClassName}": + { + deserializer: _storageClassUpdateDeserialize, + expectedStatuses: ["200", "202"], + }, + "PUT /{resourceUri}/providers/Microsoft.KubernetesRuntime/storageClasses/{storageClassName}": + { + deserializer: _storageClassCreateOrUpdateDeserialize, + expectedStatuses: ["200", "201"], + }, +}; + +function getDeserializationHelper( + urlStr: string, + method: string, +): DeserializationHelper | undefined { + const path = new URL(urlStr).pathname; + const pathParts = path.split("/"); + + // Traverse list to match the longest candidate + // matchedLen: the length of candidate path + // matchedValue: the matched status code array + let matchedLen = -1, + matchedValue: DeserializationHelper | undefined; + + // Iterate the responseMap to find a match + for (const [key, value] of Object.entries(deserializeMap)) { + // Extracting the path from the map key which is in format + // GET /path/foo + if (!key.startsWith(method)) { + continue; + } + const candidatePath = getPathFromMapKey(key); + // Get each part of the url path + const candidateParts = candidatePath.split("/"); + + // track if we have found a match to return the values found. + let found = true; + for ( + let i = candidateParts.length - 1, j = pathParts.length - 1; + i >= 1 && j >= 1; + i--, j-- + ) { + if ( + candidateParts[i]?.startsWith("{") && + candidateParts[i]?.indexOf("}") !== -1 + ) { + const start = candidateParts[i]!.indexOf("}") + 1, + end = candidateParts[i]?.length; + // If the current part of the candidate is a "template" part + // Try to use the suffix of pattern to match the path + // {guid} ==> $ + // {guid}:export ==> :export$ + const isMatched = new RegExp( + `${candidateParts[i]?.slice(start, end)}`, + ).test(pathParts[j] || ""); + + if (!isMatched) { + found = false; + break; + } + continue; + } + + // If the candidate part is not a template and + // the parts don't match mark the candidate as not found + // to move on with the next candidate path. + if (candidateParts[i] !== pathParts[j]) { + found = false; + break; + } + } + + // We finished evaluating the current candidate parts + // Update the matched value if and only if we found the longer pattern + if (found && candidatePath.length > matchedLen) { + matchedLen = candidatePath.length; + matchedValue = value; + } + } + + return matchedValue; +} + +function getPathFromMapKey(mapKey: string): string { + const pathStart = mapKey.indexOf("/"); + return mapKey.slice(pathStart); +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/static-helpers/pagingHelpers.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/static-helpers/pagingHelpers.ts new file mode 100644 index 000000000000..97a81e74e301 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/static-helpers/pagingHelpers.ts @@ -0,0 +1,274 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + Client, + createRestError, + PathUncheckedResponse, +} from "@azure-rest/core-client"; +import { RestError } from "@azure/core-rest-pipeline"; + +/** + * Options for the byPage method + */ +export interface PageSettings { + /** + * A reference to a specific page to start iterating from. + */ + continuationToken?: string; +} + +/** + * An interface that describes a page of results. + */ +export type ContinuablePage = TPage & { + /** + * The token that keeps track of where to continue the iterator + */ + continuationToken?: string; +}; + +/** + * An interface that allows async iterable iteration both to completion and by page. + */ +export interface PagedAsyncIterableIterator< + TElement, + TPage = TElement[], + TPageSettings extends PageSettings = PageSettings, +> { + /** + * The next method, part of the iteration protocol + */ + next(): Promise>; + /** + * The connection to the async iterator, part of the iteration protocol + */ + [Symbol.asyncIterator](): PagedAsyncIterableIterator< + TElement, + TPage, + TPageSettings + >; + /** + * Return an AsyncIterableIterator that works a page at a time + */ + byPage: ( + settings?: TPageSettings, + ) => AsyncIterableIterator>; +} + +/** + * An interface that describes how to communicate with the service. + */ +export interface PagedResult< + TElement, + TPage = TElement[], + TPageSettings extends PageSettings = PageSettings, +> { + /** + * Link to the first page of results. + */ + firstPageLink?: string; + /** + * A method that returns a page of results. + */ + getPage: ( + pageLink?: string, + ) => Promise<{ page: TPage; nextPageLink?: string } | undefined>; + /** + * a function to implement the `byPage` method on the paged async iterator. + */ + byPage?: ( + settings?: TPageSettings, + ) => AsyncIterableIterator>; + + /** + * A function to extract elements from a page. + */ + toElements?: (page: TPage) => TElement[]; +} + +/** + * Options for the paging helper + */ +export interface BuildPagedAsyncIteratorOptions { + itemName?: string; + nextLinkName?: string; +} + +/** + * Helper to paginate results in a generic way and return a PagedAsyncIterableIterator + */ +export function buildPagedAsyncIterator< + TElement, + TPage = TElement[], + TPageSettings extends PageSettings = PageSettings, + TResponse extends PathUncheckedResponse = PathUncheckedResponse, +>( + client: Client, + getInitialResponse: () => PromiseLike, + processResponseBody: (result: TResponse) => PromiseLike, + expectedStatuses: string[], + options: BuildPagedAsyncIteratorOptions = {}, +): PagedAsyncIterableIterator { + const itemName = options.itemName ?? "value"; + const nextLinkName = options.nextLinkName ?? "nextLink"; + const pagedResult: PagedResult = { + getPage: async (pageLink?: string) => { + const result = + pageLink === undefined + ? await getInitialResponse() + : await client.pathUnchecked(pageLink).get(); + checkPagingRequest(result, expectedStatuses); + const results = await processResponseBody(result as TResponse); + const nextLink = getNextLink(results, nextLinkName); + const values = getElements(results, itemName) as TPage; + return { + page: values, + nextPageLink: nextLink, + }; + }, + byPage: (settings?: TPageSettings) => { + const { continuationToken } = settings ?? {}; + return getPageAsyncIterator(pagedResult, { + pageLink: continuationToken, + }); + }, + }; + return getPagedAsyncIterator(pagedResult); +} + +/** + * returns an async iterator that iterates over results. It also has a `byPage` + * method that returns pages of items at once. + * + * @param pagedResult - an object that specifies how to get pages. + * @returns a paged async iterator that iterates over results. + */ + +function getPagedAsyncIterator< + TElement, + TPage = TElement[], + TPageSettings extends PageSettings = PageSettings, +>( + pagedResult: PagedResult, +): PagedAsyncIterableIterator { + const iter = getItemAsyncIterator( + pagedResult, + ); + return { + next() { + return iter.next(); + }, + [Symbol.asyncIterator]() { + return this; + }, + byPage: + pagedResult?.byPage ?? + ((settings?: TPageSettings) => { + const { continuationToken } = settings ?? {}; + return getPageAsyncIterator(pagedResult, { + pageLink: continuationToken, + }); + }), + }; +} + +async function* getItemAsyncIterator< + TElement, + TPage, + TPageSettings extends PageSettings, +>( + pagedResult: PagedResult, +): AsyncIterableIterator { + const pages = getPageAsyncIterator(pagedResult); + for await (const page of pages) { + yield* page as unknown as TElement[]; + } +} + +async function* getPageAsyncIterator< + TElement, + TPage, + TPageSettings extends PageSettings, +>( + pagedResult: PagedResult, + options: { + pageLink?: string; + } = {}, +): AsyncIterableIterator> { + const { pageLink } = options; + let response = await pagedResult.getPage( + pageLink ?? pagedResult.firstPageLink, + ); + if (!response) { + return; + } + let result = response.page as ContinuablePage; + result.continuationToken = response.nextPageLink; + yield result; + while (response.nextPageLink) { + response = await pagedResult.getPage(response.nextPageLink); + if (!response) { + return; + } + result = response.page as ContinuablePage; + result.continuationToken = response.nextPageLink; + yield result; + } +} + +/** + * Gets for the value of nextLink in the body + */ +function getNextLink(body: unknown, nextLinkName?: string): string | undefined { + if (!nextLinkName) { + return undefined; + } + + const nextLink = (body as Record)[nextLinkName]; + + if ( + typeof nextLink !== "string" && + typeof nextLink !== "undefined" && + nextLink !== null + ) { + throw new RestError( + `Body Property ${nextLinkName} should be a string or undefined or null but got ${typeof nextLink}`, + ); + } + + if (nextLink === null) { + return undefined; + } + + return nextLink; +} + +/** + * Gets the elements of the current request in the body. + */ +function getElements(body: unknown, itemName: string): T[] { + const value = (body as Record)[itemName] as T[]; + if (!Array.isArray(value)) { + throw new RestError( + `Couldn't paginate response\n Body doesn't contain an array property with name: ${itemName}`, + ); + } + + return value ?? []; +} + +/** + * Checks if a request failed + */ +function checkPagingRequest( + response: PathUncheckedResponse, + expectedStatuses: string[], +): void { + if (!expectedStatuses.includes(response.status)) { + throw createRestError( + `Pagination failed with unexpected statusCode ${response.status}`, + response, + ); + } +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/src/static-helpers/pollingHelpers.ts b/kubernetesruntime/arm-containerorchestratorruntime/src/static-helpers/pollingHelpers.ts new file mode 100644 index 000000000000..2edbf783be53 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/src/static-helpers/pollingHelpers.ts @@ -0,0 +1,137 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + PollerLike, + OperationState, + ResourceLocationConfig, + RunningOperation, + createHttpPoller, + OperationResponse, +} from "@azure/core-lro"; + +import { + Client, + PathUncheckedResponse, + createRestError, +} from "@azure-rest/core-client"; +import { AbortSignalLike } from "@azure/abort-controller"; + +export interface GetLongRunningPollerOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; + /** + * The signal which can be used to abort requests. + */ + abortSignal?: AbortSignalLike; + /** + * The potential location of the result of the LRO if specified by the LRO extension in the swagger. + */ + resourceLocationConfig?: ResourceLocationConfig; + /** + * The original url of the LRO + * Should not be null when restoreFrom is set + */ + initialRequestUrl?: string; + /** + * A serialized poller which can be used to resume an existing paused Long-Running-Operation. + */ + restoreFrom?: string; + /** + * The function to get the initial response + */ + getInitialResponse?: () => PromiseLike; +} +export function getLongRunningPoller< + TResponse extends PathUncheckedResponse, + TResult = void, +>( + client: Client, + processResponseBody: (result: TResponse) => Promise, + expectedStatuses: string[], + options: GetLongRunningPollerOptions, +): PollerLike, TResult> { + const { restoreFrom, getInitialResponse } = options; + if (!restoreFrom && !getInitialResponse) { + throw new Error( + "Either restoreFrom or getInitialResponse must be specified", + ); + } + let initialResponse: TResponse | undefined = undefined; + const pollAbortController = new AbortController(); + const poller: RunningOperation = { + sendInitialRequest: async () => { + if (!getInitialResponse) { + throw new Error( + "getInitialResponse is required when initializing a new poller", + ); + } + initialResponse = await getInitialResponse(); + return getLroResponse(initialResponse, expectedStatuses); + }, + sendPollRequest: async ( + path: string, + pollOptions?: { + abortSignal?: AbortSignalLike; + }, + ) => { + // The poll request would both listen to the user provided abort signal and the poller's own abort signal + function abortListener(): void { + pollAbortController.abort(); + } + const abortSignal = pollAbortController.signal; + if (options.abortSignal?.aborted) { + pollAbortController.abort(); + } else if (pollOptions?.abortSignal?.aborted) { + pollAbortController.abort(); + } else if (!abortSignal.aborted) { + options.abortSignal?.addEventListener("abort", abortListener, { + once: true, + }); + pollOptions?.abortSignal?.addEventListener("abort", abortListener, { + once: true, + }); + } + let response; + try { + response = await client.pathUnchecked(path).get({ abortSignal }); + } finally { + options.abortSignal?.removeEventListener("abort", abortListener); + pollOptions?.abortSignal?.removeEventListener("abort", abortListener); + } + + return getLroResponse(response as TResponse, expectedStatuses); + }, + }; + return createHttpPoller(poller, { + intervalInMs: options?.updateIntervalInMs, + resourceLocationConfig: options?.resourceLocationConfig, + restoreFrom: options?.restoreFrom, + processResult: (result: unknown) => { + return processResponseBody(result as TResponse); + }, + }); +} +/** + * Converts a Rest Client response to a response that the LRO implementation understands + * @param response - a rest client http response + * @param deserializeFn - deserialize function to convert Rest response to modular output + * @returns - An LRO response that the LRO implementation understands + */ +function getLroResponse( + response: TResponse, + expectedStatuses: string[], +): OperationResponse { + if (!expectedStatuses.includes(response.status)) { + throw createRestError(response); + } + + return { + flatResponse: response, + rawResponse: { + ...response, + statusCode: Number.parseInt(response.status), + body: response.body, + }, + }; +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/test/public/sampleTest.spec.ts b/kubernetesruntime/arm-containerorchestratorruntime/test/public/sampleTest.spec.ts new file mode 100644 index 000000000000..d4919ac91ac5 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/test/public/sampleTest.spec.ts @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { createRecorder } from "./utils/recordedClient.js"; +import { assert, beforeEach, afterEach, it, describe } from "vitest"; + +describe("My test", () => { + // let recorder: Recorder; + + beforeEach(async function () { + // recorder = await createRecorder(this); + }); + + afterEach(async function () { + // await recorder.stop(); + }); + + it("sample test", async function () { + assert.equal(1, 1); + }); +}); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/test/public/utils/recordedClient.ts b/kubernetesruntime/arm-containerorchestratorruntime/test/public/utils/recordedClient.ts new file mode 100644 index 000000000000..6e425fdcfdf9 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/test/public/utils/recordedClient.ts @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + Recorder, + RecorderStartOptions, + VitestTestContext, +} from "@azure-tools/test-recorder"; + +const replaceableVariables: Record = { + SUBSCRIPTION_ID: "azure_subscription_id", +}; + +const recorderEnvSetup: RecorderStartOptions = { + envSetupForPlayback: replaceableVariables, +}; + +/** + * creates the recorder and reads the environment variables from the `.env` file. + * Should be called first in the test suite to make sure environment variables are + * read before they are being used. + */ +export async function createRecorder( + context: VitestTestContext, +): Promise { + const recorder = new Recorder(context); + await recorder.start(recorderEnvSetup); + return recorder; +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/test/snippets.spec.ts b/kubernetesruntime/arm-containerorchestratorruntime/test/snippets.spec.ts new file mode 100644 index 000000000000..5d362c7cd0c2 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/test/snippets.spec.ts @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { KubernetesRuntimeClient } from "../src/index.js"; +import { + DefaultAzureCredential, + InteractiveBrowserCredential, +} from "@azure/identity"; +import { setLogLevel } from "@azure/logger"; +import { describe, it } from "vitest"; + +describe("snippets", () => { + it("ReadmeSampleCreateClient_Node", async () => { + const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const client = new KubernetesRuntimeClient( + new DefaultAzureCredential(), + subscriptionId, + ); + }); + + it("ReadmeSampleCreateClient_Browser", async () => { + const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const credential = new InteractiveBrowserCredential({ + tenantId: "", + clientId: "", + }); + const client = new KubernetesRuntimeClient(credential, subscriptionId); + }); + + it("SetLogLevel", async () => { + setLogLevel("info"); + }); +}); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/tsconfig.browser.config.json b/kubernetesruntime/arm-containerorchestratorruntime/tsconfig.browser.config.json new file mode 100644 index 000000000000..091177fcb991 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/tsconfig.browser.config.json @@ -0,0 +1,10 @@ +{ + "extends": "./.tshy/build.json", + "include": ["src/**/*.ts", "src/**/*.mts", "test/**/*.spec.ts"], + "exclude": ["test/**/node/**/*.ts"], + "compilerOptions": { + "outDir": "./dist-test/browser", + "rootDir": ".", + "skipLibCheck": true + } +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/tsconfig.json b/kubernetesruntime/arm-containerorchestratorruntime/tsconfig.json new file mode 100644 index 000000000000..8ff7ff4ac6e1 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "../../../tsconfig", + "compilerOptions": { + "module": "NodeNext", + "moduleResolution": "NodeNext", + "rootDir": ".", + "skipLibCheck": true, + "paths": { "@azure/arm-containerorchestratorruntime": ["./src/index"] } + }, + "include": [ + "src/**/*.ts", + "src/**/*.mts", + "src/**/*.cts", + "test/**/*.ts", + "test/**/*.ts", + "samples-dev/**/*.ts" + ] +} diff --git a/kubernetesruntime/arm-containerorchestratorruntime/tsp-location.yaml b/kubernetesruntime/arm-containerorchestratorruntime/tsp-location.yaml new file mode 100644 index 000000000000..948dbabd8639 --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/tsp-location.yaml @@ -0,0 +1,4 @@ +directory: specification/kubernetesruntime/KubernetesRuntime.Management +commit: c0d702050e711d4c52d5fe6744191c5c6ca1df4c +repo: ../azure-rest-api-specs +additionalDirectories: diff --git a/kubernetesruntime/arm-containerorchestratorruntime/vitest.browser.config.ts b/kubernetesruntime/arm-containerorchestratorruntime/vitest.browser.config.ts new file mode 100644 index 000000000000..da68c1d231aa --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/vitest.browser.config.ts @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { defineConfig } from "vitest/config"; +import { relativeRecordingsPath } from "@azure-tools/test-recorder"; + +process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath(); + +export default defineConfig({ + define: { + "process.env": process.env, + }, + test: { + reporters: ["basic", "junit"], + outputFile: { + junit: "test-results.browser.xml", + }, + browser: { + enabled: true, + headless: true, + name: "chromium", + provider: "playwright", + }, + fakeTimers: { + toFake: ["setTimeout", "Date"], + }, + watch: false, + include: ["dist-test/browser/**/*.spec.js"], + coverage: { + include: ["dist-test/browser/**/*.spec.js"], + provider: "istanbul", + reporter: ["text", "json", "html"], + reportsDirectory: "coverage-browser", + }, + testTimeout: 1200000, + hookTimeout: 1200000, + }, +}); diff --git a/kubernetesruntime/arm-containerorchestratorruntime/vitest.config.ts b/kubernetesruntime/arm-containerorchestratorruntime/vitest.config.ts new file mode 100644 index 000000000000..2cf5d0e02c2e --- /dev/null +++ b/kubernetesruntime/arm-containerorchestratorruntime/vitest.config.ts @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { defineConfig } from "vitest/config"; +import { relativeRecordingsPath } from "@azure-tools/test-recorder"; + +export default defineConfig({ + test: { + reporters: ["basic", "junit"], + outputFile: { + junit: "test-results.browser.xml", + }, + fakeTimers: { + toFake: ["setTimeout", "Date"], + }, + watch: false, + include: ["test/**/*.spec.ts"], + exclude: ["test/**/browser/*.spec.ts"], + coverage: { + include: ["src/**/*.ts"], + exclude: [ + "src/**/*-browser.mts", + "src/**/*-react-native.mts", + "vitest*.config.ts", + "samples-dev/**/*.ts", + ], + provider: "istanbul", + reporter: ["text", "json", "html"], + reportsDirectory: "coverage", + }, + testTimeout: 1200000, + hookTimeout: 1200000, + }, +});