From bc217d490e2bef515942ae7236b19f5e1ae51f04 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Mon, 28 Oct 2024 10:43:06 +0000 Subject: [PATCH] CodeGen from PR 31198 in Azure/azure-rest-api-specs Merge 0756ab6749f87d935a6a0c497523fa021a4a55e3 into 697d0fcc7cb65998b2dc60860fb6e0499831a324 --- eng/versioning/version_client.txt | 1 + pom.xml | 1 + .../CHANGELOG.md | 8 + .../azure-resourcemanager-terraform/README.md | 104 ++++++ .../azure-resourcemanager-terraform/SAMPLE.md | 60 ++++ .../azure-resourcemanager-terraform/pom.xml | 63 ++++ .../terraform/AzureTerraformManager.java | 291 +++++++++++++++++ .../AzureTerraformManagementClient.java | 62 ++++ .../terraform/fluent/OperationsClient.java | 40 +++ .../terraform/fluent/TerraformsClient.java | 65 ++++ .../fluent/models/OperationInner.java | 172 ++++++++++ .../terraform/fluent/models/package-info.java | 9 + .../terraform/fluent/package-info.java | 9 + ...AzureTerraformManagementClientBuilder.java | 138 ++++++++ .../AzureTerraformManagementClientImpl.java | 304 ++++++++++++++++++ .../implementation/OperationImpl.java | 51 +++ .../implementation/OperationsClientImpl.java | 235 ++++++++++++++ .../implementation/OperationsImpl.java | 45 +++ .../implementation/ResourceManagerUtils.java | 195 +++++++++++ .../implementation/TerraformsClientImpl.java | 255 +++++++++++++++ .../implementation/TerraformsImpl.java | 41 +++ .../implementation/package-info.java | 9 + .../terraform/models/ActionType.java | 46 +++ .../terraform/models/BaseExportModel.java | 199 ++++++++++++ .../terraform/models/ExportQuery.java | 214 ++++++++++++ .../terraform/models/ExportResource.java | 241 ++++++++++++++ .../terraform/models/ExportResourceGroup.java | 184 +++++++++++ .../terraform/models/Operation.java | 58 ++++ .../terraform/models/OperationDisplay.java | 136 ++++++++ .../terraform/models/OperationListResult.java | 104 ++++++ .../terraform/models/Operations.java | 35 ++ .../terraform/models/Origin.java | 57 ++++ .../terraform/models/TargetProvider.java | 51 +++ .../terraform/models/Terraforms.java | 33 ++ .../terraform/models/Type.java | 56 ++++ .../terraform/models/package-info.java | 9 + .../terraform/package-info.java | 9 + .../src/main/java/module-info.java | 15 + .../proxy-config.json | 1 + .../reflect-config.json | 1 + .../generated/OperationsListSamples.java | 25 ++ .../TerraformExportTerraformSamples.java | 27 ++ sdk/terraform/ci.yml | 46 +++ sdk/terraform/pom.xml | 15 + 44 files changed, 3720 insertions(+) create mode 100644 sdk/terraform/azure-resourcemanager-terraform/CHANGELOG.md create mode 100644 sdk/terraform/azure-resourcemanager-terraform/README.md create mode 100644 sdk/terraform/azure-resourcemanager-terraform/SAMPLE.md create mode 100644 sdk/terraform/azure-resourcemanager-terraform/pom.xml create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/AzureTerraformManager.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/AzureTerraformManagementClient.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/OperationsClient.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/TerraformsClient.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/models/OperationInner.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/models/package-info.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/package-info.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/AzureTerraformManagementClientBuilder.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/AzureTerraformManagementClientImpl.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/OperationImpl.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/OperationsClientImpl.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/OperationsImpl.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/ResourceManagerUtils.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/TerraformsClientImpl.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/TerraformsImpl.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/package-info.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ActionType.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/BaseExportModel.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ExportQuery.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ExportResource.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ExportResourceGroup.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Operation.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/OperationDisplay.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/OperationListResult.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Operations.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Origin.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/TargetProvider.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Terraforms.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Type.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/package-info.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/package-info.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/java/module-info.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-terraform/proxy-config.json create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-terraform/reflect-config.json create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/samples/java/com/azure/resourcemanager/terraform/generated/OperationsListSamples.java create mode 100644 sdk/terraform/azure-resourcemanager-terraform/src/samples/java/com/azure/resourcemanager/terraform/generated/TerraformExportTerraformSamples.java create mode 100644 sdk/terraform/ci.yml create mode 100644 sdk/terraform/pom.xml diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index 5840de5bf47d..73392975485e 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -476,6 +476,7 @@ com.azure.resourcemanager:azure-resourcemanager-computeschedule;1.0.0-beta.1;1.0 com.azure.resourcemanager:azure-resourcemanager-trustedsigning;1.0.0-beta.1;1.0.0-beta.2 com.azure.resourcemanager:azure-resourcemanager-iotoperations;1.0.0-beta.1;1.0.0-beta.2 com.azure.resourcemanager:azure-resourcemanager-containerorchestratorruntime;1.0.0-beta.1;1.0.0-beta.2 +com.azure.resourcemanager:azure-resourcemanager-terraform;1.0.0-beta.1;1.0.0-beta.1 com.azure.tools:azure-sdk-archetype;1.0.0;1.2.0-beta.1 com.azure.tools:azure-sdk-build-tool;1.0.0;1.1.0-beta.1 io.clientcore:clientcore-parent;1.0.0-beta.1;1.0.0-beta.1 diff --git a/pom.xml b/pom.xml index 866c8c788a53..9d0b20c2a60e 100644 --- a/pom.xml +++ b/pom.xml @@ -220,6 +220,7 @@ sdk/synapse sdk/tables sdk/template + sdk/terraform sdk/textanalytics sdk/timeseriesinsights sdk/tools diff --git a/sdk/terraform/azure-resourcemanager-terraform/CHANGELOG.md b/sdk/terraform/azure-resourcemanager-terraform/CHANGELOG.md new file mode 100644 index 000000000000..748ecc3d757a --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/CHANGELOG.md @@ -0,0 +1,8 @@ +# Release History + +## 1.0.0-beta.1 (2024-10-28) + +- Azure Resource Manager AzureTerraform client library for Java. This package contains Microsoft Azure SDK for AzureTerraform Management SDK. AzureTerraform Client. Package tag package-2023-07-01-preview. For documentation on how to use this package, please see [Azure Management Libraries for Java](https://aka.ms/azsdk/java/mgmt). +### Features Added + +- Initial release for the azure-resourcemanager-terraform Java SDK. diff --git a/sdk/terraform/azure-resourcemanager-terraform/README.md b/sdk/terraform/azure-resourcemanager-terraform/README.md new file mode 100644 index 000000000000..201791a46b94 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/README.md @@ -0,0 +1,104 @@ +# Azure Resource Manager AzureTerraform client library for Java + +Azure Resource Manager AzureTerraform client library for Java. + +This package contains Microsoft Azure SDK for AzureTerraform Management SDK. AzureTerraform Client. Package tag package-2023-07-01-preview. For documentation on how to use this package, please see [Azure Management Libraries for Java](https://aka.ms/azsdk/java/mgmt). + +## We'd love to hear your feedback + +We're always working on improving our products and the way we communicate with our users. So we'd love to learn what's working and how we can do better. + +If you haven't already, please take a few minutes to [complete this short survey][survey] we have put together. + +Thank you in advance for your collaboration. We really appreciate your time! + +## Documentation + +Various documentation is available to help you get started + +- [API reference documentation][docs] + +## Getting started + +### Prerequisites + +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] + +### Adding the package to your product + +[//]: # ({x-version-update-start;com.azure.resourcemanager:azure-resourcemanager-terraform;current}) +```xml + + com.azure.resourcemanager + azure-resourcemanager-terraform + 1.0.0-beta.1 + +``` +[//]: # ({x-version-update-end}) + +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] and [Azure Core Netty HTTP][azure_core_http_netty] packages provide the default implementation. + +### Authentication + +Microsoft Entra ID token authentication relies on the [credential class][azure_identity_credentials] from [Azure Identity][azure_identity] package. + +Azure subscription ID can be configured via `AZURE_SUBSCRIPTION_ID` environment variable. + +Assuming the use of the `DefaultAzureCredential` credential class, the client can be authenticated using the following code: + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +AzureTerraformManager manager = AzureTerraformManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + +## Key concepts + +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + +## Examples + +[Code snippets and samples](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/terraform/azure-resourcemanager-terraform/SAMPLE.md) + + +## Troubleshooting + +## Next steps + +## Contributing + +For details on contributing to this repository, see the [contributing guide][cg]. + +This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit . + +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repositories using our CLA. + +This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For more information see the [Code of Conduct FAQ][coc_faq] or contact with any additional questions or comments. + + +[survey]: https://microsoft.qualtrics.com/jfe/form/SV_ehN0lIk2FKEBkwd?Q_CHL=DOCS +[docs]: https://azure.github.io/azure-sdk-for-java/ +[jdk]: https://learn.microsoft.com/azure/developer/java/fundamentals/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity +[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/identity/azure-identity#credentials +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/docs/AUTH.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/docs/DESIGN.md +[cg]: https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md +[coc]: https://opensource.microsoft.com/codeofconduct/ +[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ + +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fterraform%2Fazure-resourcemanager-terraform%2FREADME.png) diff --git a/sdk/terraform/azure-resourcemanager-terraform/SAMPLE.md b/sdk/terraform/azure-resourcemanager-terraform/SAMPLE.md new file mode 100644 index 000000000000..226ac954650a --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/SAMPLE.md @@ -0,0 +1,60 @@ +# Code snippets and samples + + +## Operations + +- [List](#operations_list) + +## Terraform + +- [ExportTerraform](#terraform_exportterraform) +### Operations_List + +```java +/** + * Samples for Operations List. + */ +public final class OperationsListSamples { + /* + * x-ms-original-file: + * specification/terraform/resource-manager/Microsoft.AzureTerraform/preview/2023-07-01-preview/examples/ + * ListOperations.json + */ + /** + * Sample code: Get a list of operations for a resource provider. + * + * @param manager Entry point to AzureTerraformManager. + */ + public static void + getAListOfOperationsForAResourceProvider(com.azure.resourcemanager.terraform.AzureTerraformManager manager) { + manager.operations().list(com.azure.core.util.Context.NONE); + } +} +``` + +### Terraform_ExportTerraform + +```java +import com.azure.resourcemanager.terraform.models.ExportResourceGroup; + +/** + * Samples for Terraform ExportTerraform. + */ +public final class TerraformExportTerraformSamples { + /* + * x-ms-original-file: + * specification/terraform/resource-manager/Microsoft.AzureTerraform/preview/2023-07-01-preview/examples/ + * ExportTerraform.json + */ + /** + * Sample code: ExportTerraform. + * + * @param manager Entry point to AzureTerraformManager. + */ + public static void exportTerraform(com.azure.resourcemanager.terraform.AzureTerraformManager manager) { + manager.terraforms() + .exportTerraform(new ExportResourceGroup().withResourceGroupName("rg1"), com.azure.core.util.Context.NONE); + } +} +``` + diff --git a/sdk/terraform/azure-resourcemanager-terraform/pom.xml b/sdk/terraform/azure-resourcemanager-terraform/pom.xml new file mode 100644 index 000000000000..97c3ecd53290 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + com.azure + azure-client-sdk-parent + 1.7.0 + ../../parents/azure-client-sdk-parent + + + com.azure.resourcemanager + azure-resourcemanager-terraform + 1.0.0-beta.1 + jar + + Microsoft Azure SDK for AzureTerraform Management + This package contains Microsoft Azure SDK for AzureTerraform Management SDK. For documentation on how to use this package, please see https://aka.ms/azsdk/java/mgmt. AzureTerraform Client. Package tag package-2023-07-01-preview. + https://github.com/Azure/azure-sdk-for-java + + + + The MIT License (MIT) + http://opensource.org/licenses/MIT + repo + + + + + https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + + microsoft + Microsoft + + + + UTF-8 + 0 + 0 + true + false + + + + com.azure + azure-core + 1.53.0 + + + com.azure + azure-core-management + 1.15.4 + + + diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/AzureTerraformManager.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/AzureTerraformManager.java new file mode 100644 index 000000000000..9557ff8ce389 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/AzureTerraformManager.java @@ -0,0 +1,291 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.management.http.policy.ArmChallengeAuthenticationPolicy; +import com.azure.core.management.profile.AzureProfile; +import com.azure.core.util.Configuration; +import com.azure.core.util.logging.ClientLogger; +import com.azure.resourcemanager.terraform.fluent.AzureTerraformManagementClient; +import com.azure.resourcemanager.terraform.implementation.AzureTerraformManagementClientBuilder; +import com.azure.resourcemanager.terraform.implementation.OperationsImpl; +import com.azure.resourcemanager.terraform.implementation.TerraformsImpl; +import com.azure.resourcemanager.terraform.models.Operations; +import com.azure.resourcemanager.terraform.models.Terraforms; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * Entry point to AzureTerraformManager. + * AzureTerraform Client. + */ +public final class AzureTerraformManager { + private Operations operations; + + private Terraforms terraforms; + + private final AzureTerraformManagementClient clientObject; + + private AzureTerraformManager(HttpPipeline httpPipeline, AzureProfile profile, Duration defaultPollInterval) { + Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + this.clientObject = new AzureTerraformManagementClientBuilder().pipeline(httpPipeline) + .endpoint(profile.getEnvironment().getResourceManagerEndpoint()) + .subscriptionId(profile.getSubscriptionId()) + .defaultPollInterval(defaultPollInterval) + .buildClient(); + } + + /** + * Creates an instance of AzureTerraform service API entry point. + * + * @param credential the credential to use. + * @param profile the Azure profile for client. + * @return the AzureTerraform service API instance. + */ + public static AzureTerraformManager authenticate(TokenCredential credential, AzureProfile profile) { + Objects.requireNonNull(credential, "'credential' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + return configure().authenticate(credential, profile); + } + + /** + * Creates an instance of AzureTerraform service API entry point. + * + * @param httpPipeline the {@link HttpPipeline} configured with Azure authentication credential. + * @param profile the Azure profile for client. + * @return the AzureTerraform service API instance. + */ + public static AzureTerraformManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) { + Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + return new AzureTerraformManager(httpPipeline, profile, null); + } + + /** + * Gets a Configurable instance that can be used to create AzureTerraformManager with optional configuration. + * + * @return the Configurable instance allowing configurations. + */ + public static Configurable configure() { + return new AzureTerraformManager.Configurable(); + } + + /** + * The Configurable allowing configurations to be set. + */ + public static final class Configurable { + private static final ClientLogger LOGGER = new ClientLogger(Configurable.class); + + private HttpClient httpClient; + private HttpLogOptions httpLogOptions; + private final List policies = new ArrayList<>(); + private final List scopes = new ArrayList<>(); + private RetryPolicy retryPolicy; + private RetryOptions retryOptions; + private Duration defaultPollInterval; + + private Configurable() { + } + + /** + * Sets the http client. + * + * @param httpClient the HTTP client. + * @return the configurable object itself. + */ + public Configurable withHttpClient(HttpClient httpClient) { + this.httpClient = Objects.requireNonNull(httpClient, "'httpClient' cannot be null."); + return this; + } + + /** + * Sets the logging options to the HTTP pipeline. + * + * @param httpLogOptions the HTTP log options. + * @return the configurable object itself. + */ + public Configurable withLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = Objects.requireNonNull(httpLogOptions, "'httpLogOptions' cannot be null."); + return this; + } + + /** + * Adds the pipeline policy to the HTTP pipeline. + * + * @param policy the HTTP pipeline policy. + * @return the configurable object itself. + */ + public Configurable withPolicy(HttpPipelinePolicy policy) { + this.policies.add(Objects.requireNonNull(policy, "'policy' cannot be null.")); + return this; + } + + /** + * Adds the scope to permission sets. + * + * @param scope the scope. + * @return the configurable object itself. + */ + public Configurable withScope(String scope) { + this.scopes.add(Objects.requireNonNull(scope, "'scope' cannot be null.")); + return this; + } + + /** + * Sets the retry policy to the HTTP pipeline. + * + * @param retryPolicy the HTTP pipeline retry policy. + * @return the configurable object itself. + */ + public Configurable withRetryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = Objects.requireNonNull(retryPolicy, "'retryPolicy' cannot be null."); + return this; + } + + /** + * Sets the retry options for the HTTP pipeline retry policy. + *

