From 48bd68d8348f71c564dd09bcbe6bd5c2b69d4136 Mon Sep 17 00:00:00 2001 From: jliusan Date: Tue, 10 Dec 2024 17:38:53 +0800 Subject: [PATCH 1/2] [Release] sdk/resourcemanager/durabletask/armdurabletask/0.1.0 generation from spec commit: ab04533261eff228f28e08900445d0edef3eb70c --- .../durabletask/armdurabletask/CHANGELOG.md | 8 + .../durabletask/armdurabletask/LICENSE.txt | 21 + .../durabletask/armdurabletask/README.md | 90 ++++ .../durabletask/armdurabletask/ci.yml | 28 ++ .../armdurabletask/client_factory.go | 56 +++ .../durabletask/armdurabletask/constants.go | 122 +++++ .../armdurabletask/fake/internal.go | 65 +++ .../armdurabletask/fake/operations_server.go | 117 +++++ .../armdurabletask/fake/schedulers_server.go | 374 ++++++++++++++ .../armdurabletask/fake/server_factory.go | 86 ++++ .../armdurabletask/fake/taskhubs_server.go | 293 +++++++++++ .../armdurabletask/fake/time_rfc3339.go | 109 +++++ .../durabletask/armdurabletask/go.mod | 21 + .../durabletask/armdurabletask/go.sum | 29 ++ .../durabletask/armdurabletask/models.go | 173 +++++++ .../armdurabletask/models_serde.go | 453 +++++++++++++++++ .../armdurabletask/operations_client.go | 84 ++++ .../operations_client_example_test.go | 56 +++ .../durabletask/armdurabletask/options.go | 68 +++ .../durabletask/armdurabletask/responses.go | 69 +++ .../armdurabletask/schedulers_client.go | 455 ++++++++++++++++++ .../schedulers_client_example_test.go | 347 +++++++++++++ .../armdurabletask/taskhubs_client.go | 340 +++++++++++++ .../taskhubs_client_example_test.go | 166 +++++++ .../armdurabletask/time_rfc3339.go | 109 +++++ .../armdurabletask/tsp-location.yaml | 4 + 26 files changed, 3743 insertions(+) create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/CHANGELOG.md create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/LICENSE.txt create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/README.md create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/ci.yml create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/client_factory.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/constants.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/fake/internal.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/fake/operations_server.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/fake/schedulers_server.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/fake/server_factory.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/fake/taskhubs_server.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/fake/time_rfc3339.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/go.mod create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/go.sum create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/models.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/models_serde.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/operations_client.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/operations_client_example_test.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/options.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/responses.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/schedulers_client.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/schedulers_client_example_test.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/taskhubs_client.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/taskhubs_client_example_test.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/time_rfc3339.go create mode 100644 sdk/resourcemanager/durabletask/armdurabletask/tsp-location.yaml diff --git a/sdk/resourcemanager/durabletask/armdurabletask/CHANGELOG.md b/sdk/resourcemanager/durabletask/armdurabletask/CHANGELOG.md new file mode 100644 index 000000000000..a8718c316a03 --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/CHANGELOG.md @@ -0,0 +1,8 @@ +# Release History + +## 0.1.0 (2024-12-10) +### Other Changes + +The package of `github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/durabletask/armdurabletask` 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/durabletask/armdurabletask/LICENSE.txt b/sdk/resourcemanager/durabletask/armdurabletask/LICENSE.txt new file mode 100644 index 000000000000..dc0c2ffb3dc1 --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/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/durabletask/armdurabletask/README.md b/sdk/resourcemanager/durabletask/armdurabletask/README.md new file mode 100644 index 000000000000..2e67416415e4 --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/README.md @@ -0,0 +1,90 @@ +# Azure Durabletask Module for Go + +The `armdurabletask` module provides operations for working with Azure Durabletask. + +[Source code](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/resourcemanager/durabletask/armdurabletask) + +# 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 Durabletask module: + +```sh +go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/durabletask/armdurabletask +``` + +## Authorization + +When creating a client, you will need to provide a credential for authenticating with Azure Durabletask. 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 Durabletask 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 := armdurabletask.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 := armdurabletask.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.NewSchedulersClient() +``` + +## 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 `Durabletask` 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/durabletask/armdurabletask/ci.yml b/sdk/resourcemanager/durabletask/armdurabletask/ci.yml new file mode 100644 index 000000000000..10ccccb34798 --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/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/durabletask/armdurabletask/ + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/durabletask/armdurabletask/ + +extends: + template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml + parameters: + IncludeRelease: true + ServiceDirectory: 'resourcemanager/durabletask/armdurabletask' diff --git a/sdk/resourcemanager/durabletask/armdurabletask/client_factory.go b/sdk/resourcemanager/durabletask/armdurabletask/client_factory.go new file mode 100644 index 000000000000..033693e3a42f --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/client_factory.go @@ -0,0 +1,56 @@ +// 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) Go Code Generator. DO NOT EDIT. + +package armdurabletask + +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 +} + +// NewOperationsClient creates a new instance of OperationsClient. +func (c *ClientFactory) NewOperationsClient() *OperationsClient { + return &OperationsClient{ + internal: c.internal, + } +} + +// NewSchedulersClient creates a new instance of SchedulersClient. +func (c *ClientFactory) NewSchedulersClient() *SchedulersClient { + return &SchedulersClient{ + subscriptionID: c.subscriptionID, + internal: c.internal, + } +} + +// NewTaskHubsClient creates a new instance of TaskHubsClient. +func (c *ClientFactory) NewTaskHubsClient() *TaskHubsClient { + return &TaskHubsClient{ + subscriptionID: c.subscriptionID, + internal: c.internal, + } +} diff --git a/sdk/resourcemanager/durabletask/armdurabletask/constants.go b/sdk/resourcemanager/durabletask/armdurabletask/constants.go new file mode 100644 index 000000000000..768812617398 --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/constants.go @@ -0,0 +1,122 @@ +// 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) Go Code Generator. DO NOT EDIT. + +package armdurabletask + +const ( + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/durabletask/armdurabletask" + moduleVersion = "v0.1.0" +) + +// ActionType - Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. +type ActionType string + +const ( + // ActionTypeInternal - Actions are for internal-only APIs. + ActionTypeInternal ActionType = "Internal" +) + +// PossibleActionTypeValues returns the possible values for the ActionType const type. +func PossibleActionTypeValues() []ActionType { + return []ActionType{ + ActionTypeInternal, + } +} + +// CreatedByType - The kind of entity that created the resource. +type CreatedByType string + +const ( + // CreatedByTypeApplication - The entity was created by an application. + CreatedByTypeApplication CreatedByType = "Application" + // CreatedByTypeKey - The entity was created by a key. + CreatedByTypeKey CreatedByType = "Key" + // CreatedByTypeManagedIdentity - The entity was created by a managed identity. + CreatedByTypeManagedIdentity CreatedByType = "ManagedIdentity" + // CreatedByTypeUser - The entity was created by a user. + 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 - Indicates the operation is initiated by a system. + OriginSystem Origin = "system" + // OriginUser - Indicates the operation is initiated by a user. + OriginUser Origin = "user" + // OriginUserSystem - Indicates the operation is initiated by a user or system. + OriginUserSystem Origin = "user,system" +) + +// PossibleOriginValues returns the possible values for the Origin const type. +func PossibleOriginValues() []Origin { + return []Origin{ + OriginSystem, + OriginUser, + OriginUserSystem, + } +} + +// ProvisioningState - The status of the current operation +type ProvisioningState string + +const ( + // ProvisioningStateAccepted - The resource create request has been accepted + ProvisioningStateAccepted ProvisioningState = "Accepted" + // ProvisioningStateCanceled - Resource creation was canceled. + ProvisioningStateCanceled ProvisioningState = "Canceled" + // ProvisioningStateDeleting - The resource is being deleted + ProvisioningStateDeleting ProvisioningState = "Deleting" + // ProvisioningStateFailed - Resource creation failed. + ProvisioningStateFailed ProvisioningState = "Failed" + // ProvisioningStateProvisioning - The resource is being provisioned + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + // ProvisioningStateSucceeded - Resource has been created. + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + // ProvisioningStateUpdating - The resource is updating + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +// PossibleProvisioningStateValues returns the possible values for the ProvisioningState const type. +func PossibleProvisioningStateValues() []ProvisioningState { + return []ProvisioningState{ + ProvisioningStateAccepted, + ProvisioningStateCanceled, + ProvisioningStateDeleting, + ProvisioningStateFailed, + ProvisioningStateProvisioning, + ProvisioningStateSucceeded, + ProvisioningStateUpdating, + } +} + +// RedundancyState - The state of the resource redundancy +type RedundancyState string + +const ( + // RedundancyStateNone - The resource is not redundant + RedundancyStateNone RedundancyState = "None" + // RedundancyStateZone - The resource is zone redundant + RedundancyStateZone RedundancyState = "Zone" +) + +// PossibleRedundancyStateValues returns the possible values for the RedundancyState const type. +func PossibleRedundancyStateValues() []RedundancyState { + return []RedundancyState{ + RedundancyStateNone, + RedundancyStateZone, + } +} diff --git a/sdk/resourcemanager/durabletask/armdurabletask/fake/internal.go b/sdk/resourcemanager/durabletask/armdurabletask/fake/internal.go new file mode 100644 index 000000000000..7425b6a669e2 --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/fake/internal.go @@ -0,0 +1,65 @@ +// 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) Go Code Generator. DO NOT EDIT. + +package fake + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "net/http" + "sync" +) + +type result struct { + resp *http.Response + err error +} + +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/durabletask/armdurabletask/fake/operations_server.go b/sdk/resourcemanager/durabletask/armdurabletask/fake/operations_server.go new file mode 100644 index 000000000000..d147c87663ca --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/fake/operations_server.go @@ -0,0 +1,117 @@ +// 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) Go Code Generator. DO NOT EDIT. + +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/durabletask/armdurabletask" + "net/http" +) + +// OperationsServer is a fake server for instances of the armdurabletask.OperationsClient type. +type OperationsServer struct { + // NewListPager is the fake for method OperationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armdurabletask.OperationsClientListOptions) (resp azfake.PagerResponder[armdurabletask.OperationsClientListResponse]) +} + +// NewOperationsServerTransport creates a new instance of OperationsServerTransport with the provided implementation. +// The returned OperationsServerTransport instance is connected to an instance of armdurabletask.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[armdurabletask.OperationsClientListResponse]](), + } +} + +// OperationsServerTransport connects instances of armdurabletask.OperationsClient to instances of OperationsServer. +// Don't use this type directly, use NewOperationsServerTransport instead. +type OperationsServerTransport struct { + srv *OperationsServer + newListPager *tracker[azfake.PagerResponder[armdurabletask.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")} + } + + return o.dispatchToMethodFake(req, method) +} + +func (o *OperationsServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if operationsServerTransportInterceptor != nil { + res.resp, res.err, intercepted = operationsServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "OperationsClient.NewListPager": + res.resp, res.err = o.dispatchNewListPager(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +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 *armdurabletask.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 +} + +// set this to conditionally intercept incoming requests to OperationsServerTransport +var operationsServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/sdk/resourcemanager/durabletask/armdurabletask/fake/schedulers_server.go b/sdk/resourcemanager/durabletask/armdurabletask/fake/schedulers_server.go new file mode 100644 index 000000000000..98c282491c57 --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/fake/schedulers_server.go @@ -0,0 +1,374 @@ +// 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) Go Code Generator. DO NOT EDIT. + +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/durabletask/armdurabletask" + "net/http" + "net/url" + "regexp" +) + +// SchedulersServer is a fake server for instances of the armdurabletask.SchedulersClient type. +type SchedulersServer struct { + // BeginCreateOrUpdate is the fake for method SchedulersClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, schedulerName string, resource armdurabletask.Scheduler, options *armdurabletask.SchedulersClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armdurabletask.SchedulersClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method SchedulersClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, schedulerName string, options *armdurabletask.SchedulersClientBeginDeleteOptions) (resp azfake.PollerResponder[armdurabletask.SchedulersClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method SchedulersClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, schedulerName string, options *armdurabletask.SchedulersClientGetOptions) (resp azfake.Responder[armdurabletask.SchedulersClientGetResponse], errResp azfake.ErrorResponder) + + // NewListByResourceGroupPager is the fake for method SchedulersClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armdurabletask.SchedulersClientListByResourceGroupOptions) (resp azfake.PagerResponder[armdurabletask.SchedulersClientListByResourceGroupResponse]) + + // NewListBySubscriptionPager is the fake for method SchedulersClient.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armdurabletask.SchedulersClientListBySubscriptionOptions) (resp azfake.PagerResponder[armdurabletask.SchedulersClientListBySubscriptionResponse]) + + // BeginUpdate is the fake for method SchedulersClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdate func(ctx context.Context, resourceGroupName string, schedulerName string, properties armdurabletask.Scheduler, options *armdurabletask.SchedulersClientBeginUpdateOptions) (resp azfake.PollerResponder[armdurabletask.SchedulersClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewSchedulersServerTransport creates a new instance of SchedulersServerTransport with the provided implementation. +// The returned SchedulersServerTransport instance is connected to an instance of armdurabletask.SchedulersClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewSchedulersServerTransport(srv *SchedulersServer) *SchedulersServerTransport { + return &SchedulersServerTransport{ + srv: srv, + beginCreateOrUpdate: newTracker[azfake.PollerResponder[armdurabletask.SchedulersClientCreateOrUpdateResponse]](), + beginDelete: newTracker[azfake.PollerResponder[armdurabletask.SchedulersClientDeleteResponse]](), + newListByResourceGroupPager: newTracker[azfake.PagerResponder[armdurabletask.SchedulersClientListByResourceGroupResponse]](), + newListBySubscriptionPager: newTracker[azfake.PagerResponder[armdurabletask.SchedulersClientListBySubscriptionResponse]](), + beginUpdate: newTracker[azfake.PollerResponder[armdurabletask.SchedulersClientUpdateResponse]](), + } +} + +// SchedulersServerTransport connects instances of armdurabletask.SchedulersClient to instances of SchedulersServer. +// Don't use this type directly, use NewSchedulersServerTransport instead. +type SchedulersServerTransport struct { + srv *SchedulersServer + beginCreateOrUpdate *tracker[azfake.PollerResponder[armdurabletask.SchedulersClientCreateOrUpdateResponse]] + beginDelete *tracker[azfake.PollerResponder[armdurabletask.SchedulersClientDeleteResponse]] + newListByResourceGroupPager *tracker[azfake.PagerResponder[armdurabletask.SchedulersClientListByResourceGroupResponse]] + newListBySubscriptionPager *tracker[azfake.PagerResponder[armdurabletask.SchedulersClientListBySubscriptionResponse]] + beginUpdate *tracker[azfake.PollerResponder[armdurabletask.SchedulersClientUpdateResponse]] +} + +// Do implements the policy.Transporter interface for SchedulersServerTransport. +func (s *SchedulersServerTransport) 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")} + } + + return s.dispatchToMethodFake(req, method) +} + +func (s *SchedulersServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if schedulersServerTransportInterceptor != nil { + res.resp, res.err, intercepted = schedulersServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "SchedulersClient.BeginCreateOrUpdate": + res.resp, res.err = s.dispatchBeginCreateOrUpdate(req) + case "SchedulersClient.BeginDelete": + res.resp, res.err = s.dispatchBeginDelete(req) + case "SchedulersClient.Get": + res.resp, res.err = s.dispatchGet(req) + case "SchedulersClient.NewListByResourceGroupPager": + res.resp, res.err = s.dispatchNewListByResourceGroupPager(req) + case "SchedulersClient.NewListBySubscriptionPager": + res.resp, res.err = s.dispatchNewListBySubscriptionPager(req) + case "SchedulersClient.BeginUpdate": + res.resp, res.err = s.dispatchBeginUpdate(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (s *SchedulersServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + beginCreateOrUpdate := s.beginCreateOrUpdate.get(req) + if beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DurableTask/schedulers/(?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[armdurabletask.Scheduler](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + schedulerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("schedulerName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, schedulerNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdate = &respr + s.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) { + s.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) { + s.beginCreateOrUpdate.remove(req) + } + + return resp, nil +} + +func (s *SchedulersServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if s.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + beginDelete := s.beginDelete.get(req) + if beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DurableTask/schedulers/(?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 + } + schedulerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("schedulerName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginDelete(req.Context(), resourceGroupNameParam, schedulerNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDelete = &respr + s.beginDelete.add(req, beginDelete) + } + + resp, err := server.PollerResponderNext(beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + s.beginDelete.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(beginDelete) { + s.beginDelete.remove(req) + } + + return resp, nil +} + +func (s *SchedulersServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if s.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\.DurableTask/schedulers/(?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 + } + schedulerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("schedulerName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameParam, schedulerNameParam, 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).Scheduler, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SchedulersServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + newListByResourceGroupPager := s.newListByResourceGroupPager.get(req) + if newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DurableTask/schedulers` + 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 := s.srv.NewListByResourceGroupPager(resourceGroupNameParam, nil) + newListByResourceGroupPager = &resp + s.newListByResourceGroupPager.add(req, newListByResourceGroupPager) + server.PagerResponderInjectNextLinks(newListByResourceGroupPager, req, func(page *armdurabletask.SchedulersClientListByResourceGroupResponse, 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) { + s.newListByResourceGroupPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListByResourceGroupPager) { + s.newListByResourceGroupPager.remove(req) + } + return resp, nil +} + +func (s *SchedulersServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListBySubscriptionPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListBySubscriptionPager not implemented")} + } + newListBySubscriptionPager := s.newListBySubscriptionPager.get(req) + if newListBySubscriptionPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DurableTask/schedulers` + 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 := s.srv.NewListBySubscriptionPager(nil) + newListBySubscriptionPager = &resp + s.newListBySubscriptionPager.add(req, newListBySubscriptionPager) + server.PagerResponderInjectNextLinks(newListBySubscriptionPager, req, func(page *armdurabletask.SchedulersClientListBySubscriptionResponse, 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) { + s.newListBySubscriptionPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListBySubscriptionPager) { + s.newListBySubscriptionPager.remove(req) + } + return resp, nil +} + +func (s *SchedulersServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if s.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} + } + beginUpdate := s.beginUpdate.get(req) + if beginUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DurableTask/schedulers/(?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[armdurabletask.Scheduler](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + schedulerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("schedulerName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginUpdate(req.Context(), resourceGroupNameParam, schedulerNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginUpdate = &respr + s.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) { + s.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) { + s.beginUpdate.remove(req) + } + + return resp, nil +} + +// set this to conditionally intercept incoming requests to SchedulersServerTransport +var schedulersServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/sdk/resourcemanager/durabletask/armdurabletask/fake/server_factory.go b/sdk/resourcemanager/durabletask/armdurabletask/fake/server_factory.go new file mode 100644 index 000000000000..c848fe8a7065 --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/fake/server_factory.go @@ -0,0 +1,86 @@ +// 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) Go Code Generator. DO NOT EDIT. + +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 armdurabletask.ClientFactory type. +type ServerFactory struct { + // OperationsServer contains the fakes for client OperationsClient + OperationsServer OperationsServer + + // SchedulersServer contains the fakes for client SchedulersClient + SchedulersServer SchedulersServer + + // TaskHubsServer contains the fakes for client TaskHubsClient + TaskHubsServer TaskHubsServer +} + +// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. +// The returned ServerFactoryTransport instance is connected to an instance of armdurabletask.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 armdurabletask.ClientFactory to instances of ServerFactory. +// Don't use this type directly, use NewServerFactoryTransport instead. +type ServerFactoryTransport struct { + srv *ServerFactory + trMu sync.Mutex + trOperationsServer *OperationsServerTransport + trSchedulersServer *SchedulersServerTransport + trTaskHubsServer *TaskHubsServerTransport +} + +// 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 "OperationsClient": + initServer(s, &s.trOperationsServer, func() *OperationsServerTransport { return NewOperationsServerTransport(&s.srv.OperationsServer) }) + resp, err = s.trOperationsServer.Do(req) + case "SchedulersClient": + initServer(s, &s.trSchedulersServer, func() *SchedulersServerTransport { return NewSchedulersServerTransport(&s.srv.SchedulersServer) }) + resp, err = s.trSchedulersServer.Do(req) + case "TaskHubsClient": + initServer(s, &s.trTaskHubsServer, func() *TaskHubsServerTransport { return NewTaskHubsServerTransport(&s.srv.TaskHubsServer) }) + resp, err = s.trTaskHubsServer.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/durabletask/armdurabletask/fake/taskhubs_server.go b/sdk/resourcemanager/durabletask/armdurabletask/fake/taskhubs_server.go new file mode 100644 index 000000000000..07438a60184c --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/fake/taskhubs_server.go @@ -0,0 +1,293 @@ +// 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) Go Code Generator. DO NOT EDIT. + +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/durabletask/armdurabletask" + "net/http" + "net/url" + "regexp" +) + +// TaskHubsServer is a fake server for instances of the armdurabletask.TaskHubsClient type. +type TaskHubsServer struct { + // BeginCreateOrUpdate is the fake for method TaskHubsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, schedulerName string, taskHubName string, resource armdurabletask.TaskHub, options *armdurabletask.TaskHubsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armdurabletask.TaskHubsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method TaskHubsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, schedulerName string, taskHubName string, options *armdurabletask.TaskHubsClientBeginDeleteOptions) (resp azfake.PollerResponder[armdurabletask.TaskHubsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method TaskHubsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, schedulerName string, taskHubName string, options *armdurabletask.TaskHubsClientGetOptions) (resp azfake.Responder[armdurabletask.TaskHubsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListBySchedulerPager is the fake for method TaskHubsClient.NewListBySchedulerPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySchedulerPager func(resourceGroupName string, schedulerName string, options *armdurabletask.TaskHubsClientListBySchedulerOptions) (resp azfake.PagerResponder[armdurabletask.TaskHubsClientListBySchedulerResponse]) +} + +// NewTaskHubsServerTransport creates a new instance of TaskHubsServerTransport with the provided implementation. +// The returned TaskHubsServerTransport instance is connected to an instance of armdurabletask.TaskHubsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewTaskHubsServerTransport(srv *TaskHubsServer) *TaskHubsServerTransport { + return &TaskHubsServerTransport{ + srv: srv, + beginCreateOrUpdate: newTracker[azfake.PollerResponder[armdurabletask.TaskHubsClientCreateOrUpdateResponse]](), + beginDelete: newTracker[azfake.PollerResponder[armdurabletask.TaskHubsClientDeleteResponse]](), + newListBySchedulerPager: newTracker[azfake.PagerResponder[armdurabletask.TaskHubsClientListBySchedulerResponse]](), + } +} + +// TaskHubsServerTransport connects instances of armdurabletask.TaskHubsClient to instances of TaskHubsServer. +// Don't use this type directly, use NewTaskHubsServerTransport instead. +type TaskHubsServerTransport struct { + srv *TaskHubsServer + beginCreateOrUpdate *tracker[azfake.PollerResponder[armdurabletask.TaskHubsClientCreateOrUpdateResponse]] + beginDelete *tracker[azfake.PollerResponder[armdurabletask.TaskHubsClientDeleteResponse]] + newListBySchedulerPager *tracker[azfake.PagerResponder[armdurabletask.TaskHubsClientListBySchedulerResponse]] +} + +// Do implements the policy.Transporter interface for TaskHubsServerTransport. +func (t *TaskHubsServerTransport) 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")} + } + + return t.dispatchToMethodFake(req, method) +} + +func (t *TaskHubsServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if taskHubsServerTransportInterceptor != nil { + res.resp, res.err, intercepted = taskHubsServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "TaskHubsClient.BeginCreateOrUpdate": + res.resp, res.err = t.dispatchBeginCreateOrUpdate(req) + case "TaskHubsClient.BeginDelete": + res.resp, res.err = t.dispatchBeginDelete(req) + case "TaskHubsClient.Get": + res.resp, res.err = t.dispatchGet(req) + case "TaskHubsClient.NewListBySchedulerPager": + res.resp, res.err = t.dispatchNewListBySchedulerPager(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (t *TaskHubsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if t.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + beginCreateOrUpdate := t.beginCreateOrUpdate.get(req) + if beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DurableTask/schedulers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/taskHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armdurabletask.TaskHub](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + schedulerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("schedulerName")]) + if err != nil { + return nil, err + } + taskHubNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("taskHubName")]) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, schedulerNameParam, taskHubNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdate = &respr + t.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) { + t.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) { + t.beginCreateOrUpdate.remove(req) + } + + return resp, nil +} + +func (t *TaskHubsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if t.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + beginDelete := t.beginDelete.get(req) + if beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DurableTask/schedulers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/taskHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + 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 + } + schedulerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("schedulerName")]) + if err != nil { + return nil, err + } + taskHubNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("taskHubName")]) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.BeginDelete(req.Context(), resourceGroupNameParam, schedulerNameParam, taskHubNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDelete = &respr + t.beginDelete.add(req, beginDelete) + } + + resp, err := server.PollerResponderNext(beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + t.beginDelete.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(beginDelete) { + t.beginDelete.remove(req) + } + + return resp, nil +} + +func (t *TaskHubsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if t.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\.DurableTask/schedulers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/taskHubs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + 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 + } + schedulerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("schedulerName")]) + if err != nil { + return nil, err + } + taskHubNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("taskHubName")]) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.Get(req.Context(), resourceGroupNameParam, schedulerNameParam, taskHubNameParam, 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).TaskHub, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (t *TaskHubsServerTransport) dispatchNewListBySchedulerPager(req *http.Request) (*http.Response, error) { + if t.srv.NewListBySchedulerPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListBySchedulerPager not implemented")} + } + newListBySchedulerPager := t.newListBySchedulerPager.get(req) + if newListBySchedulerPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DurableTask/schedulers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/taskHubs` + 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 + } + schedulerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("schedulerName")]) + if err != nil { + return nil, err + } + resp := t.srv.NewListBySchedulerPager(resourceGroupNameParam, schedulerNameParam, nil) + newListBySchedulerPager = &resp + t.newListBySchedulerPager.add(req, newListBySchedulerPager) + server.PagerResponderInjectNextLinks(newListBySchedulerPager, req, func(page *armdurabletask.TaskHubsClientListBySchedulerResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListBySchedulerPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + t.newListBySchedulerPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListBySchedulerPager) { + t.newListBySchedulerPager.remove(req) + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to TaskHubsServerTransport +var taskHubsServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/sdk/resourcemanager/durabletask/armdurabletask/fake/time_rfc3339.go b/sdk/resourcemanager/durabletask/armdurabletask/fake/time_rfc3339.go new file mode 100644 index 000000000000..87ee11e83b32 --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/fake/time_rfc3339.go @@ -0,0 +1,109 @@ +// 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) Go Code Generator. DO NOT EDIT. + +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 { + if len(data) == 0 { + return nil + } + 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/durabletask/armdurabletask/go.mod b/sdk/resourcemanager/durabletask/armdurabletask/go.mod new file mode 100644 index 000000000000..f77beed24400 --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/go.mod @@ -0,0 +1,21 @@ +module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/durabletask/armdurabletask + +go 1.18 + +require ( + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0 +) + +require ( + github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect + github.com/golang-jwt/jwt/v5 v5.2.1 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/kylelemons/godebug v1.1.0 // indirect + github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect + golang.org/x/crypto v0.27.0 // indirect + golang.org/x/net v0.29.0 // indirect + golang.org/x/sys v0.25.0 // indirect + golang.org/x/text v0.18.0 // indirect +) diff --git a/sdk/resourcemanager/durabletask/armdurabletask/go.sum b/sdk/resourcemanager/durabletask/armdurabletask/go.sum new file mode 100644 index 000000000000..cbddbbd9ecec --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/go.sum @@ -0,0 +1,29 @@ +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 h1:JZg6HRh6W6U4OLl6lk7BZ7BLisIzM9dG1R50zUk9C/M= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0/go.mod h1:YL1xnZ6QejvQHWJrX/AvhFl4WW4rqHVoKspWNVwFk0M= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0 h1:tfLQ34V6F7tVSwoTf/4lH5sE0o6eCJuNDTmH09nDpbc= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0/go.mod h1:9kIvujWAA58nmPmWB1m23fyWic1kYZMxD9CxaWn4Qpg= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0/go.mod h1:iZDifYGJTIgIIkYRNWPENUnqx6bJ2xnSDFI2tjwZNuY= +github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 h1:XHOnouVk1mxXfQidrMEnLlPk9UMeRtyBTnEFtxkV0kU= +github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= +github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= +github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/sdk/resourcemanager/durabletask/armdurabletask/models.go b/sdk/resourcemanager/durabletask/armdurabletask/models.go new file mode 100644 index 000000000000..214506bc8410 --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/models.go @@ -0,0 +1,173 @@ +// 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) Go Code Generator. DO NOT EDIT. + +package armdurabletask + +import "time" + +// Operation - Details of a REST API operation, returned from the Resource Provider Operations API +type Operation struct { + // Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + ActionType *ActionType + + // READ-ONLY; Localized display information for this particular operation. + Display *OperationDisplay + + // READ-ONLY; Whether the operation applies to data-plane. This is "true" for data-plane operations and "false" for Azure + // Resource Manager/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 and 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 { + // REQUIRED; The Operation items on this page + Value []*Operation + + // The link to the next page of items + NextLink *string +} + +// Scheduler - A Durable Task Scheduler resource +type Scheduler struct { + // REQUIRED; The geo-location where the resource lives + Location *string + + // The resource-specific properties for this resource. + Properties *SchedulerProperties + + // Resource tags. + Tags map[string]*string + + // READ-ONLY; The name of the Scheduler + Name *string + + // READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *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 +} + +// SchedulerListResult - The response of a Scheduler list operation. +type SchedulerListResult struct { + // REQUIRED; The Scheduler items on this page + Value []*Scheduler + + // The link to the next page of items + NextLink *string +} + +// SchedulerProperties - Details of the Scheduler +type SchedulerProperties struct { + // REQUIRED; IP allow list for durable task scheduler. Values can be IPv4, IPv6 or CIDR + IPAllowlist []*string + + // REQUIRED; SKU of the durable task scheduler + SKU *SchedulerSKU + + // READ-ONLY; URL of the durable task scheduler + Endpoint *string + + // READ-ONLY; The status of the last operation + ProvisioningState *ProvisioningState +} + +// SchedulerSKU - The SKU (Stock Keeping Unit) assigned to this durable task scheduler +type SchedulerSKU struct { + // REQUIRED; The name of the SKU + Name *string + + // The SKU capacity. This allows scale out/in for the resource and impacts zone redundancy + Capacity *int32 + + // READ-ONLY; Indicates whether the current SKU configuration is zone redundant + RedundancyState *RedundancyState +} + +// 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 +} + +// TaskHub - A Task Hub resource belonging to the scheduler +type TaskHub struct { + // The resource-specific properties for this resource. + Properties *TaskHubProperties + + // READ-ONLY; The name of the TaskHub + Name *string + + // READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *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 +} + +// TaskHubListResult - The response of a TaskHub list operation. +type TaskHubListResult struct { + // REQUIRED; The TaskHub items on this page + Value []*TaskHub + + // The link to the next page of items + NextLink *string +} + +// TaskHubProperties - The properties of Task Hub +type TaskHubProperties struct { + // READ-ONLY; URL of the durable task scheduler dashboard + DashboardURL *string + + // READ-ONLY; The status of the last operation + ProvisioningState *ProvisioningState +} diff --git a/sdk/resourcemanager/durabletask/armdurabletask/models_serde.go b/sdk/resourcemanager/durabletask/armdurabletask/models_serde.go new file mode 100644 index 000000000000..26f2e2d7d9fb --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/models_serde.go @@ -0,0 +1,453 @@ +// 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) Go Code Generator. DO NOT EDIT. + +package armdurabletask + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" +) + +// 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 Scheduler. +func (s Scheduler) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", s.ID) + populate(objectMap, "location", s.Location) + populate(objectMap, "name", s.Name) + populate(objectMap, "properties", s.Properties) + populate(objectMap, "systemData", s.SystemData) + populate(objectMap, "tags", s.Tags) + populate(objectMap, "type", s.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Scheduler. +func (s *Scheduler) 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 "id": + err = unpopulate(val, "ID", &s.ID) + delete(rawMsg, key) + case "location": + err = unpopulate(val, "Location", &s.Location) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &s.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &s.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &s.SystemData) + delete(rawMsg, key) + case "tags": + err = unpopulate(val, "Tags", &s.Tags) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &s.Type) + 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 SchedulerListResult. +func (s SchedulerListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", s.NextLink) + populate(objectMap, "value", s.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SchedulerListResult. +func (s *SchedulerListResult) 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 "nextLink": + err = unpopulate(val, "NextLink", &s.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &s.Value) + 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 SchedulerProperties. +func (s SchedulerProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "endpoint", s.Endpoint) + populate(objectMap, "ipAllowlist", s.IPAllowlist) + populate(objectMap, "provisioningState", s.ProvisioningState) + populate(objectMap, "sku", s.SKU) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SchedulerProperties. +func (s *SchedulerProperties) 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 "endpoint": + err = unpopulate(val, "Endpoint", &s.Endpoint) + delete(rawMsg, key) + case "ipAllowlist": + err = unpopulate(val, "IPAllowlist", &s.IPAllowlist) + delete(rawMsg, key) + case "provisioningState": + err = unpopulate(val, "ProvisioningState", &s.ProvisioningState) + delete(rawMsg, key) + case "sku": + err = unpopulate(val, "SKU", &s.SKU) + 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 SchedulerSKU. +func (s SchedulerSKU) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "capacity", s.Capacity) + populate(objectMap, "name", s.Name) + populate(objectMap, "redundancyState", s.RedundancyState) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SchedulerSKU. +func (s *SchedulerSKU) 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 "capacity": + err = unpopulate(val, "Capacity", &s.Capacity) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &s.Name) + delete(rawMsg, key) + case "redundancyState": + err = unpopulate(val, "RedundancyState", &s.RedundancyState) + 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 +} + +// MarshalJSON implements the json.Marshaller interface for type TaskHub. +func (t TaskHub) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", t.ID) + populate(objectMap, "name", t.Name) + populate(objectMap, "properties", t.Properties) + populate(objectMap, "systemData", t.SystemData) + populate(objectMap, "type", t.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type TaskHub. +func (t *TaskHub) 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", t, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &t.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &t.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &t.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &t.SystemData) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &t.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type TaskHubListResult. +func (t TaskHubListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", t.NextLink) + populate(objectMap, "value", t.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type TaskHubListResult. +func (t *TaskHubListResult) 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", t, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &t.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &t.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type TaskHubProperties. +func (t TaskHubProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "dashboardUrl", t.DashboardURL) + populate(objectMap, "provisioningState", t.ProvisioningState) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type TaskHubProperties. +func (t *TaskHubProperties) 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", t, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "dashboardUrl": + err = unpopulate(val, "DashboardURL", &t.DashboardURL) + delete(rawMsg, key) + case "provisioningState": + err = unpopulate(val, "ProvisioningState", &t.ProvisioningState) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, 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/durabletask/armdurabletask/operations_client.go b/sdk/resourcemanager/durabletask/armdurabletask/operations_client.go new file mode 100644 index 000000000000..e04bf17dd55d --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/operations_client.go @@ -0,0 +1,84 @@ +// 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) Go Code Generator. DO NOT EDIT. + +package armdurabletask + +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-10-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, _ *OperationsClientListOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.DurableTask/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-10-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/durabletask/armdurabletask/operations_client_example_test.go b/sdk/resourcemanager/durabletask/armdurabletask/operations_client_example_test.go new file mode 100644 index 000000000000..b6a09b3c04bf --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/operations_client_example_test.go @@ -0,0 +1,56 @@ +// 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) Go Code Generator. DO NOT EDIT. + +package armdurabletask_test + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/durabletask/armdurabletask" + "log" +) + +// Generated from example definition: 2024-10-01-preview/Operations_List.json +func ExampleOperationsClient_NewListPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armdurabletask.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewOperationsClient().NewListPager(nil) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page = armdurabletask.OperationsClientListResponse{ + // OperationListResult: armdurabletask.OperationListResult{ + // Value: []*armdurabletask.Operation{ + // { + // Name: to.Ptr("jqsgzvpbtspnikfz"), + // IsDataAction: to.Ptr(true), + // Display: &armdurabletask.OperationDisplay{ + // Provider: to.Ptr("bosyazksbxugcbsdipxwmdc"), + // Resource: to.Ptr("texxqckghuv"), + // Operation: to.Ptr("cwgwrxyusyqdrcbxrlmnjzpwxatuk"), + // Description: to.Ptr("mqzopqigvcyggcvezqgvyufbd"), + // }, + // Origin: to.Ptr(armdurabletask.OriginUser), + // ActionType: to.Ptr(armdurabletask.ActionTypeInternal), + // }, + // }, + // NextLink: to.Ptr("https://microsoft.com/akpblld"), + // }, + // } + } +} diff --git a/sdk/resourcemanager/durabletask/armdurabletask/options.go b/sdk/resourcemanager/durabletask/armdurabletask/options.go new file mode 100644 index 000000000000..0b89a2fa1e01 --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/options.go @@ -0,0 +1,68 @@ +// 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) Go Code Generator. DO NOT EDIT. + +package armdurabletask + +// OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. +type OperationsClientListOptions struct { + // placeholder for future optional parameters +} + +// SchedulersClientBeginCreateOrUpdateOptions contains the optional parameters for the SchedulersClient.BeginCreateOrUpdate +// method. +type SchedulersClientBeginCreateOrUpdateOptions struct { + // Resumes the long-running operation from the provided token. + ResumeToken string +} + +// SchedulersClientBeginDeleteOptions contains the optional parameters for the SchedulersClient.BeginDelete method. +type SchedulersClientBeginDeleteOptions struct { + // Resumes the long-running operation from the provided token. + ResumeToken string +} + +// SchedulersClientBeginUpdateOptions contains the optional parameters for the SchedulersClient.BeginUpdate method. +type SchedulersClientBeginUpdateOptions struct { + // Resumes the long-running operation from the provided token. + ResumeToken string +} + +// SchedulersClientGetOptions contains the optional parameters for the SchedulersClient.Get method. +type SchedulersClientGetOptions struct { + // placeholder for future optional parameters +} + +// SchedulersClientListByResourceGroupOptions contains the optional parameters for the SchedulersClient.NewListByResourceGroupPager +// method. +type SchedulersClientListByResourceGroupOptions struct { + // placeholder for future optional parameters +} + +// SchedulersClientListBySubscriptionOptions contains the optional parameters for the SchedulersClient.NewListBySubscriptionPager +// method. +type SchedulersClientListBySubscriptionOptions struct { + // placeholder for future optional parameters +} + +// TaskHubsClientBeginCreateOrUpdateOptions contains the optional parameters for the TaskHubsClient.BeginCreateOrUpdate method. +type TaskHubsClientBeginCreateOrUpdateOptions struct { + // Resumes the long-running operation from the provided token. + ResumeToken string +} + +// TaskHubsClientBeginDeleteOptions contains the optional parameters for the TaskHubsClient.BeginDelete method. +type TaskHubsClientBeginDeleteOptions struct { + // Resumes the long-running operation from the provided token. + ResumeToken string +} + +// TaskHubsClientGetOptions contains the optional parameters for the TaskHubsClient.Get method. +type TaskHubsClientGetOptions struct { + // placeholder for future optional parameters +} + +// TaskHubsClientListBySchedulerOptions contains the optional parameters for the TaskHubsClient.NewListBySchedulerPager method. +type TaskHubsClientListBySchedulerOptions struct { + // placeholder for future optional parameters +} diff --git a/sdk/resourcemanager/durabletask/armdurabletask/responses.go b/sdk/resourcemanager/durabletask/armdurabletask/responses.go new file mode 100644 index 000000000000..98a93ab5ca8b --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/responses.go @@ -0,0 +1,69 @@ +// 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) Go Code Generator. DO NOT EDIT. + +package armdurabletask + +// 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 +} + +// SchedulersClientCreateOrUpdateResponse contains the response from method SchedulersClient.BeginCreateOrUpdate. +type SchedulersClientCreateOrUpdateResponse struct { + // A Durable Task Scheduler resource + Scheduler +} + +// SchedulersClientDeleteResponse contains the response from method SchedulersClient.BeginDelete. +type SchedulersClientDeleteResponse struct { + // placeholder for future response values +} + +// SchedulersClientGetResponse contains the response from method SchedulersClient.Get. +type SchedulersClientGetResponse struct { + // A Durable Task Scheduler resource + Scheduler +} + +// SchedulersClientListByResourceGroupResponse contains the response from method SchedulersClient.NewListByResourceGroupPager. +type SchedulersClientListByResourceGroupResponse struct { + // The response of a Scheduler list operation. + SchedulerListResult +} + +// SchedulersClientListBySubscriptionResponse contains the response from method SchedulersClient.NewListBySubscriptionPager. +type SchedulersClientListBySubscriptionResponse struct { + // The response of a Scheduler list operation. + SchedulerListResult +} + +// SchedulersClientUpdateResponse contains the response from method SchedulersClient.BeginUpdate. +type SchedulersClientUpdateResponse struct { + // A Durable Task Scheduler resource + Scheduler +} + +// TaskHubsClientCreateOrUpdateResponse contains the response from method TaskHubsClient.BeginCreateOrUpdate. +type TaskHubsClientCreateOrUpdateResponse struct { + // A Task Hub resource belonging to the scheduler + TaskHub +} + +// TaskHubsClientDeleteResponse contains the response from method TaskHubsClient.BeginDelete. +type TaskHubsClientDeleteResponse struct { + // placeholder for future response values +} + +// TaskHubsClientGetResponse contains the response from method TaskHubsClient.Get. +type TaskHubsClientGetResponse struct { + // A Task Hub resource belonging to the scheduler + TaskHub +} + +// TaskHubsClientListBySchedulerResponse contains the response from method TaskHubsClient.NewListBySchedulerPager. +type TaskHubsClientListBySchedulerResponse struct { + // The response of a TaskHub list operation. + TaskHubListResult +} diff --git a/sdk/resourcemanager/durabletask/armdurabletask/schedulers_client.go b/sdk/resourcemanager/durabletask/armdurabletask/schedulers_client.go new file mode 100644 index 000000000000..73494324aaf6 --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/schedulers_client.go @@ -0,0 +1,455 @@ +// 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) Go Code Generator. DO NOT EDIT. + +package armdurabletask + +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" +) + +// SchedulersClient contains the methods for the Schedulers group. +// Don't use this type directly, use NewSchedulersClient() instead. +type SchedulersClient struct { + internal *arm.Client + subscriptionID string +} + +// NewSchedulersClient creates a new instance of SchedulersClient 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 NewSchedulersClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*SchedulersClient, error) { + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &SchedulersClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// BeginCreateOrUpdate - Create or update a Scheduler +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-10-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - schedulerName - The name of the Scheduler +// - resource - Resource create parameters. +// - options - SchedulersClientBeginCreateOrUpdateOptions contains the optional parameters for the SchedulersClient.BeginCreateOrUpdate +// method. +func (client *SchedulersClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, schedulerName string, resource Scheduler, options *SchedulersClientBeginCreateOrUpdateOptions) (*runtime.Poller[SchedulersClientCreateOrUpdateResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.createOrUpdate(ctx, resourceGroupName, schedulerName, resource, options) + if err != nil { + return nil, err + } + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SchedulersClientCreateOrUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) + return poller, err + } else { + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[SchedulersClientCreateOrUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) + } +} + +// CreateOrUpdate - Create or update a Scheduler +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-10-01-preview +func (client *SchedulersClient) createOrUpdate(ctx context.Context, resourceGroupName string, schedulerName string, resource Scheduler, options *SchedulersClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "SchedulersClient.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, schedulerName, 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 *SchedulersClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, schedulerName string, resource Scheduler, _ *SchedulersClientBeginCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}" + 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 schedulerName == "" { + return nil, errors.New("parameter schedulerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{schedulerName}", url.PathEscape(schedulerName)) + 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-10-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + req.Raw().Header["Content-Type"] = []string{"application/json"} + if err := runtime.MarshalAsJSON(req, resource); err != nil { + return nil, err + } + return req, nil +} + +// BeginDelete - Delete a Scheduler +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-10-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - schedulerName - The name of the Scheduler +// - options - SchedulersClientBeginDeleteOptions contains the optional parameters for the SchedulersClient.BeginDelete method. +func (client *SchedulersClient) BeginDelete(ctx context.Context, resourceGroupName string, schedulerName string, options *SchedulersClientBeginDeleteOptions) (*runtime.Poller[SchedulersClientDeleteResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.deleteOperation(ctx, resourceGroupName, schedulerName, options) + if err != nil { + return nil, err + } + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SchedulersClientDeleteResponse]{ + Tracer: client.internal.Tracer(), + }) + return poller, err + } else { + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[SchedulersClientDeleteResponse]{ + Tracer: client.internal.Tracer(), + }) + } +} + +// Delete - Delete a Scheduler +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-10-01-preview +func (client *SchedulersClient) deleteOperation(ctx context.Context, resourceGroupName string, schedulerName string, options *SchedulersClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "SchedulersClient.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, schedulerName, 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 *SchedulersClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, schedulerName string, _ *SchedulersClientBeginDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}" + 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 schedulerName == "" { + return nil, errors.New("parameter schedulerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{schedulerName}", url.PathEscape(schedulerName)) + 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-10-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// Get - Get a Scheduler +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-10-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - schedulerName - The name of the Scheduler +// - options - SchedulersClientGetOptions contains the optional parameters for the SchedulersClient.Get method. +func (client *SchedulersClient) Get(ctx context.Context, resourceGroupName string, schedulerName string, options *SchedulersClientGetOptions) (SchedulersClientGetResponse, error) { + var err error + const operationName = "SchedulersClient.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, schedulerName, options) + if err != nil { + return SchedulersClientGetResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return SchedulersClientGetResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SchedulersClientGetResponse{}, err + } + resp, err := client.getHandleResponse(httpResp) + return resp, err +} + +// getCreateRequest creates the Get request. +func (client *SchedulersClient) getCreateRequest(ctx context.Context, resourceGroupName string, schedulerName string, _ *SchedulersClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}" + 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 schedulerName == "" { + return nil, errors.New("parameter schedulerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{schedulerName}", url.PathEscape(schedulerName)) + 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-10-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 *SchedulersClient) getHandleResponse(resp *http.Response) (SchedulersClientGetResponse, error) { + result := SchedulersClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.Scheduler); err != nil { + return SchedulersClientGetResponse{}, err + } + return result, nil +} + +// NewListByResourceGroupPager - List Schedulers by resource group +// +// Generated from API version 2024-10-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - options - SchedulersClientListByResourceGroupOptions contains the optional parameters for the SchedulersClient.NewListByResourceGroupPager +// method. +func (client *SchedulersClient) NewListByResourceGroupPager(resourceGroupName string, options *SchedulersClientListByResourceGroupOptions) *runtime.Pager[SchedulersClientListByResourceGroupResponse] { + return runtime.NewPager(runtime.PagingHandler[SchedulersClientListByResourceGroupResponse]{ + More: func(page SchedulersClientListByResourceGroupResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *SchedulersClientListByResourceGroupResponse) (SchedulersClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SchedulersClient.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 SchedulersClientListByResourceGroupResponse{}, err + } + return client.listByResourceGroupHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listByResourceGroupCreateRequest creates the ListByResourceGroup request. +func (client *SchedulersClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, _ *SchedulersClientListByResourceGroupOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers" + 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-10-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 *SchedulersClient) listByResourceGroupHandleResponse(resp *http.Response) (SchedulersClientListByResourceGroupResponse, error) { + result := SchedulersClientListByResourceGroupResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.SchedulerListResult); err != nil { + return SchedulersClientListByResourceGroupResponse{}, err + } + return result, nil +} + +// NewListBySubscriptionPager - List Schedulers by subscription +// +// Generated from API version 2024-10-01-preview +// - options - SchedulersClientListBySubscriptionOptions contains the optional parameters for the SchedulersClient.NewListBySubscriptionPager +// method. +func (client *SchedulersClient) NewListBySubscriptionPager(options *SchedulersClientListBySubscriptionOptions) *runtime.Pager[SchedulersClientListBySubscriptionResponse] { + return runtime.NewPager(runtime.PagingHandler[SchedulersClientListBySubscriptionResponse]{ + More: func(page SchedulersClientListBySubscriptionResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *SchedulersClientListBySubscriptionResponse) (SchedulersClientListBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SchedulersClient.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 SchedulersClientListBySubscriptionResponse{}, err + } + return client.listBySubscriptionHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listBySubscriptionCreateRequest creates the ListBySubscription request. +func (client *SchedulersClient) listBySubscriptionCreateRequest(ctx context.Context, _ *SchedulersClientListBySubscriptionOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.DurableTask/schedulers" + 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-10-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 *SchedulersClient) listBySubscriptionHandleResponse(resp *http.Response) (SchedulersClientListBySubscriptionResponse, error) { + result := SchedulersClientListBySubscriptionResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.SchedulerListResult); err != nil { + return SchedulersClientListBySubscriptionResponse{}, err + } + return result, nil +} + +// BeginUpdate - Update a Scheduler +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-10-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - schedulerName - The name of the Scheduler +// - properties - The resource properties to be updated. +// - options - SchedulersClientBeginUpdateOptions contains the optional parameters for the SchedulersClient.BeginUpdate method. +func (client *SchedulersClient) BeginUpdate(ctx context.Context, resourceGroupName string, schedulerName string, properties Scheduler, options *SchedulersClientBeginUpdateOptions) (*runtime.Poller[SchedulersClientUpdateResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.update(ctx, resourceGroupName, schedulerName, properties, options) + if err != nil { + return nil, err + } + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SchedulersClientUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) + return poller, err + } else { + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[SchedulersClientUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) + } +} + +// Update - Update a Scheduler +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-10-01-preview +func (client *SchedulersClient) update(ctx context.Context, resourceGroupName string, schedulerName string, properties Scheduler, options *SchedulersClientBeginUpdateOptions) (*http.Response, error) { + var err error + const operationName = "SchedulersClient.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, schedulerName, 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 *SchedulersClient) updateCreateRequest(ctx context.Context, resourceGroupName string, schedulerName string, properties Scheduler, _ *SchedulersClientBeginUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}" + 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 schedulerName == "" { + return nil, errors.New("parameter schedulerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{schedulerName}", url.PathEscape(schedulerName)) + 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-10-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + req.Raw().Header["Content-Type"] = []string{"application/json"} + if err := runtime.MarshalAsJSON(req, properties); err != nil { + return nil, err + } + return req, nil +} diff --git a/sdk/resourcemanager/durabletask/armdurabletask/schedulers_client_example_test.go b/sdk/resourcemanager/durabletask/armdurabletask/schedulers_client_example_test.go new file mode 100644 index 000000000000..72474d070a4b --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/schedulers_client_example_test.go @@ -0,0 +1,347 @@ +// 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) Go Code Generator. DO NOT EDIT. + +package armdurabletask_test + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/durabletask/armdurabletask" + "log" +) + +// Generated from example definition: 2024-10-01-preview/Schedulers_CreateOrUpdate.json +func ExampleSchedulersClient_BeginCreateOrUpdate() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armdurabletask.NewClientFactory("EE9BD735-67CE-4A90-89C4-439D3F6A4C93", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewSchedulersClient().BeginCreateOrUpdate(ctx, "rgopenapi", "testscheduler", armdurabletask.Scheduler{ + Location: to.Ptr("northcentralus"), + Properties: &armdurabletask.SchedulerProperties{ + IPAllowlist: []*string{ + to.Ptr("10.0.0.0/8"), + }, + SKU: &armdurabletask.SchedulerSKU{ + Name: to.Ptr("Dedicated"), + }, + }, + Tags: map[string]*string{ + "key7131": to.Ptr("ryohwcoiccwsnewjigfmijz"), + "key2138": to.Ptr("fjaeecgnvqd"), + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res = armdurabletask.SchedulersClientCreateOrUpdateResponse{ + // Scheduler: &armdurabletask.Scheduler{ + // Location: to.Ptr("northcentralus"), + // Properties: &armdurabletask.SchedulerProperties{ + // ProvisioningState: to.Ptr(armdurabletask.ProvisioningStateSucceeded), + // Endpoint: to.Ptr("https://test.northcentralus.1.durabletask.io"), + // IPAllowlist: []*string{ + // to.Ptr("10.0.0.0/8"), + // }, + // SKU: &armdurabletask.SchedulerSKU{ + // Name: to.Ptr("Dedicated"), + // Capacity: to.Ptr[int32](3), + // RedundancyState: to.Ptr(armdurabletask.RedundancyStateZone), + // }, + // }, + // Tags: map[string]*string{ + // "key7131": to.Ptr("ryohwcoiccwsnewjigfmijz"), + // "key2138": to.Ptr("fjaeecgnvqd"), + // }, + // ID: to.Ptr("/subscriptions/EE9BD735-67CE-4A90-89C4-439D3F6A4C93/resourceGroups/rgopenapi/providers/Microsoft.DurableTask/schedulers/testscheduler"), + // Name: to.Ptr("fwxpolhofploqzwdooyg"), + // Type: to.Ptr("vwqdbpynxwfhiopdypuabwvfohnr"), + // SystemData: &armdurabletask.SystemData{ + // CreatedBy: to.Ptr("tenmbevaunjzikxowqexrsx"), + // CreatedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.365Z"); return t}()), + // LastModifiedBy: to.Ptr("xfvdcegtj"), + // LastModifiedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.366Z"); return t}()), + // }, + // }, + // } +} + +// Generated from example definition: 2024-10-01-preview/Schedulers_Delete.json +func ExampleSchedulersClient_BeginDelete() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armdurabletask.NewClientFactory("EE9BD735-67CE-4A90-89C4-439D3F6A4C93", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewSchedulersClient().BeginDelete(ctx, "rgopenapi", "testscheduler", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + _, err = poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } +} + +// Generated from example definition: 2024-10-01-preview/Schedulers_Get.json +func ExampleSchedulersClient_Get() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armdurabletask.NewClientFactory("EE9BD735-67CE-4A90-89C4-439D3F6A4C93", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewSchedulersClient().Get(ctx, "rgopenapi", "testscheduler", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res = armdurabletask.SchedulersClientGetResponse{ + // Scheduler: &armdurabletask.Scheduler{ + // Location: to.Ptr("northcentralus"), + // Properties: &armdurabletask.SchedulerProperties{ + // ProvisioningState: to.Ptr(armdurabletask.ProvisioningStateSucceeded), + // Endpoint: to.Ptr("https://test.northcentralus.1.durabletask.io"), + // IPAllowlist: []*string{ + // to.Ptr("10.0.0.0/8"), + // }, + // SKU: &armdurabletask.SchedulerSKU{ + // Name: to.Ptr("Dedicated"), + // Capacity: to.Ptr[int32](3), + // RedundancyState: to.Ptr(armdurabletask.RedundancyStateZone), + // }, + // }, + // Tags: map[string]*string{ + // "key7131": to.Ptr("ryohwcoiccwsnewjigfmijz"), + // "key2138": to.Ptr("fjaeecgnvqd"), + // }, + // ID: to.Ptr("/subscriptions/EE9BD735-67CE-4A90-89C4-439D3F6A4C93/resourceGroups/rgopenapi/providers/Microsoft.DurableTask/schedulers/testscheduler"), + // Name: to.Ptr("testscheduler"), + // Type: to.Ptr("vwqdbpynxwfhiopdypuabwvfohnr"), + // SystemData: &armdurabletask.SystemData{ + // CreatedBy: to.Ptr("tenmbevaunjzikxowqexrsx"), + // CreatedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.365Z"); return t}()), + // LastModifiedBy: to.Ptr("xfvdcegtj"), + // LastModifiedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.366Z"); return t}()), + // }, + // }, + // } +} + +// Generated from example definition: 2024-10-01-preview/Schedulers_ListByResourceGroup.json +func ExampleSchedulersClient_NewListByResourceGroupPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armdurabletask.NewClientFactory("EE9BD735-67CE-4A90-89C4-439D3F6A4C93", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewSchedulersClient().NewListByResourceGroupPager("rgopenapi", nil) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page = armdurabletask.SchedulersClientListByResourceGroupResponse{ + // SchedulerListResult: armdurabletask.SchedulerListResult{ + // Value: []*armdurabletask.Scheduler{ + // { + // ID: to.Ptr("/subscriptions/EE9BD735-67CE-4A90-89C4-439D3F6A4C93/resourceGroups/rgopenapi/providers/Microsoft.DurableTask/schedulers/testscheduler"), + // Location: to.Ptr("northcentralus"), + // Properties: &armdurabletask.SchedulerProperties{ + // ProvisioningState: to.Ptr(armdurabletask.ProvisioningStateSucceeded), + // Endpoint: to.Ptr("https://test.northcentralus.1.durabletask.io"), + // IPAllowlist: []*string{ + // to.Ptr("10.0.0.0/8"), + // }, + // SKU: &armdurabletask.SchedulerSKU{ + // Name: to.Ptr("Dedicated"), + // Capacity: to.Ptr[int32](3), + // RedundancyState: to.Ptr(armdurabletask.RedundancyStateZone), + // }, + // }, + // Tags: map[string]*string{ + // "key2138": to.Ptr("fjaeecgnvqd"), + // }, + // Name: to.Ptr("testscheduler"), + // Type: to.Ptr("tglszobjxdhauglzxuqozeg"), + // SystemData: &armdurabletask.SystemData{ + // CreatedBy: to.Ptr("tenmbevaunjzikxowqexrsx"), + // CreatedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.365Z"); return t}()), + // LastModifiedBy: to.Ptr("xfvdcegtj"), + // LastModifiedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.366Z"); return t}()), + // }, + // }, + // }, + // NextLink: to.Ptr("https://microsoft.com/a"), + // }, + // } + } +} + +// Generated from example definition: 2024-10-01-preview/Schedulers_ListBySubscription.json +func ExampleSchedulersClient_NewListBySubscriptionPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armdurabletask.NewClientFactory("EE9BD735-67CE-4A90-89C4-439D3F6A4C93", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewSchedulersClient().NewListBySubscriptionPager(nil) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page = armdurabletask.SchedulersClientListBySubscriptionResponse{ + // SchedulerListResult: armdurabletask.SchedulerListResult{ + // Value: []*armdurabletask.Scheduler{ + // { + // ID: to.Ptr("/subscriptions/EE9BD735-67CE-4A90-89C4-439D3F6A4C93/resourceGroups/rgopenapi/providers/Microsoft.DurableTask/schedulers/testscheduler"), + // Location: to.Ptr("northcentralus"), + // Properties: &armdurabletask.SchedulerProperties{ + // ProvisioningState: to.Ptr(armdurabletask.ProvisioningStateSucceeded), + // Endpoint: to.Ptr("https://test.northcentralus.1.durabletask.io"), + // IPAllowlist: []*string{ + // to.Ptr("10.0.0.0/8"), + // }, + // SKU: &armdurabletask.SchedulerSKU{ + // Name: to.Ptr("Dedicated"), + // Capacity: to.Ptr[int32](3), + // RedundancyState: to.Ptr(armdurabletask.RedundancyStateZone), + // }, + // }, + // Tags: map[string]*string{ + // "key2138": to.Ptr("fjaeecgnvqd"), + // }, + // Name: to.Ptr("testscheduler"), + // Type: to.Ptr("tglszobjxdhauglzxuqozeg"), + // SystemData: &armdurabletask.SystemData{ + // CreatedBy: to.Ptr("tenmbevaunjzikxowqexrsx"), + // CreatedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.365Z"); return t}()), + // LastModifiedBy: to.Ptr("xfvdcegtj"), + // LastModifiedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.366Z"); return t}()), + // }, + // }, + // }, + // NextLink: to.Ptr("https://microsoft.com/a"), + // }, + // } + } +} + +// Generated from example definition: 2024-10-01-preview/Schedulers_Update.json +func ExampleSchedulersClient_BeginUpdate() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armdurabletask.NewClientFactory("EE9BD735-67CE-4A90-89C4-439D3F6A4C93", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewSchedulersClient().BeginUpdate(ctx, "rgopenapi", "testscheduler", armdurabletask.Scheduler{ + Tags: map[string]*string{ + "key8653": to.Ptr("lr"), + }, + Properties: &armdurabletask.SchedulerProperties{ + IPAllowlist: []*string{ + to.Ptr("10.0.0.0/8"), + }, + SKU: &armdurabletask.SchedulerSKU{ + Name: to.Ptr("Dedicated"), + Capacity: to.Ptr[int32](10), + }, + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res = armdurabletask.SchedulersClientUpdateResponse{ + // Scheduler: &armdurabletask.Scheduler{ + // Location: to.Ptr("northcentralus"), + // Properties: &armdurabletask.SchedulerProperties{ + // ProvisioningState: to.Ptr(armdurabletask.ProvisioningStateSucceeded), + // Endpoint: to.Ptr("https://test.northcentralus.1.durabletask.io"), + // IPAllowlist: []*string{ + // to.Ptr("10.0.0.0/8"), + // }, + // SKU: &armdurabletask.SchedulerSKU{ + // Name: to.Ptr("Dedicated"), + // Capacity: to.Ptr[int32](3), + // RedundancyState: to.Ptr(armdurabletask.RedundancyStateZone), + // }, + // }, + // Tags: map[string]*string{ + // "key7131": to.Ptr("ryohwcoiccwsnewjigfmijz"), + // "key2138": to.Ptr("fjaeecgnvqd"), + // }, + // ID: to.Ptr("/subscriptions/EE9BD735-67CE-4A90-89C4-439D3F6A4C93/resourceGroups/rgopenapi/providers/Microsoft.DurableTask/schedulers/testscheduler"), + // Name: to.Ptr("testscheduler"), + // Type: to.Ptr("vwqdbpynxwfhiopdypuabwvfohnr"), + // SystemData: &armdurabletask.SystemData{ + // CreatedBy: to.Ptr("tenmbevaunjzikxowqexrsx"), + // CreatedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.365Z"); return t}()), + // LastModifiedBy: to.Ptr("xfvdcegtj"), + // LastModifiedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.366Z"); return t}()), + // }, + // }, + // } +} diff --git a/sdk/resourcemanager/durabletask/armdurabletask/taskhubs_client.go b/sdk/resourcemanager/durabletask/armdurabletask/taskhubs_client.go new file mode 100644 index 000000000000..f03e53eb2ca6 --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/taskhubs_client.go @@ -0,0 +1,340 @@ +// 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) Go Code Generator. DO NOT EDIT. + +package armdurabletask + +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" +) + +// TaskHubsClient contains the methods for the TaskHubs group. +// Don't use this type directly, use NewTaskHubsClient() instead. +type TaskHubsClient struct { + internal *arm.Client + subscriptionID string +} + +// NewTaskHubsClient creates a new instance of TaskHubsClient 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 NewTaskHubsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*TaskHubsClient, error) { + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &TaskHubsClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// BeginCreateOrUpdate - Create or Update a Task Hub +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-10-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - schedulerName - The name of the Scheduler +// - taskHubName - The name of the TaskHub +// - resource - Resource create parameters. +// - options - TaskHubsClientBeginCreateOrUpdateOptions contains the optional parameters for the TaskHubsClient.BeginCreateOrUpdate +// method. +func (client *TaskHubsClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, schedulerName string, taskHubName string, resource TaskHub, options *TaskHubsClientBeginCreateOrUpdateOptions) (*runtime.Poller[TaskHubsClientCreateOrUpdateResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.createOrUpdate(ctx, resourceGroupName, schedulerName, taskHubName, resource, options) + if err != nil { + return nil, err + } + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[TaskHubsClientCreateOrUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) + return poller, err + } else { + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[TaskHubsClientCreateOrUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) + } +} + +// CreateOrUpdate - Create or Update a Task Hub +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-10-01-preview +func (client *TaskHubsClient) createOrUpdate(ctx context.Context, resourceGroupName string, schedulerName string, taskHubName string, resource TaskHub, options *TaskHubsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "TaskHubsClient.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, schedulerName, taskHubName, 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 *TaskHubsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, schedulerName string, taskHubName string, resource TaskHub, _ *TaskHubsClientBeginCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/taskHubs/{taskHubName}" + 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 schedulerName == "" { + return nil, errors.New("parameter schedulerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{schedulerName}", url.PathEscape(schedulerName)) + if taskHubName == "" { + return nil, errors.New("parameter taskHubName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{taskHubName}", url.PathEscape(taskHubName)) + 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-10-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + req.Raw().Header["Content-Type"] = []string{"application/json"} + if err := runtime.MarshalAsJSON(req, resource); err != nil { + return nil, err + } + return req, nil +} + +// BeginDelete - Delete a Task Hub +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-10-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - schedulerName - The name of the Scheduler +// - taskHubName - The name of the TaskHub +// - options - TaskHubsClientBeginDeleteOptions contains the optional parameters for the TaskHubsClient.BeginDelete method. +func (client *TaskHubsClient) BeginDelete(ctx context.Context, resourceGroupName string, schedulerName string, taskHubName string, options *TaskHubsClientBeginDeleteOptions) (*runtime.Poller[TaskHubsClientDeleteResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.deleteOperation(ctx, resourceGroupName, schedulerName, taskHubName, options) + if err != nil { + return nil, err + } + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[TaskHubsClientDeleteResponse]{ + Tracer: client.internal.Tracer(), + }) + return poller, err + } else { + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[TaskHubsClientDeleteResponse]{ + Tracer: client.internal.Tracer(), + }) + } +} + +// Delete - Delete a Task Hub +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-10-01-preview +func (client *TaskHubsClient) deleteOperation(ctx context.Context, resourceGroupName string, schedulerName string, taskHubName string, options *TaskHubsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "TaskHubsClient.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, schedulerName, taskHubName, 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 *TaskHubsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, schedulerName string, taskHubName string, _ *TaskHubsClientBeginDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/taskHubs/{taskHubName}" + 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 schedulerName == "" { + return nil, errors.New("parameter schedulerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{schedulerName}", url.PathEscape(schedulerName)) + if taskHubName == "" { + return nil, errors.New("parameter taskHubName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{taskHubName}", url.PathEscape(taskHubName)) + 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-10-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// Get - Get a Task Hub +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-10-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - schedulerName - The name of the Scheduler +// - taskHubName - The name of the TaskHub +// - options - TaskHubsClientGetOptions contains the optional parameters for the TaskHubsClient.Get method. +func (client *TaskHubsClient) Get(ctx context.Context, resourceGroupName string, schedulerName string, taskHubName string, options *TaskHubsClientGetOptions) (TaskHubsClientGetResponse, error) { + var err error + const operationName = "TaskHubsClient.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, schedulerName, taskHubName, options) + if err != nil { + return TaskHubsClientGetResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return TaskHubsClientGetResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return TaskHubsClientGetResponse{}, err + } + resp, err := client.getHandleResponse(httpResp) + return resp, err +} + +// getCreateRequest creates the Get request. +func (client *TaskHubsClient) getCreateRequest(ctx context.Context, resourceGroupName string, schedulerName string, taskHubName string, _ *TaskHubsClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/taskHubs/{taskHubName}" + 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 schedulerName == "" { + return nil, errors.New("parameter schedulerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{schedulerName}", url.PathEscape(schedulerName)) + if taskHubName == "" { + return nil, errors.New("parameter taskHubName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{taskHubName}", url.PathEscape(taskHubName)) + 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-10-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 *TaskHubsClient) getHandleResponse(resp *http.Response) (TaskHubsClientGetResponse, error) { + result := TaskHubsClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.TaskHub); err != nil { + return TaskHubsClientGetResponse{}, err + } + return result, nil +} + +// NewListBySchedulerPager - List Task Hubs +// +// Generated from API version 2024-10-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - schedulerName - The name of the Scheduler +// - options - TaskHubsClientListBySchedulerOptions contains the optional parameters for the TaskHubsClient.NewListBySchedulerPager +// method. +func (client *TaskHubsClient) NewListBySchedulerPager(resourceGroupName string, schedulerName string, options *TaskHubsClientListBySchedulerOptions) *runtime.Pager[TaskHubsClientListBySchedulerResponse] { + return runtime.NewPager(runtime.PagingHandler[TaskHubsClientListBySchedulerResponse]{ + More: func(page TaskHubsClientListBySchedulerResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *TaskHubsClientListBySchedulerResponse) (TaskHubsClientListBySchedulerResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "TaskHubsClient.NewListBySchedulerPager") + 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.listBySchedulerCreateRequest(ctx, resourceGroupName, schedulerName, options) + }, nil) + if err != nil { + return TaskHubsClientListBySchedulerResponse{}, err + } + return client.listBySchedulerHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listBySchedulerCreateRequest creates the ListByScheduler request. +func (client *TaskHubsClient) listBySchedulerCreateRequest(ctx context.Context, resourceGroupName string, schedulerName string, _ *TaskHubsClientListBySchedulerOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/taskHubs" + 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 schedulerName == "" { + return nil, errors.New("parameter schedulerName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{schedulerName}", url.PathEscape(schedulerName)) + 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-10-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listBySchedulerHandleResponse handles the ListByScheduler response. +func (client *TaskHubsClient) listBySchedulerHandleResponse(resp *http.Response) (TaskHubsClientListBySchedulerResponse, error) { + result := TaskHubsClientListBySchedulerResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.TaskHubListResult); err != nil { + return TaskHubsClientListBySchedulerResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/durabletask/armdurabletask/taskhubs_client_example_test.go b/sdk/resourcemanager/durabletask/armdurabletask/taskhubs_client_example_test.go new file mode 100644 index 000000000000..08af105cf7ba --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/taskhubs_client_example_test.go @@ -0,0 +1,166 @@ +// 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) Go Code Generator. DO NOT EDIT. + +package armdurabletask_test + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/durabletask/armdurabletask" + "log" +) + +// Generated from example definition: 2024-10-01-preview/TaskHubs_CreateOrUpdate.json +func ExampleTaskHubsClient_BeginCreateOrUpdate() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armdurabletask.NewClientFactory("EE9BD735-67CE-4A90-89C4-439D3F6A4C93", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewTaskHubsClient().BeginCreateOrUpdate(ctx, "rgopenapi", "testscheduler", "testtaskhub", armdurabletask.TaskHub{ + Properties: &armdurabletask.TaskHubProperties{}, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res = armdurabletask.TaskHubsClientCreateOrUpdateResponse{ + // TaskHub: &armdurabletask.TaskHub{ + // Properties: &armdurabletask.TaskHubProperties{ + // ProvisioningState: to.Ptr(armdurabletask.ProvisioningStateSucceeded), + // DashboardURL: to.Ptr("https://test-db.northcentralus.1.durabletask.io/taskhubs/testtaskhub"), + // }, + // ID: to.Ptr("/subscriptions/EE9BD735-67CE-4A90-89C4-439D3F6A4C93/resourceGroups/rgopenapi/providers/Microsoft.DurableTask/schedulers/testscheduler/taskHubs/testtaskhub"), + // Name: to.Ptr("testtaskhub"), + // Type: to.Ptr("afoounwhp"), + // SystemData: &armdurabletask.SystemData{ + // CreatedBy: to.Ptr("tenmbevaunjzikxowqexrsx"), + // CreatedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.365Z"); return t}()), + // LastModifiedBy: to.Ptr("xfvdcegtj"), + // LastModifiedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.366Z"); return t}()), + // }, + // }, + // } +} + +// Generated from example definition: 2024-10-01-preview/TaskHubs_Delete.json +func ExampleTaskHubsClient_BeginDelete() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armdurabletask.NewClientFactory("EE9BD735-67CE-4A90-89C4-439D3F6A4C93", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewTaskHubsClient().BeginDelete(ctx, "rgopenapi", "testscheduler", "testtuskhub", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + _, err = poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } +} + +// Generated from example definition: 2024-10-01-preview/TaskHubs_Get.json +func ExampleTaskHubsClient_Get() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armdurabletask.NewClientFactory("EE9BD735-67CE-4A90-89C4-439D3F6A4C93", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewTaskHubsClient().Get(ctx, "rgopenapi", "testscheduler", "testtuskhub", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res = armdurabletask.TaskHubsClientGetResponse{ + // TaskHub: &armdurabletask.TaskHub{ + // Properties: &armdurabletask.TaskHubProperties{ + // ProvisioningState: to.Ptr(armdurabletask.ProvisioningStateSucceeded), + // DashboardURL: to.Ptr("https://test-db.northcentralus.1.durabletask.io/taskhubs/testtaskhub"), + // }, + // ID: to.Ptr("/subscriptions/EE9BD735-67CE-4A90-89C4-439D3F6A4C93/resourceGroups/rgopenapi/providers/Microsoft.DurableTask/schedulers/testscheduler/taskHubs/testtaskhub"), + // Name: to.Ptr("testtaskhub"), + // Type: to.Ptr("afoounwhp"), + // SystemData: &armdurabletask.SystemData{ + // CreatedBy: to.Ptr("tenmbevaunjzikxowqexrsx"), + // CreatedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.365Z"); return t}()), + // LastModifiedBy: to.Ptr("xfvdcegtj"), + // LastModifiedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.366Z"); return t}()), + // }, + // }, + // } +} + +// Generated from example definition: 2024-10-01-preview/TaskHubs_ListByScheduler.json +func ExampleTaskHubsClient_NewListBySchedulerPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armdurabletask.NewClientFactory("EE9BD735-67CE-4A90-89C4-439D3F6A4C93", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewTaskHubsClient().NewListBySchedulerPager("rgopenapi", "testtaskhub", nil) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page = armdurabletask.TaskHubsClientListBySchedulerResponse{ + // TaskHubListResult: armdurabletask.TaskHubListResult{ + // Value: []*armdurabletask.TaskHub{ + // { + // ID: to.Ptr("/subscriptions/EE9BD735-67CE-4A90-89C4-439D3F6A4C93/resourceGroups/rgopenapi/providers/Microsoft.DurableTask/schedulers/testscheduler/taskHubs/testtaskhub"), + // Properties: &armdurabletask.TaskHubProperties{ + // ProvisioningState: to.Ptr(armdurabletask.ProvisioningStateSucceeded), + // DashboardURL: to.Ptr("https://test-db.northcentralus.1.durabletask.io/taskhubs/testtaskhub"), + // }, + // Name: to.Ptr("testtaskhub"), + // Type: to.Ptr("enkfjxsqktqyeiibofppkxruyb"), + // SystemData: &armdurabletask.SystemData{ + // CreatedBy: to.Ptr("tenmbevaunjzikxowqexrsx"), + // CreatedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.365Z"); return t}()), + // LastModifiedBy: to.Ptr("xfvdcegtj"), + // LastModifiedByType: to.Ptr(armdurabletask.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2024-04-17T15:34:17.366Z"); return t}()), + // }, + // }, + // }, + // NextLink: to.Ptr("https://microsoft.com/a"), + // }, + // } + } +} diff --git a/sdk/resourcemanager/durabletask/armdurabletask/time_rfc3339.go b/sdk/resourcemanager/durabletask/armdurabletask/time_rfc3339.go new file mode 100644 index 000000000000..3324a2c277ad --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/time_rfc3339.go @@ -0,0 +1,109 @@ +// 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) Go Code Generator. DO NOT EDIT. + +package armdurabletask + +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 { + if len(data) == 0 { + return nil + } + 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/durabletask/armdurabletask/tsp-location.yaml b/sdk/resourcemanager/durabletask/armdurabletask/tsp-location.yaml new file mode 100644 index 000000000000..def398fec1bf --- /dev/null +++ b/sdk/resourcemanager/durabletask/armdurabletask/tsp-location.yaml @@ -0,0 +1,4 @@ +directory: specification/durabletask/DurableTask.Management +commit: ab04533261eff228f28e08900445d0edef3eb70c +repo: Azure/azure-rest-api-specs +additionalDirectories: From 0f5266307374f52226d9f0909a2770057bc31c3a Mon Sep 17 00:00:00 2001 From: Chenjie Shi Date: Fri, 13 Dec 2024 16:26:46 +0800 Subject: [PATCH 2/2] Fix typos in README for Azure Durable Task --- .../durabletask/armdurabletask/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/resourcemanager/durabletask/armdurabletask/README.md b/sdk/resourcemanager/durabletask/armdurabletask/README.md index 2e67416415e4..72b4380d6a63 100644 --- a/sdk/resourcemanager/durabletask/armdurabletask/README.md +++ b/sdk/resourcemanager/durabletask/armdurabletask/README.md @@ -1,6 +1,6 @@ -# Azure Durabletask Module for Go +# Azure Durable Task Module for Go -The `armdurabletask` module provides operations for working with Azure Durabletask. +The `armdurabletask` module provides operations for working with Azure Durable Task. [Source code](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/resourcemanager/durabletask/armdurabletask) @@ -15,7 +15,7 @@ The `armdurabletask` module provides operations for working with Azure Durableta This project uses [Go modules](https://github.com/golang/go/wiki/Modules) for versioning and dependency management. -Install the Azure Durabletask module: +Install the Azure Durable Task module: ```sh go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/durabletask/armdurabletask @@ -23,7 +23,7 @@ go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/durabletask/armdura ## Authorization -When creating a client, you will need to provide a credential for authenticating with Azure Durabletask. The `azidentity` module provides facilities for various ways of authenticating with Azure including client/secret, certificate, managed identity, and more. +When creating a client, you will need to provide a credential for authenticating with Azure Durable Task. 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) @@ -33,7 +33,7 @@ For more information on authentication, please see the documentation for `aziden ## Client Factory -Azure Durabletask module consists of one or more clients. We provide a client factory which could be used to create any client in this module. +Azure Durable Task 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 := armdurabletask.NewClientFactory(, cred, nil) @@ -68,7 +68,7 @@ Please see https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/samples/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 `Durabletask` label. +[open an issue](https://github.com/Azure/azure-sdk-for-go/issues) and assign the `Durable Task` label. # Contributing