diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/CHANGELOG.md b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/CHANGELOG.md new file mode 100644 index 000000000000..ae935589fb7f --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/CHANGELOG.md @@ -0,0 +1,7 @@ +# Release History + +## 0.1.0 (2024-02-22) + +The package of `github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/hybridonboarding/armhybridonboarding` is using our [next generation design principles](https://azure.github.io/azure-sdk/general_introduction.html). + +To learn more, please refer to our documentation [Quick Start](https://aka.ms/azsdk/go/mgmt). \ No newline at end of file diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/LICENSE.txt b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/LICENSE.txt new file mode 100644 index 000000000000..dc0c2ffb3dc1 --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Microsoft Corporation. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/README.md b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/README.md new file mode 100644 index 000000000000..231f9e920eca --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/README.md @@ -0,0 +1,92 @@ +# Azure Hybridonboarding Module for Go + +[![PkgGoDev](https://pkg.go.dev/badge/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/hybridonboarding/armhybridonboarding)](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/hybridonboarding/armhybridonboarding) + +The `armhybridonboarding` module provides operations for working with Azure Hybridonboarding. + +[Source code](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/resourcemanager/hybridonboarding/armhybridonboarding) + +# Getting started + +## Prerequisites + +- an [Azure subscription](https://azure.microsoft.com/free/) +- Go 1.18 or above (You could download and install the latest version of Go from [here](https://go.dev/doc/install). It will replace the existing Go on your machine. If you want to install multiple Go versions on the same machine, you could refer this [doc](https://go.dev/doc/manage-install).) + +## Install the package + +This project uses [Go modules](https://github.com/golang/go/wiki/Modules) for versioning and dependency management. + +Install the Azure Hybridonboarding module: + +```sh +go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/hybridonboarding/armhybridonboarding +``` + +## Authorization + +When creating a client, you will need to provide a credential for authenticating with Azure Hybridonboarding. The `azidentity` module provides facilities for various ways of authenticating with Azure including client/secret, certificate, managed identity, and more. + +```go +cred, err := azidentity.NewDefaultAzureCredential(nil) +``` + +For more information on authentication, please see the documentation for `azidentity` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity). + +## Client Factory + +Azure Hybridonboarding module consists of one or more clients. We provide a client factory which could be used to create any client in this module. + +```go +clientFactory, err := armhybridonboarding.NewClientFactory(, cred, nil) +``` + +You can use `ClientOptions` in package `github.com/Azure/azure-sdk-for-go/sdk/azcore/arm` to set endpoint to connect with public and sovereign clouds as well as Azure Stack. For more information, please see the documentation for `azcore` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore). + +```go +options := arm.ClientOptions { + ClientOptions: azcore.ClientOptions { + Cloud: cloud.AzureChina, + }, +} +clientFactory, err := armhybridonboarding.NewClientFactory(, cred, &options) +``` + +## Clients + +A client groups a set of related APIs, providing access to its functionality. Create one or more clients to access the APIs you require using client factory. + +```go +client := clientFactory.NewExtensionManagersClient() +``` + +## Fakes + +The fake package contains types used for constructing in-memory fake servers used in unit tests. +This allows writing tests to cover various success/error conditions without the need for connecting to a live service. + +Please see https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/samples/fakes for details and examples on how to use fakes. + +## Provide Feedback + +If you encounter bugs or have suggestions, please +[open an issue](https://github.com/Azure/azure-sdk-for-go/issues) and assign the `Hybridonboarding` label. + +# Contributing + +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 [https://cla.microsoft.com](https://cla.microsoft.com). + +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 repos using our CLA. + +This project has adopted the +[Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information, see the +[Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) +or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any +additional questions or comments. \ No newline at end of file diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/autorest.md b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/autorest.md new file mode 100644 index 000000000000..8cb33d441f1e --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/autorest.md @@ -0,0 +1,13 @@ +### AutoRest Configuration + +> see https://aka.ms/autorest + +``` yaml +azure-arm: true +require: +- /mnt/vss/_work/1/s/azure-rest-api-specs/specification/hybridonboarding/resource-manager/readme.md +- /mnt/vss/_work/1/s/azure-rest-api-specs/specification/hybridonboarding/resource-manager/readme.go.md +license-header: MICROSOFT_MIT_NO_VERSION +module-version: 0.1.0 + +``` \ No newline at end of file diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/build.go b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/build.go new file mode 100644 index 000000000000..86d1feb57b4e --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/build.go @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +// This file enables 'go generate' to regenerate this specific SDK +//go:generate pwsh ../../../../eng/scripts/build.ps1 -skipBuild -cleanGenerated -format -tidy -generate -alwaysSetBodyParamRequired -removeUnreferencedTypes resourcemanager/hybridonboarding/armhybridonboarding + +package armhybridonboarding diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/ci.yml b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/ci.yml new file mode 100644 index 000000000000..2f9b8c35403f --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/ci.yml @@ -0,0 +1,28 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. +trigger: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/hybridonboarding/armhybridonboarding/ + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/hybridonboarding/armhybridonboarding/ + +stages: +- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml + parameters: + IncludeRelease: true + ServiceDirectory: 'resourcemanager/hybridonboarding/armhybridonboarding' diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/client_factory.go b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/client_factory.go new file mode 100644 index 000000000000..c68b707961e6 --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/client_factory.go @@ -0,0 +1,52 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armhybridonboarding + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" +) + +// ClientFactory is a client factory used to create any client in this module. +// Don't use this type directly, use NewClientFactory instead. +type ClientFactory struct { + subscriptionID string + internal *arm.Client +} + +// NewClientFactory creates a new instance of ClientFactory with the specified values. +// The parameter values will be propagated to any client created from this factory. +// - subscriptionID - The ID of the target subscription. The value must be an UUID. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ClientFactory, error) { + internal, err := arm.NewClient(moduleName, moduleVersion, credential, options) + if err != nil { + return nil, err + } + return &ClientFactory{ + subscriptionID: subscriptionID, + internal: internal, + }, nil +} + +// NewExtensionManagersClient creates a new instance of ExtensionManagersClient. +func (c *ClientFactory) NewExtensionManagersClient() *ExtensionManagersClient { + return &ExtensionManagersClient{ + subscriptionID: c.subscriptionID, + internal: c.internal, + } +} + +// NewOperationsClient creates a new instance of OperationsClient. +func (c *ClientFactory) NewOperationsClient() *OperationsClient { + return &OperationsClient{ + internal: c.internal, + } +} diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/constants.go b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/constants.go new file mode 100644 index 000000000000..dd1641cdb97c --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/constants.go @@ -0,0 +1,100 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armhybridonboarding + +const ( + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/hybridonboarding/armhybridonboarding" + moduleVersion = "v0.1.0" +) + +// ActionType - Enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. +type ActionType string + +const ( + ActionTypeInternal ActionType = "Internal" +) + +// PossibleActionTypeValues returns the possible values for the ActionType const type. +func PossibleActionTypeValues() []ActionType { + return []ActionType{ + ActionTypeInternal, + } +} + +// CreatedByType - The type of identity that created the resource. +type CreatedByType string + +const ( + CreatedByTypeApplication CreatedByType = "Application" + CreatedByTypeKey CreatedByType = "Key" + CreatedByTypeManagedIdentity CreatedByType = "ManagedIdentity" + CreatedByTypeUser CreatedByType = "User" +) + +// PossibleCreatedByTypeValues returns the possible values for the CreatedByType const type. +func PossibleCreatedByTypeValues() []CreatedByType { + return []CreatedByType{ + CreatedByTypeApplication, + CreatedByTypeKey, + CreatedByTypeManagedIdentity, + CreatedByTypeUser, + } +} + +// Origin - The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default +// value is "user,system" +type Origin string + +const ( + OriginSystem Origin = "system" + OriginUser Origin = "user" + OriginUserSystem Origin = "user,system" +) + +// PossibleOriginValues returns the possible values for the Origin const type. +func PossibleOriginValues() []Origin { + return []Origin{ + OriginSystem, + OriginUser, + OriginUserSystem, + } +} + +// ProvisioningState - Provisioning state of the resource +type ProvisioningState string + +const ( + // ProvisioningStateAccepted - accepted provisioning state + ProvisioningStateAccepted ProvisioningState = "Accepted" + // ProvisioningStateCanceled - Resource creation was canceled. + ProvisioningStateCanceled ProvisioningState = "Canceled" + // ProvisioningStateCreating - creating provisioning state + ProvisioningStateCreating ProvisioningState = "Creating" + // ProvisioningStateDeleting - deleting provisioning state + ProvisioningStateDeleting ProvisioningState = "Deleting" + // ProvisioningStateFailed - Resource creation failed. + ProvisioningStateFailed ProvisioningState = "Failed" + // ProvisioningStateSucceeded - Resource has been created. + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + // ProvisioningStateUpdating - updating provisioning state + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +// PossibleProvisioningStateValues returns the possible values for the ProvisioningState const type. +func PossibleProvisioningStateValues() []ProvisioningState { + return []ProvisioningState{ + ProvisioningStateAccepted, + ProvisioningStateCanceled, + ProvisioningStateCreating, + ProvisioningStateDeleting, + ProvisioningStateFailed, + ProvisioningStateSucceeded, + ProvisioningStateUpdating, + } +} diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/extensionmanagers_client.go b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/extensionmanagers_client.go new file mode 100644 index 000000000000..26d2cd014846 --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/extensionmanagers_client.go @@ -0,0 +1,786 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armhybridonboarding + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strings" +) + +// ExtensionManagersClient contains the methods for the ExtensionManagers group. +// Don't use this type directly, use NewExtensionManagersClient() instead. +type ExtensionManagersClient struct { + internal *arm.Client + subscriptionID string +} + +// NewExtensionManagersClient creates a new instance of ExtensionManagersClient with the specified values. +// - subscriptionID - The ID of the target subscription. The value must be an UUID. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewExtensionManagersClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ExtensionManagersClient, error) { + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &ExtensionManagersClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// BeginAddNewFabric - Add new fabric/infra/scenario on the extension manager resource +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-06-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - extensionManagerName - Extension Manager resource +// - body - The content of the action request +// - options - ExtensionManagersClientBeginAddNewFabricOptions contains the optional parameters for the ExtensionManagersClient.BeginAddNewFabric +// method. +func (client *ExtensionManagersClient) BeginAddNewFabric(ctx context.Context, resourceGroupName string, extensionManagerName string, body AddFabricRequestDetails, options *ExtensionManagersClientBeginAddNewFabricOptions) (*runtime.Poller[ExtensionManagersClientAddNewFabricResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.addNewFabric(ctx, resourceGroupName, extensionManagerName, body, options) + if err != nil { + return nil, err + } + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExtensionManagersClientAddNewFabricResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + Tracer: client.internal.Tracer(), + }) + return poller, err + } else { + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ExtensionManagersClientAddNewFabricResponse]{ + Tracer: client.internal.Tracer(), + }) + } +} + +// AddNewFabric - Add new fabric/infra/scenario on the extension manager resource +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-06-01-preview +func (client *ExtensionManagersClient) addNewFabric(ctx context.Context, resourceGroupName string, extensionManagerName string, body AddFabricRequestDetails, options *ExtensionManagersClientBeginAddNewFabricOptions) (*http.Response, error) { + var err error + const operationName = "ExtensionManagersClient.BeginAddNewFabric" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.addNewFabricCreateRequest(ctx, resourceGroupName, extensionManagerName, body, options) + if err != nil { + return nil, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err + } + return httpResp, nil +} + +// addNewFabricCreateRequest creates the AddNewFabric request. +func (client *ExtensionManagersClient) addNewFabricCreateRequest(ctx context.Context, resourceGroupName string, extensionManagerName string, body AddFabricRequestDetails, options *ExtensionManagersClientBeginAddNewFabricOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridOnboarding/extensionManagers/{extensionManagerName}/addNewFabric" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if extensionManagerName == "" { + return nil, errors.New("parameter extensionManagerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{extensionManagerName}", url.PathEscape(extensionManagerName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-06-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + if err := runtime.MarshalAsJSON(req, body); err != nil { + return nil, err + } + return req, nil +} + +// BeginCreateOrUpdate - Create a ExtensionManager +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-06-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - extensionManagerName - Extension Manager resource +// - resource - Resource create parameters. +// - options - ExtensionManagersClientBeginCreateOrUpdateOptions contains the optional parameters for the ExtensionManagersClient.BeginCreateOrUpdate +// method. +func (client *ExtensionManagersClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, extensionManagerName string, resource ExtensionManager, options *ExtensionManagersClientBeginCreateOrUpdateOptions) (*runtime.Poller[ExtensionManagersClientCreateOrUpdateResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.createOrUpdate(ctx, resourceGroupName, extensionManagerName, resource, options) + if err != nil { + return nil, err + } + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExtensionManagersClientCreateOrUpdateResponse]{ + FinalStateVia: runtime.FinalStateViaAzureAsyncOp, + Tracer: client.internal.Tracer(), + }) + return poller, err + } else { + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ExtensionManagersClientCreateOrUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) + } +} + +// CreateOrUpdate - Create a ExtensionManager +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-06-01-preview +func (client *ExtensionManagersClient) createOrUpdate(ctx context.Context, resourceGroupName string, extensionManagerName string, resource ExtensionManager, options *ExtensionManagersClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ExtensionManagersClient.BeginCreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, extensionManagerName, resource, options) + if err != nil { + return nil, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return nil, err + } + return httpResp, nil +} + +// createOrUpdateCreateRequest creates the CreateOrUpdate request. +func (client *ExtensionManagersClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, extensionManagerName string, resource ExtensionManager, options *ExtensionManagersClientBeginCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridOnboarding/extensionManagers/{extensionManagerName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if extensionManagerName == "" { + return nil, errors.New("parameter extensionManagerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{extensionManagerName}", url.PathEscape(extensionManagerName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-06-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + if err := runtime.MarshalAsJSON(req, resource); err != nil { + return nil, err + } + return req, nil +} + +// BeginDelete - Delete a ExtensionManager +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-06-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - extensionManagerName - Extension Manager resource +// - options - ExtensionManagersClientBeginDeleteOptions contains the optional parameters for the ExtensionManagersClient.BeginDelete +// method. +func (client *ExtensionManagersClient) BeginDelete(ctx context.Context, resourceGroupName string, extensionManagerName string, options *ExtensionManagersClientBeginDeleteOptions) (*runtime.Poller[ExtensionManagersClientDeleteResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.deleteOperation(ctx, resourceGroupName, extensionManagerName, options) + if err != nil { + return nil, err + } + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExtensionManagersClientDeleteResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + Tracer: client.internal.Tracer(), + }) + return poller, err + } else { + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ExtensionManagersClientDeleteResponse]{ + Tracer: client.internal.Tracer(), + }) + } +} + +// Delete - Delete a ExtensionManager +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-06-01-preview +func (client *ExtensionManagersClient) deleteOperation(ctx context.Context, resourceGroupName string, extensionManagerName string, options *ExtensionManagersClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ExtensionManagersClient.BeginDelete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.deleteCreateRequest(ctx, resourceGroupName, extensionManagerName, options) + if err != nil { + return nil, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err + } + return httpResp, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *ExtensionManagersClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, extensionManagerName string, options *ExtensionManagersClientBeginDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridOnboarding/extensionManagers/{extensionManagerName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if extensionManagerName == "" { + return nil, errors.New("parameter extensionManagerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{extensionManagerName}", url.PathEscape(extensionManagerName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-06-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// BeginDisableExtensions - Disable extensions on the extension manager resource +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-06-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - extensionManagerName - Extension Manager resource +// - body - The content of the action request +// - options - ExtensionManagersClientBeginDisableExtensionsOptions contains the optional parameters for the ExtensionManagersClient.BeginDisableExtensions +// method. +func (client *ExtensionManagersClient) BeginDisableExtensions(ctx context.Context, resourceGroupName string, extensionManagerName string, body []*DisableExtensionsRequestDetails, options *ExtensionManagersClientBeginDisableExtensionsOptions) (*runtime.Poller[ExtensionManagersClientDisableExtensionsResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.disableExtensions(ctx, resourceGroupName, extensionManagerName, body, options) + if err != nil { + return nil, err + } + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExtensionManagersClientDisableExtensionsResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + Tracer: client.internal.Tracer(), + }) + return poller, err + } else { + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ExtensionManagersClientDisableExtensionsResponse]{ + Tracer: client.internal.Tracer(), + }) + } +} + +// DisableExtensions - Disable extensions on the extension manager resource +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-06-01-preview +func (client *ExtensionManagersClient) disableExtensions(ctx context.Context, resourceGroupName string, extensionManagerName string, body []*DisableExtensionsRequestDetails, options *ExtensionManagersClientBeginDisableExtensionsOptions) (*http.Response, error) { + var err error + const operationName = "ExtensionManagersClient.BeginDisableExtensions" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.disableExtensionsCreateRequest(ctx, resourceGroupName, extensionManagerName, body, options) + if err != nil { + return nil, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err + } + return httpResp, nil +} + +// disableExtensionsCreateRequest creates the DisableExtensions request. +func (client *ExtensionManagersClient) disableExtensionsCreateRequest(ctx context.Context, resourceGroupName string, extensionManagerName string, body []*DisableExtensionsRequestDetails, options *ExtensionManagersClientBeginDisableExtensionsOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridOnboarding/extensionManagers/{extensionManagerName}/disableExtensions" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if extensionManagerName == "" { + return nil, errors.New("parameter extensionManagerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{extensionManagerName}", url.PathEscape(extensionManagerName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-06-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + if err := runtime.MarshalAsJSON(req, body); err != nil { + return nil, err + } + return req, nil +} + +// BeginEnableExtensions - Enable extensions on the extension manager resource +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-06-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - extensionManagerName - Extension Manager resource +// - body - The content of the action request +// - options - ExtensionManagersClientBeginEnableExtensionsOptions contains the optional parameters for the ExtensionManagersClient.BeginEnableExtensions +// method. +func (client *ExtensionManagersClient) BeginEnableExtensions(ctx context.Context, resourceGroupName string, extensionManagerName string, body []*EnableExtensionsRequestDetails, options *ExtensionManagersClientBeginEnableExtensionsOptions) (*runtime.Poller[ExtensionManagersClientEnableExtensionsResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.enableExtensions(ctx, resourceGroupName, extensionManagerName, body, options) + if err != nil { + return nil, err + } + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExtensionManagersClientEnableExtensionsResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + Tracer: client.internal.Tracer(), + }) + return poller, err + } else { + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ExtensionManagersClientEnableExtensionsResponse]{ + Tracer: client.internal.Tracer(), + }) + } +} + +// EnableExtensions - Enable extensions on the extension manager resource +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-06-01-preview +func (client *ExtensionManagersClient) enableExtensions(ctx context.Context, resourceGroupName string, extensionManagerName string, body []*EnableExtensionsRequestDetails, options *ExtensionManagersClientBeginEnableExtensionsOptions) (*http.Response, error) { + var err error + const operationName = "ExtensionManagersClient.BeginEnableExtensions" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.enableExtensionsCreateRequest(ctx, resourceGroupName, extensionManagerName, body, options) + if err != nil { + return nil, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err + } + return httpResp, nil +} + +// enableExtensionsCreateRequest creates the EnableExtensions request. +func (client *ExtensionManagersClient) enableExtensionsCreateRequest(ctx context.Context, resourceGroupName string, extensionManagerName string, body []*EnableExtensionsRequestDetails, options *ExtensionManagersClientBeginEnableExtensionsOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridOnboarding/extensionManagers/{extensionManagerName}/enableExtensions" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if extensionManagerName == "" { + return nil, errors.New("parameter extensionManagerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{extensionManagerName}", url.PathEscape(extensionManagerName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-06-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + if err := runtime.MarshalAsJSON(req, body); err != nil { + return nil, err + } + return req, nil +} + +// Get - Get a ExtensionManager +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-06-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - extensionManagerName - Extension Manager resource +// - options - ExtensionManagersClientGetOptions contains the optional parameters for the ExtensionManagersClient.Get method. +func (client *ExtensionManagersClient) Get(ctx context.Context, resourceGroupName string, extensionManagerName string, options *ExtensionManagersClientGetOptions) (ExtensionManagersClientGetResponse, error) { + var err error + const operationName = "ExtensionManagersClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.getCreateRequest(ctx, resourceGroupName, extensionManagerName, options) + if err != nil { + return ExtensionManagersClientGetResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ExtensionManagersClientGetResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ExtensionManagersClientGetResponse{}, err + } + resp, err := client.getHandleResponse(httpResp) + return resp, err +} + +// getCreateRequest creates the Get request. +func (client *ExtensionManagersClient) getCreateRequest(ctx context.Context, resourceGroupName string, extensionManagerName string, options *ExtensionManagersClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridOnboarding/extensionManagers/{extensionManagerName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if extensionManagerName == "" { + return nil, errors.New("parameter extensionManagerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{extensionManagerName}", url.PathEscape(extensionManagerName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-06-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *ExtensionManagersClient) getHandleResponse(resp *http.Response) (ExtensionManagersClientGetResponse, error) { + result := ExtensionManagersClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.ExtensionManager); err != nil { + return ExtensionManagersClientGetResponse{}, err + } + return result, nil +} + +// NewListByResourceGroupPager - List ExtensionManager resources by resource group +// +// Generated from API version 2024-06-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - options - ExtensionManagersClientListByResourceGroupOptions contains the optional parameters for the ExtensionManagersClient.NewListByResourceGroupPager +// method. +func (client *ExtensionManagersClient) NewListByResourceGroupPager(resourceGroupName string, options *ExtensionManagersClientListByResourceGroupOptions) *runtime.Pager[ExtensionManagersClientListByResourceGroupResponse] { + return runtime.NewPager(runtime.PagingHandler[ExtensionManagersClientListByResourceGroupResponse]{ + More: func(page ExtensionManagersClientListByResourceGroupResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *ExtensionManagersClientListByResourceGroupResponse) (ExtensionManagersClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExtensionManagersClient.NewListByResourceGroupPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink + } + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) + }, nil) + if err != nil { + return ExtensionManagersClientListByResourceGroupResponse{}, err + } + return client.listByResourceGroupHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listByResourceGroupCreateRequest creates the ListByResourceGroup request. +func (client *ExtensionManagersClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, options *ExtensionManagersClientListByResourceGroupOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridOnboarding/extensionManagers" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-06-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listByResourceGroupHandleResponse handles the ListByResourceGroup response. +func (client *ExtensionManagersClient) listByResourceGroupHandleResponse(resp *http.Response) (ExtensionManagersClientListByResourceGroupResponse, error) { + result := ExtensionManagersClientListByResourceGroupResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.ExtensionManagerListResult); err != nil { + return ExtensionManagersClientListByResourceGroupResponse{}, err + } + return result, nil +} + +// NewListBySubscriptionPager - List ExtensionManager resources by subscription ID +// +// Generated from API version 2024-06-01-preview +// - options - ExtensionManagersClientListBySubscriptionOptions contains the optional parameters for the ExtensionManagersClient.NewListBySubscriptionPager +// method. +func (client *ExtensionManagersClient) NewListBySubscriptionPager(options *ExtensionManagersClientListBySubscriptionOptions) *runtime.Pager[ExtensionManagersClientListBySubscriptionResponse] { + return runtime.NewPager(runtime.PagingHandler[ExtensionManagersClientListBySubscriptionResponse]{ + More: func(page ExtensionManagersClientListBySubscriptionResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *ExtensionManagersClientListBySubscriptionResponse) (ExtensionManagersClientListBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExtensionManagersClient.NewListBySubscriptionPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink + } + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listBySubscriptionCreateRequest(ctx, options) + }, nil) + if err != nil { + return ExtensionManagersClientListBySubscriptionResponse{}, err + } + return client.listBySubscriptionHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listBySubscriptionCreateRequest creates the ListBySubscription request. +func (client *ExtensionManagersClient) listBySubscriptionCreateRequest(ctx context.Context, options *ExtensionManagersClientListBySubscriptionOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.HybridOnboarding/extensionManagers" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-06-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listBySubscriptionHandleResponse handles the ListBySubscription response. +func (client *ExtensionManagersClient) listBySubscriptionHandleResponse(resp *http.Response) (ExtensionManagersClientListBySubscriptionResponse, error) { + result := ExtensionManagersClientListBySubscriptionResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.ExtensionManagerListResult); err != nil { + return ExtensionManagersClientListBySubscriptionResponse{}, err + } + return result, nil +} + +// BeginRemoveInfraAndScenario - Remove a fabric/infra/scenario on the extension manager resource +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-06-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - extensionManagerName - Extension Manager resource +// - body - The content of the action request +// - options - ExtensionManagersClientBeginRemoveInfraAndScenarioOptions contains the optional parameters for the ExtensionManagersClient.BeginRemoveInfraAndScenario +// method. +func (client *ExtensionManagersClient) BeginRemoveInfraAndScenario(ctx context.Context, resourceGroupName string, extensionManagerName string, body RemoveInfraAndScenarioDetails, options *ExtensionManagersClientBeginRemoveInfraAndScenarioOptions) (*runtime.Poller[ExtensionManagersClientRemoveInfraAndScenarioResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.removeInfraAndScenario(ctx, resourceGroupName, extensionManagerName, body, options) + if err != nil { + return nil, err + } + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExtensionManagersClientRemoveInfraAndScenarioResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + Tracer: client.internal.Tracer(), + }) + return poller, err + } else { + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ExtensionManagersClientRemoveInfraAndScenarioResponse]{ + Tracer: client.internal.Tracer(), + }) + } +} + +// RemoveInfraAndScenario - Remove a fabric/infra/scenario on the extension manager resource +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-06-01-preview +func (client *ExtensionManagersClient) removeInfraAndScenario(ctx context.Context, resourceGroupName string, extensionManagerName string, body RemoveInfraAndScenarioDetails, options *ExtensionManagersClientBeginRemoveInfraAndScenarioOptions) (*http.Response, error) { + var err error + const operationName = "ExtensionManagersClient.BeginRemoveInfraAndScenario" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.removeInfraAndScenarioCreateRequest(ctx, resourceGroupName, extensionManagerName, body, options) + if err != nil { + return nil, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err + } + return httpResp, nil +} + +// removeInfraAndScenarioCreateRequest creates the RemoveInfraAndScenario request. +func (client *ExtensionManagersClient) removeInfraAndScenarioCreateRequest(ctx context.Context, resourceGroupName string, extensionManagerName string, body RemoveInfraAndScenarioDetails, options *ExtensionManagersClientBeginRemoveInfraAndScenarioOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridOnboarding/extensionManagers/{extensionManagerName}/removeInfraAndScenario" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if extensionManagerName == "" { + return nil, errors.New("parameter extensionManagerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{extensionManagerName}", url.PathEscape(extensionManagerName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-06-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + if err := runtime.MarshalAsJSON(req, body); err != nil { + return nil, err + } + return req, nil +} + +// BeginUpdate - Update a ExtensionManager +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-06-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - extensionManagerName - Extension Manager resource +// - properties - The resource properties to be updated. +// - options - ExtensionManagersClientBeginUpdateOptions contains the optional parameters for the ExtensionManagersClient.BeginUpdate +// method. +func (client *ExtensionManagersClient) BeginUpdate(ctx context.Context, resourceGroupName string, extensionManagerName string, properties ExtensionManagerPatch, options *ExtensionManagersClientBeginUpdateOptions) (*runtime.Poller[ExtensionManagersClientUpdateResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.update(ctx, resourceGroupName, extensionManagerName, properties, options) + if err != nil { + return nil, err + } + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExtensionManagersClientUpdateResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + Tracer: client.internal.Tracer(), + }) + return poller, err + } else { + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ExtensionManagersClientUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) + } +} + +// Update - Update a ExtensionManager +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-06-01-preview +func (client *ExtensionManagersClient) update(ctx context.Context, resourceGroupName string, extensionManagerName string, properties ExtensionManagerPatch, options *ExtensionManagersClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ExtensionManagersClient.BeginUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.updateCreateRequest(ctx, resourceGroupName, extensionManagerName, properties, options) + if err != nil { + return nil, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err + } + return httpResp, nil +} + +// updateCreateRequest creates the Update request. +func (client *ExtensionManagersClient) updateCreateRequest(ctx context.Context, resourceGroupName string, extensionManagerName string, properties ExtensionManagerPatch, options *ExtensionManagersClientBeginUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridOnboarding/extensionManagers/{extensionManagerName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if extensionManagerName == "" { + return nil, errors.New("parameter extensionManagerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{extensionManagerName}", url.PathEscape(extensionManagerName)) + req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-06-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + if err := runtime.MarshalAsJSON(req, properties); err != nil { + return nil, err + } + return req, nil +} diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/fake/extensionmanagers_server.go b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/fake/extensionmanagers_server.go new file mode 100644 index 000000000000..259bed1a4d54 --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/fake/extensionmanagers_server.go @@ -0,0 +1,577 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/hybridonboarding/armhybridonboarding" + "net/http" + "net/url" + "regexp" +) + +// ExtensionManagersServer is a fake server for instances of the armhybridonboarding.ExtensionManagersClient type. +type ExtensionManagersServer struct { + // BeginAddNewFabric is the fake for method ExtensionManagersClient.BeginAddNewFabric + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginAddNewFabric func(ctx context.Context, resourceGroupName string, extensionManagerName string, body armhybridonboarding.AddFabricRequestDetails, options *armhybridonboarding.ExtensionManagersClientBeginAddNewFabricOptions) (resp azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientAddNewFabricResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdate is the fake for method ExtensionManagersClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, extensionManagerName string, resource armhybridonboarding.ExtensionManager, options *armhybridonboarding.ExtensionManagersClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ExtensionManagersClient.BeginDelete + // HTTP status codes to indicate success: http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, extensionManagerName string, options *armhybridonboarding.ExtensionManagersClientBeginDeleteOptions) (resp azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientDeleteResponse], errResp azfake.ErrorResponder) + + // BeginDisableExtensions is the fake for method ExtensionManagersClient.BeginDisableExtensions + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginDisableExtensions func(ctx context.Context, resourceGroupName string, extensionManagerName string, body []*armhybridonboarding.DisableExtensionsRequestDetails, options *armhybridonboarding.ExtensionManagersClientBeginDisableExtensionsOptions) (resp azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientDisableExtensionsResponse], errResp azfake.ErrorResponder) + + // BeginEnableExtensions is the fake for method ExtensionManagersClient.BeginEnableExtensions + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginEnableExtensions func(ctx context.Context, resourceGroupName string, extensionManagerName string, body []*armhybridonboarding.EnableExtensionsRequestDetails, options *armhybridonboarding.ExtensionManagersClientBeginEnableExtensionsOptions) (resp azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientEnableExtensionsResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ExtensionManagersClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, extensionManagerName string, options *armhybridonboarding.ExtensionManagersClientGetOptions) (resp azfake.Responder[armhybridonboarding.ExtensionManagersClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByResourceGroupPager is the fake for method ExtensionManagersClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armhybridonboarding.ExtensionManagersClientListByResourceGroupOptions) (resp azfake.PagerResponder[armhybridonboarding.ExtensionManagersClientListByResourceGroupResponse]) + + // NewListBySubscriptionPager is the fake for method ExtensionManagersClient.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armhybridonboarding.ExtensionManagersClientListBySubscriptionOptions) (resp azfake.PagerResponder[armhybridonboarding.ExtensionManagersClientListBySubscriptionResponse]) + + // BeginRemoveInfraAndScenario is the fake for method ExtensionManagersClient.BeginRemoveInfraAndScenario + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginRemoveInfraAndScenario func(ctx context.Context, resourceGroupName string, extensionManagerName string, body armhybridonboarding.RemoveInfraAndScenarioDetails, options *armhybridonboarding.ExtensionManagersClientBeginRemoveInfraAndScenarioOptions) (resp azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientRemoveInfraAndScenarioResponse], errResp azfake.ErrorResponder) + + // BeginUpdate is the fake for method ExtensionManagersClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdate func(ctx context.Context, resourceGroupName string, extensionManagerName string, properties armhybridonboarding.ExtensionManagerPatch, options *armhybridonboarding.ExtensionManagersClientBeginUpdateOptions) (resp azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewExtensionManagersServerTransport creates a new instance of ExtensionManagersServerTransport with the provided implementation. +// The returned ExtensionManagersServerTransport instance is connected to an instance of armhybridonboarding.ExtensionManagersClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewExtensionManagersServerTransport(srv *ExtensionManagersServer) *ExtensionManagersServerTransport { + return &ExtensionManagersServerTransport{ + srv: srv, + beginAddNewFabric: newTracker[azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientAddNewFabricResponse]](), + beginCreateOrUpdate: newTracker[azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientCreateOrUpdateResponse]](), + beginDelete: newTracker[azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientDeleteResponse]](), + beginDisableExtensions: newTracker[azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientDisableExtensionsResponse]](), + beginEnableExtensions: newTracker[azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientEnableExtensionsResponse]](), + newListByResourceGroupPager: newTracker[azfake.PagerResponder[armhybridonboarding.ExtensionManagersClientListByResourceGroupResponse]](), + newListBySubscriptionPager: newTracker[azfake.PagerResponder[armhybridonboarding.ExtensionManagersClientListBySubscriptionResponse]](), + beginRemoveInfraAndScenario: newTracker[azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientRemoveInfraAndScenarioResponse]](), + beginUpdate: newTracker[azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientUpdateResponse]](), + } +} + +// ExtensionManagersServerTransport connects instances of armhybridonboarding.ExtensionManagersClient to instances of ExtensionManagersServer. +// Don't use this type directly, use NewExtensionManagersServerTransport instead. +type ExtensionManagersServerTransport struct { + srv *ExtensionManagersServer + beginAddNewFabric *tracker[azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientAddNewFabricResponse]] + beginCreateOrUpdate *tracker[azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientCreateOrUpdateResponse]] + beginDelete *tracker[azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientDeleteResponse]] + beginDisableExtensions *tracker[azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientDisableExtensionsResponse]] + beginEnableExtensions *tracker[azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientEnableExtensionsResponse]] + newListByResourceGroupPager *tracker[azfake.PagerResponder[armhybridonboarding.ExtensionManagersClientListByResourceGroupResponse]] + newListBySubscriptionPager *tracker[azfake.PagerResponder[armhybridonboarding.ExtensionManagersClientListBySubscriptionResponse]] + beginRemoveInfraAndScenario *tracker[azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientRemoveInfraAndScenarioResponse]] + beginUpdate *tracker[azfake.PollerResponder[armhybridonboarding.ExtensionManagersClientUpdateResponse]] +} + +// Do implements the policy.Transporter interface for ExtensionManagersServerTransport. +func (e *ExtensionManagersServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "ExtensionManagersClient.BeginAddNewFabric": + resp, err = e.dispatchBeginAddNewFabric(req) + case "ExtensionManagersClient.BeginCreateOrUpdate": + resp, err = e.dispatchBeginCreateOrUpdate(req) + case "ExtensionManagersClient.BeginDelete": + resp, err = e.dispatchBeginDelete(req) + case "ExtensionManagersClient.BeginDisableExtensions": + resp, err = e.dispatchBeginDisableExtensions(req) + case "ExtensionManagersClient.BeginEnableExtensions": + resp, err = e.dispatchBeginEnableExtensions(req) + case "ExtensionManagersClient.Get": + resp, err = e.dispatchGet(req) + case "ExtensionManagersClient.NewListByResourceGroupPager": + resp, err = e.dispatchNewListByResourceGroupPager(req) + case "ExtensionManagersClient.NewListBySubscriptionPager": + resp, err = e.dispatchNewListBySubscriptionPager(req) + case "ExtensionManagersClient.BeginRemoveInfraAndScenario": + resp, err = e.dispatchBeginRemoveInfraAndScenario(req) + case "ExtensionManagersClient.BeginUpdate": + resp, err = e.dispatchBeginUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExtensionManagersServerTransport) dispatchBeginAddNewFabric(req *http.Request) (*http.Response, error) { + if e.srv.BeginAddNewFabric == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginAddNewFabric not implemented")} + } + beginAddNewFabric := e.beginAddNewFabric.get(req) + if beginAddNewFabric == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.HybridOnboarding/extensionManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/addNewFabric` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armhybridonboarding.AddFabricRequestDetails](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + extensionManagerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("extensionManagerName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginAddNewFabric(req.Context(), resourceGroupNameParam, extensionManagerNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginAddNewFabric = &respr + e.beginAddNewFabric.add(req, beginAddNewFabric) + } + + resp, err := server.PollerResponderNext(beginAddNewFabric, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + e.beginAddNewFabric.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(beginAddNewFabric) { + e.beginAddNewFabric.remove(req) + } + + return resp, nil +} + +func (e *ExtensionManagersServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if e.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + beginCreateOrUpdate := e.beginCreateOrUpdate.get(req) + if beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.HybridOnboarding/extensionManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armhybridonboarding.ExtensionManager](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + extensionManagerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("extensionManagerName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, extensionManagerNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdate = &respr + e.beginCreateOrUpdate.add(req, beginCreateOrUpdate) + } + + resp, err := server.PollerResponderNext(beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + e.beginCreateOrUpdate.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(beginCreateOrUpdate) { + e.beginCreateOrUpdate.remove(req) + } + + return resp, nil +} + +func (e *ExtensionManagersServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if e.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + beginDelete := e.beginDelete.get(req) + if beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.HybridOnboarding/extensionManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + extensionManagerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("extensionManagerName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginDelete(req.Context(), resourceGroupNameParam, extensionManagerNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDelete = &respr + e.beginDelete.add(req, beginDelete) + } + + resp, err := server.PollerResponderNext(beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + e.beginDelete.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(beginDelete) { + e.beginDelete.remove(req) + } + + return resp, nil +} + +func (e *ExtensionManagersServerTransport) dispatchBeginDisableExtensions(req *http.Request) (*http.Response, error) { + if e.srv.BeginDisableExtensions == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDisableExtensions not implemented")} + } + beginDisableExtensions := e.beginDisableExtensions.get(req) + if beginDisableExtensions == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.HybridOnboarding/extensionManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/disableExtensions` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[[]*armhybridonboarding.DisableExtensionsRequestDetails](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + extensionManagerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("extensionManagerName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginDisableExtensions(req.Context(), resourceGroupNameParam, extensionManagerNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDisableExtensions = &respr + e.beginDisableExtensions.add(req, beginDisableExtensions) + } + + resp, err := server.PollerResponderNext(beginDisableExtensions, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + e.beginDisableExtensions.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(beginDisableExtensions) { + e.beginDisableExtensions.remove(req) + } + + return resp, nil +} + +func (e *ExtensionManagersServerTransport) dispatchBeginEnableExtensions(req *http.Request) (*http.Response, error) { + if e.srv.BeginEnableExtensions == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginEnableExtensions not implemented")} + } + beginEnableExtensions := e.beginEnableExtensions.get(req) + if beginEnableExtensions == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.HybridOnboarding/extensionManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/enableExtensions` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[[]*armhybridonboarding.EnableExtensionsRequestDetails](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + extensionManagerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("extensionManagerName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginEnableExtensions(req.Context(), resourceGroupNameParam, extensionManagerNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginEnableExtensions = &respr + e.beginEnableExtensions.add(req, beginEnableExtensions) + } + + resp, err := server.PollerResponderNext(beginEnableExtensions, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + e.beginEnableExtensions.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(beginEnableExtensions) { + e.beginEnableExtensions.remove(req) + } + + return resp, nil +} + +func (e *ExtensionManagersServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if e.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.HybridOnboarding/extensionManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + extensionManagerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("extensionManagerName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Get(req.Context(), resourceGroupNameParam, extensionManagerNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ExtensionManager, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExtensionManagersServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + newListByResourceGroupPager := e.newListByResourceGroupPager.get(req) + if newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.HybridOnboarding/extensionManagers` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := e.srv.NewListByResourceGroupPager(resourceGroupNameParam, nil) + newListByResourceGroupPager = &resp + e.newListByResourceGroupPager.add(req, newListByResourceGroupPager) + server.PagerResponderInjectNextLinks(newListByResourceGroupPager, req, func(page *armhybridonboarding.ExtensionManagersClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListByResourceGroupPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + e.newListByResourceGroupPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListByResourceGroupPager) { + e.newListByResourceGroupPager.remove(req) + } + return resp, nil +} + +func (e *ExtensionManagersServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListBySubscriptionPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListBySubscriptionPager not implemented")} + } + newListBySubscriptionPager := e.newListBySubscriptionPager.get(req) + if newListBySubscriptionPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.HybridOnboarding/extensionManagers` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resp := e.srv.NewListBySubscriptionPager(nil) + newListBySubscriptionPager = &resp + e.newListBySubscriptionPager.add(req, newListBySubscriptionPager) + server.PagerResponderInjectNextLinks(newListBySubscriptionPager, req, func(page *armhybridonboarding.ExtensionManagersClientListBySubscriptionResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListBySubscriptionPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + e.newListBySubscriptionPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListBySubscriptionPager) { + e.newListBySubscriptionPager.remove(req) + } + return resp, nil +} + +func (e *ExtensionManagersServerTransport) dispatchBeginRemoveInfraAndScenario(req *http.Request) (*http.Response, error) { + if e.srv.BeginRemoveInfraAndScenario == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginRemoveInfraAndScenario not implemented")} + } + beginRemoveInfraAndScenario := e.beginRemoveInfraAndScenario.get(req) + if beginRemoveInfraAndScenario == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.HybridOnboarding/extensionManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/removeInfraAndScenario` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armhybridonboarding.RemoveInfraAndScenarioDetails](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + extensionManagerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("extensionManagerName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginRemoveInfraAndScenario(req.Context(), resourceGroupNameParam, extensionManagerNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginRemoveInfraAndScenario = &respr + e.beginRemoveInfraAndScenario.add(req, beginRemoveInfraAndScenario) + } + + resp, err := server.PollerResponderNext(beginRemoveInfraAndScenario, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + e.beginRemoveInfraAndScenario.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(beginRemoveInfraAndScenario) { + e.beginRemoveInfraAndScenario.remove(req) + } + + return resp, nil +} + +func (e *ExtensionManagersServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if e.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} + } + beginUpdate := e.beginUpdate.get(req) + if beginUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.HybridOnboarding/extensionManagers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armhybridonboarding.ExtensionManagerPatch](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + extensionManagerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("extensionManagerName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.BeginUpdate(req.Context(), resourceGroupNameParam, extensionManagerNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginUpdate = &respr + e.beginUpdate.add(req, beginUpdate) + } + + resp, err := server.PollerResponderNext(beginUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + e.beginUpdate.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(beginUpdate) { + e.beginUpdate.remove(req) + } + + return resp, nil +} diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/fake/internal.go b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/fake/internal.go new file mode 100644 index 000000000000..5f75802a569e --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/fake/internal.go @@ -0,0 +1,64 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "net/http" + "sync" +) + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} + +func newTracker[T any]() *tracker[T] { + return &tracker[T]{ + items: map[string]*T{}, + } +} + +type tracker[T any] struct { + items map[string]*T + mu sync.Mutex +} + +func (p *tracker[T]) get(req *http.Request) *T { + p.mu.Lock() + defer p.mu.Unlock() + if item, ok := p.items[server.SanitizePagerPollerPath(req.URL.Path)]; ok { + return item + } + return nil +} + +func (p *tracker[T]) add(req *http.Request, item *T) { + p.mu.Lock() + defer p.mu.Unlock() + p.items[server.SanitizePagerPollerPath(req.URL.Path)] = item +} + +func (p *tracker[T]) remove(req *http.Request) { + p.mu.Lock() + defer p.mu.Unlock() + delete(p.items, server.SanitizePagerPollerPath(req.URL.Path)) +} diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/fake/operations_server.go b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/fake/operations_server.go new file mode 100644 index 000000000000..cd2648e8e70a --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/fake/operations_server.go @@ -0,0 +1,96 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/hybridonboarding/armhybridonboarding" + "net/http" +) + +// OperationsServer is a fake server for instances of the armhybridonboarding.OperationsClient type. +type OperationsServer struct { + // NewListPager is the fake for method OperationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armhybridonboarding.OperationsClientListOptions) (resp azfake.PagerResponder[armhybridonboarding.OperationsClientListResponse]) +} + +// NewOperationsServerTransport creates a new instance of OperationsServerTransport with the provided implementation. +// The returned OperationsServerTransport instance is connected to an instance of armhybridonboarding.OperationsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewOperationsServerTransport(srv *OperationsServer) *OperationsServerTransport { + return &OperationsServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[armhybridonboarding.OperationsClientListResponse]](), + } +} + +// OperationsServerTransport connects instances of armhybridonboarding.OperationsClient to instances of OperationsServer. +// Don't use this type directly, use NewOperationsServerTransport instead. +type OperationsServerTransport struct { + srv *OperationsServer + newListPager *tracker[azfake.PagerResponder[armhybridonboarding.OperationsClientListResponse]] +} + +// Do implements the policy.Transporter interface for OperationsServerTransport. +func (o *OperationsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "OperationsClient.NewListPager": + resp, err = o.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (o *OperationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if o.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := o.newListPager.get(req) + if newListPager == nil { + resp := o.srv.NewListPager(nil) + newListPager = &resp + o.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armhybridonboarding.OperationsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + o.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + o.newListPager.remove(req) + } + return resp, nil +} diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/fake/server_factory.go b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/fake/server_factory.go new file mode 100644 index 000000000000..8879a6e8b733 --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/fake/server_factory.go @@ -0,0 +1,82 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" + "sync" +) + +// ServerFactory is a fake server for instances of the armhybridonboarding.ClientFactory type. +type ServerFactory struct { + ExtensionManagersServer ExtensionManagersServer + OperationsServer OperationsServer +} + +// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. +// The returned ServerFactoryTransport instance is connected to an instance of armhybridonboarding.ClientFactory via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewServerFactoryTransport(srv *ServerFactory) *ServerFactoryTransport { + return &ServerFactoryTransport{ + srv: srv, + } +} + +// ServerFactoryTransport connects instances of armhybridonboarding.ClientFactory to instances of ServerFactory. +// Don't use this type directly, use NewServerFactoryTransport instead. +type ServerFactoryTransport struct { + srv *ServerFactory + trMu sync.Mutex + trExtensionManagersServer *ExtensionManagersServerTransport + trOperationsServer *OperationsServerTransport +} + +// Do implements the policy.Transporter interface for ServerFactoryTransport. +func (s *ServerFactoryTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + client := method[:strings.Index(method, ".")] + var resp *http.Response + var err error + + switch client { + case "ExtensionManagersClient": + initServer(s, &s.trExtensionManagersServer, func() *ExtensionManagersServerTransport { + return NewExtensionManagersServerTransport(&s.srv.ExtensionManagersServer) + }) + resp, err = s.trExtensionManagersServer.Do(req) + case "OperationsClient": + initServer(s, &s.trOperationsServer, func() *OperationsServerTransport { return NewOperationsServerTransport(&s.srv.OperationsServer) }) + resp, err = s.trOperationsServer.Do(req) + default: + err = fmt.Errorf("unhandled client %s", client) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func initServer[T any](s *ServerFactoryTransport, dst **T, src func() *T) { + s.trMu.Lock() + if *dst == nil { + *dst = src() + } + s.trMu.Unlock() +} diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/fake/time_rfc3339.go b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/fake/time_rfc3339.go new file mode 100644 index 000000000000..81f308b0d343 --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/fake/time_rfc3339.go @@ -0,0 +1,110 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "regexp" + "strings" + "time" +) + +// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. +var tzOffsetRegex = regexp.MustCompile(`(?:Z|z|\+|-)(?:\d+:\d+)*"*$`) + +const ( + utcDateTime = "2006-01-02T15:04:05.999999999" + utcDateTimeJSON = `"` + utcDateTime + `"` + utcDateTimeNoT = "2006-01-02 15:04:05.999999999" + utcDateTimeJSONNoT = `"` + utcDateTimeNoT + `"` + dateTimeNoT = `2006-01-02 15:04:05.999999999Z07:00` + dateTimeJSON = `"` + time.RFC3339Nano + `"` + dateTimeJSONNoT = `"` + dateTimeNoT + `"` +) + +type dateTimeRFC3339 time.Time + +func (t dateTimeRFC3339) MarshalJSON() ([]byte, error) { + tt := time.Time(t) + return tt.MarshalJSON() +} + +func (t dateTimeRFC3339) MarshalText() ([]byte, error) { + tt := time.Time(t) + return tt.MarshalText() +} + +func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { + tzOffset := tzOffsetRegex.Match(data) + hasT := strings.Contains(string(data), "T") || strings.Contains(string(data), "t") + var layout string + if tzOffset && hasT { + layout = dateTimeJSON + } else if tzOffset { + layout = dateTimeJSONNoT + } else if hasT { + layout = utcDateTimeJSON + } else { + layout = utcDateTimeJSONNoT + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + tzOffset := tzOffsetRegex.Match(data) + hasT := strings.Contains(string(data), "T") || strings.Contains(string(data), "t") + var layout string + if tzOffset && hasT { + layout = time.RFC3339Nano + } else if tzOffset { + layout = dateTimeNoT + } else if hasT { + layout = utcDateTime + } else { + layout = utcDateTimeNoT + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) Parse(layout, value string) error { + p, err := time.Parse(layout, strings.ToUpper(value)) + *t = dateTimeRFC3339(p) + return err +} + +func (t dateTimeRFC3339) String() string { + return time.Time(t).Format(time.RFC3339Nano) +} + +func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { + if t == nil { + return + } else if azcore.IsNullValue(t) { + m[k] = nil + return + } else if reflect.ValueOf(t).IsNil() { + return + } + m[k] = (*dateTimeRFC3339)(t) +} + +func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { + if data == nil || string(data) == "null" { + return nil + } + var aux dateTimeRFC3339 + if err := json.Unmarshal(data, &aux); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + *t = (*time.Time)(&aux) + return nil +} diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/go.mod b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/go.mod new file mode 100644 index 000000000000..87519861f3ed --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/go.mod @@ -0,0 +1,11 @@ +module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/hybridonboarding/armhybridonboarding + +go 1.18 + +require github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.2 + +require ( + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 // indirect + golang.org/x/net v0.20.0 // indirect + golang.org/x/text v0.14.0 // indirect +) diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/go.sum b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/go.sum new file mode 100644 index 000000000000..03ce617a1873 --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/go.sum @@ -0,0 +1,12 @@ +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.2 h1:c4k2FIYIh4xtwqrQwV0Ct1v5+ehlNXj5NI/MWVsiTkQ= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.2/go.mod h1:5FDJtLEO/GxwNgUxbwrY3LP0pEoThTQJtk2oysdXHxM= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 h1:LqbJ/WzJUwBf8UiaSzgX7aMclParm9/5Vgp+TY51uBQ= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2/go.mod h1:yInRyqWXAuaPrgI7p70+lDDgh3mlBohis29jGMISnmc= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= +golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/models.go b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/models.go new file mode 100644 index 000000000000..db2713a7e84b --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/models.go @@ -0,0 +1,213 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armhybridonboarding + +import "time" + +// AddFabricRequestDetails - Request body for adding new fabric/scenario/infra POST action +type AddFabricRequestDetails struct { + // REQUIRED; Infra of new fabric. + Infrastructure *string + + // REQUIRED; Azure scenario enabled. Ex: Migrate + Scenario *string +} + +// DisableExtensionsRequestDetails - Request body details for disabling extensions POST action +type DisableExtensionsRequestDetails struct { + // REQUIRED; Infra on which the extension will be disabled. + Infrastructure *string + + // REQUIRED; Name of the extension + Name *string + + // REQUIRED; Azure scenario enabled. Ex: Migrate + Scenario *string +} + +// EnableExtensionsRequestDetails - Request body details for enabling extensions POST action +type EnableExtensionsRequestDetails struct { + // REQUIRED; Number of additional custom locations required for the extension + AdditionalCustomLocationCount *int64 + + // REQUIRED; Infra on which the extension will be enabled. + Infrastructure *string + + // REQUIRED; Name of the extension + Name *string + + // REQUIRED; Azure scenario enabled. Ex: Migrate + Scenario *string +} + +// ExtensionDetails - Extension details of an extension in extension profile. +type ExtensionDetails struct { + // REQUIRED; Infra on which extension is deployed. + Infrastructure *string + + // REQUIRED; Azure scenario enabled. Ex: Migrate + Scenario *string + + // READ-ONLY; Custom Location of the extension + CustomLocation *string +} + +// ExtensionManager - Extension Manager Resource +type ExtensionManager struct { + // REQUIRED; The geo-location where the resource lives + Location *string + + // The resource-specific properties for this resource. + Properties *ExtensionManagerProperties + + // Resource tags. + Tags map[string]*string + + // READ-ONLY; Fully qualified resource ID for the resource. E.g. "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}" + ID *string + + // READ-ONLY; The name of the resource + Name *string + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string +} + +// ExtensionManagerListResult - The response of a ExtensionManager list operation. +type ExtensionManagerListResult struct { + // REQUIRED; The ExtensionManager items on this page + Value []*ExtensionManager + + // The link to the next page of items + NextLink *string +} + +// ExtensionManagerPatch - Properties of a Extension Manager that can be patched. +type ExtensionManagerPatch struct { + // Resource tags. + Tags map[string]*string +} + +// ExtensionManagerProperties - The properties of Extension Manager resource +type ExtensionManagerProperties struct { + // REQUIRED; ARM ID of the custom location resource deployed on the Onboarding Appliance + ExtendedLocation *string + + // Scenario profile of the extension manager resource + ScenarioProfile []*ScenarioObject + + // READ-ONLY; Extension profile of the extension manager resource + ExtensionProfile []*ExtensionObject + + // READ-ONLY; Provisioning state of Extension Manager resource. + ProvisioningState *ProvisioningState +} + +// ExtensionObject - Extension object inside the extension profile. +type ExtensionObject struct { + // REQUIRED; Flag to enable/disable the extension + Enabled *bool + + // REQUIRED; Extension details of an extension in extension profile. + ExtensionDetails []*ExtensionDetails + + // REQUIRED; Name of the extension + Name *string +} + +// Operation - Details of a REST API operation, returned from the Resource Provider Operations API +type Operation struct { + // Localized display information for this particular operation. + Display *OperationDisplay + + // READ-ONLY; Enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + ActionType *ActionType + + // READ-ONLY; Whether the operation applies to data-plane. This is "true" for data-plane operations and "false" for ARM/control-plane + // operations. + IsDataAction *bool + + // READ-ONLY; The name of the operation, as per Resource-Based Access Control (RBAC). Examples: "Microsoft.Compute/virtualMachines/write", + // "Microsoft.Compute/virtualMachines/capture/action" + Name *string + + // READ-ONLY; The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default + // value is "user,system" + Origin *Origin +} + +// OperationDisplay - Localized display information for this particular operation. +type OperationDisplay struct { + // READ-ONLY; The short, localized friendly description of the operation; suitable for tool tips and detailed views. + Description *string + + // READ-ONLY; The concise, localized friendly name for the operation; suitable for dropdowns. E.g. "Create or Update Virtual + // Machine", "Restart Virtual Machine". + Operation *string + + // READ-ONLY; The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring Insights" or "Microsoft + // Compute". + Provider *string + + // READ-ONLY; The localized friendly name of the resource type related to this operation. E.g. "Virtual Machines" or "Job + // Schedule Collections". + Resource *string +} + +// OperationListResult - A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to +// get the next set of results. +type OperationListResult struct { + // READ-ONLY; URL to get the next set of operation list results (if there are any). + NextLink *string + + // READ-ONLY; List of operations supported by the resource provider + Value []*Operation +} + +// RemoveInfraAndScenarioDetails - Request body for removing a fabric/scenario/infra POST action +type RemoveInfraAndScenarioDetails struct { + // REQUIRED; Infra of fabric to be removed. + Infrastructure *string + + // REQUIRED; Azure scenario enabled. Ex: Migrate + Scenario *string +} + +// ScenarioObject - Scenario object inside the scenario profile. +type ScenarioObject struct { + // REQUIRED; Infra on which extension is deployed. + Infrastructure *string + + // REQUIRED; Azure scenario enabled. Ex: Migrate + Scenario *string +} + +// SystemData - Metadata pertaining to creation and last modification of the resource. +type SystemData struct { + // The timestamp of resource creation (UTC). + CreatedAt *time.Time + + // The identity that created the resource. + CreatedBy *string + + // The type of identity that created the resource. + CreatedByType *CreatedByType + + // The timestamp of resource last modification (UTC) + LastModifiedAt *time.Time + + // The identity that last modified the resource. + LastModifiedBy *string + + // The type of identity that last modified the resource. + LastModifiedByType *CreatedByType +} diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/models_serde.go b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/models_serde.go new file mode 100644 index 000000000000..338746817a39 --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/models_serde.go @@ -0,0 +1,581 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armhybridonboarding + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" +) + +// MarshalJSON implements the json.Marshaller interface for type AddFabricRequestDetails. +func (a AddFabricRequestDetails) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "infrastructure", a.Infrastructure) + populate(objectMap, "scenario", a.Scenario) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type AddFabricRequestDetails. +func (a *AddFabricRequestDetails) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", a, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "infrastructure": + err = unpopulate(val, "Infrastructure", &a.Infrastructure) + delete(rawMsg, key) + case "scenario": + err = unpopulate(val, "Scenario", &a.Scenario) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", a, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type DisableExtensionsRequestDetails. +func (d DisableExtensionsRequestDetails) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "infrastructure", d.Infrastructure) + populate(objectMap, "name", d.Name) + populate(objectMap, "scenario", d.Scenario) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type DisableExtensionsRequestDetails. +func (d *DisableExtensionsRequestDetails) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "infrastructure": + err = unpopulate(val, "Infrastructure", &d.Infrastructure) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &d.Name) + delete(rawMsg, key) + case "scenario": + err = unpopulate(val, "Scenario", &d.Scenario) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type EnableExtensionsRequestDetails. +func (e EnableExtensionsRequestDetails) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "additionalCustomLocationCount", e.AdditionalCustomLocationCount) + populate(objectMap, "infrastructure", e.Infrastructure) + populate(objectMap, "name", e.Name) + populate(objectMap, "scenario", e.Scenario) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type EnableExtensionsRequestDetails. +func (e *EnableExtensionsRequestDetails) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "additionalCustomLocationCount": + err = unpopulate(val, "AdditionalCustomLocationCount", &e.AdditionalCustomLocationCount) + delete(rawMsg, key) + case "infrastructure": + err = unpopulate(val, "Infrastructure", &e.Infrastructure) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &e.Name) + delete(rawMsg, key) + case "scenario": + err = unpopulate(val, "Scenario", &e.Scenario) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ExtensionDetails. +func (e ExtensionDetails) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "customLocation", e.CustomLocation) + populate(objectMap, "infrastructure", e.Infrastructure) + populate(objectMap, "scenario", e.Scenario) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ExtensionDetails. +func (e *ExtensionDetails) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "customLocation": + err = unpopulate(val, "CustomLocation", &e.CustomLocation) + delete(rawMsg, key) + case "infrastructure": + err = unpopulate(val, "Infrastructure", &e.Infrastructure) + delete(rawMsg, key) + case "scenario": + err = unpopulate(val, "Scenario", &e.Scenario) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ExtensionManager. +func (e ExtensionManager) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", e.ID) + populate(objectMap, "location", e.Location) + populate(objectMap, "name", e.Name) + populate(objectMap, "properties", e.Properties) + populate(objectMap, "systemData", e.SystemData) + populate(objectMap, "tags", e.Tags) + populate(objectMap, "type", e.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ExtensionManager. +func (e *ExtensionManager) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &e.ID) + delete(rawMsg, key) + case "location": + err = unpopulate(val, "Location", &e.Location) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &e.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &e.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &e.SystemData) + delete(rawMsg, key) + case "tags": + err = unpopulate(val, "Tags", &e.Tags) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &e.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ExtensionManagerListResult. +func (e ExtensionManagerListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", e.NextLink) + populate(objectMap, "value", e.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ExtensionManagerListResult. +func (e *ExtensionManagerListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &e.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &e.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ExtensionManagerPatch. +func (e ExtensionManagerPatch) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "tags", e.Tags) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ExtensionManagerPatch. +func (e *ExtensionManagerPatch) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "tags": + err = unpopulate(val, "Tags", &e.Tags) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ExtensionManagerProperties. +func (e ExtensionManagerProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "extendedLocation", e.ExtendedLocation) + populate(objectMap, "extensionProfile", e.ExtensionProfile) + populate(objectMap, "provisioningState", e.ProvisioningState) + populate(objectMap, "scenarioProfile", e.ScenarioProfile) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ExtensionManagerProperties. +func (e *ExtensionManagerProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "extendedLocation": + err = unpopulate(val, "ExtendedLocation", &e.ExtendedLocation) + delete(rawMsg, key) + case "extensionProfile": + err = unpopulate(val, "ExtensionProfile", &e.ExtensionProfile) + delete(rawMsg, key) + case "provisioningState": + err = unpopulate(val, "ProvisioningState", &e.ProvisioningState) + delete(rawMsg, key) + case "scenarioProfile": + err = unpopulate(val, "ScenarioProfile", &e.ScenarioProfile) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ExtensionObject. +func (e ExtensionObject) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "enabled", e.Enabled) + populate(objectMap, "extensionDetails", e.ExtensionDetails) + populate(objectMap, "name", e.Name) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ExtensionObject. +func (e *ExtensionObject) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "enabled": + err = unpopulate(val, "Enabled", &e.Enabled) + delete(rawMsg, key) + case "extensionDetails": + err = unpopulate(val, "ExtensionDetails", &e.ExtensionDetails) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &e.Name) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type Operation. +func (o Operation) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "actionType", o.ActionType) + populate(objectMap, "display", o.Display) + populate(objectMap, "isDataAction", o.IsDataAction) + populate(objectMap, "name", o.Name) + populate(objectMap, "origin", o.Origin) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Operation. +func (o *Operation) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "actionType": + err = unpopulate(val, "ActionType", &o.ActionType) + delete(rawMsg, key) + case "display": + err = unpopulate(val, "Display", &o.Display) + delete(rawMsg, key) + case "isDataAction": + err = unpopulate(val, "IsDataAction", &o.IsDataAction) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &o.Name) + delete(rawMsg, key) + case "origin": + err = unpopulate(val, "Origin", &o.Origin) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type OperationDisplay. +func (o OperationDisplay) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "description", o.Description) + populate(objectMap, "operation", o.Operation) + populate(objectMap, "provider", o.Provider) + populate(objectMap, "resource", o.Resource) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type OperationDisplay. +func (o *OperationDisplay) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "description": + err = unpopulate(val, "Description", &o.Description) + delete(rawMsg, key) + case "operation": + err = unpopulate(val, "Operation", &o.Operation) + delete(rawMsg, key) + case "provider": + err = unpopulate(val, "Provider", &o.Provider) + delete(rawMsg, key) + case "resource": + err = unpopulate(val, "Resource", &o.Resource) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type OperationListResult. +func (o OperationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", o.NextLink) + populate(objectMap, "value", o.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type OperationListResult. +func (o *OperationListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &o.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &o.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type RemoveInfraAndScenarioDetails. +func (r RemoveInfraAndScenarioDetails) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "infrastructure", r.Infrastructure) + populate(objectMap, "scenario", r.Scenario) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type RemoveInfraAndScenarioDetails. +func (r *RemoveInfraAndScenarioDetails) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "infrastructure": + err = unpopulate(val, "Infrastructure", &r.Infrastructure) + delete(rawMsg, key) + case "scenario": + err = unpopulate(val, "Scenario", &r.Scenario) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ScenarioObject. +func (s ScenarioObject) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "infrastructure", s.Infrastructure) + populate(objectMap, "scenario", s.Scenario) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ScenarioObject. +func (s *ScenarioObject) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "infrastructure": + err = unpopulate(val, "Infrastructure", &s.Infrastructure) + delete(rawMsg, key) + case "scenario": + err = unpopulate(val, "Scenario", &s.Scenario) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type SystemData. +func (s SystemData) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populateDateTimeRFC3339(objectMap, "createdAt", s.CreatedAt) + populate(objectMap, "createdBy", s.CreatedBy) + populate(objectMap, "createdByType", s.CreatedByType) + populateDateTimeRFC3339(objectMap, "lastModifiedAt", s.LastModifiedAt) + populate(objectMap, "lastModifiedBy", s.LastModifiedBy) + populate(objectMap, "lastModifiedByType", s.LastModifiedByType) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SystemData. +func (s *SystemData) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "createdAt": + err = unpopulateDateTimeRFC3339(val, "CreatedAt", &s.CreatedAt) + delete(rawMsg, key) + case "createdBy": + err = unpopulate(val, "CreatedBy", &s.CreatedBy) + delete(rawMsg, key) + case "createdByType": + err = unpopulate(val, "CreatedByType", &s.CreatedByType) + delete(rawMsg, key) + case "lastModifiedAt": + err = unpopulateDateTimeRFC3339(val, "LastModifiedAt", &s.LastModifiedAt) + delete(rawMsg, key) + case "lastModifiedBy": + err = unpopulate(val, "LastModifiedBy", &s.LastModifiedBy) + delete(rawMsg, key) + case "lastModifiedByType": + err = unpopulate(val, "LastModifiedByType", &s.LastModifiedByType) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +func populate(m map[string]any, k string, v any) { + if v == nil { + return + } else if azcore.IsNullValue(v) { + m[k] = nil + } else if !reflect.ValueOf(v).IsNil() { + m[k] = v + } +} + +func unpopulate(data json.RawMessage, fn string, v any) error { + if data == nil || string(data) == "null" { + return nil + } + if err := json.Unmarshal(data, v); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + return nil +} diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/operations_client.go b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/operations_client.go new file mode 100644 index 000000000000..bcc4d86c1e26 --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/operations_client.go @@ -0,0 +1,88 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armhybridonboarding + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" +) + +// OperationsClient contains the methods for the Operations group. +// Don't use this type directly, use NewOperationsClient() instead. +type OperationsClient struct { + internal *arm.Client +} + +// NewOperationsClient creates a new instance of OperationsClient with the specified values. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewOperationsClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*OperationsClient, error) { + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &OperationsClient{ + internal: cl, + } + return client, nil +} + +// NewListPager - List the operations for the provider +// +// Generated from API version 2024-06-01-preview +// - options - OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. +func (client *OperationsClient) NewListPager(options *OperationsClientListOptions) *runtime.Pager[OperationsClientListResponse] { + return runtime.NewPager(runtime.PagingHandler[OperationsClientListResponse]{ + More: func(page OperationsClientListResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *OperationsClientListResponse) (OperationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "OperationsClient.NewListPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink + } + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listCreateRequest(ctx, options) + }, nil) + if err != nil { + return OperationsClientListResponse{}, err + } + return client.listHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listCreateRequest creates the List request. +func (client *OperationsClient) listCreateRequest(ctx context.Context, options *OperationsClientListOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.HybridOnboarding/operations" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-06-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listHandleResponse handles the List response. +func (client *OperationsClient) listHandleResponse(resp *http.Response) (OperationsClientListResponse, error) { + result := OperationsClientListResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.OperationListResult); err != nil { + return OperationsClientListResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/options.go b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/options.go new file mode 100644 index 000000000000..3bef744ab427 --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/options.go @@ -0,0 +1,80 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armhybridonboarding + +// ExtensionManagersClientBeginAddNewFabricOptions contains the optional parameters for the ExtensionManagersClient.BeginAddNewFabric +// method. +type ExtensionManagersClientBeginAddNewFabricOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ExtensionManagersClientBeginCreateOrUpdateOptions contains the optional parameters for the ExtensionManagersClient.BeginCreateOrUpdate +// method. +type ExtensionManagersClientBeginCreateOrUpdateOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ExtensionManagersClientBeginDeleteOptions contains the optional parameters for the ExtensionManagersClient.BeginDelete +// method. +type ExtensionManagersClientBeginDeleteOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ExtensionManagersClientBeginDisableExtensionsOptions contains the optional parameters for the ExtensionManagersClient.BeginDisableExtensions +// method. +type ExtensionManagersClientBeginDisableExtensionsOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ExtensionManagersClientBeginEnableExtensionsOptions contains the optional parameters for the ExtensionManagersClient.BeginEnableExtensions +// method. +type ExtensionManagersClientBeginEnableExtensionsOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ExtensionManagersClientBeginRemoveInfraAndScenarioOptions contains the optional parameters for the ExtensionManagersClient.BeginRemoveInfraAndScenario +// method. +type ExtensionManagersClientBeginRemoveInfraAndScenarioOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ExtensionManagersClientBeginUpdateOptions contains the optional parameters for the ExtensionManagersClient.BeginUpdate +// method. +type ExtensionManagersClientBeginUpdateOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ExtensionManagersClientGetOptions contains the optional parameters for the ExtensionManagersClient.Get method. +type ExtensionManagersClientGetOptions struct { + // placeholder for future optional parameters +} + +// ExtensionManagersClientListByResourceGroupOptions contains the optional parameters for the ExtensionManagersClient.NewListByResourceGroupPager +// method. +type ExtensionManagersClientListByResourceGroupOptions struct { + // placeholder for future optional parameters +} + +// ExtensionManagersClientListBySubscriptionOptions contains the optional parameters for the ExtensionManagersClient.NewListBySubscriptionPager +// method. +type ExtensionManagersClientListBySubscriptionOptions struct { + // placeholder for future optional parameters +} + +// OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. +type OperationsClientListOptions struct { + // placeholder for future optional parameters +} diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/responses.go b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/responses.go new file mode 100644 index 000000000000..eb127509c7eb --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/responses.go @@ -0,0 +1,74 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armhybridonboarding + +// ExtensionManagersClientAddNewFabricResponse contains the response from method ExtensionManagersClient.BeginAddNewFabric. +type ExtensionManagersClientAddNewFabricResponse struct { + // Extension Manager Resource + ExtensionManager +} + +// ExtensionManagersClientCreateOrUpdateResponse contains the response from method ExtensionManagersClient.BeginCreateOrUpdate. +type ExtensionManagersClientCreateOrUpdateResponse struct { + // Extension Manager Resource + ExtensionManager +} + +// ExtensionManagersClientDeleteResponse contains the response from method ExtensionManagersClient.BeginDelete. +type ExtensionManagersClientDeleteResponse struct { + // placeholder for future response values +} + +// ExtensionManagersClientDisableExtensionsResponse contains the response from method ExtensionManagersClient.BeginDisableExtensions. +type ExtensionManagersClientDisableExtensionsResponse struct { + // Extension Manager Resource + ExtensionManager +} + +// ExtensionManagersClientEnableExtensionsResponse contains the response from method ExtensionManagersClient.BeginEnableExtensions. +type ExtensionManagersClientEnableExtensionsResponse struct { + // Extension Manager Resource + ExtensionManager +} + +// ExtensionManagersClientGetResponse contains the response from method ExtensionManagersClient.Get. +type ExtensionManagersClientGetResponse struct { + // Extension Manager Resource + ExtensionManager +} + +// ExtensionManagersClientListByResourceGroupResponse contains the response from method ExtensionManagersClient.NewListByResourceGroupPager. +type ExtensionManagersClientListByResourceGroupResponse struct { + // The response of a ExtensionManager list operation. + ExtensionManagerListResult +} + +// ExtensionManagersClientListBySubscriptionResponse contains the response from method ExtensionManagersClient.NewListBySubscriptionPager. +type ExtensionManagersClientListBySubscriptionResponse struct { + // The response of a ExtensionManager list operation. + ExtensionManagerListResult +} + +// ExtensionManagersClientRemoveInfraAndScenarioResponse contains the response from method ExtensionManagersClient.BeginRemoveInfraAndScenario. +type ExtensionManagersClientRemoveInfraAndScenarioResponse struct { + // Extension Manager Resource + ExtensionManager +} + +// ExtensionManagersClientUpdateResponse contains the response from method ExtensionManagersClient.BeginUpdate. +type ExtensionManagersClientUpdateResponse struct { + // Extension Manager Resource + ExtensionManager +} + +// OperationsClientListResponse contains the response from method OperationsClient.NewListPager. +type OperationsClientListResponse struct { + // A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to get the next set of results. + OperationListResult +} diff --git a/sdk/resourcemanager/hybridonboarding/armhybridonboarding/time_rfc3339.go b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/time_rfc3339.go new file mode 100644 index 000000000000..a44e2666cc3a --- /dev/null +++ b/sdk/resourcemanager/hybridonboarding/armhybridonboarding/time_rfc3339.go @@ -0,0 +1,110 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armhybridonboarding + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "regexp" + "strings" + "time" +) + +// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. +var tzOffsetRegex = regexp.MustCompile(`(?:Z|z|\+|-)(?:\d+:\d+)*"*$`) + +const ( + utcDateTime = "2006-01-02T15:04:05.999999999" + utcDateTimeJSON = `"` + utcDateTime + `"` + utcDateTimeNoT = "2006-01-02 15:04:05.999999999" + utcDateTimeJSONNoT = `"` + utcDateTimeNoT + `"` + dateTimeNoT = `2006-01-02 15:04:05.999999999Z07:00` + dateTimeJSON = `"` + time.RFC3339Nano + `"` + dateTimeJSONNoT = `"` + dateTimeNoT + `"` +) + +type dateTimeRFC3339 time.Time + +func (t dateTimeRFC3339) MarshalJSON() ([]byte, error) { + tt := time.Time(t) + return tt.MarshalJSON() +} + +func (t dateTimeRFC3339) MarshalText() ([]byte, error) { + tt := time.Time(t) + return tt.MarshalText() +} + +func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { + tzOffset := tzOffsetRegex.Match(data) + hasT := strings.Contains(string(data), "T") || strings.Contains(string(data), "t") + var layout string + if tzOffset && hasT { + layout = dateTimeJSON + } else if tzOffset { + layout = dateTimeJSONNoT + } else if hasT { + layout = utcDateTimeJSON + } else { + layout = utcDateTimeJSONNoT + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + tzOffset := tzOffsetRegex.Match(data) + hasT := strings.Contains(string(data), "T") || strings.Contains(string(data), "t") + var layout string + if tzOffset && hasT { + layout = time.RFC3339Nano + } else if tzOffset { + layout = dateTimeNoT + } else if hasT { + layout = utcDateTime + } else { + layout = utcDateTimeNoT + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) Parse(layout, value string) error { + p, err := time.Parse(layout, strings.ToUpper(value)) + *t = dateTimeRFC3339(p) + return err +} + +func (t dateTimeRFC3339) String() string { + return time.Time(t).Format(time.RFC3339Nano) +} + +func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { + if t == nil { + return + } else if azcore.IsNullValue(t) { + m[k] = nil + return + } else if reflect.ValueOf(t).IsNil() { + return + } + m[k] = (*dateTimeRFC3339)(t) +} + +func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { + if data == nil || string(data) == "null" { + return nil + } + var aux dateTimeRFC3339 + if err := json.Unmarshal(data, &aux); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + *t = (*time.Time)(&aux) + return nil +}