+ * This setting has no effect, if retry policy is set via {@link #withRetryPolicy(RetryPolicy)}. + * + * @param retryOptions the retry options for the HTTP pipeline retry policy. + * @return the configurable object itself. + */ + public Configurable withRetryOptions(RetryOptions retryOptions) { + this.retryOptions = Objects.requireNonNull(retryOptions, "'retryOptions' cannot be null."); + return this; + } + + /** + * Sets the default poll interval, used when service does not provide "Retry-After" header. + * + * @param defaultPollInterval the default poll interval. + * @return the configurable object itself. + */ + public Configurable withDefaultPollInterval(Duration defaultPollInterval) { + this.defaultPollInterval + = Objects.requireNonNull(defaultPollInterval, "'defaultPollInterval' cannot be null."); + if (this.defaultPollInterval.isNegative()) { + throw LOGGER + .logExceptionAsError(new IllegalArgumentException("'defaultPollInterval' cannot be negative")); + } + return this; + } + + /** + * Creates an instance of AzureTerraform service API entry point. + * + * @param credential the credential to use. + * @param profile the Azure profile for client. + * @return the AzureTerraform service API instance. + */ + public AzureTerraformManager authenticate(TokenCredential credential, AzureProfile profile) { + Objects.requireNonNull(credential, "'credential' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + + StringBuilder userAgentBuilder = new StringBuilder(); + userAgentBuilder.append("azsdk-java") + .append("-") + .append("com.azure.resourcemanager.terraform") + .append("/") + .append("1.0.0-beta.1"); + if (!Configuration.getGlobalConfiguration().get("AZURE_TELEMETRY_DISABLED", false)) { + userAgentBuilder.append(" (") + .append(Configuration.getGlobalConfiguration().get("java.version")) + .append("; ") + .append(Configuration.getGlobalConfiguration().get("os.name")) + .append("; ") + .append(Configuration.getGlobalConfiguration().get("os.version")) + .append("; auto-generated)"); + } else { + userAgentBuilder.append(" (auto-generated)"); + } + + if (scopes.isEmpty()) { + scopes.add(profile.getEnvironment().getManagementEndpoint() + "/.default"); + } + if (retryPolicy == null) { + if (retryOptions != null) { + retryPolicy = new RetryPolicy(retryOptions); + } else { + retryPolicy = new RetryPolicy("Retry-After", ChronoUnit.SECONDS); + } + } + List policies = new ArrayList<>(); + policies.add(new UserAgentPolicy(userAgentBuilder.toString())); + policies.add(new AddHeadersFromContextPolicy()); + policies.add(new RequestIdPolicy()); + policies.addAll(this.policies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .collect(Collectors.toList())); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(retryPolicy); + policies.add(new AddDatePolicy()); + policies.add(new ArmChallengeAuthenticationPolicy(credential, scopes.toArray(new String[0]))); + policies.addAll(this.policies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .collect(Collectors.toList())); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(httpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(httpClient) + .policies(policies.toArray(new HttpPipelinePolicy[0])) + .build(); + return new AzureTerraformManager(httpPipeline, profile, defaultPollInterval); + } + } + + /** + * Gets the resource collection API of Operations. + * + * @return Resource collection API of Operations. + */ + public Operations operations() { + if (this.operations == null) { + this.operations = new OperationsImpl(clientObject.getOperations(), this); + } + return operations; + } + + /** + * Gets the resource collection API of Terraforms. + * + * @return Resource collection API of Terraforms. + */ + public Terraforms terraforms() { + if (this.terraforms == null) { + this.terraforms = new TerraformsImpl(clientObject.getTerraforms(), this); + } + return terraforms; + } + + /** + * Gets wrapped service client AzureTerraformManagementClient providing direct access to the underlying + * auto-generated API implementation, based on Azure REST API. + * + * @return Wrapped service client AzureTerraformManagementClient. + */ + public AzureTerraformManagementClient serviceClient() { + return this.clientObject; + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/AzureTerraformManagementClient.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/AzureTerraformManagementClient.java new file mode 100644 index 000000000000..a90b5f233a42 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/AzureTerraformManagementClient.java @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.fluent; + +import com.azure.core.http.HttpPipeline; +import java.time.Duration; + +/** + * The interface for AzureTerraformManagementClient class. + */ +public interface AzureTerraformManagementClient { + /** + * Gets The ID of the target subscription. The value must be an UUID. + * + * @return the subscriptionId value. + */ + String getSubscriptionId(); + + /** + * Gets server parameter. + * + * @return the endpoint value. + */ + String getEndpoint(); + + /** + * Gets Api Version. + * + * @return the apiVersion value. + */ + String getApiVersion(); + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + HttpPipeline getHttpPipeline(); + + /** + * Gets The default poll interval for long-running operation. + * + * @return the defaultPollInterval value. + */ + Duration getDefaultPollInterval(); + + /** + * Gets the OperationsClient object to access its operations. + * + * @return the OperationsClient object. + */ + OperationsClient getOperations(); + + /** + * Gets the TerraformsClient object to access its operations. + * + * @return the TerraformsClient object. + */ + TerraformsClient getTerraforms(); +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/OperationsClient.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/OperationsClient.java new file mode 100644 index 000000000000..856ee475d007 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/OperationsClient.java @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.fluent; + +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.util.Context; +import com.azure.resourcemanager.terraform.fluent.models.OperationInner; + +/** + * An instance of this class provides access to all the operations defined in OperationsClient. + */ +public interface OperationsClient { + /** + * List the operations for the provider. + * + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable list(); + + /** + * List the operations for the provider. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable list(Context context); +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/TerraformsClient.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/TerraformsClient.java new file mode 100644 index 000000000000..131f567b4cc2 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/TerraformsClient.java @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.fluent; + +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.Context; +import com.azure.core.util.polling.SyncPoller; +import com.azure.resourcemanager.terraform.models.BaseExportModel; + +/** + * An instance of this class provides access to all the operations defined in TerraformsClient. + */ +public interface TerraformsClient { + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of long-running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, Void> beginExportTerraform(BaseExportModel body); + + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of long-running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, Void> beginExportTerraform(BaseExportModel body, Context context); + + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + void exportTerraform(BaseExportModel body); + + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + void exportTerraform(BaseExportModel body, Context context); +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/models/OperationInner.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/models/OperationInner.java new file mode 100644 index 000000000000..4cab8acb0ab9 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/models/OperationInner.java @@ -0,0 +1,172 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.fluent.models; + +import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import com.azure.resourcemanager.terraform.models.ActionType; +import com.azure.resourcemanager.terraform.models.OperationDisplay; +import com.azure.resourcemanager.terraform.models.Origin; +import java.io.IOException; + +/** + * REST API Operation + * + * Details of a REST API operation, returned from the Resource Provider Operations API. + */ +@Fluent +public final class OperationInner implements JsonSerializable { + /* + * The name of the operation, as per Resource-Based Access Control (RBAC). Examples: + * "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action" + */ + private String name; + + /* + * Whether the operation applies to data-plane. This is "true" for data-plane operations and "false" for + * ARM/control-plane operations. + */ + private Boolean isDataAction; + + /* + * Localized display information for this particular operation. + */ + private OperationDisplay display; + + /* + * The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default + * value is "user,system" + */ + private Origin origin; + + /* + * Enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + */ + private ActionType actionType; + + /** + * Creates an instance of OperationInner class. + */ + public OperationInner() { + } + + /** + * Get the name property: The name of the operation, as per Resource-Based Access Control (RBAC). Examples: + * "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action". + * + * @return the name value. + */ + public String name() { + return this.name; + } + + /** + * Get the isDataAction property: Whether the operation applies to data-plane. This is "true" for data-plane + * operations and "false" for ARM/control-plane operations. + * + * @return the isDataAction value. + */ + public Boolean isDataAction() { + return this.isDataAction; + } + + /** + * Get the display property: Localized display information for this particular operation. + * + * @return the display value. + */ + public OperationDisplay display() { + return this.display; + } + + /** + * Set the display property: Localized display information for this particular operation. + * + * @param display the display value to set. + * @return the OperationInner object itself. + */ + public OperationInner withDisplay(OperationDisplay display) { + this.display = display; + return this; + } + + /** + * Get the origin property: The intended executor of the operation; as in Resource Based Access Control (RBAC) and + * audit logs UX. Default value is "user,system". + * + * @return the origin value. + */ + public Origin origin() { + return this.origin; + } + + /** + * Get the actionType property: Enum. Indicates the action type. "Internal" refers to actions that are for internal + * only APIs. + * + * @return the actionType value. + */ + public ActionType actionType() { + return this.actionType; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + if (display() != null) { + display().validate(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("display", this.display); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of OperationInner from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of OperationInner if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IOException If an error occurs while reading the OperationInner. + */ + public static OperationInner fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + OperationInner deserializedOperationInner = new OperationInner(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("name".equals(fieldName)) { + deserializedOperationInner.name = reader.getString(); + } else if ("isDataAction".equals(fieldName)) { + deserializedOperationInner.isDataAction = reader.getNullable(JsonReader::getBoolean); + } else if ("display".equals(fieldName)) { + deserializedOperationInner.display = OperationDisplay.fromJson(reader); + } else if ("origin".equals(fieldName)) { + deserializedOperationInner.origin = Origin.fromString(reader.getString()); + } else if ("actionType".equals(fieldName)) { + deserializedOperationInner.actionType = ActionType.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + + return deserializedOperationInner; + }); + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/models/package-info.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/models/package-info.java new file mode 100644 index 000000000000..51f0eb89f869 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/models/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** + * Package containing the inner data models for AzureTerraformManagementClient. + * AzureTerraform Client. + */ +package com.azure.resourcemanager.terraform.fluent.models; diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/package-info.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/package-info.java new file mode 100644 index 000000000000..65302ccd0c87 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/fluent/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** + * Package containing the service clients for AzureTerraformManagementClient. + * AzureTerraform Client. + */ +package com.azure.resourcemanager.terraform.fluent; diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/AzureTerraformManagementClientBuilder.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/AzureTerraformManagementClientBuilder.java new file mode 100644 index 000000000000..1f623452d9ff --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/AzureTerraformManagementClientBuilder.java @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.implementation; + +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.serializer.SerializerFactory; +import com.azure.core.util.serializer.SerializerAdapter; +import java.time.Duration; + +/** + * A builder for creating a new instance of the AzureTerraformManagementClientImpl type. + */ +@ServiceClientBuilder(serviceClients = { AzureTerraformManagementClientImpl.class }) +public final class AzureTerraformManagementClientBuilder { + /* + * The ID of the target subscription. The value must be an UUID. + */ + private String subscriptionId; + + /** + * Sets The ID of the target subscription. The value must be an UUID. + * + * @param subscriptionId the subscriptionId value. + * @return the AzureTerraformManagementClientBuilder. + */ + public AzureTerraformManagementClientBuilder subscriptionId(String subscriptionId) { + this.subscriptionId = subscriptionId; + return this; + } + + /* + * server parameter + */ + private String endpoint; + + /** + * Sets server parameter. + * + * @param endpoint the endpoint value. + * @return the AzureTerraformManagementClientBuilder. + */ + public AzureTerraformManagementClientBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * The environment to connect to + */ + private AzureEnvironment environment; + + /** + * Sets The environment to connect to. + * + * @param environment the environment value. + * @return the AzureTerraformManagementClientBuilder. + */ + public AzureTerraformManagementClientBuilder environment(AzureEnvironment environment) { + this.environment = environment; + return this; + } + + /* + * The HTTP pipeline to send requests through + */ + private HttpPipeline pipeline; + + /** + * Sets The HTTP pipeline to send requests through. + * + * @param pipeline the pipeline value. + * @return the AzureTerraformManagementClientBuilder. + */ + public AzureTerraformManagementClientBuilder pipeline(HttpPipeline pipeline) { + this.pipeline = pipeline; + return this; + } + + /* + * The default poll interval for long-running operation + */ + private Duration defaultPollInterval; + + /** + * Sets The default poll interval for long-running operation. + * + * @param defaultPollInterval the defaultPollInterval value. + * @return the AzureTerraformManagementClientBuilder. + */ + public AzureTerraformManagementClientBuilder defaultPollInterval(Duration defaultPollInterval) { + this.defaultPollInterval = defaultPollInterval; + return this; + } + + /* + * The serializer to serialize an object into a string + */ + private SerializerAdapter serializerAdapter; + + /** + * Sets The serializer to serialize an object into a string. + * + * @param serializerAdapter the serializerAdapter value. + * @return the AzureTerraformManagementClientBuilder. + */ + public AzureTerraformManagementClientBuilder serializerAdapter(SerializerAdapter serializerAdapter) { + this.serializerAdapter = serializerAdapter; + return this; + } + + /** + * Builds an instance of AzureTerraformManagementClientImpl with the provided parameters. + * + * @return an instance of AzureTerraformManagementClientImpl. + */ + public AzureTerraformManagementClientImpl buildClient() { + String localEndpoint = (endpoint != null) ? endpoint : "https://management.azure.com"; + AzureEnvironment localEnvironment = (environment != null) ? environment : AzureEnvironment.AZURE; + HttpPipeline localPipeline = (pipeline != null) + ? pipeline + : new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(); + Duration localDefaultPollInterval + = (defaultPollInterval != null) ? defaultPollInterval : Duration.ofSeconds(30); + SerializerAdapter localSerializerAdapter = (serializerAdapter != null) + ? serializerAdapter + : SerializerFactory.createDefaultManagementSerializerAdapter(); + AzureTerraformManagementClientImpl client = new AzureTerraformManagementClientImpl(localPipeline, + localSerializerAdapter, localDefaultPollInterval, localEnvironment, this.subscriptionId, localEndpoint); + return client; + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/AzureTerraformManagementClientImpl.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/AzureTerraformManagementClientImpl.java new file mode 100644 index 000000000000..c22d214410b3 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/AzureTerraformManagementClientImpl.java @@ -0,0 +1,304 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.implementation; + +import com.azure.core.annotation.ServiceClient; +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpResponse; +import com.azure.core.http.rest.Response; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.exception.ManagementError; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.polling.PollResult; +import com.azure.core.management.polling.PollerFactory; +import com.azure.core.util.Context; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.polling.AsyncPollResponse; +import com.azure.core.util.polling.LongRunningOperationStatus; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.core.util.serializer.SerializerEncoding; +import com.azure.resourcemanager.terraform.fluent.AzureTerraformManagementClient; +import com.azure.resourcemanager.terraform.fluent.OperationsClient; +import com.azure.resourcemanager.terraform.fluent.TerraformsClient; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.time.Duration; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * Initializes a new instance of the AzureTerraformManagementClientImpl type. + */ +@ServiceClient(builder = AzureTerraformManagementClientBuilder.class) +public final class AzureTerraformManagementClientImpl implements AzureTerraformManagementClient { + /** + * The ID of the target subscription. The value must be an UUID. + */ + private final String subscriptionId; + + /** + * Gets The ID of the target subscription. The value must be an UUID. + * + * @return the subscriptionId value. + */ + public String getSubscriptionId() { + return this.subscriptionId; + } + + /** + * server parameter. + */ + private final String endpoint; + + /** + * Gets server parameter. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** + * Api Version. + */ + private final String apiVersion; + + /** + * Gets Api Version. + * + * @return the apiVersion value. + */ + public String getApiVersion() { + return this.apiVersion; + } + + /** + * The HTTP pipeline to send requests through. + */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The serializer to serialize an object into a string. + */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * The default poll interval for long-running operation. + */ + private final Duration defaultPollInterval; + + /** + * Gets The default poll interval for long-running operation. + * + * @return the defaultPollInterval value. + */ + public Duration getDefaultPollInterval() { + return this.defaultPollInterval; + } + + /** + * The OperationsClient object to access its operations. + */ + private final OperationsClient operations; + + /** + * Gets the OperationsClient object to access its operations. + * + * @return the OperationsClient object. + */ + public OperationsClient getOperations() { + return this.operations; + } + + /** + * The TerraformsClient object to access its operations. + */ + private final TerraformsClient terraforms; + + /** + * Gets the TerraformsClient object to access its operations. + * + * @return the TerraformsClient object. + */ + public TerraformsClient getTerraforms() { + return this.terraforms; + } + + /** + * Initializes an instance of AzureTerraformManagementClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param defaultPollInterval The default poll interval for long-running operation. + * @param environment The Azure environment. + * @param subscriptionId The ID of the target subscription. The value must be an UUID. + * @param endpoint server parameter. + */ + AzureTerraformManagementClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, + Duration defaultPollInterval, AzureEnvironment environment, String subscriptionId, String endpoint) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.defaultPollInterval = defaultPollInterval; + this.subscriptionId = subscriptionId; + this.endpoint = endpoint; + this.apiVersion = "2023-07-01-preview"; + this.operations = new OperationsClientImpl(this); + this.terraforms = new TerraformsClientImpl(this); + } + + /** + * Gets default client context. + * + * @return the default client context. + */ + public Context getContext() { + return Context.NONE; + } + + /** + * Merges default client context with provided context. + * + * @param context the context to be merged with default client context. + * @return the merged context. + */ + public Context mergeContext(Context context) { + return CoreUtils.mergeContexts(this.getContext(), context); + } + + /** + * Gets long running operation result. + * + * @param activationResponse the response of activation operation. + * @param httpPipeline the http pipeline. + * @param pollResultType type of poll result. + * @param finalResultType type of final result. + * @param context the context shared by all requests. + * @param type of poll result. + * @param type of final result. + * @return poller flux for poll result and final result. + */ + public PollerFlux, U> getLroResult(Mono>> activationResponse, + HttpPipeline httpPipeline, Type pollResultType, Type finalResultType, Context context) { + return PollerFactory.create(serializerAdapter, httpPipeline, pollResultType, finalResultType, + defaultPollInterval, activationResponse, context); + } + + /** + * Gets the final result, or an error, based on last async poll response. + * + * @param response the last async poll response. + * @param type of poll result. + * @param type of final result. + * @return the final result, or an error. + */ + public Mono getLroFinalResultOrError(AsyncPollResponse, U> response) { + if (response.getStatus() != LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) { + String errorMessage; + ManagementError managementError = null; + HttpResponse errorResponse = null; + PollResult.Error lroError = response.getValue().getError(); + if (lroError != null) { + errorResponse = new HttpResponseImpl(lroError.getResponseStatusCode(), lroError.getResponseHeaders(), + lroError.getResponseBody()); + + errorMessage = response.getValue().getError().getMessage(); + String errorBody = response.getValue().getError().getResponseBody(); + if (errorBody != null) { + // try to deserialize error body to ManagementError + try { + managementError = this.getSerializerAdapter() + .deserialize(errorBody, ManagementError.class, SerializerEncoding.JSON); + if (managementError.getCode() == null || managementError.getMessage() == null) { + managementError = null; + } + } catch (IOException | RuntimeException ioe) { + LOGGER.logThrowableAsWarning(ioe); + } + } + } else { + // fallback to default error message + errorMessage = "Long running operation failed."; + } + if (managementError == null) { + // fallback to default ManagementError + managementError = new ManagementError(response.getStatus().toString(), errorMessage); + } + return Mono.error(new ManagementException(errorMessage, errorResponse, managementError)); + } else { + return response.getFinalResult(); + } + } + + private static final class HttpResponseImpl extends HttpResponse { + private final int statusCode; + + private final byte[] responseBody; + + private final HttpHeaders httpHeaders; + + HttpResponseImpl(int statusCode, HttpHeaders httpHeaders, String responseBody) { + super(null); + this.statusCode = statusCode; + this.httpHeaders = httpHeaders; + this.responseBody = responseBody == null ? null : responseBody.getBytes(StandardCharsets.UTF_8); + } + + public int getStatusCode() { + return statusCode; + } + + public String getHeaderValue(String s) { + return httpHeaders.getValue(HttpHeaderName.fromString(s)); + } + + public HttpHeaders getHeaders() { + return httpHeaders; + } + + public Flux getBody() { + return Flux.just(ByteBuffer.wrap(responseBody)); + } + + public Mono getBodyAsByteArray() { + return Mono.just(responseBody); + } + + public Mono getBodyAsString() { + return Mono.just(new String(responseBody, StandardCharsets.UTF_8)); + } + + public Mono getBodyAsString(Charset charset) { + return Mono.just(new String(responseBody, charset)); + } + } + + private static final ClientLogger LOGGER = new ClientLogger(AzureTerraformManagementClientImpl.class); +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/OperationImpl.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/OperationImpl.java new file mode 100644 index 000000000000..3a938e90ab45 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/OperationImpl.java @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.implementation; + +import com.azure.resourcemanager.terraform.fluent.models.OperationInner; +import com.azure.resourcemanager.terraform.models.ActionType; +import com.azure.resourcemanager.terraform.models.Operation; +import com.azure.resourcemanager.terraform.models.OperationDisplay; +import com.azure.resourcemanager.terraform.models.Origin; + +public final class OperationImpl implements Operation { + private OperationInner innerObject; + + private final com.azure.resourcemanager.terraform.AzureTerraformManager serviceManager; + + OperationImpl(OperationInner innerObject, + com.azure.resourcemanager.terraform.AzureTerraformManager serviceManager) { + this.innerObject = innerObject; + this.serviceManager = serviceManager; + } + + public String name() { + return this.innerModel().name(); + } + + public Boolean isDataAction() { + return this.innerModel().isDataAction(); + } + + public OperationDisplay display() { + return this.innerModel().display(); + } + + public Origin origin() { + return this.innerModel().origin(); + } + + public ActionType actionType() { + return this.innerModel().actionType(); + } + + public OperationInner innerModel() { + return this.innerObject; + } + + private com.azure.resourcemanager.terraform.AzureTerraformManager manager() { + return this.serviceManager; + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/OperationsClientImpl.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/OperationsClientImpl.java new file mode 100644 index 000000000000..346cb3689cbd --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/OperationsClientImpl.java @@ -0,0 +1,235 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.implementation; + +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Headers; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.resourcemanager.terraform.fluent.OperationsClient; +import com.azure.resourcemanager.terraform.fluent.models.OperationInner; +import com.azure.resourcemanager.terraform.models.OperationListResult; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in OperationsClient. + */ +public final class OperationsClientImpl implements OperationsClient { + /** + * The proxy service used to perform REST calls. + */ + private final OperationsService service; + + /** + * The service client containing this operation class. + */ + private final AzureTerraformManagementClientImpl client; + + /** + * Initializes an instance of OperationsClientImpl. + * + * @param client the instance of the service client containing this operation class. + */ + OperationsClientImpl(AzureTerraformManagementClientImpl client) { + this.service + = RestProxy.create(OperationsService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for AzureTerraformManagementClientOperations to be used by the proxy + * service to perform REST calls. + */ + @Host("{$host}") + @ServiceInterface(name = "AzureTerraformManage") + public interface OperationsService { + @Headers({ "Content-Type: application/json" }) + @Get("/providers/Microsoft.AzureTerraform/operations") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> list(@HostParam("$host") String endpoint, + @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> listNext(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("$host") String endpoint, @HeaderParam("Accept") String accept, Context context); + } + + /** + * List the operations for the provider. + * + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider along with {@link PagedResponse} on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listSinglePageAsync() { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.list(this.client.getEndpoint(), this.client.getApiVersion(), accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), + res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * List the operations for the provider. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider along with {@link PagedResponse} on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listSinglePageAsync(Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.list(this.client.getEndpoint(), this.client.getApiVersion(), accept, context) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + res.getValue().value(), res.getValue().nextLink(), null)); + } + + /** + * List the operations for the provider. + * + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listAsync() { + return new PagedFlux<>(() -> listSinglePageAsync(), nextLink -> listNextSinglePageAsync(nextLink)); + } + + /** + * List the operations for the provider. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listAsync(Context context) { + return new PagedFlux<>(() -> listSinglePageAsync(context), + nextLink -> listNextSinglePageAsync(nextLink, context)); + } + + /** + * List the operations for the provider. + * + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable list() { + return new PagedIterable<>(listAsync()); + } + + /** + * List the operations for the provider. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable list(Context context) { + return new PagedIterable<>(listAsync(context)); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider along with {@link PagedResponse} on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listNextSinglePageAsync(String nextLink) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.listNext(nextLink, this.client.getEndpoint(), accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), + res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider along with {@link PagedResponse} on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listNextSinglePageAsync(String nextLink, Context context) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.listNext(nextLink, this.client.getEndpoint(), accept, context) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + res.getValue().value(), res.getValue().nextLink(), null)); + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/OperationsImpl.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/OperationsImpl.java new file mode 100644 index 000000000000..bd73cc9ba6a2 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/OperationsImpl.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.implementation; + +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.util.Context; +import com.azure.core.util.logging.ClientLogger; +import com.azure.resourcemanager.terraform.fluent.OperationsClient; +import com.azure.resourcemanager.terraform.fluent.models.OperationInner; +import com.azure.resourcemanager.terraform.models.Operation; +import com.azure.resourcemanager.terraform.models.Operations; + +public final class OperationsImpl implements Operations { + private static final ClientLogger LOGGER = new ClientLogger(OperationsImpl.class); + + private final OperationsClient innerClient; + + private final com.azure.resourcemanager.terraform.AzureTerraformManager serviceManager; + + public OperationsImpl(OperationsClient innerClient, + com.azure.resourcemanager.terraform.AzureTerraformManager serviceManager) { + this.innerClient = innerClient; + this.serviceManager = serviceManager; + } + + public PagedIterable list() { + PagedIterable inner = this.serviceClient().list(); + return ResourceManagerUtils.mapPage(inner, inner1 -> new OperationImpl(inner1, this.manager())); + } + + public PagedIterable list(Context context) { + PagedIterable inner = this.serviceClient().list(context); + return ResourceManagerUtils.mapPage(inner, inner1 -> new OperationImpl(inner1, this.manager())); + } + + private OperationsClient serviceClient() { + return this.innerClient; + } + + private com.azure.resourcemanager.terraform.AzureTerraformManager manager() { + return this.serviceManager; + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/ResourceManagerUtils.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/ResourceManagerUtils.java new file mode 100644 index 000000000000..62cc0e32cd48 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/ResourceManagerUtils.java @@ -0,0 +1,195 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.implementation; + +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.util.CoreUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import reactor.core.publisher.Flux; + +final class ResourceManagerUtils { + private ResourceManagerUtils() { + } + + static String getValueFromIdByName(String id, String name) { + if (id == null) { + return null; + } + Iterator itr = Arrays.stream(id.split("/")).iterator(); + while (itr.hasNext()) { + String part = itr.next(); + if (part != null && !part.trim().isEmpty()) { + if (part.equalsIgnoreCase(name)) { + if (itr.hasNext()) { + return itr.next(); + } else { + return null; + } + } + } + } + return null; + } + + static String getValueFromIdByParameterName(String id, String pathTemplate, String parameterName) { + if (id == null || pathTemplate == null) { + return null; + } + String parameterNameParentheses = "{" + parameterName + "}"; + List idSegmentsReverted = Arrays.asList(id.split("/")); + List pathSegments = Arrays.asList(pathTemplate.split("/")); + Collections.reverse(idSegmentsReverted); + Iterator idItrReverted = idSegmentsReverted.iterator(); + int pathIndex = pathSegments.size(); + while (idItrReverted.hasNext() && pathIndex > 0) { + String idSegment = idItrReverted.next(); + String pathSegment = pathSegments.get(--pathIndex); + if (!CoreUtils.isNullOrEmpty(idSegment) && !CoreUtils.isNullOrEmpty(pathSegment)) { + if (pathSegment.equalsIgnoreCase(parameterNameParentheses)) { + if (pathIndex == 0 || (pathIndex == 1 && pathSegments.get(0).isEmpty())) { + List segments = new ArrayList<>(); + segments.add(idSegment); + idItrReverted.forEachRemaining(segments::add); + Collections.reverse(segments); + if (!segments.isEmpty() && segments.get(0).isEmpty()) { + segments.remove(0); + } + return String.join("/", segments); + } else { + return idSegment; + } + } + } + } + return null; + } + + static PagedIterable mapPage(PagedIterable pageIterable, Function mapper) { + return new PagedIterableImpl<>(pageIterable, mapper); + } + + private static final class PagedIterableImpl extends PagedIterable { + + private final PagedIterable pagedIterable; + private final Function mapper; + private final Function, PagedResponse> pageMapper; + + private PagedIterableImpl(PagedIterable pagedIterable, Function mapper) { + super(PagedFlux.create(() -> (continuationToken, pageSize) -> Flux + .fromStream(pagedIterable.streamByPage().map(getPageMapper(mapper))))); + this.pagedIterable = pagedIterable; + this.mapper = mapper; + this.pageMapper = getPageMapper(mapper); + } + + private static Function, PagedResponse> getPageMapper(Function mapper) { + return page -> new PagedResponseBase(page.getRequest(), page.getStatusCode(), page.getHeaders(), + page.getElements().stream().map(mapper).collect(Collectors.toList()), page.getContinuationToken(), + null); + } + + @Override + public Stream stream() { + return pagedIterable.stream().map(mapper); + } + + @Override + public Stream> streamByPage() { + return pagedIterable.streamByPage().map(pageMapper); + } + + @Override + public Stream> streamByPage(String continuationToken) { + return pagedIterable.streamByPage(continuationToken).map(pageMapper); + } + + @Override + public Stream> streamByPage(int preferredPageSize) { + return pagedIterable.streamByPage(preferredPageSize).map(pageMapper); + } + + @Override + public Stream> streamByPage(String continuationToken, int preferredPageSize) { + return pagedIterable.streamByPage(continuationToken, preferredPageSize).map(pageMapper); + } + + @Override + public Iterator iterator() { + return new IteratorImpl<>(pagedIterable.iterator(), mapper); + } + + @Override + public Iterable> iterableByPage() { + return new IterableImpl<>(pagedIterable.iterableByPage(), pageMapper); + } + + @Override + public Iterable> iterableByPage(String continuationToken) { + return new IterableImpl<>(pagedIterable.iterableByPage(continuationToken), pageMapper); + } + + @Override + public Iterable> iterableByPage(int preferredPageSize) { + return new IterableImpl<>(pagedIterable.iterableByPage(preferredPageSize), pageMapper); + } + + @Override + public Iterable> iterableByPage(String continuationToken, int preferredPageSize) { + return new IterableImpl<>(pagedIterable.iterableByPage(continuationToken, preferredPageSize), pageMapper); + } + } + + private static final class IteratorImpl implements Iterator { + + private final Iterator iterator; + private final Function mapper; + + private IteratorImpl(Iterator iterator, Function mapper) { + this.iterator = iterator; + this.mapper = mapper; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public S next() { + return mapper.apply(iterator.next()); + } + + @Override + public void remove() { + iterator.remove(); + } + } + + private static final class IterableImpl implements Iterable { + + private final Iterable iterable; + private final Function mapper; + + private IterableImpl(Iterable iterable, Function mapper) { + this.iterable = iterable; + this.mapper = mapper; + } + + @Override + public Iterator iterator() { + return new IteratorImpl<>(iterable.iterator(), mapper); + } + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/TerraformsClientImpl.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/TerraformsClientImpl.java new file mode 100644 index 000000000000..f2448b7d83e3 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/TerraformsClientImpl.java @@ -0,0 +1,255 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.implementation; + +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Headers; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Post; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.polling.SyncPoller; +import com.azure.resourcemanager.terraform.fluent.TerraformsClient; +import com.azure.resourcemanager.terraform.models.BaseExportModel; +import java.nio.ByteBuffer; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in TerraformsClient. + */ +public final class TerraformsClientImpl implements TerraformsClient { + /** + * The proxy service used to perform REST calls. + */ + private final TerraformsService service; + + /** + * The service client containing this operation class. + */ + private final AzureTerraformManagementClientImpl client; + + /** + * Initializes an instance of TerraformsClientImpl. + * + * @param client the instance of the service client containing this operation class. + */ + TerraformsClientImpl(AzureTerraformManagementClientImpl client) { + this.service + = RestProxy.create(TerraformsService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for AzureTerraformManagementClientTerraforms to be used by the proxy + * service to perform REST calls. + */ + @Host("{$host}") + @ServiceInterface(name = "AzureTerraformManage") + public interface TerraformsService { + @Headers({ "Content-Type: application/json" }) + @Post("/subscriptions/{subscriptionId}/providers/Microsoft.AzureTerraform/exportTerraform") + @ExpectedResponses({ 202 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono>> exportTerraform(@HostParam("$host") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @BodyParam("application/json") BaseExportModel body, @HeaderParam("Accept") String accept, Context context); + } + + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono>> exportTerraformWithResponseAsync(BaseExportModel body) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } else { + body.validate(); + } + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.exportTerraform(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), body, accept, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono>> exportTerraformWithResponseAsync(BaseExportModel body, Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } else { + body.validate(); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.exportTerraform(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), body, accept, context); + } + + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of long-running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, Void> beginExportTerraformAsync(BaseExportModel body) { + Mono>> mono = exportTerraformWithResponseAsync(body); + return this.client.getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, + this.client.getContext()); + } + + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of long-running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, Void> beginExportTerraformAsync(BaseExportModel body, Context context) { + context = this.client.mergeContext(context); + Mono>> mono = exportTerraformWithResponseAsync(body, context); + return this.client.getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, + context); + } + + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of long-running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, Void> beginExportTerraform(BaseExportModel body) { + return this.beginExportTerraformAsync(body).getSyncPoller(); + } + + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of long-running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, Void> beginExportTerraform(BaseExportModel body, Context context) { + return this.beginExportTerraformAsync(body, context).getSyncPoller(); + } + + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return A {@link Mono} that completes when a successful response is received. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono exportTerraformAsync(BaseExportModel body) { + return beginExportTerraformAsync(body).last().flatMap(this.client::getLroFinalResultOrError); + } + + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return A {@link Mono} that completes when a successful response is received. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono exportTerraformAsync(BaseExportModel body, Context context) { + return beginExportTerraformAsync(body, context).last().flatMap(this.client::getLroFinalResultOrError); + } + + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void exportTerraform(BaseExportModel body) { + exportTerraformAsync(body).block(); + } + + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void exportTerraform(BaseExportModel body, Context context) { + exportTerraformAsync(body, context).block(); + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/TerraformsImpl.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/TerraformsImpl.java new file mode 100644 index 000000000000..2da563cefb2c --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/TerraformsImpl.java @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.implementation; + +import com.azure.core.util.Context; +import com.azure.core.util.logging.ClientLogger; +import com.azure.resourcemanager.terraform.fluent.TerraformsClient; +import com.azure.resourcemanager.terraform.models.BaseExportModel; +import com.azure.resourcemanager.terraform.models.Terraforms; + +public final class TerraformsImpl implements Terraforms { + private static final ClientLogger LOGGER = new ClientLogger(TerraformsImpl.class); + + private final TerraformsClient innerClient; + + private final com.azure.resourcemanager.terraform.AzureTerraformManager serviceManager; + + public TerraformsImpl(TerraformsClient innerClient, + com.azure.resourcemanager.terraform.AzureTerraformManager serviceManager) { + this.innerClient = innerClient; + this.serviceManager = serviceManager; + } + + public void exportTerraform(BaseExportModel body) { + this.serviceClient().exportTerraform(body); + } + + public void exportTerraform(BaseExportModel body, Context context) { + this.serviceClient().exportTerraform(body, context); + } + + private TerraformsClient serviceClient() { + return this.innerClient; + } + + private com.azure.resourcemanager.terraform.AzureTerraformManager manager() { + return this.serviceManager; + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/package-info.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/package-info.java new file mode 100644 index 000000000000..080047e393bd --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/implementation/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** + * Package containing the implementations for AzureTerraformManagementClient. + * AzureTerraform Client. + */ +package com.azure.resourcemanager.terraform.implementation; diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ActionType.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ActionType.java new file mode 100644 index 000000000000..76bee14c7edd --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ActionType.java @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * Enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + */ +public final class ActionType extends ExpandableStringEnum { + /** + * Static value Internal for ActionType. + */ + public static final ActionType INTERNAL = fromString("Internal"); + + /** + * Creates a new instance of ActionType value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public ActionType() { + } + + /** + * Creates or finds a ActionType from its string representation. + * + * @param name a name to look for. + * @return the corresponding ActionType. + */ + public static ActionType fromString(String name) { + return fromString(name, ActionType.class); + } + + /** + * Gets known ActionType values. + * + * @return known ActionType values. + */ + public static Collection values() { + return values(ActionType.class); + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/BaseExportModel.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/BaseExportModel.java new file mode 100644 index 000000000000..694d5fe7ac36 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/BaseExportModel.java @@ -0,0 +1,199 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.models; + +import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The base export parameter. + */ +@Fluent +public class BaseExportModel implements JsonSerializable { + /* + * The parameter type + */ + private Type type = Type.fromString("BaseExportModel"); + + /* + * The target Azure Terraform Provider + */ + private TargetProvider targetProvider; + + /* + * Whether to output all non-computed properties in the generated Terraform configuration? This probably needs + * manual modifications to make it valid + */ + private Boolean fullProperties; + + /* + * Mask sensitive attributes in the Terraform configuration + */ + private Boolean maskSensitive; + + /** + * Creates an instance of BaseExportModel class. + */ + public BaseExportModel() { + } + + /** + * Get the type property: The parameter type. + * + * @return the type value. + */ + public Type type() { + return this.type; + } + + /** + * Get the targetProvider property: The target Azure Terraform Provider. + * + * @return the targetProvider value. + */ + public TargetProvider targetProvider() { + return this.targetProvider; + } + + /** + * Set the targetProvider property: The target Azure Terraform Provider. + * + * @param targetProvider the targetProvider value to set. + * @return the BaseExportModel object itself. + */ + public BaseExportModel withTargetProvider(TargetProvider targetProvider) { + this.targetProvider = targetProvider; + return this; + } + + /** + * Get the fullProperties property: Whether to output all non-computed properties in the generated Terraform + * configuration? This probably needs manual modifications to make it valid. + * + * @return the fullProperties value. + */ + public Boolean fullProperties() { + return this.fullProperties; + } + + /** + * Set the fullProperties property: Whether to output all non-computed properties in the generated Terraform + * configuration? This probably needs manual modifications to make it valid. + * + * @param fullProperties the fullProperties value to set. + * @return the BaseExportModel object itself. + */ + public BaseExportModel withFullProperties(Boolean fullProperties) { + this.fullProperties = fullProperties; + return this; + } + + /** + * Get the maskSensitive property: Mask sensitive attributes in the Terraform configuration. + * + * @return the maskSensitive value. + */ + public Boolean maskSensitive() { + return this.maskSensitive; + } + + /** + * Set the maskSensitive property: Mask sensitive attributes in the Terraform configuration. + * + * @param maskSensitive the maskSensitive value to set. + * @return the BaseExportModel object itself. + */ + public BaseExportModel withMaskSensitive(Boolean maskSensitive) { + this.maskSensitive = maskSensitive; + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString()); + jsonWriter.writeStringField("targetProvider", + this.targetProvider == null ? null : this.targetProvider.toString()); + jsonWriter.writeBooleanField("fullProperties", this.fullProperties); + jsonWriter.writeBooleanField("maskSensitive", this.maskSensitive); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of BaseExportModel from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of BaseExportModel if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IOException If an error occurs while reading the BaseExportModel. + */ + public static BaseExportModel fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String discriminatorValue = null; + try (JsonReader readerToUse = reader.bufferObject()) { + readerToUse.nextToken(); // Prepare for reading + while (readerToUse.nextToken() != JsonToken.END_OBJECT) { + String fieldName = readerToUse.getFieldName(); + readerToUse.nextToken(); + if ("type".equals(fieldName)) { + discriminatorValue = readerToUse.getString(); + break; + } else { + readerToUse.skipChildren(); + } + } + // Use the discriminator value to determine which subtype should be deserialized. + if ("ExportQuery".equals(discriminatorValue)) { + return ExportQuery.fromJson(readerToUse.reset()); + } else if ("ExportResource".equals(discriminatorValue)) { + return ExportResource.fromJson(readerToUse.reset()); + } else if ("ExportResourceGroup".equals(discriminatorValue)) { + return ExportResourceGroup.fromJson(readerToUse.reset()); + } else { + return fromJsonKnownDiscriminator(readerToUse.reset()); + } + } + }); + } + + static BaseExportModel fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + BaseExportModel deserializedBaseExportModel = new BaseExportModel(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("type".equals(fieldName)) { + deserializedBaseExportModel.type = Type.fromString(reader.getString()); + } else if ("targetProvider".equals(fieldName)) { + deserializedBaseExportModel.targetProvider = TargetProvider.fromString(reader.getString()); + } else if ("fullProperties".equals(fieldName)) { + deserializedBaseExportModel.fullProperties = reader.getNullable(JsonReader::getBoolean); + } else if ("maskSensitive".equals(fieldName)) { + deserializedBaseExportModel.maskSensitive = reader.getNullable(JsonReader::getBoolean); + } else { + reader.skipChildren(); + } + } + + return deserializedBaseExportModel; + }); + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ExportQuery.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ExportQuery.java new file mode 100644 index 000000000000..1e11596fe8ce --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ExportQuery.java @@ -0,0 +1,214 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.util.logging.ClientLogger; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Export parameter for resources queried by ARG (Azure Resource Graph). + */ +@Fluent +public final class ExportQuery extends BaseExportModel { + /* + * The parameter type + */ + private Type type = Type.EXPORT_QUERY; + + /* + * The ARG where predicate. Note that you can combine multiple conditions in one `where` predicate, e.g. + * `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"` + */ + private String query; + + /* + * The name pattern of the Terraform resources + */ + private String namePattern; + + /* + * Whether to recursively list child resources of the query result + */ + private Boolean recursive; + + /** + * Creates an instance of ExportQuery class. + */ + public ExportQuery() { + } + + /** + * Get the type property: The parameter type. + * + * @return the type value. + */ + @Override + public Type type() { + return this.type; + } + + /** + * Get the query property: The ARG where predicate. Note that you can combine multiple conditions in one `where` + * predicate, e.g. `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"`. + * + * @return the query value. + */ + public String query() { + return this.query; + } + + /** + * Set the query property: The ARG where predicate. Note that you can combine multiple conditions in one `where` + * predicate, e.g. `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"`. + * + * @param query the query value to set. + * @return the ExportQuery object itself. + */ + public ExportQuery withQuery(String query) { + this.query = query; + return this; + } + + /** + * Get the namePattern property: The name pattern of the Terraform resources. + * + * @return the namePattern value. + */ + public String namePattern() { + return this.namePattern; + } + + /** + * Set the namePattern property: The name pattern of the Terraform resources. + * + * @param namePattern the namePattern value to set. + * @return the ExportQuery object itself. + */ + public ExportQuery withNamePattern(String namePattern) { + this.namePattern = namePattern; + return this; + } + + /** + * Get the recursive property: Whether to recursively list child resources of the query result. + * + * @return the recursive value. + */ + public Boolean recursive() { + return this.recursive; + } + + /** + * Set the recursive property: Whether to recursively list child resources of the query result. + * + * @param recursive the recursive value to set. + * @return the ExportQuery object itself. + */ + public ExportQuery withRecursive(Boolean recursive) { + this.recursive = recursive; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public ExportQuery withTargetProvider(TargetProvider targetProvider) { + super.withTargetProvider(targetProvider); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public ExportQuery withFullProperties(Boolean fullProperties) { + super.withFullProperties(fullProperties); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public ExportQuery withMaskSensitive(Boolean maskSensitive) { + super.withMaskSensitive(maskSensitive); + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + @Override + public void validate() { + if (query() == null) { + throw LOGGER.atError() + .log(new IllegalArgumentException("Missing required property query in model ExportQuery")); + } + } + + private static final ClientLogger LOGGER = new ClientLogger(ExportQuery.class); + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("targetProvider", targetProvider() == null ? null : targetProvider().toString()); + jsonWriter.writeBooleanField("fullProperties", fullProperties()); + jsonWriter.writeBooleanField("maskSensitive", maskSensitive()); + jsonWriter.writeStringField("query", this.query); + jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString()); + jsonWriter.writeStringField("namePattern", this.namePattern); + jsonWriter.writeBooleanField("recursive", this.recursive); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ExportQuery from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ExportQuery if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the ExportQuery. + */ + public static ExportQuery fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ExportQuery deserializedExportQuery = new ExportQuery(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("targetProvider".equals(fieldName)) { + deserializedExportQuery.withTargetProvider(TargetProvider.fromString(reader.getString())); + } else if ("fullProperties".equals(fieldName)) { + deserializedExportQuery.withFullProperties(reader.getNullable(JsonReader::getBoolean)); + } else if ("maskSensitive".equals(fieldName)) { + deserializedExportQuery.withMaskSensitive(reader.getNullable(JsonReader::getBoolean)); + } else if ("query".equals(fieldName)) { + deserializedExportQuery.query = reader.getString(); + } else if ("type".equals(fieldName)) { + deserializedExportQuery.type = Type.fromString(reader.getString()); + } else if ("namePattern".equals(fieldName)) { + deserializedExportQuery.namePattern = reader.getString(); + } else if ("recursive".equals(fieldName)) { + deserializedExportQuery.recursive = reader.getNullable(JsonReader::getBoolean); + } else { + reader.skipChildren(); + } + } + + return deserializedExportQuery; + }); + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ExportResource.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ExportResource.java new file mode 100644 index 000000000000..d726ac793098 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ExportResource.java @@ -0,0 +1,241 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.util.logging.ClientLogger; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.List; + +/** + * Export parameter for individual resources. + */ +@Fluent +public final class ExportResource extends BaseExportModel { + /* + * The parameter type + */ + private Type type = Type.EXPORT_RESOURCE; + + /* + * The id of the resource to be exported + */ + private List resourceIds; + + /* + * The Terraform resource name. Only works when `resourceIds` contains only one item. + */ + private String resourceName; + + /* + * The Terraform resource type. Only works when `resourceIds` contains only one item. + */ + private String resourceType; + + /* + * The name pattern of the Terraform resources + */ + private String namePattern; + + /** + * Creates an instance of ExportResource class. + */ + public ExportResource() { + } + + /** + * Get the type property: The parameter type. + * + * @return the type value. + */ + @Override + public Type type() { + return this.type; + } + + /** + * Get the resourceIds property: The id of the resource to be exported. + * + * @return the resourceIds value. + */ + public List resourceIds() { + return this.resourceIds; + } + + /** + * Set the resourceIds property: The id of the resource to be exported. + * + * @param resourceIds the resourceIds value to set. + * @return the ExportResource object itself. + */ + public ExportResource withResourceIds(List resourceIds) { + this.resourceIds = resourceIds; + return this; + } + + /** + * Get the resourceName property: The Terraform resource name. Only works when `resourceIds` contains only one item. + * + * @return the resourceName value. + */ + public String resourceName() { + return this.resourceName; + } + + /** + * Set the resourceName property: The Terraform resource name. Only works when `resourceIds` contains only one item. + * + * @param resourceName the resourceName value to set. + * @return the ExportResource object itself. + */ + public ExportResource withResourceName(String resourceName) { + this.resourceName = resourceName; + return this; + } + + /** + * Get the resourceType property: The Terraform resource type. Only works when `resourceIds` contains only one item. + * + * @return the resourceType value. + */ + public String resourceType() { + return this.resourceType; + } + + /** + * Set the resourceType property: The Terraform resource type. Only works when `resourceIds` contains only one item. + * + * @param resourceType the resourceType value to set. + * @return the ExportResource object itself. + */ + public ExportResource withResourceType(String resourceType) { + this.resourceType = resourceType; + return this; + } + + /** + * Get the namePattern property: The name pattern of the Terraform resources. + * + * @return the namePattern value. + */ + public String namePattern() { + return this.namePattern; + } + + /** + * Set the namePattern property: The name pattern of the Terraform resources. + * + * @param namePattern the namePattern value to set. + * @return the ExportResource object itself. + */ + public ExportResource withNamePattern(String namePattern) { + this.namePattern = namePattern; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public ExportResource withTargetProvider(TargetProvider targetProvider) { + super.withTargetProvider(targetProvider); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public ExportResource withFullProperties(Boolean fullProperties) { + super.withFullProperties(fullProperties); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public ExportResource withMaskSensitive(Boolean maskSensitive) { + super.withMaskSensitive(maskSensitive); + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + @Override + public void validate() { + if (resourceIds() == null) { + throw LOGGER.atError() + .log(new IllegalArgumentException("Missing required property resourceIds in model ExportResource")); + } + } + + private static final ClientLogger LOGGER = new ClientLogger(ExportResource.class); + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("targetProvider", targetProvider() == null ? null : targetProvider().toString()); + jsonWriter.writeBooleanField("fullProperties", fullProperties()); + jsonWriter.writeBooleanField("maskSensitive", maskSensitive()); + jsonWriter.writeArrayField("resourceIds", this.resourceIds, (writer, element) -> writer.writeString(element)); + jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString()); + jsonWriter.writeStringField("resourceName", this.resourceName); + jsonWriter.writeStringField("resourceType", this.resourceType); + jsonWriter.writeStringField("namePattern", this.namePattern); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ExportResource from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ExportResource if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the ExportResource. + */ + public static ExportResource fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ExportResource deserializedExportResource = new ExportResource(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("targetProvider".equals(fieldName)) { + deserializedExportResource.withTargetProvider(TargetProvider.fromString(reader.getString())); + } else if ("fullProperties".equals(fieldName)) { + deserializedExportResource.withFullProperties(reader.getNullable(JsonReader::getBoolean)); + } else if ("maskSensitive".equals(fieldName)) { + deserializedExportResource.withMaskSensitive(reader.getNullable(JsonReader::getBoolean)); + } else if ("resourceIds".equals(fieldName)) { + List resourceIds = reader.readArray(reader1 -> reader1.getString()); + deserializedExportResource.resourceIds = resourceIds; + } else if ("type".equals(fieldName)) { + deserializedExportResource.type = Type.fromString(reader.getString()); + } else if ("resourceName".equals(fieldName)) { + deserializedExportResource.resourceName = reader.getString(); + } else if ("resourceType".equals(fieldName)) { + deserializedExportResource.resourceType = reader.getString(); + } else if ("namePattern".equals(fieldName)) { + deserializedExportResource.namePattern = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedExportResource; + }); + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ExportResourceGroup.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ExportResourceGroup.java new file mode 100644 index 000000000000..33feaf9e3caf --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/ExportResourceGroup.java @@ -0,0 +1,184 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.util.logging.ClientLogger; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Export parameter for a resource group. + */ +@Fluent +public final class ExportResourceGroup extends BaseExportModel { + /* + * The parameter type + */ + private Type type = Type.EXPORT_RESOURCE_GROUP; + + /* + * The name of the resource group to be exported + */ + private String resourceGroupName; + + /* + * The name pattern of the Terraform resources + */ + private String namePattern; + + /** + * Creates an instance of ExportResourceGroup class. + */ + public ExportResourceGroup() { + } + + /** + * Get the type property: The parameter type. + * + * @return the type value. + */ + @Override + public Type type() { + return this.type; + } + + /** + * Get the resourceGroupName property: The name of the resource group to be exported. + * + * @return the resourceGroupName value. + */ + public String resourceGroupName() { + return this.resourceGroupName; + } + + /** + * Set the resourceGroupName property: The name of the resource group to be exported. + * + * @param resourceGroupName the resourceGroupName value to set. + * @return the ExportResourceGroup object itself. + */ + public ExportResourceGroup withResourceGroupName(String resourceGroupName) { + this.resourceGroupName = resourceGroupName; + return this; + } + + /** + * Get the namePattern property: The name pattern of the Terraform resources. + * + * @return the namePattern value. + */ + public String namePattern() { + return this.namePattern; + } + + /** + * Set the namePattern property: The name pattern of the Terraform resources. + * + * @param namePattern the namePattern value to set. + * @return the ExportResourceGroup object itself. + */ + public ExportResourceGroup withNamePattern(String namePattern) { + this.namePattern = namePattern; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public ExportResourceGroup withTargetProvider(TargetProvider targetProvider) { + super.withTargetProvider(targetProvider); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public ExportResourceGroup withFullProperties(Boolean fullProperties) { + super.withFullProperties(fullProperties); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public ExportResourceGroup withMaskSensitive(Boolean maskSensitive) { + super.withMaskSensitive(maskSensitive); + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + @Override + public void validate() { + if (resourceGroupName() == null) { + throw LOGGER.atError() + .log(new IllegalArgumentException( + "Missing required property resourceGroupName in model ExportResourceGroup")); + } + } + + private static final ClientLogger LOGGER = new ClientLogger(ExportResourceGroup.class); + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("targetProvider", targetProvider() == null ? null : targetProvider().toString()); + jsonWriter.writeBooleanField("fullProperties", fullProperties()); + jsonWriter.writeBooleanField("maskSensitive", maskSensitive()); + jsonWriter.writeStringField("resourceGroupName", this.resourceGroupName); + jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString()); + jsonWriter.writeStringField("namePattern", this.namePattern); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ExportResourceGroup from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ExportResourceGroup if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the ExportResourceGroup. + */ + public static ExportResourceGroup fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ExportResourceGroup deserializedExportResourceGroup = new ExportResourceGroup(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("targetProvider".equals(fieldName)) { + deserializedExportResourceGroup.withTargetProvider(TargetProvider.fromString(reader.getString())); + } else if ("fullProperties".equals(fieldName)) { + deserializedExportResourceGroup.withFullProperties(reader.getNullable(JsonReader::getBoolean)); + } else if ("maskSensitive".equals(fieldName)) { + deserializedExportResourceGroup.withMaskSensitive(reader.getNullable(JsonReader::getBoolean)); + } else if ("resourceGroupName".equals(fieldName)) { + deserializedExportResourceGroup.resourceGroupName = reader.getString(); + } else if ("type".equals(fieldName)) { + deserializedExportResourceGroup.type = Type.fromString(reader.getString()); + } else if ("namePattern".equals(fieldName)) { + deserializedExportResourceGroup.namePattern = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedExportResourceGroup; + }); + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Operation.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Operation.java new file mode 100644 index 000000000000..e5fd3caf173c --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Operation.java @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.models; + +import com.azure.resourcemanager.terraform.fluent.models.OperationInner; + +/** + * An immutable client-side representation of Operation. + */ +public interface Operation { + /** + * Gets the name property: The name of the operation, as per Resource-Based Access Control (RBAC). Examples: + * "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action". + * + * @return the name value. + */ + String name(); + + /** + * Gets the isDataAction property: Whether the operation applies to data-plane. This is "true" for data-plane + * operations and "false" for ARM/control-plane operations. + * + * @return the isDataAction value. + */ + Boolean isDataAction(); + + /** + * Gets the display property: Localized display information for this particular operation. + * + * @return the display value. + */ + OperationDisplay display(); + + /** + * Gets the origin property: The intended executor of the operation; as in Resource Based Access Control (RBAC) and + * audit logs UX. Default value is "user,system". + * + * @return the origin value. + */ + Origin origin(); + + /** + * Gets the actionType property: Enum. Indicates the action type. "Internal" refers to actions that are for internal + * only APIs. + * + * @return the actionType value. + */ + ActionType actionType(); + + /** + * Gets the inner com.azure.resourcemanager.terraform.fluent.models.OperationInner object. + * + * @return the inner object. + */ + OperationInner innerModel(); +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/OperationDisplay.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/OperationDisplay.java new file mode 100644 index 000000000000..a6a5161c653c --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/OperationDisplay.java @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.models; + +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Localized display information for this particular operation. + */ +@Immutable +public final class OperationDisplay implements JsonSerializable { + /* + * The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring Insights" or + * "Microsoft Compute". + */ + private String provider; + + /* + * The localized friendly name of the resource type related to this operation. E.g. "Virtual Machines" or + * "Job Schedule Collections". + */ + private String resource; + + /* + * The concise, localized friendly name for the operation; suitable for dropdowns. E.g. + * "Create or Update Virtual Machine", "Restart Virtual Machine". + */ + private String operation; + + /* + * The short, localized friendly description of the operation; suitable for tool tips and detailed views. + */ + private String description; + + /** + * Creates an instance of OperationDisplay class. + */ + public OperationDisplay() { + } + + /** + * Get the provider property: The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring + * Insights" or "Microsoft Compute". + * + * @return the provider value. + */ + public String provider() { + return this.provider; + } + + /** + * Get the resource property: The localized friendly name of the resource type related to this operation. E.g. + * "Virtual Machines" or "Job Schedule Collections". + * + * @return the resource value. + */ + public String resource() { + return this.resource; + } + + /** + * Get the operation property: The concise, localized friendly name for the operation; suitable for dropdowns. E.g. + * "Create or Update Virtual Machine", "Restart Virtual Machine". + * + * @return the operation value. + */ + public String operation() { + return this.operation; + } + + /** + * Get the description property: The short, localized friendly description of the operation; suitable for tool tips + * and detailed views. + * + * @return the description value. + */ + public String description() { + return this.description; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of OperationDisplay from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of OperationDisplay if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IOException If an error occurs while reading the OperationDisplay. + */ + public static OperationDisplay fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + OperationDisplay deserializedOperationDisplay = new OperationDisplay(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("provider".equals(fieldName)) { + deserializedOperationDisplay.provider = reader.getString(); + } else if ("resource".equals(fieldName)) { + deserializedOperationDisplay.resource = reader.getString(); + } else if ("operation".equals(fieldName)) { + deserializedOperationDisplay.operation = reader.getString(); + } else if ("description".equals(fieldName)) { + deserializedOperationDisplay.description = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedOperationDisplay; + }); + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/OperationListResult.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/OperationListResult.java new file mode 100644 index 000000000000..22bfbc8f9186 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/OperationListResult.java @@ -0,0 +1,104 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.models; + +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import com.azure.resourcemanager.terraform.fluent.models.OperationInner; +import java.io.IOException; +import java.util.List; + +/** + * A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to get the next set of + * results. + */ +@Immutable +public final class OperationListResult implements JsonSerializable { + /* + * List of operations supported by the resource provider + */ + private List value; + + /* + * URL to get the next set of operation list results (if there are any). + */ + private String nextLink; + + /** + * Creates an instance of OperationListResult class. + */ + public OperationListResult() { + } + + /** + * Get the value property: List of operations supported by the resource provider. + * + * @return the value value. + */ + public List value() { + return this.value; + } + + /** + * Get the nextLink property: URL to get the next set of operation list results (if there are any). + * + * @return the nextLink value. + */ + public String nextLink() { + return this.nextLink; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + if (value() != null) { + value().forEach(e -> e.validate()); + } + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of OperationListResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of OperationListResult if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IOException If an error occurs while reading the OperationListResult. + */ + public static OperationListResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + OperationListResult deserializedOperationListResult = new OperationListResult(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + List value = reader.readArray(reader1 -> OperationInner.fromJson(reader1)); + deserializedOperationListResult.value = value; + } else if ("nextLink".equals(fieldName)) { + deserializedOperationListResult.nextLink = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedOperationListResult; + }); + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Operations.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Operations.java new file mode 100644 index 000000000000..f4763428997f --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Operations.java @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.models; + +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.util.Context; + +/** + * Resource collection API of Operations. + */ +public interface Operations { + /** + * List the operations for the provider. + * + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + PagedIterable list(); + + /** + * List the operations for the provider. + * + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + PagedIterable list(Context context); +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Origin.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Origin.java new file mode 100644 index 000000000000..14988acf9352 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Origin.java @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value + * is "user,system". + */ +public final class Origin extends ExpandableStringEnum { + /** + * Static value user for Origin. + */ + public static final Origin USER = fromString("user"); + + /** + * Static value system for Origin. + */ + public static final Origin SYSTEM = fromString("system"); + + /** + * Static value user,system for Origin. + */ + public static final Origin USER_SYSTEM = fromString("user,system"); + + /** + * Creates a new instance of Origin value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public Origin() { + } + + /** + * Creates or finds a Origin from its string representation. + * + * @param name a name to look for. + * @return the corresponding Origin. + */ + public static Origin fromString(String name) { + return fromString(name, Origin.class); + } + + /** + * Gets known Origin values. + * + * @return known Origin values. + */ + public static Collection values() { + return values(Origin.class); + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/TargetProvider.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/TargetProvider.java new file mode 100644 index 000000000000..168558590999 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/TargetProvider.java @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * The target Azure Terraform Provider. + */ +public final class TargetProvider extends ExpandableStringEnum { + /** + * Static value azurerm for TargetProvider. + */ + public static final TargetProvider AZURERM = fromString("azurerm"); + + /** + * Static value azapi for TargetProvider. + */ + public static final TargetProvider AZAPI = fromString("azapi"); + + /** + * Creates a new instance of TargetProvider value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public TargetProvider() { + } + + /** + * Creates or finds a TargetProvider from its string representation. + * + * @param name a name to look for. + * @return the corresponding TargetProvider. + */ + public static TargetProvider fromString(String name) { + return fromString(name, TargetProvider.class); + } + + /** + * Gets known TargetProvider values. + * + * @return known TargetProvider values. + */ + public static Collection values() { + return values(TargetProvider.class); + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Terraforms.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Terraforms.java new file mode 100644 index 000000000000..19c10ac580dc --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Terraforms.java @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.models; + +import com.azure.core.util.Context; + +/** + * Resource collection API of Terraforms. + */ +public interface Terraforms { + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + void exportTerraform(BaseExportModel body); + + /** + * Exports the Terraform configuration of the specified resource(s). + * + * @param body The request body. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + void exportTerraform(BaseExportModel body, Context context); +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Type.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Type.java new file mode 100644 index 000000000000..00c5e0893e2e --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/Type.java @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * The parameter type. + */ +public final class Type extends ExpandableStringEnum { + /** + * Static value ExportResource for Type. + */ + public static final Type EXPORT_RESOURCE = fromString("ExportResource"); + + /** + * Static value ExportResourceGroup for Type. + */ + public static final Type EXPORT_RESOURCE_GROUP = fromString("ExportResourceGroup"); + + /** + * Static value ExportQuery for Type. + */ + public static final Type EXPORT_QUERY = fromString("ExportQuery"); + + /** + * Creates a new instance of Type value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public Type() { + } + + /** + * Creates or finds a Type from its string representation. + * + * @param name a name to look for. + * @return the corresponding Type. + */ + public static Type fromString(String name) { + return fromString(name, Type.class); + } + + /** + * Gets known Type values. + * + * @return known Type values. + */ + public static Collection values() { + return values(Type.class); + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/package-info.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/package-info.java new file mode 100644 index 000000000000..3c41ba14d92e --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/models/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** + * Package containing the data models for AzureTerraformManagementClient. + * AzureTerraform Client. + */ +package com.azure.resourcemanager.terraform.models; diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/package-info.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/package-info.java new file mode 100644 index 000000000000..f69b31c596db --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/com/azure/resourcemanager/terraform/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** + * Package containing the classes for AzureTerraformManagementClient. + * AzureTerraform Client. + */ +package com.azure.resourcemanager.terraform; diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/java/module-info.java b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/module-info.java new file mode 100644 index 000000000000..1d3d8ef8d271 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/java/module-info.java @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +module com.azure.resourcemanager.terraform { + requires transitive com.azure.core.management; + + exports com.azure.resourcemanager.terraform; + exports com.azure.resourcemanager.terraform.fluent; + exports com.azure.resourcemanager.terraform.fluent.models; + exports com.azure.resourcemanager.terraform.models; + + opens com.azure.resourcemanager.terraform.fluent.models to com.azure.core; + opens com.azure.resourcemanager.terraform.models to com.azure.core; +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-terraform/proxy-config.json b/sdk/terraform/azure-resourcemanager-terraform/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-terraform/proxy-config.json new file mode 100644 index 000000000000..0790a839ed52 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-terraform/proxy-config.json @@ -0,0 +1 @@ +[["com.azure.resourcemanager.terraform.implementation.OperationsClientImpl$OperationsService"],["com.azure.resourcemanager.terraform.implementation.TerraformsClientImpl$TerraformsService"]] \ No newline at end of file diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-terraform/reflect-config.json b/sdk/terraform/azure-resourcemanager-terraform/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-terraform/reflect-config.json new file mode 100644 index 000000000000..0637a088a01e --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-terraform/reflect-config.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/samples/java/com/azure/resourcemanager/terraform/generated/OperationsListSamples.java b/sdk/terraform/azure-resourcemanager-terraform/src/samples/java/com/azure/resourcemanager/terraform/generated/OperationsListSamples.java new file mode 100644 index 000000000000..caf715fd6395 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/samples/java/com/azure/resourcemanager/terraform/generated/OperationsListSamples.java @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.generated; + +/** + * Samples for Operations List. + */ +public final class OperationsListSamples { + /* + * x-ms-original-file: + * specification/terraform/resource-manager/Microsoft.AzureTerraform/preview/2023-07-01-preview/examples/ + * ListOperations.json + */ + /** + * Sample code: Get a list of operations for a resource provider. + * + * @param manager Entry point to AzureTerraformManager. + */ + public static void + getAListOfOperationsForAResourceProvider(com.azure.resourcemanager.terraform.AzureTerraformManager manager) { + manager.operations().list(com.azure.core.util.Context.NONE); + } +} diff --git a/sdk/terraform/azure-resourcemanager-terraform/src/samples/java/com/azure/resourcemanager/terraform/generated/TerraformExportTerraformSamples.java b/sdk/terraform/azure-resourcemanager-terraform/src/samples/java/com/azure/resourcemanager/terraform/generated/TerraformExportTerraformSamples.java new file mode 100644 index 000000000000..29109feedbb6 --- /dev/null +++ b/sdk/terraform/azure-resourcemanager-terraform/src/samples/java/com/azure/resourcemanager/terraform/generated/TerraformExportTerraformSamples.java @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.resourcemanager.terraform.generated; + +import com.azure.resourcemanager.terraform.models.ExportResourceGroup; + +/** + * Samples for Terraform ExportTerraform. + */ +public final class TerraformExportTerraformSamples { + /* + * x-ms-original-file: + * specification/terraform/resource-manager/Microsoft.AzureTerraform/preview/2023-07-01-preview/examples/ + * ExportTerraform.json + */ + /** + * Sample code: ExportTerraform. + * + * @param manager Entry point to AzureTerraformManager. + */ + public static void exportTerraform(com.azure.resourcemanager.terraform.AzureTerraformManager manager) { + manager.terraforms() + .exportTerraform(new ExportResourceGroup().withResourceGroupName("rg1"), com.azure.core.util.Context.NONE); + } +} diff --git a/sdk/terraform/ci.yml b/sdk/terraform/ci.yml new file mode 100644 index 000000000000..fcb7855a2dc8 --- /dev/null +++ b/sdk/terraform/ci.yml @@ -0,0 +1,46 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. + +trigger: + branches: + include: + - main + - hotfix/* + - release/* + paths: + include: + - sdk/terraform/ci.yml + - sdk/terraform/azure-resourcemanager-terraform/ + exclude: + - sdk/terraform/pom.xml + - sdk/terraform/azure-resourcemanager-terraform/pom.xml + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/terraform/ci.yml + - sdk/terraform/azure-resourcemanager-terraform/ + exclude: + - sdk/terraform/pom.xml + - sdk/terraform/azure-resourcemanager-terraform/pom.xml + +parameters: + - name: release_azureresourcemanagerterraform + displayName: azure-resourcemanager-terraform + type: boolean + default: false + +extends: + template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml + parameters: + ServiceDirectory: terraform + Artifacts: + - name: azure-resourcemanager-terraform + groupId: com.azure.resourcemanager + safeName: azureresourcemanagerterraform + releaseInBatch: ${{ parameters.release_azureresourcemanagerterraform }} diff --git a/sdk/terraform/pom.xml b/sdk/terraform/pom.xml new file mode 100644 index 000000000000..87c4380d39f7 --- /dev/null +++ b/sdk/terraform/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + com.azure + azure-terraform-service + pom + 1.0.0 + + + azure-resourcemanager-terraform + +