From 425cb1ade21cdc991ec656c77111ffb46ae06f99 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 15:14:24 +0800 Subject: [PATCH 01/18] [Release] sdk/resourcemanager/resources/armchanges/1.2.0 generation from spec commit: bf204aab860f2eb58a9d346b00d44760f2a9b0a2 --- .../resources/armchanges/CHANGELOG.md | 6 + .../resources/armchanges/README.md | 7 + .../resources/armchanges/autorest.md | 2 +- .../resources/armchanges/client.go | 41 ++-- .../resources/armchanges/client_factory.go | 6 +- .../resources/armchanges/constants.go | 31 ++- .../resources/armchanges/fake/internal.go | 83 ++++++++ .../resources/armchanges/fake/server.go | 200 ++++++++++++++++++ .../armchanges/fake/server_factory.go | 75 +++++++ .../resources/armchanges/go.mod | 20 +- .../resources/armchanges/go.sum | 46 ++-- .../resources/armchanges/models.go | 16 +- .../resources/armchanges/models_serde.go | 3 +- .../resources/armchanges/options.go | 23 ++ .../resources/armchanges/response_types.go | 5 +- 15 files changed, 472 insertions(+), 92 deletions(-) create mode 100644 sdk/resourcemanager/resources/armchanges/fake/internal.go create mode 100644 sdk/resourcemanager/resources/armchanges/fake/server.go create mode 100644 sdk/resourcemanager/resources/armchanges/fake/server_factory.go create mode 100644 sdk/resourcemanager/resources/armchanges/options.go diff --git a/sdk/resourcemanager/resources/armchanges/CHANGELOG.md b/sdk/resourcemanager/resources/armchanges/CHANGELOG.md index 686b7b67c2cd..7e46a86ac2b8 100644 --- a/sdk/resourcemanager/resources/armchanges/CHANGELOG.md +++ b/sdk/resourcemanager/resources/armchanges/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 1.2.0 (2023-11-24) +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + + ## 1.1.1 (2023-04-14) ### Bug Fixes diff --git a/sdk/resourcemanager/resources/armchanges/README.md b/sdk/resourcemanager/resources/armchanges/README.md index 3917038dee5b..e511fa5dfb69 100644 --- a/sdk/resourcemanager/resources/armchanges/README.md +++ b/sdk/resourcemanager/resources/armchanges/README.md @@ -60,6 +60,13 @@ A client groups a set of related APIs, providing access to its functionality. C client := clientFactory.NewClient() ``` +## 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 diff --git a/sdk/resourcemanager/resources/armchanges/autorest.md b/sdk/resourcemanager/resources/armchanges/autorest.md index 0cc9777a317e..88dfde006675 100644 --- a/sdk/resourcemanager/resources/armchanges/autorest.md +++ b/sdk/resourcemanager/resources/armchanges/autorest.md @@ -8,6 +8,6 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/0cc5e2efd6ffccf30e80d1e150b488dd87198b94/specification/resources/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/0cc5e2efd6ffccf30e80d1e150b488dd87198b94/specification/resources/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 1.1.1 +module-version: 1.2.0 package-changes: true ``` \ No newline at end of file diff --git a/sdk/resourcemanager/resources/armchanges/client.go b/sdk/resourcemanager/resources/armchanges/client.go index 3df3b93a0c6d..1bd5ada6743b 100644 --- a/sdk/resourcemanager/resources/armchanges/client.go +++ b/sdk/resourcemanager/resources/armchanges/client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armchanges @@ -34,7 +33,7 @@ type Client struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*Client, error) { - cl, err := arm.NewClient(moduleName+".Client", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -56,18 +55,25 @@ func NewClient(subscriptionID string, credential azcore.TokenCredential, options // - changeResourceID - The ID of the change resource // - options - ClientGetOptions contains the optional parameters for the Client.Get method. func (client *Client) Get(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, resourceType string, resourceName string, changeResourceID string, options *ClientGetOptions) (ClientGetResponse, error) { + var err error + const operationName = "Client.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, resourceProviderNamespace, resourceType, resourceName, changeResourceID, options) if err != nil { return ClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -131,25 +137,20 @@ func (client *Client) NewListPager(resourceGroupName string, resourceProviderNam return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ClientListResponse) (ClientListResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, resourceGroupName, resourceProviderNamespace, resourceType, resourceName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.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, resourceGroupName, resourceProviderNamespace, resourceType, resourceName, options) + }, nil) if err != nil { return ClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armchanges/client_factory.go b/sdk/resourcemanager/resources/armchanges/client_factory.go index c42409412eca..b1eb0676c4bd 100644 --- a/sdk/resourcemanager/resources/armchanges/client_factory.go +++ b/sdk/resourcemanager/resources/armchanges/client_factory.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armchanges @@ -28,7 +27,7 @@ type ClientFactory struct { // - 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) { - _, err := arm.NewClient(moduleName+".ClientFactory", moduleVersion, credential, options) + _, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -38,6 +37,7 @@ func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, }, nil } +// NewClient creates a new instance of Client. func (c *ClientFactory) NewClient() *Client { subClient, _ := NewClient(c.subscriptionID, c.credential, c.options) return subClient diff --git a/sdk/resourcemanager/resources/armchanges/constants.go b/sdk/resourcemanager/resources/armchanges/constants.go index 8fa775c2d196..127888bd0061 100644 --- a/sdk/resourcemanager/resources/armchanges/constants.go +++ b/sdk/resourcemanager/resources/armchanges/constants.go @@ -3,32 +3,31 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armchanges const ( - moduleName = "armchanges" - moduleVersion = "v1.1.1" + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armchanges" + moduleVersion = "v1.2.0" ) // ChangeCategory - The entity that made the change type ChangeCategory string const ( - // ChangeCategoryUser - User initiated change - ChangeCategoryUser ChangeCategory = "User" // ChangeCategorySystem - System initiated change ChangeCategorySystem ChangeCategory = "System" + // ChangeCategoryUser - User initiated change + ChangeCategoryUser ChangeCategory = "User" ) // PossibleChangeCategoryValues returns the possible values for the ChangeCategory const type. func PossibleChangeCategoryValues() []ChangeCategory { return []ChangeCategory{ - ChangeCategoryUser, ChangeCategorySystem, + ChangeCategoryUser, } } @@ -36,20 +35,20 @@ func PossibleChangeCategoryValues() []ChangeCategory { type ChangeType string const ( - // ChangeTypeUpdate - An existing resource underwent a change - ChangeTypeUpdate ChangeType = "Update" - // ChangeTypeDelete - An existing resource was deleted - ChangeTypeDelete ChangeType = "Delete" // ChangeTypeCreate - A newly created resource ChangeTypeCreate ChangeType = "Create" + // ChangeTypeDelete - An existing resource was deleted + ChangeTypeDelete ChangeType = "Delete" + // ChangeTypeUpdate - An existing resource underwent a change + ChangeTypeUpdate ChangeType = "Update" ) // PossibleChangeTypeValues returns the possible values for the ChangeType const type. func PossibleChangeTypeValues() []ChangeType { return []ChangeType{ - ChangeTypeUpdate, - ChangeTypeDelete, ChangeTypeCreate, + ChangeTypeDelete, + ChangeTypeUpdate, } } @@ -57,19 +56,19 @@ func PossibleChangeTypeValues() []ChangeType { type PropertyChangeType string const ( - // PropertyChangeTypeUpdate - An existing property underwent a change - PropertyChangeTypeUpdate PropertyChangeType = "Update" // PropertyChangeTypeInsert - A property was newly created PropertyChangeTypeInsert PropertyChangeType = "Insert" // PropertyChangeTypeRemove - An existing property was deleted PropertyChangeTypeRemove PropertyChangeType = "Remove" + // PropertyChangeTypeUpdate - An existing property underwent a change + PropertyChangeTypeUpdate PropertyChangeType = "Update" ) // PossiblePropertyChangeTypeValues returns the possible values for the PropertyChangeType const type. func PossiblePropertyChangeTypeValues() []PropertyChangeType { return []PropertyChangeType{ - PropertyChangeTypeUpdate, PropertyChangeTypeInsert, PropertyChangeTypeRemove, + PropertyChangeTypeUpdate, } } diff --git a/sdk/resourcemanager/resources/armchanges/fake/internal.go b/sdk/resourcemanager/resources/armchanges/fake/internal.go new file mode 100644 index 000000000000..7d2f89ba4bb2 --- /dev/null +++ b/sdk/resourcemanager/resources/armchanges/fake/internal.go @@ -0,0 +1,83 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "net/http" + "reflect" + "sync" +) + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} + +func getOptional[T any](v T) *T { + if reflect.ValueOf(v).IsZero() { + return nil + } + return &v +} + +func parseOptional[T any](v string, parse func(v string) (T, error)) (*T, error) { + if v == "" { + return nil, nil + } + t, err := parse(v) + if err != nil { + return nil, err + } + return &t, err +} + +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/resources/armchanges/fake/server.go b/sdk/resourcemanager/resources/armchanges/fake/server.go new file mode 100644 index 000000000000..48c0bdbf5c15 --- /dev/null +++ b/sdk/resourcemanager/resources/armchanges/fake/server.go @@ -0,0 +1,200 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armchanges" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// Server is a fake server for instances of the armchanges.Client type. +type Server struct { + // Get is the fake for method Client.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, resourceType string, resourceName string, changeResourceID string, options *armchanges.ClientGetOptions) (resp azfake.Responder[armchanges.ClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method Client.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, resourceProviderNamespace string, resourceType string, resourceName string, options *armchanges.ClientListOptions) (resp azfake.PagerResponder[armchanges.ClientListResponse]) +} + +// NewServerTransport creates a new instance of ServerTransport with the provided implementation. +// The returned ServerTransport instance is connected to an instance of armchanges.Client via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewServerTransport(srv *Server) *ServerTransport { + return &ServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[armchanges.ClientListResponse]](), + } +} + +// ServerTransport connects instances of armchanges.Client to instances of Server. +// Don't use this type directly, use NewServerTransport instead. +type ServerTransport struct { + srv *Server + newListPager *tracker[azfake.PagerResponder[armchanges.ClientListResponse]] +} + +// Do implements the policy.Transporter interface for ServerTransport. +func (s *ServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "Client.Get": + resp, err = s.dispatchGet(req) + case "Client.NewListPager": + resp, err = s.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *ServerTransport) 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/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/changes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 6 { + 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 + } + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + resourceTypeParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + if err != nil { + return nil, err + } + resourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + changeResourceIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("changeResourceId")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameParam, resourceProviderNamespaceParam, resourceTypeParam, resourceNameParam, changeResourceIDParam, 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).ChangeResourceResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := s.newListPager.get(req) + if newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/changes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 5 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + resourceTypeParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + if err != nil { + return nil, err + } + resourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int64, error) { + p, parseErr := strconv.ParseInt(v, 10, 64) + if parseErr != nil { + return 0, parseErr + } + return p, nil + }) + if err != nil { + return nil, err + } + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armchanges.ClientListOptions + if topParam != nil || skipTokenParam != nil { + options = &armchanges.ClientListOptions{ + Top: topParam, + SkipToken: skipTokenParam, + } + } + resp := s.srv.NewListPager(resourceGroupNameParam, resourceProviderNamespaceParam, resourceTypeParam, resourceNameParam, options) + newListPager = &resp + s.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armchanges.ClientListResponse, 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) { + s.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + s.newListPager.remove(req) + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armchanges/fake/server_factory.go b/sdk/resourcemanager/resources/armchanges/fake/server_factory.go new file mode 100644 index 000000000000..e2cccec4594e --- /dev/null +++ b/sdk/resourcemanager/resources/armchanges/fake/server_factory.go @@ -0,0 +1,75 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" + "sync" +) + +// ServerFactory is a fake server for instances of the armchanges.ClientFactory type. +type ServerFactory struct { + Server Server +} + +// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. +// The returned ServerFactoryTransport instance is connected to an instance of armchanges.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 armchanges.ClientFactory to instances of ServerFactory. +// Don't use this type directly, use NewServerFactoryTransport instead. +type ServerFactoryTransport struct { + srv *ServerFactory + trMu sync.Mutex + trServer *ServerTransport +} + +// 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 "Client": + initServer(s, &s.trServer, func() *ServerTransport { return NewServerTransport(&s.srv.Server) }) + resp, err = s.trServer.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/resources/armchanges/go.mod b/sdk/resourcemanager/resources/armchanges/go.mod index e3c43a16fd73..f2065a5c2c22 100644 --- a/sdk/resourcemanager/resources/armchanges/go.mod +++ b/sdk/resourcemanager/resources/armchanges/go.mod @@ -3,19 +3,19 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armchange go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect - github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 // indirect - github.com/golang-jwt/jwt/v4 v4.5.0 // indirect - github.com/google/uuid v1.3.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect + github.com/golang-jwt/jwt/v5 v5.0.0 // indirect + github.com/google/uuid v1.3.1 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect - golang.org/x/crypto v0.6.0 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect ) diff --git a/sdk/resourcemanager/resources/armchanges/go.sum b/sdk/resourcemanager/resources/armchanges/go.sum index 8ba445a8c4da..7985f1da436f 100644 --- a/sdk/resourcemanager/resources/armchanges/go.sum +++ b/sdk/resourcemanager/resources/armchanges/go.sum @@ -1,31 +1,31 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 h1:rTnT/Jrcm+figWlYz4Ixzt0SJVR2cMC8lvZcimipiEY= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0/go.mod h1:ON4tFdPTwRcgWEaVDrN3584Ef+b7GgSJaXxe5fW9t4M= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 h1:uqM+VoHjVH6zdlkLF2b6O0ZANcHoj3rO0PoQ3jglUJA= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2/go.mod h1:twTKAa1E6hLmSDjLhaCkbTMQKc7p/rNLU40rLxGEOCI= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 h1:leh5DwKv6Ihwi+h60uHtn6UWAxBbZ0q8DwQVMzf61zw= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= -github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 h1:UE9n9rkJF62ArLb1F3DEjRt8O3jLwMWdSoypKV4f3MU= -github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 h1:fb8kj/Dh4CSwgsOzHeZY4Xh68cFVbzXx+ONXGMY//4w= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0/go.mod h1:uReU2sSxZExRPBAg3qKzmAucSi51+SP1OhohieR821Q= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 h1:BMAjVKJM0U/CYF27gA0ZMmXGkOcvfFtD0oHVZ1TIPRI= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0/go.mod h1:1fXstnBMas5kzG+S3q8UoJcmyU6nUeunJcMDHcRYHhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 h1:WpB/QDNLpMw72xHJc34BNNykqSOeEJDAWkhf0u12/Jk= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= -github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= -github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= +github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/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-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc= -golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/sdk/resourcemanager/resources/armchanges/models.go b/sdk/resourcemanager/resources/armchanges/models.go index cf31f62b053b..3627a989c4ef 100644 --- a/sdk/resourcemanager/resources/armchanges/models.go +++ b/sdk/resourcemanager/resources/armchanges/models.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armchanges @@ -84,19 +83,6 @@ type ChangeResourceResult struct { Type *string } -// ClientGetOptions contains the optional parameters for the Client.Get method. -type ClientGetOptions struct { - // placeholder for future optional parameters -} - -// ClientListOptions contains the optional parameters for the Client.NewListPager method. -type ClientListOptions struct { - // (Optional) The page-continuation token - SkipToken *string - // (Optional) Set the maximum number of results per response. - Top *int64 -} - // ErrorAdditionalInfo - The resource management error additional info. type ErrorAdditionalInfo struct { // READ-ONLY; The additional info. diff --git a/sdk/resourcemanager/resources/armchanges/models_serde.go b/sdk/resourcemanager/resources/armchanges/models_serde.go index 73fb7154607a..af114ae11505 100644 --- a/sdk/resourcemanager/resources/armchanges/models_serde.go +++ b/sdk/resourcemanager/resources/armchanges/models_serde.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armchanges diff --git a/sdk/resourcemanager/resources/armchanges/options.go b/sdk/resourcemanager/resources/armchanges/options.go new file mode 100644 index 000000000000..6f5d82ce9e98 --- /dev/null +++ b/sdk/resourcemanager/resources/armchanges/options.go @@ -0,0 +1,23 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armchanges + +// ClientGetOptions contains the optional parameters for the Client.Get method. +type ClientGetOptions struct { + // placeholder for future optional parameters +} + +// ClientListOptions contains the optional parameters for the Client.NewListPager method. +type ClientListOptions struct { + // (Optional) The page-continuation token + SkipToken *string + + // (Optional) Set the maximum number of results per response. + Top *int64 +} diff --git a/sdk/resourcemanager/resources/armchanges/response_types.go b/sdk/resourcemanager/resources/armchanges/response_types.go index c1b95c2ca3ef..2f363a93984b 100644 --- a/sdk/resourcemanager/resources/armchanges/response_types.go +++ b/sdk/resourcemanager/resources/armchanges/response_types.go @@ -3,18 +3,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armchanges // ClientGetResponse contains the response from method Client.Get. type ClientGetResponse struct { + // Change Resource ChangeResourceResult } // ClientListResponse contains the response from method Client.NewListPager. type ClientListResponse struct { + // The list of resources ChangeResourceListResult } From 52041e3f0f60fe5a9fca2d488cc7708fc88603f7 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 15:15:45 +0800 Subject: [PATCH 02/18] [Release] sdk/resourcemanager/resources/armdeploymentscripts/2.1.0 generation from spec commit: bf204aab860f2eb58a9d346b00d44760f2a9b0a2 --- .../armdeploymentscripts/CHANGELOG.md | 6 + .../resources/armdeploymentscripts/README.md | 7 + .../armdeploymentscripts/autorest.md | 2 +- .../resources/armdeploymentscripts/client.go | 152 +++--- .../client_example_test.go | 70 +-- .../armdeploymentscripts/client_factory.go | 6 +- .../armdeploymentscripts/constants.go | 7 +- .../deploymentscripts_client_live_test.go | 2 +- .../armdeploymentscripts/fake/internal.go | 88 ++++ .../fake/polymorphic_helpers.go | 37 ++ .../armdeploymentscripts/fake/server.go | 438 ++++++++++++++++++ .../fake/server_factory.go | 75 +++ .../armdeploymentscripts/fake/time_rfc3339.go | 86 ++++ .../resources/armdeploymentscripts/go.mod | 32 +- .../resources/armdeploymentscripts/go.sum | 70 +-- .../armdeploymentscripts/interfaces.go | 18 + .../resources/armdeploymentscripts/models.go | 73 +-- .../armdeploymentscripts/models_serde.go | 23 +- .../resources/armdeploymentscripts/options.go | 54 +++ .../polymorphic_helpers.go | 8 +- .../armdeploymentscripts/response_types.go | 17 +- .../armdeploymentscripts/time_rfc3339.go | 43 +- 22 files changed, 1060 insertions(+), 254 deletions(-) create mode 100644 sdk/resourcemanager/resources/armdeploymentscripts/fake/internal.go create mode 100644 sdk/resourcemanager/resources/armdeploymentscripts/fake/polymorphic_helpers.go create mode 100644 sdk/resourcemanager/resources/armdeploymentscripts/fake/server.go create mode 100644 sdk/resourcemanager/resources/armdeploymentscripts/fake/server_factory.go create mode 100644 sdk/resourcemanager/resources/armdeploymentscripts/fake/time_rfc3339.go create mode 100644 sdk/resourcemanager/resources/armdeploymentscripts/interfaces.go create mode 100644 sdk/resourcemanager/resources/armdeploymentscripts/options.go diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/CHANGELOG.md b/sdk/resourcemanager/resources/armdeploymentscripts/CHANGELOG.md index e8b874b65876..35bae96c4a63 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/CHANGELOG.md +++ b/sdk/resourcemanager/resources/armdeploymentscripts/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 2.1.0 (2023-11-24) +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + + ## 2.0.1 (2023-04-14) ### Bug Fixes diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/README.md b/sdk/resourcemanager/resources/armdeploymentscripts/README.md index cbff41544f45..932207624adf 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/README.md +++ b/sdk/resourcemanager/resources/armdeploymentscripts/README.md @@ -60,6 +60,13 @@ A client groups a set of related APIs, providing access to its functionality. C client := clientFactory.NewClient() ``` +## 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 diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/autorest.md b/sdk/resourcemanager/resources/armdeploymentscripts/autorest.md index 74f1541b6636..0f813d9df8f7 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/autorest.md +++ b/sdk/resourcemanager/resources/armdeploymentscripts/autorest.md @@ -8,6 +8,6 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 2.0.1 +module-version: 2.1.0 package-deploymentscripts: true ``` \ No newline at end of file diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/client.go b/sdk/resourcemanager/resources/armdeploymentscripts/client.go index c5c9256ca740..b9365062bfc1 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/client.go +++ b/sdk/resourcemanager/resources/armdeploymentscripts/client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armdeploymentscripts @@ -34,7 +33,7 @@ type Client struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*Client, error) { - cl, err := arm.NewClient(moduleName+".Client", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -59,9 +58,14 @@ func (client *Client) BeginCreate(ctx context.Context, resourceGroupName string, if err != nil { return nil, err } - return runtime.NewPoller[ClientCreateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClientCreateResponse]{ + Tracer: client.internal.Tracer(), + }) + return poller, err } else { - return runtime.NewPollerFromResumeToken[ClientCreateResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ClientCreateResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -70,18 +74,24 @@ func (client *Client) BeginCreate(ctx context.Context, resourceGroupName string, // // Generated from API version 2020-10-01 func (client *Client) create(ctx context.Context, resourceGroupName string, scriptName string, deploymentScript DeploymentScriptClassification, options *ClientBeginCreateOptions) (*http.Response, error) { + var err error + const operationName = "Client.BeginCreate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createCreateRequest(ctx, resourceGroupName, scriptName, deploymentScript, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // createCreateRequest creates the Create request. @@ -107,7 +117,10 @@ func (client *Client) createCreateRequest(ctx context.Context, resourceGroupName reqQP.Set("api-version", "2020-10-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, deploymentScript) + if err := runtime.MarshalAsJSON(req, deploymentScript); err != nil { + return nil, err + } + return req, nil } // Delete - Deletes a deployment script. When operation completes, status code 200 returned without content. @@ -118,16 +131,22 @@ func (client *Client) createCreateRequest(ctx context.Context, resourceGroupName // - scriptName - Name of the deployment script. // - options - ClientDeleteOptions contains the optional parameters for the Client.Delete method. func (client *Client) Delete(ctx context.Context, resourceGroupName string, scriptName string, options *ClientDeleteOptions) (ClientDeleteResponse, error) { + var err error + const operationName = "Client.Delete" + 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, scriptName, options) if err != nil { return ClientDeleteResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientDeleteResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return ClientDeleteResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return ClientDeleteResponse{}, err } return ClientDeleteResponse{}, nil } @@ -166,18 +185,25 @@ func (client *Client) deleteCreateRequest(ctx context.Context, resourceGroupName // - scriptName - Name of the deployment script. // - options - ClientGetOptions contains the optional parameters for the Client.Get method. func (client *Client) Get(ctx context.Context, resourceGroupName string, scriptName string, options *ClientGetOptions) (ClientGetResponse, error) { + var err error + const operationName = "Client.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, scriptName, options) if err != nil { return ClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -223,18 +249,25 @@ func (client *Client) getHandleResponse(resp *http.Response) (ClientGetResponse, // - scriptName - Name of the deployment script. // - options - ClientGetLogsOptions contains the optional parameters for the Client.GetLogs method. func (client *Client) GetLogs(ctx context.Context, resourceGroupName string, scriptName string, options *ClientGetLogsOptions) (ClientGetLogsResponse, error) { + var err error + const operationName = "Client.GetLogs" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getLogsCreateRequest(ctx, resourceGroupName, scriptName, options) if err != nil { return ClientGetLogsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientGetLogsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientGetLogsResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientGetLogsResponse{}, err } - return client.getLogsHandleResponse(resp) + resp, err := client.getLogsHandleResponse(httpResp) + return resp, err } // getLogsCreateRequest creates the GetLogs request. @@ -280,18 +313,25 @@ func (client *Client) getLogsHandleResponse(resp *http.Response) (ClientGetLogsR // - scriptName - Name of the deployment script. // - options - ClientGetLogsDefaultOptions contains the optional parameters for the Client.GetLogsDefault method. func (client *Client) GetLogsDefault(ctx context.Context, resourceGroupName string, scriptName string, options *ClientGetLogsDefaultOptions) (ClientGetLogsDefaultResponse, error) { + var err error + const operationName = "Client.GetLogsDefault" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getLogsDefaultCreateRequest(ctx, resourceGroupName, scriptName, options) if err != nil { return ClientGetLogsDefaultResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientGetLogsDefaultResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientGetLogsDefaultResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientGetLogsDefaultResponse{}, err } - return client.getLogsDefaultHandleResponse(resp) + resp, err := client.getLogsDefaultHandleResponse(httpResp) + return resp, err } // getLogsDefaultCreateRequest creates the GetLogsDefault request. @@ -344,25 +384,20 @@ func (client *Client) NewListByResourceGroupPager(resourceGroupName string, opti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ClientListByResourceGroupResponse) (ClientListByResourceGroupResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.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 ClientListByResourceGroupResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ClientListByResourceGroupResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListByResourceGroupResponse{}, runtime.NewResponseError(resp) - } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -407,25 +442,20 @@ func (client *Client) NewListBySubscriptionPager(options *ClientListBySubscripti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ClientListBySubscriptionResponse) (ClientListBySubscriptionResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listBySubscriptionCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return ClientListBySubscriptionResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewListBySubscriptionPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + 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 ClientListBySubscriptionResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListBySubscriptionResponse{}, runtime.NewResponseError(resp) - } return client.listBySubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -464,18 +494,25 @@ func (client *Client) listBySubscriptionHandleResponse(resp *http.Response) (Cli // - scriptName - Name of the deployment script. // - options - ClientUpdateOptions contains the optional parameters for the Client.Update method. func (client *Client) Update(ctx context.Context, resourceGroupName string, scriptName string, options *ClientUpdateOptions) (ClientUpdateResponse, error) { + var err error + const operationName = "Client.Update" + 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, scriptName, options) if err != nil { return ClientUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientUpdateResponse{}, err } - return client.updateHandleResponse(resp) + resp, err := client.updateHandleResponse(httpResp) + return resp, err } // updateCreateRequest creates the Update request. @@ -502,7 +539,10 @@ func (client *Client) updateCreateRequest(ctx context.Context, resourceGroupName req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.DeploymentScript != nil { - return req, runtime.MarshalAsJSON(req, *options.DeploymentScript) + if err := runtime.MarshalAsJSON(req, *options.DeploymentScript); err != nil { + return nil, err + } + return req, nil } return req, nil } diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/client_example_test.go b/sdk/resourcemanager/resources/armdeploymentscripts/client_example_test.go index 1ea0e3d5ebe9..75d13041bcef 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/client_example_test.go +++ b/sdk/resourcemanager/resources/armdeploymentscripts/client_example_test.go @@ -79,9 +79,9 @@ func ExampleClient_BeginCreate_deploymentScriptsCreate() { // ProvisioningState: to.Ptr(armdeploymentscripts.ScriptProvisioningStateSucceeded), // Status: &armdeploymentscripts.ScriptStatus{ // ContainerInstanceID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.ContainerInstance/containerGroups/scriptContainer"), - // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), + // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), // StorageAccountID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.Storage/storageAccounts/scriptStorage"), // }, // Arguments: to.Ptr("-Location 'westus' -Name \"*rg2\""), @@ -145,9 +145,9 @@ func ExampleClient_BeginCreate_deploymentScriptsCreateNoUserManagedIdentity() { // ProvisioningState: to.Ptr(armdeploymentscripts.ScriptProvisioningStateSucceeded), // Status: &armdeploymentscripts.ScriptStatus{ // ContainerInstanceID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.ContainerInstance/containerGroups/scriptContainer"), - // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), + // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), // StorageAccountID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.Storage/storageAccounts/scriptStorage"), // }, // Arguments: to.Ptr("-Location 'westus' -Name \"*rg2\""), @@ -219,9 +219,9 @@ func ExampleClient_BeginCreate_deploymentScriptsCreateMinCreate() { // ProvisioningState: to.Ptr(armdeploymentscripts.ScriptProvisioningStateSucceeded), // Status: &armdeploymentscripts.ScriptStatus{ // ContainerInstanceID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.ContainerInstance/containerGroups/scriptContainer"), - // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), + // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), // StorageAccountID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.Storage/storageAccounts/scriptStorage"), // }, // Arguments: to.Ptr("-Location 'westus' -Name \"*rg2\""), @@ -301,9 +301,9 @@ func ExampleClient_BeginCreate_deploymentScriptsCreateUsingCustomAciName() { // ProvisioningState: to.Ptr(armdeploymentscripts.ScriptProvisioningStateSucceeded), // Status: &armdeploymentscripts.ScriptStatus{ // ContainerInstanceID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.ContainerInstance/containerGroups/scriptContainer"), - // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), + // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), // StorageAccountID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.Storage/storageAccounts/scriptStorage"), // }, // Arguments: to.Ptr("-Location 'westus' -Name \"*rg2\""), @@ -384,9 +384,9 @@ func ExampleClient_BeginCreate_deploymentScriptsCreateUsingExistingStorageAccoun // ProvisioningState: to.Ptr(armdeploymentscripts.ScriptProvisioningStateSucceeded), // Status: &armdeploymentscripts.ScriptStatus{ // ContainerInstanceID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.ContainerInstance/containerGroups/scriptContainer"), - // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), + // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), // StorageAccountID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.Storage/storageAccounts/scriptStorage"), // }, // StorageAccountSettings: &armdeploymentscripts.StorageAccountConfiguration{ @@ -438,10 +438,10 @@ func ExampleClient_Update() { // Kind: to.Ptr(armdeploymentscripts.ScriptTypeAzurePowerShell), // Location: to.Ptr("westus"), // SystemData: &armdeploymentscripts.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentscripts.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentscripts.CreatedByTypeApplication), // }, @@ -455,9 +455,9 @@ func ExampleClient_Update() { // ProvisioningState: to.Ptr(armdeploymentscripts.ScriptProvisioningStateSucceeded), // Status: &armdeploymentscripts.ScriptStatus{ // ContainerInstanceID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.ContainerInstance/containerGroups/scriptContainer"), - // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), + // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), // StorageAccountID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.Storage/storageAccounts/scriptStorage"), // }, // Arguments: to.Ptr("-Location 'westus' -Name \"*rg2\""), @@ -503,10 +503,10 @@ func ExampleClient_Get() { // Kind: to.Ptr(armdeploymentscripts.ScriptTypeAzurePowerShell), // Location: to.Ptr("westus"), // SystemData: &armdeploymentscripts.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentscripts.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentscripts.CreatedByTypeApplication), // }, @@ -518,9 +518,9 @@ func ExampleClient_Get() { // ProvisioningState: to.Ptr(armdeploymentscripts.ScriptProvisioningStateSucceeded), // Status: &armdeploymentscripts.ScriptStatus{ // ContainerInstanceID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.ContainerInstance/containerGroups/scriptContainer"), - // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), + // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), // StorageAccountID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.Storage/storageAccounts/scriptStorage"), // }, // Arguments: to.Ptr("-Location 'westus' -Name \"*rg2\""), @@ -585,10 +585,10 @@ func ExampleClient_NewListBySubscriptionPager() { // Kind: to.Ptr(armdeploymentscripts.ScriptTypeAzurePowerShell), // Location: to.Ptr("westus"), // SystemData: &armdeploymentscripts.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentscripts.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentscripts.CreatedByTypeApplication), // }, @@ -600,9 +600,9 @@ func ExampleClient_NewListBySubscriptionPager() { // ProvisioningState: to.Ptr(armdeploymentscripts.ScriptProvisioningStateSucceeded), // Status: &armdeploymentscripts.ScriptStatus{ // ContainerInstanceID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.ContainerInstance/containerGroups/scriptContainer"), - // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), + // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), // StorageAccountID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.Storage/storageAccounts/scriptStorage"), // }, // Arguments: to.Ptr("-Location 'westus' -Name \"*rg2\""), @@ -729,10 +729,10 @@ func ExampleClient_NewListByResourceGroupPager() { // Kind: to.Ptr(armdeploymentscripts.ScriptTypeAzurePowerShell), // Location: to.Ptr("westus"), // SystemData: &armdeploymentscripts.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentscripts.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentscripts.CreatedByTypeApplication), // }, @@ -744,9 +744,9 @@ func ExampleClient_NewListByResourceGroupPager() { // ProvisioningState: to.Ptr(armdeploymentscripts.ScriptProvisioningStateSucceeded), // Status: &armdeploymentscripts.ScriptStatus{ // ContainerInstanceID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.ContainerInstance/containerGroups/scriptContainer"), - // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), - // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T15:19:45-08:00"); return t}()), + // EndTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // ExpirationTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), + // StartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-11-13T23:19:45.000Z"); return t}()), // StorageAccountID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.Storage/storageAccounts/scriptStorage"), // }, // Arguments: to.Ptr("-Location 'westus' -Name \"*rg2\""), diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/client_factory.go b/sdk/resourcemanager/resources/armdeploymentscripts/client_factory.go index 5367218c517a..893af5932ce8 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/client_factory.go +++ b/sdk/resourcemanager/resources/armdeploymentscripts/client_factory.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armdeploymentscripts @@ -28,7 +27,7 @@ type ClientFactory struct { // - 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) { - _, err := arm.NewClient(moduleName+".ClientFactory", moduleVersion, credential, options) + _, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -38,6 +37,7 @@ func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, }, nil } +// NewClient creates a new instance of Client. func (c *ClientFactory) NewClient() *Client { subClient, _ := NewClient(c.subscriptionID, c.credential, c.options) return subClient diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/constants.go b/sdk/resourcemanager/resources/armdeploymentscripts/constants.go index 834b676b4482..17c2820265ca 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/constants.go +++ b/sdk/resourcemanager/resources/armdeploymentscripts/constants.go @@ -3,15 +3,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armdeploymentscripts const ( - moduleName = "armdeploymentscripts" - moduleVersion = "v2.0.1" + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploymentscripts" + moduleVersion = "v2.1.0" ) // CleanupOptions - The clean up preference when the script execution gets in a terminal state. Default setting is 'Always'. diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/deploymentscripts_client_live_test.go b/sdk/resourcemanager/resources/armdeploymentscripts/deploymentscripts_client_live_test.go index a411eba31992..cdfde4815ccc 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/deploymentscripts_client_live_test.go +++ b/sdk/resourcemanager/resources/armdeploymentscripts/deploymentscripts_client_live_test.go @@ -14,7 +14,7 @@ import ( "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/to" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploymentscripts" "github.com/stretchr/testify/suite" diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/fake/internal.go b/sdk/resourcemanager/resources/armdeploymentscripts/fake/internal.go new file mode 100644 index 000000000000..54ad123b1b32 --- /dev/null +++ b/sdk/resourcemanager/resources/armdeploymentscripts/fake/internal.go @@ -0,0 +1,88 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "io" + "net/http" + "sync" +) + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} + +func parseOptional[T any](v string, parse func(v string) (T, error)) (*T, error) { + if v == "" { + return nil, nil + } + t, err := parse(v) + if err != nil { + return nil, err + } + return &t, err +} + +func readRequestBody(req *http.Request) ([]byte, error) { + if req.Body == nil { + return nil, nil + } + body, err := io.ReadAll(req.Body) + if err != nil { + return nil, err + } + req.Body.Close() + return body, nil +} + +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/resources/armdeploymentscripts/fake/polymorphic_helpers.go b/sdk/resourcemanager/resources/armdeploymentscripts/fake/polymorphic_helpers.go new file mode 100644 index 000000000000..7a3434cc17f1 --- /dev/null +++ b/sdk/resourcemanager/resources/armdeploymentscripts/fake/polymorphic_helpers.go @@ -0,0 +1,37 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "encoding/json" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploymentscripts/v2" +) + +func unmarshalDeploymentScriptClassification(rawMsg json.RawMessage) (armdeploymentscripts.DeploymentScriptClassification, error) { + if rawMsg == nil { + return nil, nil + } + var m map[string]any + if err := json.Unmarshal(rawMsg, &m); err != nil { + return nil, err + } + var b armdeploymentscripts.DeploymentScriptClassification + switch m["kind"] { + case string(armdeploymentscripts.ScriptTypeAzureCLI): + b = &armdeploymentscripts.AzureCliScript{} + case string(armdeploymentscripts.ScriptTypeAzurePowerShell): + b = &armdeploymentscripts.AzurePowerShellScript{} + default: + b = &armdeploymentscripts.DeploymentScript{} + } + if err := json.Unmarshal(rawMsg, b); err != nil { + return nil, err + } + return b, nil +} diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/fake/server.go b/sdk/resourcemanager/resources/armdeploymentscripts/fake/server.go new file mode 100644 index 000000000000..0a3575919294 --- /dev/null +++ b/sdk/resourcemanager/resources/armdeploymentscripts/fake/server.go @@ -0,0 +1,438 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploymentscripts/v2" + "net/http" + "net/url" + "reflect" + "regexp" + "strconv" +) + +// Server is a fake server for instances of the armdeploymentscripts.Client type. +type Server struct { + // BeginCreate is the fake for method Client.BeginCreate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreate func(ctx context.Context, resourceGroupName string, scriptName string, deploymentScript armdeploymentscripts.DeploymentScriptClassification, options *armdeploymentscripts.ClientBeginCreateOptions) (resp azfake.PollerResponder[armdeploymentscripts.ClientCreateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method Client.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, resourceGroupName string, scriptName string, options *armdeploymentscripts.ClientDeleteOptions) (resp azfake.Responder[armdeploymentscripts.ClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method Client.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, scriptName string, options *armdeploymentscripts.ClientGetOptions) (resp azfake.Responder[armdeploymentscripts.ClientGetResponse], errResp azfake.ErrorResponder) + + // GetLogs is the fake for method Client.GetLogs + // HTTP status codes to indicate success: http.StatusOK + GetLogs func(ctx context.Context, resourceGroupName string, scriptName string, options *armdeploymentscripts.ClientGetLogsOptions) (resp azfake.Responder[armdeploymentscripts.ClientGetLogsResponse], errResp azfake.ErrorResponder) + + // GetLogsDefault is the fake for method Client.GetLogsDefault + // HTTP status codes to indicate success: http.StatusOK + GetLogsDefault func(ctx context.Context, resourceGroupName string, scriptName string, options *armdeploymentscripts.ClientGetLogsDefaultOptions) (resp azfake.Responder[armdeploymentscripts.ClientGetLogsDefaultResponse], errResp azfake.ErrorResponder) + + // NewListByResourceGroupPager is the fake for method Client.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armdeploymentscripts.ClientListByResourceGroupOptions) (resp azfake.PagerResponder[armdeploymentscripts.ClientListByResourceGroupResponse]) + + // NewListBySubscriptionPager is the fake for method Client.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armdeploymentscripts.ClientListBySubscriptionOptions) (resp azfake.PagerResponder[armdeploymentscripts.ClientListBySubscriptionResponse]) + + // Update is the fake for method Client.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, resourceGroupName string, scriptName string, options *armdeploymentscripts.ClientUpdateOptions) (resp azfake.Responder[armdeploymentscripts.ClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewServerTransport creates a new instance of ServerTransport with the provided implementation. +// The returned ServerTransport instance is connected to an instance of armdeploymentscripts.Client via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewServerTransport(srv *Server) *ServerTransport { + return &ServerTransport{ + srv: srv, + beginCreate: newTracker[azfake.PollerResponder[armdeploymentscripts.ClientCreateResponse]](), + newListByResourceGroupPager: newTracker[azfake.PagerResponder[armdeploymentscripts.ClientListByResourceGroupResponse]](), + newListBySubscriptionPager: newTracker[azfake.PagerResponder[armdeploymentscripts.ClientListBySubscriptionResponse]](), + } +} + +// ServerTransport connects instances of armdeploymentscripts.Client to instances of Server. +// Don't use this type directly, use NewServerTransport instead. +type ServerTransport struct { + srv *Server + beginCreate *tracker[azfake.PollerResponder[armdeploymentscripts.ClientCreateResponse]] + newListByResourceGroupPager *tracker[azfake.PagerResponder[armdeploymentscripts.ClientListByResourceGroupResponse]] + newListBySubscriptionPager *tracker[azfake.PagerResponder[armdeploymentscripts.ClientListBySubscriptionResponse]] +} + +// Do implements the policy.Transporter interface for ServerTransport. +func (s *ServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "Client.BeginCreate": + resp, err = s.dispatchBeginCreate(req) + case "Client.Delete": + resp, err = s.dispatchDelete(req) + case "Client.Get": + resp, err = s.dispatchGet(req) + case "Client.GetLogs": + resp, err = s.dispatchGetLogs(req) + case "Client.GetLogsDefault": + resp, err = s.dispatchGetLogsDefault(req) + case "Client.NewListByResourceGroupPager": + resp, err = s.dispatchNewListByResourceGroupPager(req) + case "Client.NewListBySubscriptionPager": + resp, err = s.dispatchNewListBySubscriptionPager(req) + case "Client.Update": + resp, err = s.dispatchUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *ServerTransport) dispatchBeginCreate(req *http.Request) (*http.Response, error) { + if s.srv.BeginCreate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreate not implemented")} + } + beginCreate := s.beginCreate.get(req) + if beginCreate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentScripts/(?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) + } + raw, err := readRequestBody(req) + if err != nil { + return nil, err + } + body, err := unmarshalDeploymentScriptClassification(raw) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + scriptNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("scriptName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreate(req.Context(), resourceGroupNameParam, scriptNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreate = &respr + s.beginCreate.add(req, beginCreate) + } + + resp, err := server.PollerResponderNext(beginCreate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + s.beginCreate.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(beginCreate) { + s.beginCreate.remove(req) + } + + return resp, nil +} + +func (s *ServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if s.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentScripts/(?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 + } + scriptNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("scriptName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Delete(req.Context(), resourceGroupNameParam, scriptNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) 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\.Resources/deploymentScripts/(?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 + } + scriptNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("scriptName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameParam, scriptNameParam, 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).DeploymentScriptClassification, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchGetLogs(req *http.Request) (*http.Response, error) { + if s.srv.GetLogs == nil { + return nil, &nonRetriableError{errors.New("fake for method GetLogs not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentScripts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/logs` + 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 + } + scriptNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("scriptName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.GetLogs(req.Context(), resourceGroupNameParam, scriptNameParam, 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).ScriptLogsList, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchGetLogsDefault(req *http.Request) (*http.Response, error) { + if s.srv.GetLogsDefault == nil { + return nil, &nonRetriableError{errors.New("fake for method GetLogsDefault not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentScripts/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/logs/default` + 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) + } + qp := req.URL.Query() + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + scriptNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("scriptName")]) + if err != nil { + return nil, err + } + tailUnescaped, err := url.QueryUnescape(qp.Get("tail")) + if err != nil { + return nil, err + } + tailParam, err := parseOptional(tailUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armdeploymentscripts.ClientGetLogsDefaultOptions + if tailParam != nil { + options = &armdeploymentscripts.ClientGetLogsDefaultOptions{ + Tail: tailParam, + } + } + respr, errRespr := s.srv.GetLogsDefault(req.Context(), resourceGroupNameParam, scriptNameParam, options) + 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).ScriptLog, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) 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\.Resources/deploymentScripts` + 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 *armdeploymentscripts.ClientListByResourceGroupResponse, 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 *ServerTransport) 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\.Resources/deploymentScripts` + 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 *armdeploymentscripts.ClientListBySubscriptionResponse, 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 *ServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if s.srv.Update == nil { + return nil, &nonRetriableError{errors.New("fake for method Update not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentScripts/(?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[armdeploymentscripts.DeploymentScriptUpdateParameter](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + scriptNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("scriptName")]) + if err != nil { + return nil, err + } + var options *armdeploymentscripts.ClientUpdateOptions + if !reflect.ValueOf(body).IsZero() { + options = &armdeploymentscripts.ClientUpdateOptions{ + DeploymentScript: &body, + } + } + respr, errRespr := s.srv.Update(req.Context(), resourceGroupNameParam, scriptNameParam, options) + 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).DeploymentScriptClassification, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/fake/server_factory.go b/sdk/resourcemanager/resources/armdeploymentscripts/fake/server_factory.go new file mode 100644 index 000000000000..e6abac69aba2 --- /dev/null +++ b/sdk/resourcemanager/resources/armdeploymentscripts/fake/server_factory.go @@ -0,0 +1,75 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" + "sync" +) + +// ServerFactory is a fake server for instances of the armdeploymentscripts.ClientFactory type. +type ServerFactory struct { + Server Server +} + +// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. +// The returned ServerFactoryTransport instance is connected to an instance of armdeploymentscripts.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 armdeploymentscripts.ClientFactory to instances of ServerFactory. +// Don't use this type directly, use NewServerFactoryTransport instead. +type ServerFactoryTransport struct { + srv *ServerFactory + trMu sync.Mutex + trServer *ServerTransport +} + +// 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 "Client": + initServer(s, &s.trServer, func() *ServerTransport { return NewServerTransport(&s.srv.Server) }) + resp, err = s.trServer.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/resources/armdeploymentscripts/fake/time_rfc3339.go b/sdk/resourcemanager/resources/armdeploymentscripts/fake/time_rfc3339.go new file mode 100644 index 000000000000..b0535a7b63e6 --- /dev/null +++ b/sdk/resourcemanager/resources/armdeploymentscripts/fake/time_rfc3339.go @@ -0,0 +1,86 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "regexp" + "strings" + "time" +) + +// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. +var tzOffsetRegex = regexp.MustCompile(`(Z|z|\+|-)(\d+:\d+)*"*$`) + +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +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 { + layout := utcDateTimeJSON + if tzOffsetRegex.Match(data) { + layout = dateTimeJSON + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime + if tzOffsetRegex.Match(data) { + layout = time.RFC3339Nano + } + 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 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 || strings.EqualFold(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/resources/armdeploymentscripts/go.mod b/sdk/resourcemanager/resources/armdeploymentscripts/go.mod index 8d7224d04757..bfe38a30a1a8 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/go.mod +++ b/sdk/resourcemanager/resources/armdeploymentscripts/go.mod @@ -3,29 +3,29 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploy go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v0.6.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploymentscripts v1.0.0 - github.com/stretchr/testify v1.7.0 + github.com/stretchr/testify v1.8.4 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 // indirect - github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dnaeon/go-vcr v1.1.0 // indirect - github.com/golang-jwt/jwt/v4 v4.4.2 // indirect - github.com/google/uuid v1.1.1 // indirect + github.com/dnaeon/go-vcr v1.2.0 // indirect + github.com/golang-jwt/jwt/v5 v5.0.0 // indirect + github.com/google/uuid v1.3.1 // indirect github.com/kylelemons/godebug v1.1.0 // indirect - github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect + github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/go.sum b/sdk/resourcemanager/resources/armdeploymentscripts/go.sum index 958a9fbbe974..49581f6c4ac7 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/go.sum +++ b/sdk/resourcemanager/resources/armdeploymentscripts/go.sum @@ -1,51 +1,51 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 h1:rTnT/Jrcm+figWlYz4Ixzt0SJVR2cMC8lvZcimipiEY= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0/go.mod h1:ON4tFdPTwRcgWEaVDrN3584Ef+b7GgSJaXxe5fW9t4M= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 h1:t/W5MYAuQy81cvM8VUNfRLzhtKpXhVUAN7Cd7KVbTyc= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0/go.mod h1:NBanQUfSWiWn3QEpWDTCU0IjBECKOYvl2R8xdRtMtiM= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 h1:leh5DwKv6Ihwi+h60uHtn6UWAxBbZ0q8DwQVMzf61zw= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 h1:fb8kj/Dh4CSwgsOzHeZY4Xh68cFVbzXx+ONXGMY//4w= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0/go.mod h1:uReU2sSxZExRPBAg3qKzmAucSi51+SP1OhohieR821Q= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 h1:BMAjVKJM0U/CYF27gA0ZMmXGkOcvfFtD0oHVZ1TIPRI= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0/go.mod h1:1fXstnBMas5kzG+S3q8UoJcmyU6nUeunJcMDHcRYHhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 h1:PTFGRSlMKCQelWwxUyYVEUqseBJVemLyqWJjvMyt0do= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0/go.mod h1:LRr2FzBTQlONPPa5HREE5+RjSCTXl7BwOvYOaWTqCaI= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 h1:pPvTJ1dY0sA35JOeFq6TsY2xj6Z85Yo23Pj4wCCvu4o= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v0.6.0 h1:zSHpZY39hfFpVNixDoFOUeLwBBX0SIRe32HaWg03R8k= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v0.6.0/go.mod h1:Yu9z4VU4VeNRoZQMjAKwzXJpNAZ8SlyVg+yHyDVqvi8= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploymentscripts v1.0.0 h1:qd/BfXBy0s/cPn/hVVX+Ps0HolpC1NsHE2p+L2zB4C4= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploymentscripts v1.0.0/go.mod h1:P1SgXux7JvaLh0fwpYwtY2csL+RYAc033mNha1Txlm8= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 h1:ECsQtyERDVz3NP3kvDOTLvbQhqWp/x9EsGKtb4ogUr8= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0/go.mod h1:s1tW/At+xHqjNFvWU4G0c0Qv33KOhvbGNj0RCTQDV8s= -github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 h1:VgSJlZH5u0k2qxSpqyghcFQKmvYckj46uymKK5XzkBM= -github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0/go.mod h1:BDJ5qMFKx9DugEg3+uQSDCdbYPr5s9vBTrL9P8TpqOU= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 h1:7CBQ+Ei8SP2c6ydQTGCCrS35bDxgTMfoP2miAwK++OU= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1/go.mod h1:c/wcGeGx5FUPbM/JltUYHZcKmigwyVLJlDq+4HdtXaw= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 h1:WpB/QDNLpMw72xHJc34BNNykqSOeEJDAWkhf0u12/Jk= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= -github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= -github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs= -github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= +github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= +github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/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/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= -github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 h1:Qj1ukM4GlMWXNdMBuXcXfz/Kw9s1qm0CLY32QxuSImI= -github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 h1:Tgea0cVUD0ivh5ADBX4WwuI12DUd2to3nCYe2eayMIw= -golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/interfaces.go b/sdk/resourcemanager/resources/armdeploymentscripts/interfaces.go new file mode 100644 index 000000000000..cde83547adc2 --- /dev/null +++ b/sdk/resourcemanager/resources/armdeploymentscripts/interfaces.go @@ -0,0 +1,18 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armdeploymentscripts + +// DeploymentScriptClassification provides polymorphic access to related types. +// Call the interface's GetDeploymentScript() method to access the common type. +// Use a type switch to determine the concrete type. The possible types are: +// - *AzureCliScript, *AzurePowerShellScript, *DeploymentScript +type DeploymentScriptClassification interface { + // GetDeploymentScript returns the DeploymentScript content of the underlying type. + GetDeploymentScript() *DeploymentScript +} diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/models.go b/sdk/resourcemanager/resources/armdeploymentscripts/models.go index a42559fc0d62..8722a4717a31 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/models.go +++ b/sdk/resourcemanager/resources/armdeploymentscripts/models.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armdeploymentscripts @@ -44,13 +43,13 @@ type AzureCliScript struct { // GetDeploymentScript implements the DeploymentScriptClassification interface for type AzureCliScript. func (a *AzureCliScript) GetDeploymentScript() *DeploymentScript { return &DeploymentScript{ + ID: a.ID, Identity: a.Identity, - Location: a.Location, - Tags: a.Tags, Kind: a.Kind, - SystemData: a.SystemData, - ID: a.ID, + Location: a.Location, Name: a.Name, + SystemData: a.SystemData, + Tags: a.Tags, Type: a.Type, } } @@ -139,13 +138,13 @@ type AzurePowerShellScript struct { // GetDeploymentScript implements the DeploymentScriptClassification interface for type AzurePowerShellScript. func (a *AzurePowerShellScript) GetDeploymentScript() *DeploymentScript { return &DeploymentScript{ + ID: a.ID, Identity: a.Identity, - Location: a.Location, - Tags: a.Tags, Kind: a.Kind, - SystemData: a.SystemData, - ID: a.ID, + Location: a.Location, Name: a.Name, + SystemData: a.SystemData, + Tags: a.Tags, Type: a.Type, } } @@ -213,51 +212,6 @@ type AzureResourceBase struct { Type *string } -// ClientBeginCreateOptions contains the optional parameters for the Client.BeginCreate method. -type ClientBeginCreateOptions struct { - // Resumes the LRO from the provided token. - ResumeToken string -} - -// ClientDeleteOptions contains the optional parameters for the Client.Delete method. -type ClientDeleteOptions struct { - // placeholder for future optional parameters -} - -// ClientGetLogsDefaultOptions contains the optional parameters for the Client.GetLogsDefault method. -type ClientGetLogsDefaultOptions struct { - // The number of lines to show from the tail of the deployment script log. Valid value is a positive number up to 1000. If - // 'tail' is not provided, all available logs are shown up to container instance - // log capacity of 4mb. - Tail *int32 -} - -// ClientGetLogsOptions contains the optional parameters for the Client.GetLogs method. -type ClientGetLogsOptions struct { - // placeholder for future optional parameters -} - -// ClientGetOptions contains the optional parameters for the Client.Get method. -type ClientGetOptions struct { - // placeholder for future optional parameters -} - -// ClientListByResourceGroupOptions contains the optional parameters for the Client.NewListByResourceGroupPager method. -type ClientListByResourceGroupOptions struct { - // placeholder for future optional parameters -} - -// ClientListBySubscriptionOptions contains the optional parameters for the Client.NewListBySubscriptionPager method. -type ClientListBySubscriptionOptions struct { - // placeholder for future optional parameters -} - -// ClientUpdateOptions contains the optional parameters for the Client.Update method. -type ClientUpdateOptions struct { - // Deployment script resource with the tags to be updated. - DeploymentScript *DeploymentScriptUpdateParameter -} - // ContainerConfiguration - Settings to customize ACI container instance. type ContainerConfiguration struct { // Container group name, if not specified then the name will get auto-generated. Not specifying a 'containerGroupName' indicates @@ -272,15 +226,6 @@ type ContainerConfiguration struct { ContainerGroupName *string } -// DeploymentScriptClassification provides polymorphic access to related types. -// Call the interface's GetDeploymentScript() method to access the common type. -// Use a type switch to determine the concrete type. The possible types are: -// - *AzureCliScript, *AzurePowerShellScript, *DeploymentScript -type DeploymentScriptClassification interface { - // GetDeploymentScript returns the DeploymentScript content of the underlying type. - GetDeploymentScript() *DeploymentScript -} - // DeploymentScript - Deployment script object. type DeploymentScript struct { // REQUIRED; Type of the script. diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/models_serde.go b/sdk/resourcemanager/resources/armdeploymentscripts/models_serde.go index 4895a4b68cbe..a4b8dc462d2a 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/models_serde.go +++ b/sdk/resourcemanager/resources/armdeploymentscripts/models_serde.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armdeploymentscripts @@ -755,10 +754,10 @@ func (s *ScriptLogsList) UnmarshalJSON(data []byte) error { func (s ScriptStatus) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) populate(objectMap, "containerInstanceId", s.ContainerInstanceID) - populateTimeRFC3339(objectMap, "endTime", s.EndTime) + populateDateTimeRFC3339(objectMap, "endTime", s.EndTime) populate(objectMap, "error", s.Error) - populateTimeRFC3339(objectMap, "expirationTime", s.ExpirationTime) - populateTimeRFC3339(objectMap, "startTime", s.StartTime) + populateDateTimeRFC3339(objectMap, "expirationTime", s.ExpirationTime) + populateDateTimeRFC3339(objectMap, "startTime", s.StartTime) populate(objectMap, "storageAccountId", s.StorageAccountID) return json.Marshal(objectMap) } @@ -776,16 +775,16 @@ func (s *ScriptStatus) UnmarshalJSON(data []byte) error { err = unpopulate(val, "ContainerInstanceID", &s.ContainerInstanceID) delete(rawMsg, key) case "endTime": - err = unpopulateTimeRFC3339(val, "EndTime", &s.EndTime) + err = unpopulateDateTimeRFC3339(val, "EndTime", &s.EndTime) delete(rawMsg, key) case "error": err = unpopulate(val, "Error", &s.Error) delete(rawMsg, key) case "expirationTime": - err = unpopulateTimeRFC3339(val, "ExpirationTime", &s.ExpirationTime) + err = unpopulateDateTimeRFC3339(val, "ExpirationTime", &s.ExpirationTime) delete(rawMsg, key) case "startTime": - err = unpopulateTimeRFC3339(val, "StartTime", &s.StartTime) + err = unpopulateDateTimeRFC3339(val, "StartTime", &s.StartTime) delete(rawMsg, key) case "storageAccountId": err = unpopulate(val, "StorageAccountID", &s.StorageAccountID) @@ -832,10 +831,10 @@ func (s *StorageAccountConfiguration) UnmarshalJSON(data []byte) error { // MarshalJSON implements the json.Marshaller interface for type SystemData. func (s SystemData) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populateTimeRFC3339(objectMap, "createdAt", s.CreatedAt) + populateDateTimeRFC3339(objectMap, "createdAt", s.CreatedAt) populate(objectMap, "createdBy", s.CreatedBy) populate(objectMap, "createdByType", s.CreatedByType) - populateTimeRFC3339(objectMap, "lastModifiedAt", s.LastModifiedAt) + populateDateTimeRFC3339(objectMap, "lastModifiedAt", s.LastModifiedAt) populate(objectMap, "lastModifiedBy", s.LastModifiedBy) populate(objectMap, "lastModifiedByType", s.LastModifiedByType) return json.Marshal(objectMap) @@ -851,7 +850,7 @@ func (s *SystemData) UnmarshalJSON(data []byte) error { var err error switch key { case "createdAt": - err = unpopulateTimeRFC3339(val, "CreatedAt", &s.CreatedAt) + err = unpopulateDateTimeRFC3339(val, "CreatedAt", &s.CreatedAt) delete(rawMsg, key) case "createdBy": err = unpopulate(val, "CreatedBy", &s.CreatedBy) @@ -860,7 +859,7 @@ func (s *SystemData) UnmarshalJSON(data []byte) error { err = unpopulate(val, "CreatedByType", &s.CreatedByType) delete(rawMsg, key) case "lastModifiedAt": - err = unpopulateTimeRFC3339(val, "LastModifiedAt", &s.LastModifiedAt) + err = unpopulateDateTimeRFC3339(val, "LastModifiedAt", &s.LastModifiedAt) delete(rawMsg, key) case "lastModifiedBy": err = unpopulate(val, "LastModifiedBy", &s.LastModifiedBy) diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/options.go b/sdk/resourcemanager/resources/armdeploymentscripts/options.go new file mode 100644 index 000000000000..6dd22298aef2 --- /dev/null +++ b/sdk/resourcemanager/resources/armdeploymentscripts/options.go @@ -0,0 +1,54 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armdeploymentscripts + +// ClientBeginCreateOptions contains the optional parameters for the Client.BeginCreate method. +type ClientBeginCreateOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ClientDeleteOptions contains the optional parameters for the Client.Delete method. +type ClientDeleteOptions struct { + // placeholder for future optional parameters +} + +// ClientGetLogsDefaultOptions contains the optional parameters for the Client.GetLogsDefault method. +type ClientGetLogsDefaultOptions struct { + // The number of lines to show from the tail of the deployment script log. Valid value is a positive number up to 1000. If + // 'tail' is not provided, all available logs are shown up to container instance + // log capacity of 4mb. + Tail *int32 +} + +// ClientGetLogsOptions contains the optional parameters for the Client.GetLogs method. +type ClientGetLogsOptions struct { + // placeholder for future optional parameters +} + +// ClientGetOptions contains the optional parameters for the Client.Get method. +type ClientGetOptions struct { + // placeholder for future optional parameters +} + +// ClientListByResourceGroupOptions contains the optional parameters for the Client.NewListByResourceGroupPager method. +type ClientListByResourceGroupOptions struct { + // placeholder for future optional parameters +} + +// ClientListBySubscriptionOptions contains the optional parameters for the Client.NewListBySubscriptionPager method. +type ClientListBySubscriptionOptions struct { + // placeholder for future optional parameters +} + +// ClientUpdateOptions contains the optional parameters for the Client.Update method. +type ClientUpdateOptions struct { + // Deployment script resource with the tags to be updated. + DeploymentScript *DeploymentScriptUpdateParameter +} diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/polymorphic_helpers.go b/sdk/resourcemanager/resources/armdeploymentscripts/polymorphic_helpers.go index 075085c19b5a..ab6bf154a2d5 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/polymorphic_helpers.go +++ b/sdk/resourcemanager/resources/armdeploymentscripts/polymorphic_helpers.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armdeploymentscripts @@ -28,7 +27,10 @@ func unmarshalDeploymentScriptClassification(rawMsg json.RawMessage) (Deployment default: b = &DeploymentScript{} } - return b, json.Unmarshal(rawMsg, b) + if err := json.Unmarshal(rawMsg, b); err != nil { + return nil, err + } + return b, nil } func unmarshalDeploymentScriptClassificationArray(rawMsg json.RawMessage) ([]DeploymentScriptClassification, error) { diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/response_types.go b/sdk/resourcemanager/resources/armdeploymentscripts/response_types.go index c7f81c91b346..dc9bf73f0c63 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/response_types.go +++ b/sdk/resourcemanager/resources/armdeploymentscripts/response_types.go @@ -3,17 +3,24 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armdeploymentscripts +import "encoding/json" + // ClientCreateResponse contains the response from method Client.BeginCreate. type ClientCreateResponse struct { + // Deployment script object. DeploymentScriptClassification } +// MarshalJSON implements the json.Marshaller interface for type ClientCreateResponse. +func (c ClientCreateResponse) MarshalJSON() ([]byte, error) { + return json.Marshal(c.DeploymentScriptClassification) +} + // UnmarshalJSON implements the json.Unmarshaller interface for type ClientCreateResponse. func (c *ClientCreateResponse) UnmarshalJSON(data []byte) error { res, err := unmarshalDeploymentScriptClassification(data) @@ -31,16 +38,19 @@ type ClientDeleteResponse struct { // ClientGetLogsDefaultResponse contains the response from method Client.GetLogsDefault. type ClientGetLogsDefaultResponse struct { + // Script execution log object. ScriptLog } // ClientGetLogsResponse contains the response from method Client.GetLogs. type ClientGetLogsResponse struct { + // Deployment script execution logs. ScriptLogsList } // ClientGetResponse contains the response from method Client.Get. type ClientGetResponse struct { + // Deployment script object. DeploymentScriptClassification } @@ -56,16 +66,19 @@ func (c *ClientGetResponse) UnmarshalJSON(data []byte) error { // ClientListByResourceGroupResponse contains the response from method Client.NewListByResourceGroupPager. type ClientListByResourceGroupResponse struct { + // List of deployment scripts. DeploymentScriptListResult } // ClientListBySubscriptionResponse contains the response from method Client.NewListBySubscriptionPager. type ClientListBySubscriptionResponse struct { + // List of deployment scripts. DeploymentScriptListResult } // ClientUpdateResponse contains the response from method Client.Update. type ClientUpdateResponse struct { + // Deployment script object. DeploymentScriptClassification } diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/time_rfc3339.go b/sdk/resourcemanager/resources/armdeploymentscripts/time_rfc3339.go index 0fe44893872d..b1f88d20041a 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/time_rfc3339.go +++ b/sdk/resourcemanager/resources/armdeploymentscripts/time_rfc3339.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armdeploymentscripts @@ -19,50 +18,50 @@ import ( "time" ) -const ( - utcLayoutJSON = `"2006-01-02T15:04:05.999999999"` - utcLayout = "2006-01-02T15:04:05.999999999" - rfc3339JSON = `"` + time.RFC3339Nano + `"` -) - // 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+)*"*$`) -type timeRFC3339 time.Time +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +type dateTimeRFC3339 time.Time -func (t timeRFC3339) MarshalJSON() (json []byte, err error) { +func (t dateTimeRFC3339) MarshalJSON() ([]byte, error) { tt := time.Time(t) return tt.MarshalJSON() } -func (t timeRFC3339) MarshalText() (text []byte, err error) { +func (t dateTimeRFC3339) MarshalText() ([]byte, error) { tt := time.Time(t) return tt.MarshalText() } -func (t *timeRFC3339) UnmarshalJSON(data []byte) error { - layout := utcLayoutJSON +func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { + layout := utcDateTimeJSON if tzOffsetRegex.Match(data) { - layout = rfc3339JSON + layout = dateTimeJSON } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) UnmarshalText(data []byte) (err error) { - layout := utcLayout +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime if tzOffsetRegex.Match(data) { layout = time.RFC3339Nano } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) Parse(layout, value string) error { +func (t *dateTimeRFC3339) Parse(layout, value string) error { p, err := time.Parse(layout, strings.ToUpper(value)) - *t = timeRFC3339(p) + *t = dateTimeRFC3339(p) return err } -func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { +func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { if t == nil { return } else if azcore.IsNullValue(t) { @@ -71,14 +70,14 @@ func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { } else if reflect.ValueOf(t).IsNil() { return } - m[k] = (*timeRFC3339)(t) + m[k] = (*dateTimeRFC3339)(t) } -func unpopulateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { +func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { if data == nil || strings.EqualFold(string(data), "null") { return nil } - var aux timeRFC3339 + var aux dateTimeRFC3339 if err := json.Unmarshal(data, &aux); err != nil { return fmt.Errorf("struct field %s: %v", fn, err) } From f2a6fe2cfb6da98f295b7d1613f2b65163e6d8e6 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 15:17:02 +0800 Subject: [PATCH 03/18] [Release] sdk/resourcemanager/resources/armdeploymentstacks/0.2.0 generation from spec commit: bf204aab860f2eb58a9d346b00d44760f2a9b0a2 --- .../armdeploymentstacks/CHANGELOG.md | 6 + .../resources/armdeploymentstacks/README.md | 7 + .../resources/armdeploymentstacks/autorest.md | 2 +- .../resources/armdeploymentstacks/client.go | 143 +++- .../client_example_test.go | 48 +- .../armdeploymentstacks/client_factory.go | 3 +- .../armdeploymentstacks/constants.go | 4 +- .../armdeploymentstacks/fake/internal.go | 72 ++ .../armdeploymentstacks/fake/server.go | 797 ++++++++++++++++++ .../fake/server_factory.go | 75 ++ .../armdeploymentstacks/fake/time_rfc3339.go | 86 ++ .../resources/armdeploymentstacks/go.mod | 20 +- .../resources/armdeploymentstacks/go.sum | 42 +- .../armdeploymentstacks/models_serde.go | 8 +- .../armdeploymentstacks/time_rfc3339.go | 40 +- 15 files changed, 1224 insertions(+), 129 deletions(-) create mode 100644 sdk/resourcemanager/resources/armdeploymentstacks/fake/internal.go create mode 100644 sdk/resourcemanager/resources/armdeploymentstacks/fake/server.go create mode 100644 sdk/resourcemanager/resources/armdeploymentstacks/fake/server_factory.go create mode 100644 sdk/resourcemanager/resources/armdeploymentstacks/fake/time_rfc3339.go diff --git a/sdk/resourcemanager/resources/armdeploymentstacks/CHANGELOG.md b/sdk/resourcemanager/resources/armdeploymentstacks/CHANGELOG.md index 052b88d43dab..cfc50ca01af0 100644 --- a/sdk/resourcemanager/resources/armdeploymentstacks/CHANGELOG.md +++ b/sdk/resourcemanager/resources/armdeploymentstacks/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 0.2.0 (2023-11-24) +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + + ## 0.1.0 (2023-08-25) The package of `github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploymentstacks` is using our [next generation design principles](https://azure.github.io/azure-sdk/general_introduction.html). diff --git a/sdk/resourcemanager/resources/armdeploymentstacks/README.md b/sdk/resourcemanager/resources/armdeploymentstacks/README.md index 747e6800e691..1d8680835eb5 100644 --- a/sdk/resourcemanager/resources/armdeploymentstacks/README.md +++ b/sdk/resourcemanager/resources/armdeploymentstacks/README.md @@ -60,6 +60,13 @@ A client groups a set of related APIs, providing access to its functionality. C client := clientFactory.NewClient() ``` +## 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 diff --git a/sdk/resourcemanager/resources/armdeploymentstacks/autorest.md b/sdk/resourcemanager/resources/armdeploymentstacks/autorest.md index cfb42784d43a..119d23bdf762 100644 --- a/sdk/resourcemanager/resources/armdeploymentstacks/autorest.md +++ b/sdk/resourcemanager/resources/armdeploymentstacks/autorest.md @@ -8,6 +8,6 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/ca162308f1010bfb85b9c85021e863e7bd397a1f/specification/resources/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/ca162308f1010bfb85b9c85021e863e7bd397a1f/specification/resources/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 0.1.0 +module-version: 0.2.0 package-deploymentstacks: true ``` \ No newline at end of file diff --git a/sdk/resourcemanager/resources/armdeploymentstacks/client.go b/sdk/resourcemanager/resources/armdeploymentstacks/client.go index b31d20c51267..e8766dabf590 100644 --- a/sdk/resourcemanager/resources/armdeploymentstacks/client.go +++ b/sdk/resourcemanager/resources/armdeploymentstacks/client.go @@ -32,7 +32,7 @@ type Client struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*Client, error) { - cl, err := arm.NewClient(moduleName+".Client", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -60,10 +60,13 @@ func (client *Client) BeginCreateOrUpdateAtManagementGroup(ctx context.Context, } poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClientCreateOrUpdateAtManagementGroupResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, + Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ClientCreateOrUpdateAtManagementGroupResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ClientCreateOrUpdateAtManagementGroupResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -73,6 +76,10 @@ func (client *Client) BeginCreateOrUpdateAtManagementGroup(ctx context.Context, // Generated from API version 2022-08-01-preview func (client *Client) createOrUpdateAtManagementGroup(ctx context.Context, managementGroupID string, deploymentStackName string, deploymentStack DeploymentStack, options *ClientBeginCreateOrUpdateAtManagementGroupOptions) (*http.Response, error) { var err error + const operationName = "Client.BeginCreateOrUpdateAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateAtManagementGroupCreateRequest(ctx, managementGroupID, deploymentStackName, deploymentStack, options) if err != nil { return nil, err @@ -130,10 +137,13 @@ func (client *Client) BeginCreateOrUpdateAtResourceGroup(ctx context.Context, re } poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClientCreateOrUpdateAtResourceGroupResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, + Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ClientCreateOrUpdateAtResourceGroupResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ClientCreateOrUpdateAtResourceGroupResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -143,6 +153,10 @@ func (client *Client) BeginCreateOrUpdateAtResourceGroup(ctx context.Context, re // Generated from API version 2022-08-01-preview func (client *Client) createOrUpdateAtResourceGroup(ctx context.Context, resourceGroupName string, deploymentStackName string, deploymentStack DeploymentStack, options *ClientBeginCreateOrUpdateAtResourceGroupOptions) (*http.Response, error) { var err error + const operationName = "Client.BeginCreateOrUpdateAtResourceGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateAtResourceGroupCreateRequest(ctx, resourceGroupName, deploymentStackName, deploymentStack, options) if err != nil { return nil, err @@ -203,10 +217,13 @@ func (client *Client) BeginCreateOrUpdateAtSubscription(ctx context.Context, dep } poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClientCreateOrUpdateAtSubscriptionResponse]{ FinalStateVia: runtime.FinalStateViaAzureAsyncOp, + Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ClientCreateOrUpdateAtSubscriptionResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ClientCreateOrUpdateAtSubscriptionResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -216,6 +233,10 @@ func (client *Client) BeginCreateOrUpdateAtSubscription(ctx context.Context, dep // Generated from API version 2022-08-01-preview func (client *Client) createOrUpdateAtSubscription(ctx context.Context, deploymentStackName string, deploymentStack DeploymentStack, options *ClientBeginCreateOrUpdateAtSubscriptionOptions) (*http.Response, error) { var err error + const operationName = "Client.BeginCreateOrUpdateAtSubscription" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateAtSubscriptionCreateRequest(ctx, deploymentStackName, deploymentStack, options) if err != nil { return nil, err @@ -273,10 +294,13 @@ func (client *Client) BeginDeleteAtManagementGroup(ctx context.Context, manageme } poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClientDeleteAtManagementGroupResponse]{ FinalStateVia: runtime.FinalStateViaLocation, + Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ClientDeleteAtManagementGroupResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ClientDeleteAtManagementGroupResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -287,6 +311,10 @@ func (client *Client) BeginDeleteAtManagementGroup(ctx context.Context, manageme // Generated from API version 2022-08-01-preview func (client *Client) deleteAtManagementGroup(ctx context.Context, managementGroupID string, deploymentStackName string, options *ClientBeginDeleteAtManagementGroupOptions) (*http.Response, error) { var err error + const operationName = "Client.BeginDeleteAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAtManagementGroupCreateRequest(ctx, managementGroupID, deploymentStackName, options) if err != nil { return nil, err @@ -350,10 +378,13 @@ func (client *Client) BeginDeleteAtResourceGroup(ctx context.Context, resourceGr } poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClientDeleteAtResourceGroupResponse]{ FinalStateVia: runtime.FinalStateViaLocation, + Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ClientDeleteAtResourceGroupResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ClientDeleteAtResourceGroupResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -364,6 +395,10 @@ func (client *Client) BeginDeleteAtResourceGroup(ctx context.Context, resourceGr // Generated from API version 2022-08-01-preview func (client *Client) deleteAtResourceGroup(ctx context.Context, resourceGroupName string, deploymentStackName string, options *ClientBeginDeleteAtResourceGroupOptions) (*http.Response, error) { var err error + const operationName = "Client.BeginDeleteAtResourceGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAtResourceGroupCreateRequest(ctx, resourceGroupName, deploymentStackName, options) if err != nil { return nil, err @@ -427,10 +462,13 @@ func (client *Client) BeginDeleteAtSubscription(ctx context.Context, deploymentS } poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClientDeleteAtSubscriptionResponse]{ FinalStateVia: runtime.FinalStateViaLocation, + Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ClientDeleteAtSubscriptionResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ClientDeleteAtSubscriptionResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -440,6 +478,10 @@ func (client *Client) BeginDeleteAtSubscription(ctx context.Context, deploymentS // Generated from API version 2022-08-01-preview func (client *Client) deleteAtSubscription(ctx context.Context, deploymentStackName string, options *ClientBeginDeleteAtSubscriptionOptions) (*http.Response, error) { var err error + const operationName = "Client.BeginDeleteAtSubscription" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAtSubscriptionCreateRequest(ctx, deploymentStackName, options) if err != nil { return nil, err @@ -493,6 +535,10 @@ func (client *Client) deleteAtSubscriptionCreateRequest(ctx context.Context, dep // method. func (client *Client) ExportTemplateAtManagementGroup(ctx context.Context, managementGroupID string, deploymentStackName string, options *ClientExportTemplateAtManagementGroupOptions) (ClientExportTemplateAtManagementGroupResponse, error) { var err error + const operationName = "Client.ExportTemplateAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.exportTemplateAtManagementGroupCreateRequest(ctx, managementGroupID, deploymentStackName, options) if err != nil { return ClientExportTemplateAtManagementGroupResponse{}, err @@ -550,6 +596,10 @@ func (client *Client) exportTemplateAtManagementGroupHandleResponse(resp *http.R // method. func (client *Client) ExportTemplateAtResourceGroup(ctx context.Context, resourceGroupName string, deploymentStackName string, options *ClientExportTemplateAtResourceGroupOptions) (ClientExportTemplateAtResourceGroupResponse, error) { var err error + const operationName = "Client.ExportTemplateAtResourceGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.exportTemplateAtResourceGroupCreateRequest(ctx, resourceGroupName, deploymentStackName, options) if err != nil { return ClientExportTemplateAtResourceGroupResponse{}, err @@ -610,6 +660,10 @@ func (client *Client) exportTemplateAtResourceGroupHandleResponse(resp *http.Res // method. func (client *Client) ExportTemplateAtSubscription(ctx context.Context, deploymentStackName string, options *ClientExportTemplateAtSubscriptionOptions) (ClientExportTemplateAtSubscriptionResponse, error) { var err error + const operationName = "Client.ExportTemplateAtSubscription" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.exportTemplateAtSubscriptionCreateRequest(ctx, deploymentStackName, options) if err != nil { return ClientExportTemplateAtSubscriptionResponse{}, err @@ -666,6 +720,10 @@ func (client *Client) exportTemplateAtSubscriptionHandleResponse(resp *http.Resp // - options - ClientGetAtManagementGroupOptions contains the optional parameters for the Client.GetAtManagementGroup method. func (client *Client) GetAtManagementGroup(ctx context.Context, managementGroupID string, deploymentStackName string, options *ClientGetAtManagementGroupOptions) (ClientGetAtManagementGroupResponse, error) { var err error + const operationName = "Client.GetAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtManagementGroupCreateRequest(ctx, managementGroupID, deploymentStackName, options) if err != nil { return ClientGetAtManagementGroupResponse{}, err @@ -722,6 +780,10 @@ func (client *Client) getAtManagementGroupHandleResponse(resp *http.Response) (C // - options - ClientGetAtResourceGroupOptions contains the optional parameters for the Client.GetAtResourceGroup method. func (client *Client) GetAtResourceGroup(ctx context.Context, resourceGroupName string, deploymentStackName string, options *ClientGetAtResourceGroupOptions) (ClientGetAtResourceGroupResponse, error) { var err error + const operationName = "Client.GetAtResourceGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtResourceGroupCreateRequest(ctx, resourceGroupName, deploymentStackName, options) if err != nil { return ClientGetAtResourceGroupResponse{}, err @@ -781,6 +843,10 @@ func (client *Client) getAtResourceGroupHandleResponse(resp *http.Response) (Cli // - options - ClientGetAtSubscriptionOptions contains the optional parameters for the Client.GetAtSubscription method. func (client *Client) GetAtSubscription(ctx context.Context, deploymentStackName string, options *ClientGetAtSubscriptionOptions) (ClientGetAtSubscriptionResponse, error) { var err error + const operationName = "Client.GetAtSubscription" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtSubscriptionCreateRequest(ctx, deploymentStackName, options) if err != nil { return ClientGetAtSubscriptionResponse{}, err @@ -840,25 +906,20 @@ func (client *Client) NewListAtManagementGroupPager(managementGroupID string, op return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ClientListAtManagementGroupResponse) (ClientListAtManagementGroupResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtManagementGroupCreateRequest(ctx, managementGroupID, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return ClientListAtManagementGroupResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewListAtManagementGroupPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listAtManagementGroupCreateRequest(ctx, managementGroupID, options) + }, nil) if err != nil { return ClientListAtManagementGroupResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListAtManagementGroupResponse{}, runtime.NewResponseError(resp) - } return client.listAtManagementGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -901,25 +962,20 @@ func (client *Client) NewListAtResourceGroupPager(resourceGroupName string, opti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ClientListAtResourceGroupResponse) (ClientListAtResourceGroupResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtResourceGroupCreateRequest(ctx, resourceGroupName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewListAtResourceGroupPager") + 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.listAtResourceGroupCreateRequest(ctx, resourceGroupName, options) + }, nil) if err != nil { return ClientListAtResourceGroupResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ClientListAtResourceGroupResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListAtResourceGroupResponse{}, runtime.NewResponseError(resp) - } return client.listAtResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -964,25 +1020,20 @@ func (client *Client) NewListAtSubscriptionPager(options *ClientListAtSubscripti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ClientListAtSubscriptionResponse) (ClientListAtSubscriptionResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtSubscriptionCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewListAtSubscriptionPager") + 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.listAtSubscriptionCreateRequest(ctx, options) + }, nil) if err != nil { return ClientListAtSubscriptionResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ClientListAtSubscriptionResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListAtSubscriptionResponse{}, runtime.NewResponseError(resp) - } return client.listAtSubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armdeploymentstacks/client_example_test.go b/sdk/resourcemanager/resources/armdeploymentstacks/client_example_test.go index 4c67917a08f2..e742cef73e28 100644 --- a/sdk/resourcemanager/resources/armdeploymentstacks/client_example_test.go +++ b/sdk/resourcemanager/resources/armdeploymentstacks/client_example_test.go @@ -47,10 +47,10 @@ func ExampleClient_NewListAtResourceGroupPager() { // Type: to.Ptr("Microsoft.Resources/deploymentStacks"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/deploymentStacksRG/providers/Microsoft.Resources/deploymentStacks/simpleDeploymentStack"), // SystemData: &armdeploymentstacks.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), // }, @@ -88,10 +88,10 @@ func ExampleClient_NewListAtResourceGroupPager() { // Type: to.Ptr("Microsoft.Resources/deploymentStacks"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/deploymentStacksRG/providers/Microsoft.Resources/deploymentStacks/simpleDeploymentStack2"), // SystemData: &armdeploymentstacks.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), // }, @@ -170,10 +170,10 @@ func ExampleClient_NewListAtSubscriptionPager() { // Type: to.Ptr("Microsoft.Resources/deploymentStacks"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/deploymentStacksRG/providers/Microsoft.Resources/deploymentStacks/simpleDeploymentStack"), // SystemData: &armdeploymentstacks.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), // }, @@ -211,10 +211,10 @@ func ExampleClient_NewListAtSubscriptionPager() { // Type: to.Ptr("Microsoft.Resources/deploymentStacks"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/deploymentStacksRG/providers/Microsoft.Resources/deploymentStacks/simpleDeploymentStack2"), // SystemData: &armdeploymentstacks.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), // }, @@ -293,10 +293,10 @@ func ExampleClient_NewListAtManagementGroupPager() { // Type: to.Ptr("Microsoft.Resources/deploymentStacks"), // ID: to.Ptr("/providers/Microsoft.Management/managementGroups/myMg/providers/Microsoft.Resources/deploymentStacks/simpleDeploymentStack"), // SystemData: &armdeploymentstacks.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), // }, @@ -334,10 +334,10 @@ func ExampleClient_NewListAtManagementGroupPager() { // Type: to.Ptr("Microsoft.Resources/deploymentStacks"), // ID: to.Ptr("/providers/Microsoft.Management/managementGroups/myMg/providers/Microsoft.Resources/deploymentStacks/simpleDeploymentStack2"), // SystemData: &armdeploymentstacks.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), // }, @@ -439,10 +439,10 @@ func ExampleClient_BeginCreateOrUpdateAtResourceGroup() { // Type: to.Ptr("Microsoft.Resources/deploymentStacks"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/deploymentStacksRG/providers/Microsoft.Resources/deploymentStacks/simpleDeploymentStack"), // SystemData: &armdeploymentstacks.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), // }, @@ -498,10 +498,10 @@ func ExampleClient_GetAtResourceGroup() { // Type: to.Ptr("Microsoft.Resources/deploymentStacks"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/deploymentStacksRG/providers/Microsoft.Resources/deploymentStacks/simpleDeploymentStack"), // SystemData: &armdeploymentstacks.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), // }, @@ -626,10 +626,10 @@ func ExampleClient_BeginCreateOrUpdateAtSubscription() { // Type: to.Ptr("Microsoft.Resources/deploymentStacks"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/deploymentStacksRG/providers/Microsoft.Resources/deploymentStacks/simpleDeploymentStack"), // SystemData: &armdeploymentstacks.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), // }, @@ -685,10 +685,10 @@ func ExampleClient_GetAtSubscription() { // Type: to.Ptr("Microsoft.Resources/deploymentStacks"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/deploymentStacksRG/providers/Microsoft.Resources/deploymentStacks/simpleDeploymentStack"), // SystemData: &armdeploymentstacks.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), // }, @@ -813,10 +813,10 @@ func ExampleClient_BeginCreateOrUpdateAtManagementGroup() { // Type: to.Ptr("Microsoft.Resources/deploymentStacks"), // ID: to.Ptr("/providers/Microsoft.Management/managementGroups/myMg/providers/Microsoft.Resources/deploymentStacks/simpleDeploymentStack"), // SystemData: &armdeploymentstacks.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), // }, @@ -872,10 +872,10 @@ func ExampleClient_GetAtManagementGroup() { // Type: to.Ptr("Microsoft.Resources/deploymentStacks"), // ID: to.Ptr("/providers/Microsoft.Management/managementGroups/myMg/providers/Microsoft.Resources/deploymentStacks/simpleDeploymentStack"), // SystemData: &armdeploymentstacks.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armdeploymentstacks.CreatedByTypeApplication), // }, diff --git a/sdk/resourcemanager/resources/armdeploymentstacks/client_factory.go b/sdk/resourcemanager/resources/armdeploymentstacks/client_factory.go index fbdc410e270e..02c56e2557af 100644 --- a/sdk/resourcemanager/resources/armdeploymentstacks/client_factory.go +++ b/sdk/resourcemanager/resources/armdeploymentstacks/client_factory.go @@ -27,7 +27,7 @@ type ClientFactory struct { // - 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) { - _, err := arm.NewClient(moduleName+".ClientFactory", moduleVersion, credential, options) + _, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -37,6 +37,7 @@ func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, }, nil } +// NewClient creates a new instance of Client. func (c *ClientFactory) NewClient() *Client { subClient, _ := NewClient(c.subscriptionID, c.credential, c.options) return subClient diff --git a/sdk/resourcemanager/resources/armdeploymentstacks/constants.go b/sdk/resourcemanager/resources/armdeploymentstacks/constants.go index ae8d34caec53..2c5fa661de4c 100644 --- a/sdk/resourcemanager/resources/armdeploymentstacks/constants.go +++ b/sdk/resourcemanager/resources/armdeploymentstacks/constants.go @@ -9,8 +9,8 @@ package armdeploymentstacks const ( - moduleName = "armdeploymentstacks" - moduleVersion = "v0.1.0" + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploymentstacks" + moduleVersion = "v0.2.0" ) // CreatedByType - The type of identity that created the resource. diff --git a/sdk/resourcemanager/resources/armdeploymentstacks/fake/internal.go b/sdk/resourcemanager/resources/armdeploymentstacks/fake/internal.go new file mode 100644 index 000000000000..94e060e89dbd --- /dev/null +++ b/sdk/resourcemanager/resources/armdeploymentstacks/fake/internal.go @@ -0,0 +1,72 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "net/http" + "reflect" + "sync" +) + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} + +func getOptional[T any](v T) *T { + if reflect.ValueOf(v).IsZero() { + return nil + } + return &v +} + +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/resources/armdeploymentstacks/fake/server.go b/sdk/resourcemanager/resources/armdeploymentstacks/fake/server.go new file mode 100644 index 000000000000..a337c0d663a3 --- /dev/null +++ b/sdk/resourcemanager/resources/armdeploymentstacks/fake/server.go @@ -0,0 +1,797 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploymentstacks" + "net/http" + "net/url" + "regexp" +) + +// Server is a fake server for instances of the armdeploymentstacks.Client type. +type Server struct { + // BeginCreateOrUpdateAtManagementGroup is the fake for method Client.BeginCreateOrUpdateAtManagementGroup + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdateAtManagementGroup func(ctx context.Context, managementGroupID string, deploymentStackName string, deploymentStack armdeploymentstacks.DeploymentStack, options *armdeploymentstacks.ClientBeginCreateOrUpdateAtManagementGroupOptions) (resp azfake.PollerResponder[armdeploymentstacks.ClientCreateOrUpdateAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdateAtResourceGroup is the fake for method Client.BeginCreateOrUpdateAtResourceGroup + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdateAtResourceGroup func(ctx context.Context, resourceGroupName string, deploymentStackName string, deploymentStack armdeploymentstacks.DeploymentStack, options *armdeploymentstacks.ClientBeginCreateOrUpdateAtResourceGroupOptions) (resp azfake.PollerResponder[armdeploymentstacks.ClientCreateOrUpdateAtResourceGroupResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdateAtSubscription is the fake for method Client.BeginCreateOrUpdateAtSubscription + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdateAtSubscription func(ctx context.Context, deploymentStackName string, deploymentStack armdeploymentstacks.DeploymentStack, options *armdeploymentstacks.ClientBeginCreateOrUpdateAtSubscriptionOptions) (resp azfake.PollerResponder[armdeploymentstacks.ClientCreateOrUpdateAtSubscriptionResponse], errResp azfake.ErrorResponder) + + // BeginDeleteAtManagementGroup is the fake for method Client.BeginDeleteAtManagementGroup + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDeleteAtManagementGroup func(ctx context.Context, managementGroupID string, deploymentStackName string, options *armdeploymentstacks.ClientBeginDeleteAtManagementGroupOptions) (resp azfake.PollerResponder[armdeploymentstacks.ClientDeleteAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // BeginDeleteAtResourceGroup is the fake for method Client.BeginDeleteAtResourceGroup + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDeleteAtResourceGroup func(ctx context.Context, resourceGroupName string, deploymentStackName string, options *armdeploymentstacks.ClientBeginDeleteAtResourceGroupOptions) (resp azfake.PollerResponder[armdeploymentstacks.ClientDeleteAtResourceGroupResponse], errResp azfake.ErrorResponder) + + // BeginDeleteAtSubscription is the fake for method Client.BeginDeleteAtSubscription + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDeleteAtSubscription func(ctx context.Context, deploymentStackName string, options *armdeploymentstacks.ClientBeginDeleteAtSubscriptionOptions) (resp azfake.PollerResponder[armdeploymentstacks.ClientDeleteAtSubscriptionResponse], errResp azfake.ErrorResponder) + + // ExportTemplateAtManagementGroup is the fake for method Client.ExportTemplateAtManagementGroup + // HTTP status codes to indicate success: http.StatusOK + ExportTemplateAtManagementGroup func(ctx context.Context, managementGroupID string, deploymentStackName string, options *armdeploymentstacks.ClientExportTemplateAtManagementGroupOptions) (resp azfake.Responder[armdeploymentstacks.ClientExportTemplateAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // ExportTemplateAtResourceGroup is the fake for method Client.ExportTemplateAtResourceGroup + // HTTP status codes to indicate success: http.StatusOK + ExportTemplateAtResourceGroup func(ctx context.Context, resourceGroupName string, deploymentStackName string, options *armdeploymentstacks.ClientExportTemplateAtResourceGroupOptions) (resp azfake.Responder[armdeploymentstacks.ClientExportTemplateAtResourceGroupResponse], errResp azfake.ErrorResponder) + + // ExportTemplateAtSubscription is the fake for method Client.ExportTemplateAtSubscription + // HTTP status codes to indicate success: http.StatusOK + ExportTemplateAtSubscription func(ctx context.Context, deploymentStackName string, options *armdeploymentstacks.ClientExportTemplateAtSubscriptionOptions) (resp azfake.Responder[armdeploymentstacks.ClientExportTemplateAtSubscriptionResponse], errResp azfake.ErrorResponder) + + // GetAtManagementGroup is the fake for method Client.GetAtManagementGroup + // HTTP status codes to indicate success: http.StatusOK + GetAtManagementGroup func(ctx context.Context, managementGroupID string, deploymentStackName string, options *armdeploymentstacks.ClientGetAtManagementGroupOptions) (resp azfake.Responder[armdeploymentstacks.ClientGetAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // GetAtResourceGroup is the fake for method Client.GetAtResourceGroup + // HTTP status codes to indicate success: http.StatusOK + GetAtResourceGroup func(ctx context.Context, resourceGroupName string, deploymentStackName string, options *armdeploymentstacks.ClientGetAtResourceGroupOptions) (resp azfake.Responder[armdeploymentstacks.ClientGetAtResourceGroupResponse], errResp azfake.ErrorResponder) + + // GetAtSubscription is the fake for method Client.GetAtSubscription + // HTTP status codes to indicate success: http.StatusOK + GetAtSubscription func(ctx context.Context, deploymentStackName string, options *armdeploymentstacks.ClientGetAtSubscriptionOptions) (resp azfake.Responder[armdeploymentstacks.ClientGetAtSubscriptionResponse], errResp azfake.ErrorResponder) + + // NewListAtManagementGroupPager is the fake for method Client.NewListAtManagementGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListAtManagementGroupPager func(managementGroupID string, options *armdeploymentstacks.ClientListAtManagementGroupOptions) (resp azfake.PagerResponder[armdeploymentstacks.ClientListAtManagementGroupResponse]) + + // NewListAtResourceGroupPager is the fake for method Client.NewListAtResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListAtResourceGroupPager func(resourceGroupName string, options *armdeploymentstacks.ClientListAtResourceGroupOptions) (resp azfake.PagerResponder[armdeploymentstacks.ClientListAtResourceGroupResponse]) + + // NewListAtSubscriptionPager is the fake for method Client.NewListAtSubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListAtSubscriptionPager func(options *armdeploymentstacks.ClientListAtSubscriptionOptions) (resp azfake.PagerResponder[armdeploymentstacks.ClientListAtSubscriptionResponse]) +} + +// NewServerTransport creates a new instance of ServerTransport with the provided implementation. +// The returned ServerTransport instance is connected to an instance of armdeploymentstacks.Client via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewServerTransport(srv *Server) *ServerTransport { + return &ServerTransport{ + srv: srv, + beginCreateOrUpdateAtManagementGroup: newTracker[azfake.PollerResponder[armdeploymentstacks.ClientCreateOrUpdateAtManagementGroupResponse]](), + beginCreateOrUpdateAtResourceGroup: newTracker[azfake.PollerResponder[armdeploymentstacks.ClientCreateOrUpdateAtResourceGroupResponse]](), + beginCreateOrUpdateAtSubscription: newTracker[azfake.PollerResponder[armdeploymentstacks.ClientCreateOrUpdateAtSubscriptionResponse]](), + beginDeleteAtManagementGroup: newTracker[azfake.PollerResponder[armdeploymentstacks.ClientDeleteAtManagementGroupResponse]](), + beginDeleteAtResourceGroup: newTracker[azfake.PollerResponder[armdeploymentstacks.ClientDeleteAtResourceGroupResponse]](), + beginDeleteAtSubscription: newTracker[azfake.PollerResponder[armdeploymentstacks.ClientDeleteAtSubscriptionResponse]](), + newListAtManagementGroupPager: newTracker[azfake.PagerResponder[armdeploymentstacks.ClientListAtManagementGroupResponse]](), + newListAtResourceGroupPager: newTracker[azfake.PagerResponder[armdeploymentstacks.ClientListAtResourceGroupResponse]](), + newListAtSubscriptionPager: newTracker[azfake.PagerResponder[armdeploymentstacks.ClientListAtSubscriptionResponse]](), + } +} + +// ServerTransport connects instances of armdeploymentstacks.Client to instances of Server. +// Don't use this type directly, use NewServerTransport instead. +type ServerTransport struct { + srv *Server + beginCreateOrUpdateAtManagementGroup *tracker[azfake.PollerResponder[armdeploymentstacks.ClientCreateOrUpdateAtManagementGroupResponse]] + beginCreateOrUpdateAtResourceGroup *tracker[azfake.PollerResponder[armdeploymentstacks.ClientCreateOrUpdateAtResourceGroupResponse]] + beginCreateOrUpdateAtSubscription *tracker[azfake.PollerResponder[armdeploymentstacks.ClientCreateOrUpdateAtSubscriptionResponse]] + beginDeleteAtManagementGroup *tracker[azfake.PollerResponder[armdeploymentstacks.ClientDeleteAtManagementGroupResponse]] + beginDeleteAtResourceGroup *tracker[azfake.PollerResponder[armdeploymentstacks.ClientDeleteAtResourceGroupResponse]] + beginDeleteAtSubscription *tracker[azfake.PollerResponder[armdeploymentstacks.ClientDeleteAtSubscriptionResponse]] + newListAtManagementGroupPager *tracker[azfake.PagerResponder[armdeploymentstacks.ClientListAtManagementGroupResponse]] + newListAtResourceGroupPager *tracker[azfake.PagerResponder[armdeploymentstacks.ClientListAtResourceGroupResponse]] + newListAtSubscriptionPager *tracker[azfake.PagerResponder[armdeploymentstacks.ClientListAtSubscriptionResponse]] +} + +// Do implements the policy.Transporter interface for ServerTransport. +func (s *ServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "Client.BeginCreateOrUpdateAtManagementGroup": + resp, err = s.dispatchBeginCreateOrUpdateAtManagementGroup(req) + case "Client.BeginCreateOrUpdateAtResourceGroup": + resp, err = s.dispatchBeginCreateOrUpdateAtResourceGroup(req) + case "Client.BeginCreateOrUpdateAtSubscription": + resp, err = s.dispatchBeginCreateOrUpdateAtSubscription(req) + case "Client.BeginDeleteAtManagementGroup": + resp, err = s.dispatchBeginDeleteAtManagementGroup(req) + case "Client.BeginDeleteAtResourceGroup": + resp, err = s.dispatchBeginDeleteAtResourceGroup(req) + case "Client.BeginDeleteAtSubscription": + resp, err = s.dispatchBeginDeleteAtSubscription(req) + case "Client.ExportTemplateAtManagementGroup": + resp, err = s.dispatchExportTemplateAtManagementGroup(req) + case "Client.ExportTemplateAtResourceGroup": + resp, err = s.dispatchExportTemplateAtResourceGroup(req) + case "Client.ExportTemplateAtSubscription": + resp, err = s.dispatchExportTemplateAtSubscription(req) + case "Client.GetAtManagementGroup": + resp, err = s.dispatchGetAtManagementGroup(req) + case "Client.GetAtResourceGroup": + resp, err = s.dispatchGetAtResourceGroup(req) + case "Client.GetAtSubscription": + resp, err = s.dispatchGetAtSubscription(req) + case "Client.NewListAtManagementGroupPager": + resp, err = s.dispatchNewListAtManagementGroupPager(req) + case "Client.NewListAtResourceGroupPager": + resp, err = s.dispatchNewListAtResourceGroupPager(req) + case "Client.NewListAtSubscriptionPager": + resp, err = s.dispatchNewListAtSubscriptionPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *ServerTransport) dispatchBeginCreateOrUpdateAtManagementGroup(req *http.Request) (*http.Response, error) { + if s.srv.BeginCreateOrUpdateAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdateAtManagementGroup not implemented")} + } + beginCreateOrUpdateAtManagementGroup := s.beginCreateOrUpdateAtManagementGroup.get(req) + if beginCreateOrUpdateAtManagementGroup == nil { + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentStacks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armdeploymentstacks.DeploymentStack](req) + if err != nil { + return nil, err + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + deploymentStackNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentStackName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdateAtManagementGroup(req.Context(), managementGroupIDParam, deploymentStackNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdateAtManagementGroup = &respr + s.beginCreateOrUpdateAtManagementGroup.add(req, beginCreateOrUpdateAtManagementGroup) + } + + resp, err := server.PollerResponderNext(beginCreateOrUpdateAtManagementGroup, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + s.beginCreateOrUpdateAtManagementGroup.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(beginCreateOrUpdateAtManagementGroup) { + s.beginCreateOrUpdateAtManagementGroup.remove(req) + } + + return resp, nil +} + +func (s *ServerTransport) dispatchBeginCreateOrUpdateAtResourceGroup(req *http.Request) (*http.Response, error) { + if s.srv.BeginCreateOrUpdateAtResourceGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdateAtResourceGroup not implemented")} + } + beginCreateOrUpdateAtResourceGroup := s.beginCreateOrUpdateAtResourceGroup.get(req) + if beginCreateOrUpdateAtResourceGroup == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentStacks/(?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[armdeploymentstacks.DeploymentStack](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + deploymentStackNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentStackName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdateAtResourceGroup(req.Context(), resourceGroupNameParam, deploymentStackNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdateAtResourceGroup = &respr + s.beginCreateOrUpdateAtResourceGroup.add(req, beginCreateOrUpdateAtResourceGroup) + } + + resp, err := server.PollerResponderNext(beginCreateOrUpdateAtResourceGroup, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + s.beginCreateOrUpdateAtResourceGroup.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(beginCreateOrUpdateAtResourceGroup) { + s.beginCreateOrUpdateAtResourceGroup.remove(req) + } + + return resp, nil +} + +func (s *ServerTransport) dispatchBeginCreateOrUpdateAtSubscription(req *http.Request) (*http.Response, error) { + if s.srv.BeginCreateOrUpdateAtSubscription == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdateAtSubscription not implemented")} + } + beginCreateOrUpdateAtSubscription := s.beginCreateOrUpdateAtSubscription.get(req) + if beginCreateOrUpdateAtSubscription == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentStacks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armdeploymentstacks.DeploymentStack](req) + if err != nil { + return nil, err + } + deploymentStackNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentStackName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdateAtSubscription(req.Context(), deploymentStackNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdateAtSubscription = &respr + s.beginCreateOrUpdateAtSubscription.add(req, beginCreateOrUpdateAtSubscription) + } + + resp, err := server.PollerResponderNext(beginCreateOrUpdateAtSubscription, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + s.beginCreateOrUpdateAtSubscription.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(beginCreateOrUpdateAtSubscription) { + s.beginCreateOrUpdateAtSubscription.remove(req) + } + + return resp, nil +} + +func (s *ServerTransport) dispatchBeginDeleteAtManagementGroup(req *http.Request) (*http.Response, error) { + if s.srv.BeginDeleteAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDeleteAtManagementGroup not implemented")} + } + beginDeleteAtManagementGroup := s.beginDeleteAtManagementGroup.get(req) + if beginDeleteAtManagementGroup == nil { + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentStacks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + qp := req.URL.Query() + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + deploymentStackNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentStackName")]) + if err != nil { + return nil, err + } + unmanageActionResourcesUnescaped, err := url.QueryUnescape(qp.Get("unmanageAction.Resources")) + if err != nil { + return nil, err + } + unmanageActionResourcesParam := getOptional(armdeploymentstacks.UnmanageActionResourceMode(unmanageActionResourcesUnescaped)) + unmanageActionResourceGroupsUnescaped, err := url.QueryUnescape(qp.Get("unmanageAction.ResourceGroups")) + if err != nil { + return nil, err + } + unmanageActionResourceGroupsParam := getOptional(armdeploymentstacks.UnmanageActionResourceGroupMode(unmanageActionResourceGroupsUnescaped)) + unmanageActionManagementGroupsUnescaped, err := url.QueryUnescape(qp.Get("unmanageAction.ManagementGroups")) + if err != nil { + return nil, err + } + unmanageActionManagementGroupsParam := getOptional(armdeploymentstacks.UnmanageActionManagementGroupMode(unmanageActionManagementGroupsUnescaped)) + var options *armdeploymentstacks.ClientBeginDeleteAtManagementGroupOptions + if unmanageActionResourcesParam != nil || unmanageActionResourceGroupsParam != nil || unmanageActionManagementGroupsParam != nil { + options = &armdeploymentstacks.ClientBeginDeleteAtManagementGroupOptions{ + UnmanageActionResources: unmanageActionResourcesParam, + UnmanageActionResourceGroups: unmanageActionResourceGroupsParam, + UnmanageActionManagementGroups: unmanageActionManagementGroupsParam, + } + } + respr, errRespr := s.srv.BeginDeleteAtManagementGroup(req.Context(), managementGroupIDParam, deploymentStackNameParam, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDeleteAtManagementGroup = &respr + s.beginDeleteAtManagementGroup.add(req, beginDeleteAtManagementGroup) + } + + resp, err := server.PollerResponderNext(beginDeleteAtManagementGroup, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + s.beginDeleteAtManagementGroup.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(beginDeleteAtManagementGroup) { + s.beginDeleteAtManagementGroup.remove(req) + } + + return resp, nil +} + +func (s *ServerTransport) dispatchBeginDeleteAtResourceGroup(req *http.Request) (*http.Response, error) { + if s.srv.BeginDeleteAtResourceGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDeleteAtResourceGroup not implemented")} + } + beginDeleteAtResourceGroup := s.beginDeleteAtResourceGroup.get(req) + if beginDeleteAtResourceGroup == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentStacks/(?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) + } + qp := req.URL.Query() + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + deploymentStackNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentStackName")]) + if err != nil { + return nil, err + } + unmanageActionResourcesUnescaped, err := url.QueryUnescape(qp.Get("unmanageAction.Resources")) + if err != nil { + return nil, err + } + unmanageActionResourcesParam := getOptional(armdeploymentstacks.UnmanageActionResourceMode(unmanageActionResourcesUnescaped)) + unmanageActionResourceGroupsUnescaped, err := url.QueryUnescape(qp.Get("unmanageAction.ResourceGroups")) + if err != nil { + return nil, err + } + unmanageActionResourceGroupsParam := getOptional(armdeploymentstacks.UnmanageActionResourceGroupMode(unmanageActionResourceGroupsUnescaped)) + var options *armdeploymentstacks.ClientBeginDeleteAtResourceGroupOptions + if unmanageActionResourcesParam != nil || unmanageActionResourceGroupsParam != nil { + options = &armdeploymentstacks.ClientBeginDeleteAtResourceGroupOptions{ + UnmanageActionResources: unmanageActionResourcesParam, + UnmanageActionResourceGroups: unmanageActionResourceGroupsParam, + } + } + respr, errRespr := s.srv.BeginDeleteAtResourceGroup(req.Context(), resourceGroupNameParam, deploymentStackNameParam, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDeleteAtResourceGroup = &respr + s.beginDeleteAtResourceGroup.add(req, beginDeleteAtResourceGroup) + } + + resp, err := server.PollerResponderNext(beginDeleteAtResourceGroup, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + s.beginDeleteAtResourceGroup.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(beginDeleteAtResourceGroup) { + s.beginDeleteAtResourceGroup.remove(req) + } + + return resp, nil +} + +func (s *ServerTransport) dispatchBeginDeleteAtSubscription(req *http.Request) (*http.Response, error) { + if s.srv.BeginDeleteAtSubscription == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDeleteAtSubscription not implemented")} + } + beginDeleteAtSubscription := s.beginDeleteAtSubscription.get(req) + if beginDeleteAtSubscription == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentStacks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + qp := req.URL.Query() + deploymentStackNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentStackName")]) + if err != nil { + return nil, err + } + unmanageActionResourcesUnescaped, err := url.QueryUnescape(qp.Get("unmanageAction.Resources")) + if err != nil { + return nil, err + } + unmanageActionResourcesParam := getOptional(armdeploymentstacks.UnmanageActionResourceMode(unmanageActionResourcesUnescaped)) + unmanageActionResourceGroupsUnescaped, err := url.QueryUnescape(qp.Get("unmanageAction.ResourceGroups")) + if err != nil { + return nil, err + } + unmanageActionResourceGroupsParam := getOptional(armdeploymentstacks.UnmanageActionResourceGroupMode(unmanageActionResourceGroupsUnescaped)) + var options *armdeploymentstacks.ClientBeginDeleteAtSubscriptionOptions + if unmanageActionResourcesParam != nil || unmanageActionResourceGroupsParam != nil { + options = &armdeploymentstacks.ClientBeginDeleteAtSubscriptionOptions{ + UnmanageActionResources: unmanageActionResourcesParam, + UnmanageActionResourceGroups: unmanageActionResourceGroupsParam, + } + } + respr, errRespr := s.srv.BeginDeleteAtSubscription(req.Context(), deploymentStackNameParam, options) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDeleteAtSubscription = &respr + s.beginDeleteAtSubscription.add(req, beginDeleteAtSubscription) + } + + resp, err := server.PollerResponderNext(beginDeleteAtSubscription, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + s.beginDeleteAtSubscription.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(beginDeleteAtSubscription) { + s.beginDeleteAtSubscription.remove(req) + } + + return resp, nil +} + +func (s *ServerTransport) dispatchExportTemplateAtManagementGroup(req *http.Request) (*http.Response, error) { + if s.srv.ExportTemplateAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method ExportTemplateAtManagementGroup not implemented")} + } + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentStacks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` + 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) + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + deploymentStackNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentStackName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.ExportTemplateAtManagementGroup(req.Context(), managementGroupIDParam, deploymentStackNameParam, 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).DeploymentStackTemplateDefinition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchExportTemplateAtResourceGroup(req *http.Request) (*http.Response, error) { + if s.srv.ExportTemplateAtResourceGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method ExportTemplateAtResourceGroup not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentStacks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` + 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 + } + deploymentStackNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentStackName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.ExportTemplateAtResourceGroup(req.Context(), resourceGroupNameParam, deploymentStackNameParam, 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).DeploymentStackTemplateDefinition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchExportTemplateAtSubscription(req *http.Request) (*http.Response, error) { + if s.srv.ExportTemplateAtSubscription == nil { + return nil, &nonRetriableError{errors.New("fake for method ExportTemplateAtSubscription not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentStacks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` + 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) + } + deploymentStackNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentStackName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.ExportTemplateAtSubscription(req.Context(), deploymentStackNameParam, 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).DeploymentStackTemplateDefinition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchGetAtManagementGroup(req *http.Request) (*http.Response, error) { + if s.srv.GetAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method GetAtManagementGroup not implemented")} + } + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentStacks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + deploymentStackNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentStackName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.GetAtManagementGroup(req.Context(), managementGroupIDParam, deploymentStackNameParam, 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).DeploymentStack, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchGetAtResourceGroup(req *http.Request) (*http.Response, error) { + if s.srv.GetAtResourceGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method GetAtResourceGroup not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentStacks/(?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 + } + deploymentStackNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentStackName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.GetAtResourceGroup(req.Context(), resourceGroupNameParam, deploymentStackNameParam, 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).DeploymentStack, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchGetAtSubscription(req *http.Request) (*http.Response, error) { + if s.srv.GetAtSubscription == nil { + return nil, &nonRetriableError{errors.New("fake for method GetAtSubscription not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentStacks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + deploymentStackNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentStackName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.GetAtSubscription(req.Context(), deploymentStackNameParam, 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).DeploymentStack, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchNewListAtManagementGroupPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListAtManagementGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAtManagementGroupPager not implemented")} + } + newListAtManagementGroupPager := s.newListAtManagementGroupPager.get(req) + if newListAtManagementGroupPager == nil { + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentStacks` + 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) + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + resp := s.srv.NewListAtManagementGroupPager(managementGroupIDParam, nil) + newListAtManagementGroupPager = &resp + s.newListAtManagementGroupPager.add(req, newListAtManagementGroupPager) + server.PagerResponderInjectNextLinks(newListAtManagementGroupPager, req, func(page *armdeploymentstacks.ClientListAtManagementGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListAtManagementGroupPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + s.newListAtManagementGroupPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListAtManagementGroupPager) { + s.newListAtManagementGroupPager.remove(req) + } + return resp, nil +} + +func (s *ServerTransport) dispatchNewListAtResourceGroupPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListAtResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAtResourceGroupPager not implemented")} + } + newListAtResourceGroupPager := s.newListAtResourceGroupPager.get(req) + if newListAtResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentStacks` + 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.NewListAtResourceGroupPager(resourceGroupNameParam, nil) + newListAtResourceGroupPager = &resp + s.newListAtResourceGroupPager.add(req, newListAtResourceGroupPager) + server.PagerResponderInjectNextLinks(newListAtResourceGroupPager, req, func(page *armdeploymentstacks.ClientListAtResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListAtResourceGroupPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + s.newListAtResourceGroupPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListAtResourceGroupPager) { + s.newListAtResourceGroupPager.remove(req) + } + return resp, nil +} + +func (s *ServerTransport) dispatchNewListAtSubscriptionPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListAtSubscriptionPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAtSubscriptionPager not implemented")} + } + newListAtSubscriptionPager := s.newListAtSubscriptionPager.get(req) + if newListAtSubscriptionPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deploymentStacks` + 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.NewListAtSubscriptionPager(nil) + newListAtSubscriptionPager = &resp + s.newListAtSubscriptionPager.add(req, newListAtSubscriptionPager) + server.PagerResponderInjectNextLinks(newListAtSubscriptionPager, req, func(page *armdeploymentstacks.ClientListAtSubscriptionResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListAtSubscriptionPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + s.newListAtSubscriptionPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListAtSubscriptionPager) { + s.newListAtSubscriptionPager.remove(req) + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armdeploymentstacks/fake/server_factory.go b/sdk/resourcemanager/resources/armdeploymentstacks/fake/server_factory.go new file mode 100644 index 000000000000..9249e77d99a2 --- /dev/null +++ b/sdk/resourcemanager/resources/armdeploymentstacks/fake/server_factory.go @@ -0,0 +1,75 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" + "sync" +) + +// ServerFactory is a fake server for instances of the armdeploymentstacks.ClientFactory type. +type ServerFactory struct { + Server Server +} + +// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. +// The returned ServerFactoryTransport instance is connected to an instance of armdeploymentstacks.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 armdeploymentstacks.ClientFactory to instances of ServerFactory. +// Don't use this type directly, use NewServerFactoryTransport instead. +type ServerFactoryTransport struct { + srv *ServerFactory + trMu sync.Mutex + trServer *ServerTransport +} + +// 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 "Client": + initServer(s, &s.trServer, func() *ServerTransport { return NewServerTransport(&s.srv.Server) }) + resp, err = s.trServer.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/resources/armdeploymentstacks/fake/time_rfc3339.go b/sdk/resourcemanager/resources/armdeploymentstacks/fake/time_rfc3339.go new file mode 100644 index 000000000000..b0535a7b63e6 --- /dev/null +++ b/sdk/resourcemanager/resources/armdeploymentstacks/fake/time_rfc3339.go @@ -0,0 +1,86 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "regexp" + "strings" + "time" +) + +// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. +var tzOffsetRegex = regexp.MustCompile(`(Z|z|\+|-)(\d+:\d+)*"*$`) + +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +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 { + layout := utcDateTimeJSON + if tzOffsetRegex.Match(data) { + layout = dateTimeJSON + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime + if tzOffsetRegex.Match(data) { + layout = time.RFC3339Nano + } + 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 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 || strings.EqualFold(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/resources/armdeploymentstacks/go.mod b/sdk/resourcemanager/resources/armdeploymentstacks/go.mod index d94655799971..599e9d559aa5 100644 --- a/sdk/resourcemanager/resources/armdeploymentstacks/go.mod +++ b/sdk/resourcemanager/resources/armdeploymentstacks/go.mod @@ -3,19 +3,19 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploy go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect - github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect - github.com/golang-jwt/jwt/v4 v4.5.0 // indirect - github.com/google/uuid v1.3.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect + github.com/golang-jwt/jwt/v5 v5.0.0 // indirect + github.com/google/uuid v1.3.1 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect - golang.org/x/crypto v0.7.0 // indirect - golang.org/x/net v0.8.0 // indirect - golang.org/x/sys v0.6.0 // indirect - golang.org/x/text v0.8.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect ) diff --git a/sdk/resourcemanager/resources/armdeploymentstacks/go.sum b/sdk/resourcemanager/resources/armdeploymentstacks/go.sum index ee2bc4389c66..7985f1da436f 100644 --- a/sdk/resourcemanager/resources/armdeploymentstacks/go.sum +++ b/sdk/resourcemanager/resources/armdeploymentstacks/go.sum @@ -1,31 +1,31 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1 h1:SEy2xmstIphdPwNBUi7uhvjyjhVKISfwjfOJmuy7kg4= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 h1:vcYCAze6p19qBW7MhZybIsqD8sMV8js0NyQM8JDnVtg= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0/go.mod h1:OQeznEEkTZ9OrhHJoDD8ZDq51FHgXjqtP9z6bEwBq9U= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM= -github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 h1:OBhqkivkhkMqLPymWEppkm7vgPQY2XsHoEkaMQ0AdZY= -github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 h1:fb8kj/Dh4CSwgsOzHeZY4Xh68cFVbzXx+ONXGMY//4w= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0/go.mod h1:uReU2sSxZExRPBAg3qKzmAucSi51+SP1OhohieR821Q= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 h1:BMAjVKJM0U/CYF27gA0ZMmXGkOcvfFtD0oHVZ1TIPRI= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0/go.mod h1:1fXstnBMas5kzG+S3q8UoJcmyU6nUeunJcMDHcRYHhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 h1:WpB/QDNLpMw72xHJc34BNNykqSOeEJDAWkhf0u12/Jk= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= -github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= -github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= +github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/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-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/sdk/resourcemanager/resources/armdeploymentstacks/models_serde.go b/sdk/resourcemanager/resources/armdeploymentstacks/models_serde.go index f3dec6bfbb9e..843a40310164 100644 --- a/sdk/resourcemanager/resources/armdeploymentstacks/models_serde.go +++ b/sdk/resourcemanager/resources/armdeploymentstacks/models_serde.go @@ -552,10 +552,10 @@ func (r *ResourceReferenceExtended) UnmarshalJSON(data []byte) error { // MarshalJSON implements the json.Marshaller interface for type SystemData. func (s SystemData) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populateTimeRFC3339(objectMap, "createdAt", s.CreatedAt) + populateDateTimeRFC3339(objectMap, "createdAt", s.CreatedAt) populate(objectMap, "createdBy", s.CreatedBy) populate(objectMap, "createdByType", s.CreatedByType) - populateTimeRFC3339(objectMap, "lastModifiedAt", s.LastModifiedAt) + populateDateTimeRFC3339(objectMap, "lastModifiedAt", s.LastModifiedAt) populate(objectMap, "lastModifiedBy", s.LastModifiedBy) populate(objectMap, "lastModifiedByType", s.LastModifiedByType) return json.Marshal(objectMap) @@ -571,7 +571,7 @@ func (s *SystemData) UnmarshalJSON(data []byte) error { var err error switch key { case "createdAt": - err = unpopulateTimeRFC3339(val, "CreatedAt", &s.CreatedAt) + err = unpopulateDateTimeRFC3339(val, "CreatedAt", &s.CreatedAt) delete(rawMsg, key) case "createdBy": err = unpopulate(val, "CreatedBy", &s.CreatedBy) @@ -580,7 +580,7 @@ func (s *SystemData) UnmarshalJSON(data []byte) error { err = unpopulate(val, "CreatedByType", &s.CreatedByType) delete(rawMsg, key) case "lastModifiedAt": - err = unpopulateTimeRFC3339(val, "LastModifiedAt", &s.LastModifiedAt) + err = unpopulateDateTimeRFC3339(val, "LastModifiedAt", &s.LastModifiedAt) delete(rawMsg, key) case "lastModifiedBy": err = unpopulate(val, "LastModifiedBy", &s.LastModifiedBy) diff --git a/sdk/resourcemanager/resources/armdeploymentstacks/time_rfc3339.go b/sdk/resourcemanager/resources/armdeploymentstacks/time_rfc3339.go index ef75a16bd863..bdfc0231875a 100644 --- a/sdk/resourcemanager/resources/armdeploymentstacks/time_rfc3339.go +++ b/sdk/resourcemanager/resources/armdeploymentstacks/time_rfc3339.go @@ -18,50 +18,50 @@ import ( "time" ) -const ( - utcLayoutJSON = `"2006-01-02T15:04:05.999999999"` - utcLayout = "2006-01-02T15:04:05.999999999" - rfc3339JSON = `"` + time.RFC3339Nano + `"` -) - // 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+)*"*$`) -type timeRFC3339 time.Time +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +type dateTimeRFC3339 time.Time -func (t timeRFC3339) MarshalJSON() (json []byte, err error) { +func (t dateTimeRFC3339) MarshalJSON() ([]byte, error) { tt := time.Time(t) return tt.MarshalJSON() } -func (t timeRFC3339) MarshalText() (text []byte, err error) { +func (t dateTimeRFC3339) MarshalText() ([]byte, error) { tt := time.Time(t) return tt.MarshalText() } -func (t *timeRFC3339) UnmarshalJSON(data []byte) error { - layout := utcLayoutJSON +func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { + layout := utcDateTimeJSON if tzOffsetRegex.Match(data) { - layout = rfc3339JSON + layout = dateTimeJSON } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) UnmarshalText(data []byte) (err error) { - layout := utcLayout +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime if tzOffsetRegex.Match(data) { layout = time.RFC3339Nano } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) Parse(layout, value string) error { +func (t *dateTimeRFC3339) Parse(layout, value string) error { p, err := time.Parse(layout, strings.ToUpper(value)) - *t = timeRFC3339(p) + *t = dateTimeRFC3339(p) return err } -func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { +func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { if t == nil { return } else if azcore.IsNullValue(t) { @@ -70,14 +70,14 @@ func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { } else if reflect.ValueOf(t).IsNil() { return } - m[k] = (*timeRFC3339)(t) + m[k] = (*dateTimeRFC3339)(t) } -func unpopulateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { +func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { if data == nil || strings.EqualFold(string(data), "null") { return nil } - var aux timeRFC3339 + var aux dateTimeRFC3339 if err := json.Unmarshal(data, &aux); err != nil { return fmt.Errorf("struct field %s: %v", fn, err) } From 1984e59e5043d29d3fc1b1a17322c59d90be232d Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 15:19:31 +0800 Subject: [PATCH 04/18] [Release] sdk/resourcemanager/resources/armfeatures/1.2.0 generation from spec commit: bf204aab860f2eb58a9d346b00d44760f2a9b0a2 --- .../resources/armfeatures/CHANGELOG.md | 6 + .../resources/armfeatures/README.md | 7 + .../resources/armfeatures/autorest.md | 2 +- .../resources/armfeatures/client.go | 92 +++--- .../resources/armfeatures/client_factory.go | 16 +- .../resources/armfeatures/constants.go | 7 +- .../armfeatures/fake/feature_server.go | 96 ++++++ .../resources/armfeatures/fake/internal.go | 64 ++++ .../resources/armfeatures/fake/server.go | 267 +++++++++++++++++ .../armfeatures/fake/server_factory.go | 87 ++++++ ...subscriptionfeatureregistrations_server.go | 278 ++++++++++++++++++ .../armfeatures/fake/time_rfc3339.go | 86 ++++++ .../resources/armfeatures/feature_client.go | 26 +- .../armfeatures/features_client_live_test.go | 2 +- .../resources/armfeatures/go.mod | 32 +- .../resources/armfeatures/go.sum | 70 ++--- .../resources/armfeatures/models.go | 156 +++------- .../resources/armfeatures/models_serde.go | 19 +- .../resources/armfeatures/options.go | 70 +++++ .../resources/armfeatures/response_types.go | 14 +- ...subscriptionfeatureregistrations_client.go | 94 +++--- ...eatureregistrations_client_example_test.go | 16 +- .../resources/armfeatures/time_rfc3339.go | 43 ++- 23 files changed, 1237 insertions(+), 313 deletions(-) create mode 100644 sdk/resourcemanager/resources/armfeatures/fake/feature_server.go create mode 100644 sdk/resourcemanager/resources/armfeatures/fake/internal.go create mode 100644 sdk/resourcemanager/resources/armfeatures/fake/server.go create mode 100644 sdk/resourcemanager/resources/armfeatures/fake/server_factory.go create mode 100644 sdk/resourcemanager/resources/armfeatures/fake/subscriptionfeatureregistrations_server.go create mode 100644 sdk/resourcemanager/resources/armfeatures/fake/time_rfc3339.go create mode 100644 sdk/resourcemanager/resources/armfeatures/options.go diff --git a/sdk/resourcemanager/resources/armfeatures/CHANGELOG.md b/sdk/resourcemanager/resources/armfeatures/CHANGELOG.md index 3beb23d2c9af..d653480c8669 100644 --- a/sdk/resourcemanager/resources/armfeatures/CHANGELOG.md +++ b/sdk/resourcemanager/resources/armfeatures/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 1.2.0 (2023-11-24) +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + + ## 1.1.0 (2023-03-27) ### Features Added diff --git a/sdk/resourcemanager/resources/armfeatures/README.md b/sdk/resourcemanager/resources/armfeatures/README.md index 92507eda6302..4c6cc6305d41 100644 --- a/sdk/resourcemanager/resources/armfeatures/README.md +++ b/sdk/resourcemanager/resources/armfeatures/README.md @@ -60,6 +60,13 @@ A client groups a set of related APIs, providing access to its functionality. C client := clientFactory.NewClient() ``` +## 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 diff --git a/sdk/resourcemanager/resources/armfeatures/autorest.md b/sdk/resourcemanager/resources/armfeatures/autorest.md index e5ed13cb7e7d..1a48abbc75ad 100644 --- a/sdk/resourcemanager/resources/armfeatures/autorest.md +++ b/sdk/resourcemanager/resources/armfeatures/autorest.md @@ -8,6 +8,6 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/0cc5e2efd6ffccf30e80d1e150b488dd87198b94/specification/resources/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/0cc5e2efd6ffccf30e80d1e150b488dd87198b94/specification/resources/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 1.1.0 +module-version: 1.2.0 package-features: true ``` \ No newline at end of file diff --git a/sdk/resourcemanager/resources/armfeatures/client.go b/sdk/resourcemanager/resources/armfeatures/client.go index 4d8ac38fe166..767899bcd7e2 100644 --- a/sdk/resourcemanager/resources/armfeatures/client.go +++ b/sdk/resourcemanager/resources/armfeatures/client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armfeatures @@ -33,7 +32,7 @@ type Client struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*Client, error) { - cl, err := arm.NewClient(moduleName+".Client", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -52,18 +51,25 @@ func NewClient(subscriptionID string, credential azcore.TokenCredential, options // - featureName - The name of the feature to get. // - options - ClientGetOptions contains the optional parameters for the Client.Get method. func (client *Client) Get(ctx context.Context, resourceProviderNamespace string, featureName string, options *ClientGetOptions) (ClientGetResponse, error) { + var err error + const operationName = "Client.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, resourceProviderNamespace, featureName, options) if err != nil { return ClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -112,25 +118,20 @@ func (client *Client) NewListPager(resourceProviderNamespace string, options *Cl return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ClientListResponse) (ClientListResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, resourceProviderNamespace, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return ClientListResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewListPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listCreateRequest(ctx, resourceProviderNamespace, options) + }, nil) if err != nil { return ClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -175,25 +176,20 @@ func (client *Client) NewListAllPager(options *ClientListAllOptions) *runtime.Pa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ClientListAllResponse) (ClientListAllResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listAllCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewListAllPager") + 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.listAllCreateRequest(ctx, options) + }, nil) if err != nil { return ClientListAllResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ClientListAllResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListAllResponse{}, runtime.NewResponseError(resp) - } return client.listAllHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -232,18 +228,25 @@ func (client *Client) listAllHandleResponse(resp *http.Response) (ClientListAllR // - featureName - The name of the feature to register. // - options - ClientRegisterOptions contains the optional parameters for the Client.Register method. func (client *Client) Register(ctx context.Context, resourceProviderNamespace string, featureName string, options *ClientRegisterOptions) (ClientRegisterResponse, error) { + var err error + const operationName = "Client.Register" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.registerCreateRequest(ctx, resourceProviderNamespace, featureName, options) if err != nil { return ClientRegisterResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientRegisterResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientRegisterResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientRegisterResponse{}, err } - return client.registerHandleResponse(resp) + resp, err := client.registerHandleResponse(httpResp) + return resp, err } // registerCreateRequest creates the Register request. @@ -289,18 +292,25 @@ func (client *Client) registerHandleResponse(resp *http.Response) (ClientRegiste // - featureName - The name of the feature to unregister. // - options - ClientUnregisterOptions contains the optional parameters for the Client.Unregister method. func (client *Client) Unregister(ctx context.Context, resourceProviderNamespace string, featureName string, options *ClientUnregisterOptions) (ClientUnregisterResponse, error) { + var err error + const operationName = "Client.Unregister" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.unregisterCreateRequest(ctx, resourceProviderNamespace, featureName, options) if err != nil { return ClientUnregisterResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientUnregisterResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientUnregisterResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientUnregisterResponse{}, err } - return client.unregisterHandleResponse(resp) + resp, err := client.unregisterHandleResponse(httpResp) + return resp, err } // unregisterCreateRequest creates the Unregister request. diff --git a/sdk/resourcemanager/resources/armfeatures/client_factory.go b/sdk/resourcemanager/resources/armfeatures/client_factory.go index cd7593eced42..9b131cfb4178 100644 --- a/sdk/resourcemanager/resources/armfeatures/client_factory.go +++ b/sdk/resourcemanager/resources/armfeatures/client_factory.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armfeatures @@ -28,7 +27,7 @@ type ClientFactory struct { // - 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) { - _, err := arm.NewClient(moduleName+".ClientFactory", moduleVersion, credential, options) + _, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -38,16 +37,19 @@ func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, }, nil } -func (c *ClientFactory) NewFeatureClient() *FeatureClient { - subClient, _ := NewFeatureClient(c.credential, c.options) +// NewClient creates a new instance of Client. +func (c *ClientFactory) NewClient() *Client { + subClient, _ := NewClient(c.subscriptionID, c.credential, c.options) return subClient } -func (c *ClientFactory) NewClient() *Client { - subClient, _ := NewClient(c.subscriptionID, c.credential, c.options) +// NewFeatureClient creates a new instance of FeatureClient. +func (c *ClientFactory) NewFeatureClient() *FeatureClient { + subClient, _ := NewFeatureClient(c.credential, c.options) return subClient } +// NewSubscriptionFeatureRegistrationsClient creates a new instance of SubscriptionFeatureRegistrationsClient. func (c *ClientFactory) NewSubscriptionFeatureRegistrationsClient() *SubscriptionFeatureRegistrationsClient { subClient, _ := NewSubscriptionFeatureRegistrationsClient(c.subscriptionID, c.credential, c.options) return subClient diff --git a/sdk/resourcemanager/resources/armfeatures/constants.go b/sdk/resourcemanager/resources/armfeatures/constants.go index 30bb2b1692d2..eb6e8a88741a 100644 --- a/sdk/resourcemanager/resources/armfeatures/constants.go +++ b/sdk/resourcemanager/resources/armfeatures/constants.go @@ -3,15 +3,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armfeatures const ( - moduleName = "armfeatures" - moduleVersion = "v1.1.0" + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures" + moduleVersion = "v1.2.0" ) // SubscriptionFeatureRegistrationApprovalType - The feature approval type. diff --git a/sdk/resourcemanager/resources/armfeatures/fake/feature_server.go b/sdk/resourcemanager/resources/armfeatures/fake/feature_server.go new file mode 100644 index 000000000000..9b09f20f313e --- /dev/null +++ b/sdk/resourcemanager/resources/armfeatures/fake/feature_server.go @@ -0,0 +1,96 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures" + "net/http" +) + +// FeatureServer is a fake server for instances of the armfeatures.FeatureClient type. +type FeatureServer struct { + // NewListOperationsPager is the fake for method FeatureClient.NewListOperationsPager + // HTTP status codes to indicate success: http.StatusOK + NewListOperationsPager func(options *armfeatures.FeatureClientListOperationsOptions) (resp azfake.PagerResponder[armfeatures.FeatureClientListOperationsResponse]) +} + +// NewFeatureServerTransport creates a new instance of FeatureServerTransport with the provided implementation. +// The returned FeatureServerTransport instance is connected to an instance of armfeatures.FeatureClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewFeatureServerTransport(srv *FeatureServer) *FeatureServerTransport { + return &FeatureServerTransport{ + srv: srv, + newListOperationsPager: newTracker[azfake.PagerResponder[armfeatures.FeatureClientListOperationsResponse]](), + } +} + +// FeatureServerTransport connects instances of armfeatures.FeatureClient to instances of FeatureServer. +// Don't use this type directly, use NewFeatureServerTransport instead. +type FeatureServerTransport struct { + srv *FeatureServer + newListOperationsPager *tracker[azfake.PagerResponder[armfeatures.FeatureClientListOperationsResponse]] +} + +// Do implements the policy.Transporter interface for FeatureServerTransport. +func (f *FeatureServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "FeatureClient.NewListOperationsPager": + resp, err = f.dispatchNewListOperationsPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (f *FeatureServerTransport) dispatchNewListOperationsPager(req *http.Request) (*http.Response, error) { + if f.srv.NewListOperationsPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListOperationsPager not implemented")} + } + newListOperationsPager := f.newListOperationsPager.get(req) + if newListOperationsPager == nil { + resp := f.srv.NewListOperationsPager(nil) + newListOperationsPager = &resp + f.newListOperationsPager.add(req, newListOperationsPager) + server.PagerResponderInjectNextLinks(newListOperationsPager, req, func(page *armfeatures.FeatureClientListOperationsResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListOperationsPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + f.newListOperationsPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListOperationsPager) { + f.newListOperationsPager.remove(req) + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armfeatures/fake/internal.go b/sdk/resourcemanager/resources/armfeatures/fake/internal.go new file mode 100644 index 000000000000..5f75802a569e --- /dev/null +++ b/sdk/resourcemanager/resources/armfeatures/fake/internal.go @@ -0,0 +1,64 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "net/http" + "sync" +) + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} + +func newTracker[T any]() *tracker[T] { + return &tracker[T]{ + items: map[string]*T{}, + } +} + +type tracker[T any] struct { + items map[string]*T + mu sync.Mutex +} + +func (p *tracker[T]) get(req *http.Request) *T { + p.mu.Lock() + defer p.mu.Unlock() + if item, ok := p.items[server.SanitizePagerPollerPath(req.URL.Path)]; ok { + return item + } + return nil +} + +func (p *tracker[T]) add(req *http.Request, item *T) { + p.mu.Lock() + defer p.mu.Unlock() + p.items[server.SanitizePagerPollerPath(req.URL.Path)] = item +} + +func (p *tracker[T]) remove(req *http.Request) { + p.mu.Lock() + defer p.mu.Unlock() + delete(p.items, server.SanitizePagerPollerPath(req.URL.Path)) +} diff --git a/sdk/resourcemanager/resources/armfeatures/fake/server.go b/sdk/resourcemanager/resources/armfeatures/fake/server.go new file mode 100644 index 000000000000..e6a8f07651b8 --- /dev/null +++ b/sdk/resourcemanager/resources/armfeatures/fake/server.go @@ -0,0 +1,267 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures" + "net/http" + "net/url" + "regexp" +) + +// Server is a fake server for instances of the armfeatures.Client type. +type Server struct { + // Get is the fake for method Client.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceProviderNamespace string, featureName string, options *armfeatures.ClientGetOptions) (resp azfake.Responder[armfeatures.ClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method Client.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceProviderNamespace string, options *armfeatures.ClientListOptions) (resp azfake.PagerResponder[armfeatures.ClientListResponse]) + + // NewListAllPager is the fake for method Client.NewListAllPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllPager func(options *armfeatures.ClientListAllOptions) (resp azfake.PagerResponder[armfeatures.ClientListAllResponse]) + + // Register is the fake for method Client.Register + // HTTP status codes to indicate success: http.StatusOK + Register func(ctx context.Context, resourceProviderNamespace string, featureName string, options *armfeatures.ClientRegisterOptions) (resp azfake.Responder[armfeatures.ClientRegisterResponse], errResp azfake.ErrorResponder) + + // Unregister is the fake for method Client.Unregister + // HTTP status codes to indicate success: http.StatusOK + Unregister func(ctx context.Context, resourceProviderNamespace string, featureName string, options *armfeatures.ClientUnregisterOptions) (resp azfake.Responder[armfeatures.ClientUnregisterResponse], errResp azfake.ErrorResponder) +} + +// NewServerTransport creates a new instance of ServerTransport with the provided implementation. +// The returned ServerTransport instance is connected to an instance of armfeatures.Client via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewServerTransport(srv *Server) *ServerTransport { + return &ServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[armfeatures.ClientListResponse]](), + newListAllPager: newTracker[azfake.PagerResponder[armfeatures.ClientListAllResponse]](), + } +} + +// ServerTransport connects instances of armfeatures.Client to instances of Server. +// Don't use this type directly, use NewServerTransport instead. +type ServerTransport struct { + srv *Server + newListPager *tracker[azfake.PagerResponder[armfeatures.ClientListResponse]] + newListAllPager *tracker[azfake.PagerResponder[armfeatures.ClientListAllResponse]] +} + +// Do implements the policy.Transporter interface for ServerTransport. +func (s *ServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "Client.Get": + resp, err = s.dispatchGet(req) + case "Client.NewListPager": + resp, err = s.dispatchNewListPager(req) + case "Client.NewListAllPager": + resp, err = s.dispatchNewListAllPager(req) + case "Client.Register": + resp, err = s.dispatchRegister(req) + case "Client.Unregister": + resp, err = s.dispatchUnregister(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *ServerTransport) 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~%@]+)/providers/Microsoft\.Features/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/features/(?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) + } + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + featureNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("featureName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), resourceProviderNamespaceParam, featureNameParam, 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).FeatureResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := s.newListPager.get(req) + if newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Features/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/features` + 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) + } + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + resp := s.srv.NewListPager(resourceProviderNamespaceParam, nil) + newListPager = &resp + s.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armfeatures.ClientListResponse, 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) { + s.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + s.newListPager.remove(req) + } + return resp, nil +} + +func (s *ServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListAllPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} + } + newListAllPager := s.newListAllPager.get(req) + if newListAllPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Features/features` + 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.NewListAllPager(nil) + newListAllPager = &resp + s.newListAllPager.add(req, newListAllPager) + server.PagerResponderInjectNextLinks(newListAllPager, req, func(page *armfeatures.ClientListAllResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListAllPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + s.newListAllPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListAllPager) { + s.newListAllPager.remove(req) + } + return resp, nil +} + +func (s *ServerTransport) dispatchRegister(req *http.Request) (*http.Response, error) { + if s.srv.Register == nil { + return nil, &nonRetriableError{errors.New("fake for method Register not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Features/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/features/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/register` + 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) + } + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + featureNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("featureName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Register(req.Context(), resourceProviderNamespaceParam, featureNameParam, 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).FeatureResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchUnregister(req *http.Request) (*http.Response, error) { + if s.srv.Unregister == nil { + return nil, &nonRetriableError{errors.New("fake for method Unregister not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Features/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/features/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/unregister` + 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) + } + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + featureNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("featureName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Unregister(req.Context(), resourceProviderNamespaceParam, featureNameParam, 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).FeatureResult, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armfeatures/fake/server_factory.go b/sdk/resourcemanager/resources/armfeatures/fake/server_factory.go new file mode 100644 index 000000000000..5494daabc0c8 --- /dev/null +++ b/sdk/resourcemanager/resources/armfeatures/fake/server_factory.go @@ -0,0 +1,87 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" + "sync" +) + +// ServerFactory is a fake server for instances of the armfeatures.ClientFactory type. +type ServerFactory struct { + Server Server + FeatureServer FeatureServer + SubscriptionFeatureRegistrationsServer SubscriptionFeatureRegistrationsServer +} + +// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. +// The returned ServerFactoryTransport instance is connected to an instance of armfeatures.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 armfeatures.ClientFactory to instances of ServerFactory. +// Don't use this type directly, use NewServerFactoryTransport instead. +type ServerFactoryTransport struct { + srv *ServerFactory + trMu sync.Mutex + trServer *ServerTransport + trFeatureServer *FeatureServerTransport + trSubscriptionFeatureRegistrationsServer *SubscriptionFeatureRegistrationsServerTransport +} + +// 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 "Client": + initServer(s, &s.trServer, func() *ServerTransport { return NewServerTransport(&s.srv.Server) }) + resp, err = s.trServer.Do(req) + case "FeatureClient": + initServer(s, &s.trFeatureServer, func() *FeatureServerTransport { return NewFeatureServerTransport(&s.srv.FeatureServer) }) + resp, err = s.trFeatureServer.Do(req) + case "SubscriptionFeatureRegistrationsClient": + initServer(s, &s.trSubscriptionFeatureRegistrationsServer, func() *SubscriptionFeatureRegistrationsServerTransport { + return NewSubscriptionFeatureRegistrationsServerTransport(&s.srv.SubscriptionFeatureRegistrationsServer) + }) + resp, err = s.trSubscriptionFeatureRegistrationsServer.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/resources/armfeatures/fake/subscriptionfeatureregistrations_server.go b/sdk/resourcemanager/resources/armfeatures/fake/subscriptionfeatureregistrations_server.go new file mode 100644 index 000000000000..d1f7e69ce42f --- /dev/null +++ b/sdk/resourcemanager/resources/armfeatures/fake/subscriptionfeatureregistrations_server.go @@ -0,0 +1,278 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures" + "net/http" + "net/url" + "reflect" + "regexp" +) + +// SubscriptionFeatureRegistrationsServer is a fake server for instances of the armfeatures.SubscriptionFeatureRegistrationsClient type. +type SubscriptionFeatureRegistrationsServer struct { + // CreateOrUpdate is the fake for method SubscriptionFeatureRegistrationsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK + CreateOrUpdate func(ctx context.Context, providerNamespace string, featureName string, options *armfeatures.SubscriptionFeatureRegistrationsClientCreateOrUpdateOptions) (resp azfake.Responder[armfeatures.SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method SubscriptionFeatureRegistrationsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, providerNamespace string, featureName string, options *armfeatures.SubscriptionFeatureRegistrationsClientDeleteOptions) (resp azfake.Responder[armfeatures.SubscriptionFeatureRegistrationsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method SubscriptionFeatureRegistrationsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, providerNamespace string, featureName string, options *armfeatures.SubscriptionFeatureRegistrationsClientGetOptions) (resp azfake.Responder[armfeatures.SubscriptionFeatureRegistrationsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListAllBySubscriptionPager is the fake for method SubscriptionFeatureRegistrationsClient.NewListAllBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListAllBySubscriptionPager func(options *armfeatures.SubscriptionFeatureRegistrationsClientListAllBySubscriptionOptions) (resp azfake.PagerResponder[armfeatures.SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse]) + + // NewListBySubscriptionPager is the fake for method SubscriptionFeatureRegistrationsClient.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(providerNamespace string, options *armfeatures.SubscriptionFeatureRegistrationsClientListBySubscriptionOptions) (resp azfake.PagerResponder[armfeatures.SubscriptionFeatureRegistrationsClientListBySubscriptionResponse]) +} + +// NewSubscriptionFeatureRegistrationsServerTransport creates a new instance of SubscriptionFeatureRegistrationsServerTransport with the provided implementation. +// The returned SubscriptionFeatureRegistrationsServerTransport instance is connected to an instance of armfeatures.SubscriptionFeatureRegistrationsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewSubscriptionFeatureRegistrationsServerTransport(srv *SubscriptionFeatureRegistrationsServer) *SubscriptionFeatureRegistrationsServerTransport { + return &SubscriptionFeatureRegistrationsServerTransport{ + srv: srv, + newListAllBySubscriptionPager: newTracker[azfake.PagerResponder[armfeatures.SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse]](), + newListBySubscriptionPager: newTracker[azfake.PagerResponder[armfeatures.SubscriptionFeatureRegistrationsClientListBySubscriptionResponse]](), + } +} + +// SubscriptionFeatureRegistrationsServerTransport connects instances of armfeatures.SubscriptionFeatureRegistrationsClient to instances of SubscriptionFeatureRegistrationsServer. +// Don't use this type directly, use NewSubscriptionFeatureRegistrationsServerTransport instead. +type SubscriptionFeatureRegistrationsServerTransport struct { + srv *SubscriptionFeatureRegistrationsServer + newListAllBySubscriptionPager *tracker[azfake.PagerResponder[armfeatures.SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse]] + newListBySubscriptionPager *tracker[azfake.PagerResponder[armfeatures.SubscriptionFeatureRegistrationsClientListBySubscriptionResponse]] +} + +// Do implements the policy.Transporter interface for SubscriptionFeatureRegistrationsServerTransport. +func (s *SubscriptionFeatureRegistrationsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "SubscriptionFeatureRegistrationsClient.CreateOrUpdate": + resp, err = s.dispatchCreateOrUpdate(req) + case "SubscriptionFeatureRegistrationsClient.Delete": + resp, err = s.dispatchDelete(req) + case "SubscriptionFeatureRegistrationsClient.Get": + resp, err = s.dispatchGet(req) + case "SubscriptionFeatureRegistrationsClient.NewListAllBySubscriptionPager": + resp, err = s.dispatchNewListAllBySubscriptionPager(req) + case "SubscriptionFeatureRegistrationsClient.NewListBySubscriptionPager": + resp, err = s.dispatchNewListBySubscriptionPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *SubscriptionFeatureRegistrationsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Features/featureProviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/subscriptionFeatureRegistrations/(?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[armfeatures.SubscriptionFeatureRegistration](req) + if err != nil { + return nil, err + } + providerNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("providerNamespace")]) + if err != nil { + return nil, err + } + featureNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("featureName")]) + if err != nil { + return nil, err + } + var options *armfeatures.SubscriptionFeatureRegistrationsClientCreateOrUpdateOptions + if !reflect.ValueOf(body).IsZero() { + options = &armfeatures.SubscriptionFeatureRegistrationsClientCreateOrUpdateOptions{ + SubscriptionFeatureRegistrationType: &body, + } + } + respr, errRespr := s.srv.CreateOrUpdate(req.Context(), providerNamespaceParam, featureNameParam, options) + 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).SubscriptionFeatureRegistration, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SubscriptionFeatureRegistrationsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if s.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Features/featureProviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/subscriptionFeatureRegistrations/(?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) + } + providerNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("providerNamespace")]) + if err != nil { + return nil, err + } + featureNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("featureName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Delete(req.Context(), providerNamespaceParam, featureNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SubscriptionFeatureRegistrationsServerTransport) 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~%@]+)/providers/Microsoft\.Features/featureProviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/subscriptionFeatureRegistrations/(?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) + } + providerNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("providerNamespace")]) + if err != nil { + return nil, err + } + featureNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("featureName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), providerNamespaceParam, featureNameParam, 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).SubscriptionFeatureRegistration, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SubscriptionFeatureRegistrationsServerTransport) dispatchNewListAllBySubscriptionPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListAllBySubscriptionPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAllBySubscriptionPager not implemented")} + } + newListAllBySubscriptionPager := s.newListAllBySubscriptionPager.get(req) + if newListAllBySubscriptionPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Features/subscriptionFeatureRegistrations` + 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.NewListAllBySubscriptionPager(nil) + newListAllBySubscriptionPager = &resp + s.newListAllBySubscriptionPager.add(req, newListAllBySubscriptionPager) + server.PagerResponderInjectNextLinks(newListAllBySubscriptionPager, req, func(page *armfeatures.SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListAllBySubscriptionPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + s.newListAllBySubscriptionPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListAllBySubscriptionPager) { + s.newListAllBySubscriptionPager.remove(req) + } + return resp, nil +} + +func (s *SubscriptionFeatureRegistrationsServerTransport) 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\.Features/featureProviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/subscriptionFeatureRegistrations` + 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) + } + providerNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("providerNamespace")]) + if err != nil { + return nil, err + } + resp := s.srv.NewListBySubscriptionPager(providerNamespaceParam, nil) + newListBySubscriptionPager = &resp + s.newListBySubscriptionPager.add(req, newListBySubscriptionPager) + server.PagerResponderInjectNextLinks(newListBySubscriptionPager, req, func(page *armfeatures.SubscriptionFeatureRegistrationsClientListBySubscriptionResponse, 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 +} diff --git a/sdk/resourcemanager/resources/armfeatures/fake/time_rfc3339.go b/sdk/resourcemanager/resources/armfeatures/fake/time_rfc3339.go new file mode 100644 index 000000000000..b0535a7b63e6 --- /dev/null +++ b/sdk/resourcemanager/resources/armfeatures/fake/time_rfc3339.go @@ -0,0 +1,86 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "regexp" + "strings" + "time" +) + +// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. +var tzOffsetRegex = regexp.MustCompile(`(Z|z|\+|-)(\d+:\d+)*"*$`) + +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +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 { + layout := utcDateTimeJSON + if tzOffsetRegex.Match(data) { + layout = dateTimeJSON + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime + if tzOffsetRegex.Match(data) { + layout = time.RFC3339Nano + } + 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 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 || strings.EqualFold(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/resources/armfeatures/feature_client.go b/sdk/resourcemanager/resources/armfeatures/feature_client.go index 55795aedf0ea..b50bb8d3e355 100644 --- a/sdk/resourcemanager/resources/armfeatures/feature_client.go +++ b/sdk/resourcemanager/resources/armfeatures/feature_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armfeatures @@ -28,7 +27,7 @@ type FeatureClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewFeatureClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*FeatureClient, error) { - cl, err := arm.NewClient(moduleName+".FeatureClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -49,25 +48,20 @@ func (client *FeatureClient) NewListOperationsPager(options *FeatureClientListOp return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *FeatureClientListOperationsResponse) (FeatureClientListOperationsResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listOperationsCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "FeatureClient.NewListOperationsPager") + 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.listOperationsCreateRequest(ctx, options) + }, nil) if err != nil { return FeatureClientListOperationsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return FeatureClientListOperationsResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return FeatureClientListOperationsResponse{}, runtime.NewResponseError(resp) - } return client.listOperationsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armfeatures/features_client_live_test.go b/sdk/resourcemanager/resources/armfeatures/features_client_live_test.go index 4f65bdaf4cf2..9a3dd68935c2 100644 --- a/sdk/resourcemanager/resources/armfeatures/features_client_live_test.go +++ b/sdk/resourcemanager/resources/armfeatures/features_client_live_test.go @@ -13,7 +13,7 @@ import ( "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/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures" "github.com/stretchr/testify/suite" ) diff --git a/sdk/resourcemanager/resources/armfeatures/go.mod b/sdk/resourcemanager/resources/armfeatures/go.mod index 9765db5877e2..64441d55b66f 100644 --- a/sdk/resourcemanager/resources/armfeatures/go.mod +++ b/sdk/resourcemanager/resources/armfeatures/go.mod @@ -3,27 +3,27 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatur go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 - github.com/stretchr/testify v1.7.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 + github.com/stretchr/testify v1.8.4 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 // indirect - github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dnaeon/go-vcr v1.1.0 // indirect - github.com/golang-jwt/jwt/v4 v4.4.2 // indirect - github.com/google/uuid v1.1.1 // indirect + github.com/dnaeon/go-vcr v1.2.0 // indirect + github.com/golang-jwt/jwt/v5 v5.0.0 // indirect + github.com/google/uuid v1.3.1 // indirect github.com/kylelemons/godebug v1.1.0 // indirect - github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect + github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/sdk/resourcemanager/resources/armfeatures/go.sum b/sdk/resourcemanager/resources/armfeatures/go.sum index b0f97586a165..88bb72abf2ba 100644 --- a/sdk/resourcemanager/resources/armfeatures/go.sum +++ b/sdk/resourcemanager/resources/armfeatures/go.sum @@ -1,47 +1,47 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 h1:rTnT/Jrcm+figWlYz4Ixzt0SJVR2cMC8lvZcimipiEY= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0/go.mod h1:ON4tFdPTwRcgWEaVDrN3584Ef+b7GgSJaXxe5fW9t4M= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 h1:t/W5MYAuQy81cvM8VUNfRLzhtKpXhVUAN7Cd7KVbTyc= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0/go.mod h1:NBanQUfSWiWn3QEpWDTCU0IjBECKOYvl2R8xdRtMtiM= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 h1:leh5DwKv6Ihwi+h60uHtn6UWAxBbZ0q8DwQVMzf61zw= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 h1:fb8kj/Dh4CSwgsOzHeZY4Xh68cFVbzXx+ONXGMY//4w= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0/go.mod h1:uReU2sSxZExRPBAg3qKzmAucSi51+SP1OhohieR821Q= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 h1:BMAjVKJM0U/CYF27gA0ZMmXGkOcvfFtD0oHVZ1TIPRI= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0/go.mod h1:1fXstnBMas5kzG+S3q8UoJcmyU6nUeunJcMDHcRYHhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 h1:ECsQtyERDVz3NP3kvDOTLvbQhqWp/x9EsGKtb4ogUr8= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0/go.mod h1:s1tW/At+xHqjNFvWU4G0c0Qv33KOhvbGNj0RCTQDV8s= -github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 h1:VgSJlZH5u0k2qxSpqyghcFQKmvYckj46uymKK5XzkBM= -github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0/go.mod h1:BDJ5qMFKx9DugEg3+uQSDCdbYPr5s9vBTrL9P8TpqOU= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 h1:PTFGRSlMKCQelWwxUyYVEUqseBJVemLyqWJjvMyt0do= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0/go.mod h1:LRr2FzBTQlONPPa5HREE5+RjSCTXl7BwOvYOaWTqCaI= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 h1:pPvTJ1dY0sA35JOeFq6TsY2xj6Z85Yo23Pj4wCCvu4o= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 h1:7CBQ+Ei8SP2c6ydQTGCCrS35bDxgTMfoP2miAwK++OU= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1/go.mod h1:c/wcGeGx5FUPbM/JltUYHZcKmigwyVLJlDq+4HdtXaw= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 h1:WpB/QDNLpMw72xHJc34BNNykqSOeEJDAWkhf0u12/Jk= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= -github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= -github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs= -github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= +github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= +github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/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/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= -github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 h1:Qj1ukM4GlMWXNdMBuXcXfz/Kw9s1qm0CLY32QxuSImI= -github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 h1:Tgea0cVUD0ivh5ADBX4WwuI12DUd2to3nCYe2eayMIw= -golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/resourcemanager/resources/armfeatures/models.go b/sdk/resourcemanager/resources/armfeatures/models.go index 09eab296c3c3..22ce5dfe733c 100644 --- a/sdk/resourcemanager/resources/armfeatures/models.go +++ b/sdk/resourcemanager/resources/armfeatures/models.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armfeatures @@ -14,236 +13,175 @@ import "time" // AuthorizationProfile - Authorization Profile type AuthorizationProfile struct { // READ-ONLY; The approved time - ApprovedTime *time.Time `json:"approvedTime,omitempty" azure:"ro"` + ApprovedTime *time.Time // READ-ONLY; The approver - Approver *string `json:"approver,omitempty" azure:"ro"` + Approver *string // READ-ONLY; The requested time - RequestedTime *time.Time `json:"requestedTime,omitempty" azure:"ro"` + RequestedTime *time.Time // READ-ONLY; The requester - Requester *string `json:"requester,omitempty" azure:"ro"` + Requester *string // READ-ONLY; The requester object id - RequesterObjectID *string `json:"requesterObjectId,omitempty" azure:"ro"` -} - -// ClientGetOptions contains the optional parameters for the Client.Get method. -type ClientGetOptions struct { - // placeholder for future optional parameters -} - -// ClientListAllOptions contains the optional parameters for the Client.NewListAllPager method. -type ClientListAllOptions struct { - // placeholder for future optional parameters -} - -// ClientListOptions contains the optional parameters for the Client.NewListPager method. -type ClientListOptions struct { - // placeholder for future optional parameters -} - -// ClientRegisterOptions contains the optional parameters for the Client.Register method. -type ClientRegisterOptions struct { - // placeholder for future optional parameters -} - -// ClientUnregisterOptions contains the optional parameters for the Client.Unregister method. -type ClientUnregisterOptions struct { - // placeholder for future optional parameters + RequesterObjectID *string } // ErrorDefinition - Error definition. type ErrorDefinition struct { // Internal error details. - Details []*ErrorDefinition `json:"details,omitempty"` + Details []*ErrorDefinition // READ-ONLY; Service specific error code which serves as the substatus for the HTTP error code. - Code *string `json:"code,omitempty" azure:"ro"` + Code *string // READ-ONLY; Description of the error. - Message *string `json:"message,omitempty" azure:"ro"` + Message *string } // ErrorResponse - Error response indicates that the service is not able to process the incoming request. type ErrorResponse struct { // The error details. - Error *ErrorDefinition `json:"error,omitempty"` -} - -// FeatureClientListOperationsOptions contains the optional parameters for the FeatureClient.NewListOperationsPager method. -type FeatureClientListOperationsOptions struct { - // placeholder for future optional parameters + Error *ErrorDefinition } // FeatureOperationsListResult - List of previewed features. type FeatureOperationsListResult struct { // The URL to use for getting the next set of results. - NextLink *string `json:"nextLink,omitempty"` + NextLink *string // The array of features. - Value []*FeatureResult `json:"value,omitempty"` + Value []*FeatureResult } // FeatureProperties - Information about feature. type FeatureProperties struct { // The registration state of the feature for the subscription. - State *string `json:"state,omitempty"` + State *string } // FeatureResult - Previewed feature information. type FeatureResult struct { // The resource ID of the feature. - ID *string `json:"id,omitempty"` + ID *string // The name of the feature. - Name *string `json:"name,omitempty"` + Name *string // Properties of the previewed feature. - Properties *FeatureProperties `json:"properties,omitempty"` + Properties *FeatureProperties // The resource type of the feature. - Type *string `json:"type,omitempty"` + Type *string } // Operation - Microsoft.Features operation type Operation struct { // The object that represents the operation. - Display *OperationDisplay `json:"display,omitempty"` + Display *OperationDisplay // Operation name: {provider}/{resource}/{operation} - Name *string `json:"name,omitempty"` + Name *string } // OperationDisplay - The object that represents the operation. type OperationDisplay struct { // Operation type: Read, write, delete, etc. - Operation *string `json:"operation,omitempty"` + Operation *string // Service provider: Microsoft.Features - Provider *string `json:"provider,omitempty"` + Provider *string // Resource on which the operation is performed: Profile, endpoint, etc. - Resource *string `json:"resource,omitempty"` + Resource *string } // OperationListResult - Result of the request to list Microsoft.Features operations. It contains a list of operations and // a URL link to get the next set of results. type OperationListResult struct { // URL to get the next set of operation list results if there are any. - NextLink *string `json:"nextLink,omitempty"` + NextLink *string // List of Microsoft.Features operations. - Value []*Operation `json:"value,omitempty"` + Value []*Operation } // ProxyResource - An Azure proxy resource. type ProxyResource struct { // READ-ONLY; Azure resource Id. - ID *string `json:"id,omitempty" azure:"ro"` + ID *string // READ-ONLY; Azure resource name. - Name *string `json:"name,omitempty" azure:"ro"` + Name *string // READ-ONLY; Azure resource type. - Type *string `json:"type,omitempty" azure:"ro"` + Type *string } // SubscriptionFeatureRegistration - Subscription feature registration details type SubscriptionFeatureRegistration struct { - Properties *SubscriptionFeatureRegistrationProperties `json:"properties,omitempty"` + Properties *SubscriptionFeatureRegistrationProperties // READ-ONLY; Azure resource Id. - ID *string `json:"id,omitempty" azure:"ro"` + ID *string // READ-ONLY; Azure resource name. - Name *string `json:"name,omitempty" azure:"ro"` + Name *string // READ-ONLY; Azure resource type. - Type *string `json:"type,omitempty" azure:"ro"` + Type *string } // SubscriptionFeatureRegistrationList - The list of subscription feature registrations. type SubscriptionFeatureRegistrationList struct { // The link used to get the next page of subscription feature registrations list. - NextLink *string `json:"nextLink,omitempty"` + NextLink *string // The list of subscription feature registrations. - Value []*SubscriptionFeatureRegistration `json:"value,omitempty"` + Value []*SubscriptionFeatureRegistration } type SubscriptionFeatureRegistrationProperties struct { // Authorization Profile - AuthorizationProfile *AuthorizationProfile `json:"authorizationProfile,omitempty"` + AuthorizationProfile *AuthorizationProfile // The feature description. - Description *string `json:"description,omitempty"` + Description *string // Key-value pairs for meta data. - Metadata map[string]*string `json:"metadata,omitempty"` + Metadata map[string]*string // Indicates whether feature should be displayed in Portal. - ShouldFeatureDisplayInPortal *bool `json:"shouldFeatureDisplayInPortal,omitempty"` + ShouldFeatureDisplayInPortal *bool // The state. - State *SubscriptionFeatureRegistrationState `json:"state,omitempty"` + State *SubscriptionFeatureRegistrationState // READ-ONLY; The feature approval type. - ApprovalType *SubscriptionFeatureRegistrationApprovalType `json:"approvalType,omitempty" azure:"ro"` + ApprovalType *SubscriptionFeatureRegistrationApprovalType // READ-ONLY; The featureDisplayName. - DisplayName *string `json:"displayName,omitempty" azure:"ro"` + DisplayName *string // READ-ONLY; The feature documentation link. - DocumentationLink *string `json:"documentationLink,omitempty" azure:"ro"` + DocumentationLink *string // READ-ONLY; The featureName. - FeatureName *string `json:"featureName,omitempty" azure:"ro"` + FeatureName *string // READ-ONLY; The providerNamespace. - ProviderNamespace *string `json:"providerNamespace,omitempty" azure:"ro"` + ProviderNamespace *string // READ-ONLY; The feature registration date. - RegistrationDate *time.Time `json:"registrationDate,omitempty" azure:"ro"` + RegistrationDate *time.Time // READ-ONLY; The feature release date. - ReleaseDate *time.Time `json:"releaseDate,omitempty" azure:"ro"` + ReleaseDate *time.Time // READ-ONLY; The subscriptionId. - SubscriptionID *string `json:"subscriptionId,omitempty" azure:"ro"` + SubscriptionID *string // READ-ONLY; The tenantId. - TenantID *string `json:"tenantId,omitempty" azure:"ro"` -} - -// SubscriptionFeatureRegistrationsClientCreateOrUpdateOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.CreateOrUpdate -// method. -type SubscriptionFeatureRegistrationsClientCreateOrUpdateOptions struct { - // Subscription Feature Registration Type details. - SubscriptionFeatureRegistrationType *SubscriptionFeatureRegistration -} - -// SubscriptionFeatureRegistrationsClientDeleteOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.Delete -// method. -type SubscriptionFeatureRegistrationsClientDeleteOptions struct { - // placeholder for future optional parameters -} - -// SubscriptionFeatureRegistrationsClientGetOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.Get -// method. -type SubscriptionFeatureRegistrationsClientGetOptions struct { - // placeholder for future optional parameters -} - -// SubscriptionFeatureRegistrationsClientListAllBySubscriptionOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.NewListAllBySubscriptionPager -// method. -type SubscriptionFeatureRegistrationsClientListAllBySubscriptionOptions struct { - // placeholder for future optional parameters -} - -// SubscriptionFeatureRegistrationsClientListBySubscriptionOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.NewListBySubscriptionPager -// method. -type SubscriptionFeatureRegistrationsClientListBySubscriptionOptions struct { - // placeholder for future optional parameters + TenantID *string } diff --git a/sdk/resourcemanager/resources/armfeatures/models_serde.go b/sdk/resourcemanager/resources/armfeatures/models_serde.go index 8dc3c194867d..ca4a215d3bab 100644 --- a/sdk/resourcemanager/resources/armfeatures/models_serde.go +++ b/sdk/resourcemanager/resources/armfeatures/models_serde.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armfeatures @@ -19,9 +18,9 @@ import ( // MarshalJSON implements the json.Marshaller interface for type AuthorizationProfile. func (a AuthorizationProfile) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populateTimeRFC3339(objectMap, "approvedTime", a.ApprovedTime) + populateDateTimeRFC3339(objectMap, "approvedTime", a.ApprovedTime) populate(objectMap, "approver", a.Approver) - populateTimeRFC3339(objectMap, "requestedTime", a.RequestedTime) + populateDateTimeRFC3339(objectMap, "requestedTime", a.RequestedTime) populate(objectMap, "requester", a.Requester) populate(objectMap, "requesterObjectId", a.RequesterObjectID) return json.Marshal(objectMap) @@ -37,13 +36,13 @@ func (a *AuthorizationProfile) UnmarshalJSON(data []byte) error { var err error switch key { case "approvedTime": - err = unpopulateTimeRFC3339(val, "ApprovedTime", &a.ApprovedTime) + err = unpopulateDateTimeRFC3339(val, "ApprovedTime", &a.ApprovedTime) delete(rawMsg, key) case "approver": err = unpopulate(val, "Approver", &a.Approver) delete(rawMsg, key) case "requestedTime": - err = unpopulateTimeRFC3339(val, "RequestedTime", &a.RequestedTime) + err = unpopulateDateTimeRFC3339(val, "RequestedTime", &a.RequestedTime) delete(rawMsg, key) case "requester": err = unpopulate(val, "Requester", &a.Requester) @@ -431,8 +430,8 @@ func (s SubscriptionFeatureRegistrationProperties) MarshalJSON() ([]byte, error) populate(objectMap, "featureName", s.FeatureName) populate(objectMap, "metadata", s.Metadata) populate(objectMap, "providerNamespace", s.ProviderNamespace) - populateTimeRFC3339(objectMap, "registrationDate", s.RegistrationDate) - populateTimeRFC3339(objectMap, "releaseDate", s.ReleaseDate) + populateDateTimeRFC3339(objectMap, "registrationDate", s.RegistrationDate) + populateDateTimeRFC3339(objectMap, "releaseDate", s.ReleaseDate) populate(objectMap, "shouldFeatureDisplayInPortal", s.ShouldFeatureDisplayInPortal) populate(objectMap, "state", s.State) populate(objectMap, "subscriptionId", s.SubscriptionID) @@ -474,10 +473,10 @@ func (s *SubscriptionFeatureRegistrationProperties) UnmarshalJSON(data []byte) e err = unpopulate(val, "ProviderNamespace", &s.ProviderNamespace) delete(rawMsg, key) case "registrationDate": - err = unpopulateTimeRFC3339(val, "RegistrationDate", &s.RegistrationDate) + err = unpopulateDateTimeRFC3339(val, "RegistrationDate", &s.RegistrationDate) delete(rawMsg, key) case "releaseDate": - err = unpopulateTimeRFC3339(val, "ReleaseDate", &s.ReleaseDate) + err = unpopulateDateTimeRFC3339(val, "ReleaseDate", &s.ReleaseDate) delete(rawMsg, key) case "shouldFeatureDisplayInPortal": err = unpopulate(val, "ShouldFeatureDisplayInPortal", &s.ShouldFeatureDisplayInPortal) diff --git a/sdk/resourcemanager/resources/armfeatures/options.go b/sdk/resourcemanager/resources/armfeatures/options.go new file mode 100644 index 000000000000..5092b41920c5 --- /dev/null +++ b/sdk/resourcemanager/resources/armfeatures/options.go @@ -0,0 +1,70 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armfeatures + +// ClientGetOptions contains the optional parameters for the Client.Get method. +type ClientGetOptions struct { + // placeholder for future optional parameters +} + +// ClientListAllOptions contains the optional parameters for the Client.NewListAllPager method. +type ClientListAllOptions struct { + // placeholder for future optional parameters +} + +// ClientListOptions contains the optional parameters for the Client.NewListPager method. +type ClientListOptions struct { + // placeholder for future optional parameters +} + +// ClientRegisterOptions contains the optional parameters for the Client.Register method. +type ClientRegisterOptions struct { + // placeholder for future optional parameters +} + +// ClientUnregisterOptions contains the optional parameters for the Client.Unregister method. +type ClientUnregisterOptions struct { + // placeholder for future optional parameters +} + +// FeatureClientListOperationsOptions contains the optional parameters for the FeatureClient.NewListOperationsPager method. +type FeatureClientListOperationsOptions struct { + // placeholder for future optional parameters +} + +// SubscriptionFeatureRegistrationsClientCreateOrUpdateOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.CreateOrUpdate +// method. +type SubscriptionFeatureRegistrationsClientCreateOrUpdateOptions struct { + // Subscription Feature Registration Type details. + SubscriptionFeatureRegistrationType *SubscriptionFeatureRegistration +} + +// SubscriptionFeatureRegistrationsClientDeleteOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.Delete +// method. +type SubscriptionFeatureRegistrationsClientDeleteOptions struct { + // placeholder for future optional parameters +} + +// SubscriptionFeatureRegistrationsClientGetOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.Get +// method. +type SubscriptionFeatureRegistrationsClientGetOptions struct { + // placeholder for future optional parameters +} + +// SubscriptionFeatureRegistrationsClientListAllBySubscriptionOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.NewListAllBySubscriptionPager +// method. +type SubscriptionFeatureRegistrationsClientListAllBySubscriptionOptions struct { + // placeholder for future optional parameters +} + +// SubscriptionFeatureRegistrationsClientListBySubscriptionOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.NewListBySubscriptionPager +// method. +type SubscriptionFeatureRegistrationsClientListBySubscriptionOptions struct { + // placeholder for future optional parameters +} diff --git a/sdk/resourcemanager/resources/armfeatures/response_types.go b/sdk/resourcemanager/resources/armfeatures/response_types.go index ab54c7db036f..d30455ab2a55 100644 --- a/sdk/resourcemanager/resources/armfeatures/response_types.go +++ b/sdk/resourcemanager/resources/armfeatures/response_types.go @@ -3,44 +3,51 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armfeatures // ClientGetResponse contains the response from method Client.Get. type ClientGetResponse struct { + // Previewed feature information. FeatureResult } // ClientListAllResponse contains the response from method Client.NewListAllPager. type ClientListAllResponse struct { + // List of previewed features. FeatureOperationsListResult } // ClientListResponse contains the response from method Client.NewListPager. type ClientListResponse struct { + // List of previewed features. FeatureOperationsListResult } // ClientRegisterResponse contains the response from method Client.Register. type ClientRegisterResponse struct { + // Previewed feature information. FeatureResult } // ClientUnregisterResponse contains the response from method Client.Unregister. type ClientUnregisterResponse struct { + // Previewed feature information. FeatureResult } // FeatureClientListOperationsResponse contains the response from method FeatureClient.NewListOperationsPager. type FeatureClientListOperationsResponse struct { + // Result of the request to list Microsoft.Features operations. It contains a list of operations and a URL link to get the + // next set of results. OperationListResult } // SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse contains the response from method SubscriptionFeatureRegistrationsClient.CreateOrUpdate. type SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse struct { + // Subscription feature registration details SubscriptionFeatureRegistration } @@ -51,15 +58,18 @@ type SubscriptionFeatureRegistrationsClientDeleteResponse struct { // SubscriptionFeatureRegistrationsClientGetResponse contains the response from method SubscriptionFeatureRegistrationsClient.Get. type SubscriptionFeatureRegistrationsClientGetResponse struct { + // Subscription feature registration details SubscriptionFeatureRegistration } // SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse contains the response from method SubscriptionFeatureRegistrationsClient.NewListAllBySubscriptionPager. type SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse struct { + // The list of subscription feature registrations. SubscriptionFeatureRegistrationList } // SubscriptionFeatureRegistrationsClientListBySubscriptionResponse contains the response from method SubscriptionFeatureRegistrationsClient.NewListBySubscriptionPager. type SubscriptionFeatureRegistrationsClientListBySubscriptionResponse struct { + // The list of subscription feature registrations. SubscriptionFeatureRegistrationList } diff --git a/sdk/resourcemanager/resources/armfeatures/subscriptionfeatureregistrations_client.go b/sdk/resourcemanager/resources/armfeatures/subscriptionfeatureregistrations_client.go index 00c3ee6efcea..cc67099e7d04 100644 --- a/sdk/resourcemanager/resources/armfeatures/subscriptionfeatureregistrations_client.go +++ b/sdk/resourcemanager/resources/armfeatures/subscriptionfeatureregistrations_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armfeatures @@ -33,7 +32,7 @@ type SubscriptionFeatureRegistrationsClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewSubscriptionFeatureRegistrationsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*SubscriptionFeatureRegistrationsClient, error) { - cl, err := arm.NewClient(moduleName+".SubscriptionFeatureRegistrationsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -53,18 +52,25 @@ func NewSubscriptionFeatureRegistrationsClient(subscriptionID string, credential // - options - SubscriptionFeatureRegistrationsClientCreateOrUpdateOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.CreateOrUpdate // method. func (client *SubscriptionFeatureRegistrationsClient) CreateOrUpdate(ctx context.Context, providerNamespace string, featureName string, options *SubscriptionFeatureRegistrationsClientCreateOrUpdateOptions) (SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "SubscriptionFeatureRegistrationsClient.CreateOrUpdate" + 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, providerNamespace, featureName, options) if err != nil { return SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -91,7 +97,10 @@ func (client *SubscriptionFeatureRegistrationsClient) createOrUpdateCreateReques req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.SubscriptionFeatureRegistrationType != nil { - return req, runtime.MarshalAsJSON(req, *options.SubscriptionFeatureRegistrationType) + if err := runtime.MarshalAsJSON(req, *options.SubscriptionFeatureRegistrationType); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -114,16 +123,22 @@ func (client *SubscriptionFeatureRegistrationsClient) createOrUpdateHandleRespon // - options - SubscriptionFeatureRegistrationsClientDeleteOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.Delete // method. func (client *SubscriptionFeatureRegistrationsClient) Delete(ctx context.Context, providerNamespace string, featureName string, options *SubscriptionFeatureRegistrationsClientDeleteOptions) (SubscriptionFeatureRegistrationsClientDeleteResponse, error) { + var err error + const operationName = "SubscriptionFeatureRegistrationsClient.Delete" + 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, providerNamespace, featureName, options) if err != nil { return SubscriptionFeatureRegistrationsClientDeleteResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SubscriptionFeatureRegistrationsClientDeleteResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return SubscriptionFeatureRegistrationsClientDeleteResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return SubscriptionFeatureRegistrationsClientDeleteResponse{}, err } return SubscriptionFeatureRegistrationsClientDeleteResponse{}, nil } @@ -163,18 +178,25 @@ func (client *SubscriptionFeatureRegistrationsClient) deleteCreateRequest(ctx co // - options - SubscriptionFeatureRegistrationsClientGetOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.Get // method. func (client *SubscriptionFeatureRegistrationsClient) Get(ctx context.Context, providerNamespace string, featureName string, options *SubscriptionFeatureRegistrationsClientGetOptions) (SubscriptionFeatureRegistrationsClientGetResponse, error) { + var err error + const operationName = "SubscriptionFeatureRegistrationsClient.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, providerNamespace, featureName, options) if err != nil { return SubscriptionFeatureRegistrationsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return SubscriptionFeatureRegistrationsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SubscriptionFeatureRegistrationsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SubscriptionFeatureRegistrationsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -223,25 +245,20 @@ func (client *SubscriptionFeatureRegistrationsClient) NewListAllBySubscriptionPa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse) (SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listAllBySubscriptionCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SubscriptionFeatureRegistrationsClient.NewListAllBySubscriptionPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listAllBySubscriptionCreateRequest(ctx, options) + }, nil) if err != nil { return SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse{}, runtime.NewResponseError(resp) - } return client.listAllBySubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -284,25 +301,20 @@ func (client *SubscriptionFeatureRegistrationsClient) NewListBySubscriptionPager return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SubscriptionFeatureRegistrationsClientListBySubscriptionResponse) (SubscriptionFeatureRegistrationsClientListBySubscriptionResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listBySubscriptionCreateRequest(ctx, providerNamespace, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SubscriptionFeatureRegistrationsClient.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, providerNamespace, options) + }, nil) if err != nil { return SubscriptionFeatureRegistrationsClientListBySubscriptionResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return SubscriptionFeatureRegistrationsClientListBySubscriptionResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SubscriptionFeatureRegistrationsClientListBySubscriptionResponse{}, runtime.NewResponseError(resp) - } return client.listBySubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armfeatures/subscriptionfeatureregistrations_client_example_test.go b/sdk/resourcemanager/resources/armfeatures/subscriptionfeatureregistrations_client_example_test.go index 57e005b9b609..ec2ff1c617b1 100644 --- a/sdk/resourcemanager/resources/armfeatures/subscriptionfeatureregistrations_client_example_test.go +++ b/sdk/resourcemanager/resources/armfeatures/subscriptionfeatureregistrations_client_example_test.go @@ -45,8 +45,8 @@ func ExampleSubscriptionFeatureRegistrationsClient_Get() { // }, // FeatureName: to.Ptr("testFeature"), // ProviderNamespace: to.Ptr("Microsoft.TestRP"), - // RegistrationDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-26T01:57:51.734777Z"); return t}()), - // ReleaseDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-11-05T00:34:53.1243228Z"); return t}()), + // RegistrationDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-26T01:57:51.734Z"); return t}()), + // ReleaseDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-11-05T00:34:53.124Z"); return t}()), // State: to.Ptr(armfeatures.SubscriptionFeatureRegistrationStatePending), // SubscriptionID: to.Ptr("00000000-1111-2222-3333-444444444444"), // }, @@ -84,8 +84,8 @@ func ExampleSubscriptionFeatureRegistrationsClient_CreateOrUpdate() { // }, // FeatureName: to.Ptr("testFeature"), // ProviderNamespace: to.Ptr("Microsoft.TestRP"), - // RegistrationDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-26T01:57:51.734777Z"); return t}()), - // ReleaseDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-11-05T00:34:53.1243228Z"); return t}()), + // RegistrationDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-26T01:57:51.734Z"); return t}()), + // ReleaseDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-11-05T00:34:53.124Z"); return t}()), // State: to.Ptr(armfeatures.SubscriptionFeatureRegistrationStatePending), // SubscriptionID: to.Ptr("00000000-1111-2222-3333-444444444444"), // }, @@ -143,8 +143,8 @@ func ExampleSubscriptionFeatureRegistrationsClient_NewListBySubscriptionPager() // }, // FeatureName: to.Ptr("testFeature"), // ProviderNamespace: to.Ptr("Microsoft.TestRP"), - // RegistrationDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-26T01:57:51.734777Z"); return t}()), - // ReleaseDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-11-05T00:34:53.1243228Z"); return t}()), + // RegistrationDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-26T01:57:51.734Z"); return t}()), + // ReleaseDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-11-05T00:34:53.124Z"); return t}()), // State: to.Ptr(armfeatures.SubscriptionFeatureRegistrationStatePending), // SubscriptionID: to.Ptr("00000000-1111-2222-3333-444444444444"), // }, @@ -187,8 +187,8 @@ func ExampleSubscriptionFeatureRegistrationsClient_NewListAllBySubscriptionPager // }, // FeatureName: to.Ptr("testFeature"), // ProviderNamespace: to.Ptr("Microsoft.TestRP"), - // RegistrationDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-26T01:57:51.734777Z"); return t}()), - // ReleaseDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-11-05T00:34:53.1243228Z"); return t}()), + // RegistrationDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-26T01:57:51.734Z"); return t}()), + // ReleaseDate: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-11-05T00:34:53.124Z"); return t}()), // State: to.Ptr(armfeatures.SubscriptionFeatureRegistrationStatePending), // SubscriptionID: to.Ptr("00000000-1111-2222-3333-444444444444"), // }, diff --git a/sdk/resourcemanager/resources/armfeatures/time_rfc3339.go b/sdk/resourcemanager/resources/armfeatures/time_rfc3339.go index 95a9f1c0cd46..19d49fb2bc17 100644 --- a/sdk/resourcemanager/resources/armfeatures/time_rfc3339.go +++ b/sdk/resourcemanager/resources/armfeatures/time_rfc3339.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armfeatures @@ -19,50 +18,50 @@ import ( "time" ) -const ( - utcLayoutJSON = `"2006-01-02T15:04:05.999999999"` - utcLayout = "2006-01-02T15:04:05.999999999" - rfc3339JSON = `"` + time.RFC3339Nano + `"` -) - // 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+)*"*$`) -type timeRFC3339 time.Time +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +type dateTimeRFC3339 time.Time -func (t timeRFC3339) MarshalJSON() (json []byte, err error) { +func (t dateTimeRFC3339) MarshalJSON() ([]byte, error) { tt := time.Time(t) return tt.MarshalJSON() } -func (t timeRFC3339) MarshalText() (text []byte, err error) { +func (t dateTimeRFC3339) MarshalText() ([]byte, error) { tt := time.Time(t) return tt.MarshalText() } -func (t *timeRFC3339) UnmarshalJSON(data []byte) error { - layout := utcLayoutJSON +func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { + layout := utcDateTimeJSON if tzOffsetRegex.Match(data) { - layout = rfc3339JSON + layout = dateTimeJSON } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) UnmarshalText(data []byte) (err error) { - layout := utcLayout +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime if tzOffsetRegex.Match(data) { layout = time.RFC3339Nano } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) Parse(layout, value string) error { +func (t *dateTimeRFC3339) Parse(layout, value string) error { p, err := time.Parse(layout, strings.ToUpper(value)) - *t = timeRFC3339(p) + *t = dateTimeRFC3339(p) return err } -func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { +func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { if t == nil { return } else if azcore.IsNullValue(t) { @@ -71,14 +70,14 @@ func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { } else if reflect.ValueOf(t).IsNil() { return } - m[k] = (*timeRFC3339)(t) + m[k] = (*dateTimeRFC3339)(t) } -func unpopulateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { +func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { if data == nil || strings.EqualFold(string(data), "null") { return nil } - var aux timeRFC3339 + var aux dateTimeRFC3339 if err := json.Unmarshal(data, &aux); err != nil { return fmt.Errorf("struct field %s: %v", fn, err) } From ee6a2ecf2f8401d7532e77f847b55c4c6067a0c7 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 15:20:45 +0800 Subject: [PATCH 05/18] [Release] sdk/resourcemanager/resources/armlinks/1.2.0 generation from spec commit: bf204aab860f2eb58a9d346b00d44760f2a9b0a2 --- .../resources/armlinks/CHANGELOG.md | 6 + .../resources/armlinks/README.md | 7 + .../resources/armlinks/autorest.md | 2 +- .../resources/armlinks/client_factory.go | 7 +- .../resources/armlinks/constants.go | 7 +- .../resources/armlinks/fake/internal.go | 72 +++++ .../armlinks/fake/operations_server.go | 96 ++++++ .../armlinks/fake/resourcelinks_server.go | 283 ++++++++++++++++++ .../resources/armlinks/fake/server_factory.go | 82 +++++ sdk/resourcemanager/resources/armlinks/go.mod | 8 +- sdk/resourcemanager/resources/armlinks/go.sum | 22 +- .../resources/armlinks/models.go | 39 +-- .../resources/armlinks/models_serde.go | 3 +- .../resources/armlinks/operations_client.go | 26 +- .../resources/armlinks/options.go | 45 +++ .../armlinks/resourcelinks_client.go | 94 +++--- .../resources/armlinks/response_types.go | 9 +- 17 files changed, 686 insertions(+), 122 deletions(-) create mode 100644 sdk/resourcemanager/resources/armlinks/fake/internal.go create mode 100644 sdk/resourcemanager/resources/armlinks/fake/operations_server.go create mode 100644 sdk/resourcemanager/resources/armlinks/fake/resourcelinks_server.go create mode 100644 sdk/resourcemanager/resources/armlinks/fake/server_factory.go create mode 100644 sdk/resourcemanager/resources/armlinks/options.go diff --git a/sdk/resourcemanager/resources/armlinks/CHANGELOG.md b/sdk/resourcemanager/resources/armlinks/CHANGELOG.md index 192961186195..29bb7be8f7bd 100644 --- a/sdk/resourcemanager/resources/armlinks/CHANGELOG.md +++ b/sdk/resourcemanager/resources/armlinks/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 1.2.0 (2023-11-24) +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + + ## 1.1.1 (2023-04-14) ### Bug Fixes diff --git a/sdk/resourcemanager/resources/armlinks/README.md b/sdk/resourcemanager/resources/armlinks/README.md index d9c062381abf..e58c5a5a4c6f 100644 --- a/sdk/resourcemanager/resources/armlinks/README.md +++ b/sdk/resourcemanager/resources/armlinks/README.md @@ -60,6 +60,13 @@ A client groups a set of related APIs, providing access to its functionality. C client := clientFactory.NewResourceLinksClient() ``` +## 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 diff --git a/sdk/resourcemanager/resources/armlinks/autorest.md b/sdk/resourcemanager/resources/armlinks/autorest.md index aad2a2059e52..cd3b42a8b2b7 100644 --- a/sdk/resourcemanager/resources/armlinks/autorest.md +++ b/sdk/resourcemanager/resources/armlinks/autorest.md @@ -8,6 +8,6 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/0cc5e2efd6ffccf30e80d1e150b488dd87198b94/specification/resources/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/0cc5e2efd6ffccf30e80d1e150b488dd87198b94/specification/resources/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 1.1.1 +module-version: 1.2.0 package-links: true ``` \ No newline at end of file diff --git a/sdk/resourcemanager/resources/armlinks/client_factory.go b/sdk/resourcemanager/resources/armlinks/client_factory.go index 0a6acdd93eda..d2403f979d20 100644 --- a/sdk/resourcemanager/resources/armlinks/client_factory.go +++ b/sdk/resourcemanager/resources/armlinks/client_factory.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armlinks @@ -28,7 +27,7 @@ type ClientFactory struct { // - 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) { - _, err := arm.NewClient(moduleName+".ClientFactory", moduleVersion, credential, options) + _, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -38,11 +37,13 @@ func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, }, nil } +// NewOperationsClient creates a new instance of OperationsClient. func (c *ClientFactory) NewOperationsClient() *OperationsClient { subClient, _ := NewOperationsClient(c.credential, c.options) return subClient } +// NewResourceLinksClient creates a new instance of ResourceLinksClient. func (c *ClientFactory) NewResourceLinksClient() *ResourceLinksClient { subClient, _ := NewResourceLinksClient(c.subscriptionID, c.credential, c.options) return subClient diff --git a/sdk/resourcemanager/resources/armlinks/constants.go b/sdk/resourcemanager/resources/armlinks/constants.go index 556204af5833..754be60ee9b1 100644 --- a/sdk/resourcemanager/resources/armlinks/constants.go +++ b/sdk/resourcemanager/resources/armlinks/constants.go @@ -3,13 +3,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armlinks const ( - moduleName = "armlinks" - moduleVersion = "v1.1.1" + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armlinks" + moduleVersion = "v1.2.0" ) diff --git a/sdk/resourcemanager/resources/armlinks/fake/internal.go b/sdk/resourcemanager/resources/armlinks/fake/internal.go new file mode 100644 index 000000000000..94e060e89dbd --- /dev/null +++ b/sdk/resourcemanager/resources/armlinks/fake/internal.go @@ -0,0 +1,72 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "net/http" + "reflect" + "sync" +) + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} + +func getOptional[T any](v T) *T { + if reflect.ValueOf(v).IsZero() { + return nil + } + return &v +} + +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/resources/armlinks/fake/operations_server.go b/sdk/resourcemanager/resources/armlinks/fake/operations_server.go new file mode 100644 index 000000000000..a99eef79d634 --- /dev/null +++ b/sdk/resourcemanager/resources/armlinks/fake/operations_server.go @@ -0,0 +1,96 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armlinks" + "net/http" +) + +// OperationsServer is a fake server for instances of the armlinks.OperationsClient type. +type OperationsServer struct { + // NewListPager is the fake for method OperationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armlinks.OperationsClientListOptions) (resp azfake.PagerResponder[armlinks.OperationsClientListResponse]) +} + +// NewOperationsServerTransport creates a new instance of OperationsServerTransport with the provided implementation. +// The returned OperationsServerTransport instance is connected to an instance of armlinks.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[armlinks.OperationsClientListResponse]](), + } +} + +// OperationsServerTransport connects instances of armlinks.OperationsClient to instances of OperationsServer. +// Don't use this type directly, use NewOperationsServerTransport instead. +type OperationsServerTransport struct { + srv *OperationsServer + newListPager *tracker[azfake.PagerResponder[armlinks.OperationsClientListResponse]] +} + +// Do implements the policy.Transporter interface for OperationsServerTransport. +func (o *OperationsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "OperationsClient.NewListPager": + resp, err = o.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (o *OperationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if o.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := o.newListPager.get(req) + if newListPager == nil { + resp := o.srv.NewListPager(nil) + newListPager = &resp + o.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armlinks.OperationsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + o.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + o.newListPager.remove(req) + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armlinks/fake/resourcelinks_server.go b/sdk/resourcemanager/resources/armlinks/fake/resourcelinks_server.go new file mode 100644 index 000000000000..c476d75eefd4 --- /dev/null +++ b/sdk/resourcemanager/resources/armlinks/fake/resourcelinks_server.go @@ -0,0 +1,283 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armlinks" + "net/http" + "net/url" + "regexp" +) + +// ResourceLinksServer is a fake server for instances of the armlinks.ResourceLinksClient type. +type ResourceLinksServer struct { + // CreateOrUpdate is the fake for method ResourceLinksClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, linkID string, parameters armlinks.ResourceLink, options *armlinks.ResourceLinksClientCreateOrUpdateOptions) (resp azfake.Responder[armlinks.ResourceLinksClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method ResourceLinksClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, linkID string, options *armlinks.ResourceLinksClientDeleteOptions) (resp azfake.Responder[armlinks.ResourceLinksClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ResourceLinksClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, linkID string, options *armlinks.ResourceLinksClientGetOptions) (resp azfake.Responder[armlinks.ResourceLinksClientGetResponse], errResp azfake.ErrorResponder) + + // NewListAtSourceScopePager is the fake for method ResourceLinksClient.NewListAtSourceScopePager + // HTTP status codes to indicate success: http.StatusOK + NewListAtSourceScopePager func(scope string, options *armlinks.ResourceLinksClientListAtSourceScopeOptions) (resp azfake.PagerResponder[armlinks.ResourceLinksClientListAtSourceScopeResponse]) + + // NewListAtSubscriptionPager is the fake for method ResourceLinksClient.NewListAtSubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListAtSubscriptionPager func(options *armlinks.ResourceLinksClientListAtSubscriptionOptions) (resp azfake.PagerResponder[armlinks.ResourceLinksClientListAtSubscriptionResponse]) +} + +// NewResourceLinksServerTransport creates a new instance of ResourceLinksServerTransport with the provided implementation. +// The returned ResourceLinksServerTransport instance is connected to an instance of armlinks.ResourceLinksClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewResourceLinksServerTransport(srv *ResourceLinksServer) *ResourceLinksServerTransport { + return &ResourceLinksServerTransport{ + srv: srv, + newListAtSourceScopePager: newTracker[azfake.PagerResponder[armlinks.ResourceLinksClientListAtSourceScopeResponse]](), + newListAtSubscriptionPager: newTracker[azfake.PagerResponder[armlinks.ResourceLinksClientListAtSubscriptionResponse]](), + } +} + +// ResourceLinksServerTransport connects instances of armlinks.ResourceLinksClient to instances of ResourceLinksServer. +// Don't use this type directly, use NewResourceLinksServerTransport instead. +type ResourceLinksServerTransport struct { + srv *ResourceLinksServer + newListAtSourceScopePager *tracker[azfake.PagerResponder[armlinks.ResourceLinksClientListAtSourceScopeResponse]] + newListAtSubscriptionPager *tracker[azfake.PagerResponder[armlinks.ResourceLinksClientListAtSubscriptionResponse]] +} + +// Do implements the policy.Transporter interface for ResourceLinksServerTransport. +func (r *ResourceLinksServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "ResourceLinksClient.CreateOrUpdate": + resp, err = r.dispatchCreateOrUpdate(req) + case "ResourceLinksClient.Delete": + resp, err = r.dispatchDelete(req) + case "ResourceLinksClient.Get": + resp, err = r.dispatchGet(req) + case "ResourceLinksClient.NewListAtSourceScopePager": + resp, err = r.dispatchNewListAtSourceScopePager(req) + case "ResourceLinksClient.NewListAtSubscriptionPager": + resp, err = r.dispatchNewListAtSubscriptionPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (r *ResourceLinksServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if r.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armlinks.ResourceLink](req) + if err != nil { + return nil, err + } + linkIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("linkId")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.CreateOrUpdate(req.Context(), linkIDParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ResourceLink, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *ResourceLinksServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if r.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + linkIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("linkId")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Delete(req.Context(), linkIDParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *ResourceLinksServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if r.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + linkIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("linkId")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Get(req.Context(), linkIDParam, 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).ResourceLink, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *ResourceLinksServerTransport) dispatchNewListAtSourceScopePager(req *http.Request) (*http.Response, error) { + if r.srv.NewListAtSourceScopePager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAtSourceScopePager not implemented")} + } + newListAtSourceScopePager := r.newListAtSourceScopePager.get(req) + if newListAtSourceScopePager == nil { + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/links` + 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) + } + qp := req.URL.Query() + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + var options *armlinks.ResourceLinksClientListAtSourceScopeOptions + if filterParam != nil { + options = &armlinks.ResourceLinksClientListAtSourceScopeOptions{ + Filter: filterParam, + } + } + resp := r.srv.NewListAtSourceScopePager(scopeParam, options) + newListAtSourceScopePager = &resp + r.newListAtSourceScopePager.add(req, newListAtSourceScopePager) + server.PagerResponderInjectNextLinks(newListAtSourceScopePager, req, func(page *armlinks.ResourceLinksClientListAtSourceScopeResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListAtSourceScopePager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + r.newListAtSourceScopePager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListAtSourceScopePager) { + r.newListAtSourceScopePager.remove(req) + } + return resp, nil +} + +func (r *ResourceLinksServerTransport) dispatchNewListAtSubscriptionPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListAtSubscriptionPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAtSubscriptionPager not implemented")} + } + newListAtSubscriptionPager := r.newListAtSubscriptionPager.get(req) + if newListAtSubscriptionPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/links` + 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) + } + qp := req.URL.Query() + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + var options *armlinks.ResourceLinksClientListAtSubscriptionOptions + if filterParam != nil { + options = &armlinks.ResourceLinksClientListAtSubscriptionOptions{ + Filter: filterParam, + } + } + resp := r.srv.NewListAtSubscriptionPager(options) + newListAtSubscriptionPager = &resp + r.newListAtSubscriptionPager.add(req, newListAtSubscriptionPager) + server.PagerResponderInjectNextLinks(newListAtSubscriptionPager, req, func(page *armlinks.ResourceLinksClientListAtSubscriptionResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListAtSubscriptionPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + r.newListAtSubscriptionPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListAtSubscriptionPager) { + r.newListAtSubscriptionPager.remove(req) + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armlinks/fake/server_factory.go b/sdk/resourcemanager/resources/armlinks/fake/server_factory.go new file mode 100644 index 000000000000..1284a867b5f4 --- /dev/null +++ b/sdk/resourcemanager/resources/armlinks/fake/server_factory.go @@ -0,0 +1,82 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" + "sync" +) + +// ServerFactory is a fake server for instances of the armlinks.ClientFactory type. +type ServerFactory struct { + OperationsServer OperationsServer + ResourceLinksServer ResourceLinksServer +} + +// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. +// The returned ServerFactoryTransport instance is connected to an instance of armlinks.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 armlinks.ClientFactory to instances of ServerFactory. +// Don't use this type directly, use NewServerFactoryTransport instead. +type ServerFactoryTransport struct { + srv *ServerFactory + trMu sync.Mutex + trOperationsServer *OperationsServerTransport + trResourceLinksServer *ResourceLinksServerTransport +} + +// 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 "ResourceLinksClient": + initServer(s, &s.trResourceLinksServer, func() *ResourceLinksServerTransport { + return NewResourceLinksServerTransport(&s.srv.ResourceLinksServer) + }) + resp, err = s.trResourceLinksServer.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/resources/armlinks/go.mod b/sdk/resourcemanager/resources/armlinks/go.mod index b3af0441ac61..34bc19ea0095 100644 --- a/sdk/resourcemanager/resources/armlinks/go.mod +++ b/sdk/resourcemanager/resources/armlinks/go.mod @@ -2,10 +2,10 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armlinks go 1.18 -require github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 +require github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.2 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/text v0.7.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/text v0.13.0 // indirect ) diff --git a/sdk/resourcemanager/resources/armlinks/go.sum b/sdk/resourcemanager/resources/armlinks/go.sum index d39a720dafd8..428cd71de305 100644 --- a/sdk/resourcemanager/resources/armlinks/go.sum +++ b/sdk/resourcemanager/resources/armlinks/go.sum @@ -1,12 +1,12 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 h1:rTnT/Jrcm+figWlYz4Ixzt0SJVR2cMC8lvZcimipiEY= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0/go.mod h1:ON4tFdPTwRcgWEaVDrN3584Ef+b7GgSJaXxe5fW9t4M= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.2 h1:+5VZ72z0Qan5Bog5C+ZkgSqUbeVUd9wgtHOrIKuc5b8= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.2/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 h1:fb8kj/Dh4CSwgsOzHeZY4Xh68cFVbzXx+ONXGMY//4w= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0/go.mod h1:uReU2sSxZExRPBAg3qKzmAucSi51+SP1OhohieR821Q= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/sdk/resourcemanager/resources/armlinks/models.go b/sdk/resourcemanager/resources/armlinks/models.go index abf1ecf8e482..8afa39bdbbd5 100644 --- a/sdk/resourcemanager/resources/armlinks/models.go +++ b/sdk/resourcemanager/resources/armlinks/models.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armlinks @@ -43,11 +42,6 @@ type OperationListResult struct { Value []*Operation } -// OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. -type OperationsClientListOptions struct { - // placeholder for future optional parameters -} - // ResourceLink - The resource link. type ResourceLink struct { // Properties for resource link. @@ -89,34 +83,3 @@ type ResourceLinkResult struct { // READ-ONLY; The URL to use for getting the next set of results. NextLink *string } - -// ResourceLinksClientCreateOrUpdateOptions contains the optional parameters for the ResourceLinksClient.CreateOrUpdate method. -type ResourceLinksClientCreateOrUpdateOptions struct { - // placeholder for future optional parameters -} - -// ResourceLinksClientDeleteOptions contains the optional parameters for the ResourceLinksClient.Delete method. -type ResourceLinksClientDeleteOptions struct { - // placeholder for future optional parameters -} - -// ResourceLinksClientGetOptions contains the optional parameters for the ResourceLinksClient.Get method. -type ResourceLinksClientGetOptions struct { - // placeholder for future optional parameters -} - -// ResourceLinksClientListAtSourceScopeOptions contains the optional parameters for the ResourceLinksClient.NewListAtSourceScopePager -// method. -type ResourceLinksClientListAtSourceScopeOptions struct { - // The filter to apply when getting resource links. To get links only at the specified scope (not below the scope), use Filter.atScope().. - // Specifying any value will set the value to atScope(). - Filter *string -} - -// ResourceLinksClientListAtSubscriptionOptions contains the optional parameters for the ResourceLinksClient.NewListAtSubscriptionPager -// method. -type ResourceLinksClientListAtSubscriptionOptions struct { - // The filter to apply on the list resource links operation. The supported filter for list resource links is targetId. For - // example, $filter=targetId eq {value} - Filter *string -} diff --git a/sdk/resourcemanager/resources/armlinks/models_serde.go b/sdk/resourcemanager/resources/armlinks/models_serde.go index a68e550aef0f..acdd748cf488 100644 --- a/sdk/resourcemanager/resources/armlinks/models_serde.go +++ b/sdk/resourcemanager/resources/armlinks/models_serde.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armlinks diff --git a/sdk/resourcemanager/resources/armlinks/operations_client.go b/sdk/resourcemanager/resources/armlinks/operations_client.go index 3d1c08dc739b..41f4d008c925 100644 --- a/sdk/resourcemanager/resources/armlinks/operations_client.go +++ b/sdk/resourcemanager/resources/armlinks/operations_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armlinks @@ -28,7 +27,7 @@ type OperationsClient struct { // - 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+".OperationsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -48,25 +47,20 @@ func (client *OperationsClient) NewListPager(options *OperationsClientListOption return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *OperationsClientListResponse) (OperationsClientListResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + 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 } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return OperationsClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return OperationsClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armlinks/options.go b/sdk/resourcemanager/resources/armlinks/options.go new file mode 100644 index 000000000000..229b750e8583 --- /dev/null +++ b/sdk/resourcemanager/resources/armlinks/options.go @@ -0,0 +1,45 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armlinks + +// OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. +type OperationsClientListOptions struct { + // placeholder for future optional parameters +} + +// ResourceLinksClientCreateOrUpdateOptions contains the optional parameters for the ResourceLinksClient.CreateOrUpdate method. +type ResourceLinksClientCreateOrUpdateOptions struct { + // placeholder for future optional parameters +} + +// ResourceLinksClientDeleteOptions contains the optional parameters for the ResourceLinksClient.Delete method. +type ResourceLinksClientDeleteOptions struct { + // placeholder for future optional parameters +} + +// ResourceLinksClientGetOptions contains the optional parameters for the ResourceLinksClient.Get method. +type ResourceLinksClientGetOptions struct { + // placeholder for future optional parameters +} + +// ResourceLinksClientListAtSourceScopeOptions contains the optional parameters for the ResourceLinksClient.NewListAtSourceScopePager +// method. +type ResourceLinksClientListAtSourceScopeOptions struct { + // The filter to apply when getting resource links. To get links only at the specified scope (not below the scope), use Filter.atScope().. + // Specifying any value will set the value to atScope(). + Filter *string +} + +// ResourceLinksClientListAtSubscriptionOptions contains the optional parameters for the ResourceLinksClient.NewListAtSubscriptionPager +// method. +type ResourceLinksClientListAtSubscriptionOptions struct { + // The filter to apply on the list resource links operation. The supported filter for list resource links is targetId. For + // example, $filter=targetId eq {value} + Filter *string +} diff --git a/sdk/resourcemanager/resources/armlinks/resourcelinks_client.go b/sdk/resourcemanager/resources/armlinks/resourcelinks_client.go index 7856e5cb23a1..97406714ec9d 100644 --- a/sdk/resourcemanager/resources/armlinks/resourcelinks_client.go +++ b/sdk/resourcemanager/resources/armlinks/resourcelinks_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armlinks @@ -33,7 +32,7 @@ type ResourceLinksClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewResourceLinksClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ResourceLinksClient, error) { - cl, err := arm.NewClient(moduleName+".ResourceLinksClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -56,18 +55,25 @@ func NewResourceLinksClient(subscriptionID string, credential azcore.TokenCreden // - options - ResourceLinksClientCreateOrUpdateOptions contains the optional parameters for the ResourceLinksClient.CreateOrUpdate // method. func (client *ResourceLinksClient) CreateOrUpdate(ctx context.Context, linkID string, parameters ResourceLink, options *ResourceLinksClientCreateOrUpdateOptions) (ResourceLinksClientCreateOrUpdateResponse, error) { + var err error + const operationName = "ResourceLinksClient.CreateOrUpdate" + 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, linkID, parameters, options) if err != nil { return ResourceLinksClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ResourceLinksClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return ResourceLinksClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return ResourceLinksClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -82,7 +88,10 @@ func (client *ResourceLinksClient) createOrUpdateCreateRequest(ctx context.Conte reqQP.Set("api-version", "2016-09-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // createOrUpdateHandleResponse handles the CreateOrUpdate response. @@ -104,16 +113,22 @@ func (client *ResourceLinksClient) createOrUpdateHandleResponse(resp *http.Respo // /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myGroup/Microsoft.Web/sites/mySite/Microsoft.Resources/links/myLink // - options - ResourceLinksClientDeleteOptions contains the optional parameters for the ResourceLinksClient.Delete method. func (client *ResourceLinksClient) Delete(ctx context.Context, linkID string, options *ResourceLinksClientDeleteOptions) (ResourceLinksClientDeleteResponse, error) { + var err error + const operationName = "ResourceLinksClient.Delete" + 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, linkID, options) if err != nil { return ResourceLinksClientDeleteResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ResourceLinksClientDeleteResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return ResourceLinksClientDeleteResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return ResourceLinksClientDeleteResponse{}, err } return ResourceLinksClientDeleteResponse{}, nil } @@ -139,18 +154,25 @@ func (client *ResourceLinksClient) deleteCreateRequest(ctx context.Context, link // - linkID - The fully qualified Id of the resource link. For example, /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myGroup/Microsoft.Web/sites/mySite/Microsoft.Resources/links/myLink // - options - ResourceLinksClientGetOptions contains the optional parameters for the ResourceLinksClient.Get method. func (client *ResourceLinksClient) Get(ctx context.Context, linkID string, options *ResourceLinksClientGetOptions) (ResourceLinksClientGetResponse, error) { + var err error + const operationName = "ResourceLinksClient.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, linkID, options) if err != nil { return ResourceLinksClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ResourceLinksClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ResourceLinksClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ResourceLinksClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -191,25 +213,20 @@ func (client *ResourceLinksClient) NewListAtSourceScopePager(scope string, optio return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ResourceLinksClientListAtSourceScopeResponse) (ResourceLinksClientListAtSourceScopeResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtSourceScopeCreateRequest(ctx, scope, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return ResourceLinksClientListAtSourceScopeResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ResourceLinksClient.NewListAtSourceScopePager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listAtSourceScopeCreateRequest(ctx, scope, options) + }, nil) if err != nil { return ResourceLinksClientListAtSourceScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ResourceLinksClientListAtSourceScopeResponse{}, runtime.NewResponseError(resp) - } return client.listAtSourceScopeHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -251,25 +268,20 @@ func (client *ResourceLinksClient) NewListAtSubscriptionPager(options *ResourceL return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ResourceLinksClientListAtSubscriptionResponse) (ResourceLinksClientListAtSubscriptionResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtSubscriptionCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ResourceLinksClient.NewListAtSubscriptionPager") + 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.listAtSubscriptionCreateRequest(ctx, options) + }, nil) if err != nil { return ResourceLinksClientListAtSubscriptionResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ResourceLinksClientListAtSubscriptionResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ResourceLinksClientListAtSubscriptionResponse{}, runtime.NewResponseError(resp) - } return client.listAtSubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armlinks/response_types.go b/sdk/resourcemanager/resources/armlinks/response_types.go index 057a520fa12a..4e5421d02af3 100644 --- a/sdk/resourcemanager/resources/armlinks/response_types.go +++ b/sdk/resourcemanager/resources/armlinks/response_types.go @@ -3,19 +3,21 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armlinks // OperationsClientListResponse contains the response from method OperationsClient.NewListPager. type OperationsClientListResponse struct { + // Result of the request to list Microsoft.Resources operations. It contains a list of operations and a URL link to get the + // next set of results. OperationListResult } // ResourceLinksClientCreateOrUpdateResponse contains the response from method ResourceLinksClient.CreateOrUpdate. type ResourceLinksClientCreateOrUpdateResponse struct { + // The resource link. ResourceLink } @@ -26,15 +28,18 @@ type ResourceLinksClientDeleteResponse struct { // ResourceLinksClientGetResponse contains the response from method ResourceLinksClient.Get. type ResourceLinksClientGetResponse struct { + // The resource link. ResourceLink } // ResourceLinksClientListAtSourceScopeResponse contains the response from method ResourceLinksClient.NewListAtSourceScopePager. type ResourceLinksClientListAtSourceScopeResponse struct { + // List of resource links. ResourceLinkResult } // ResourceLinksClientListAtSubscriptionResponse contains the response from method ResourceLinksClient.NewListAtSubscriptionPager. type ResourceLinksClientListAtSubscriptionResponse struct { + // List of resource links. ResourceLinkResult } From 0481f3d3275ca18990e2aefb51ed20d6c5ef4092 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 15:26:18 +0800 Subject: [PATCH 06/18] [Release] sdk/resourcemanager/resources/armlocks/1.2.0 generation from spec commit: bf204aab860f2eb58a9d346b00d44760f2a9b0a2 --- .../resources/armlocks/CHANGELOG.md | 6 + .../resources/armlocks/README.md | 7 + .../authorizationoperations_client.go | 26 +- .../resources/armlocks/autorest.md | 2 +- .../resources/armlocks/client_factory.go | 7 +- .../resources/armlocks/constants.go | 7 +- .../fake/authorizationoperations_server.go | 96 ++ .../resources/armlocks/fake/internal.go | 72 ++ .../armlocks/fake/managementlocks_server.go | 824 ++++++++++++++++++ .../resources/armlocks/fake/server_factory.go | 84 ++ .../resources/armlocks/fake/time_rfc3339.go | 86 ++ sdk/resourcemanager/resources/armlocks/go.mod | 20 +- sdk/resourcemanager/resources/armlocks/go.sum | 46 +- .../armlocks/managementlocks_client.go | 277 +++--- .../resources/armlocks/models.go | 108 +-- .../resources/armlocks/models_serde.go | 11 +- .../resources/armlocks/options.go | 114 +++ .../resources/armlocks/response_types.go | 17 +- .../resources/armlocks/time_rfc3339.go | 43 +- 19 files changed, 1556 insertions(+), 297 deletions(-) create mode 100644 sdk/resourcemanager/resources/armlocks/fake/authorizationoperations_server.go create mode 100644 sdk/resourcemanager/resources/armlocks/fake/internal.go create mode 100644 sdk/resourcemanager/resources/armlocks/fake/managementlocks_server.go create mode 100644 sdk/resourcemanager/resources/armlocks/fake/server_factory.go create mode 100644 sdk/resourcemanager/resources/armlocks/fake/time_rfc3339.go create mode 100644 sdk/resourcemanager/resources/armlocks/options.go diff --git a/sdk/resourcemanager/resources/armlocks/CHANGELOG.md b/sdk/resourcemanager/resources/armlocks/CHANGELOG.md index 799221adc0ae..f642f9e83509 100644 --- a/sdk/resourcemanager/resources/armlocks/CHANGELOG.md +++ b/sdk/resourcemanager/resources/armlocks/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 1.2.0 (2023-11-24) +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + + ## 1.1.1 (2023-04-14) ### Bug Fixes diff --git a/sdk/resourcemanager/resources/armlocks/README.md b/sdk/resourcemanager/resources/armlocks/README.md index b63009e56f0a..92d131ed88e8 100644 --- a/sdk/resourcemanager/resources/armlocks/README.md +++ b/sdk/resourcemanager/resources/armlocks/README.md @@ -60,6 +60,13 @@ A client groups a set of related APIs, providing access to its functionality. C client := clientFactory.NewManagementLocksClient() ``` +## 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 diff --git a/sdk/resourcemanager/resources/armlocks/authorizationoperations_client.go b/sdk/resourcemanager/resources/armlocks/authorizationoperations_client.go index 960aac853cd0..8175cad10457 100644 --- a/sdk/resourcemanager/resources/armlocks/authorizationoperations_client.go +++ b/sdk/resourcemanager/resources/armlocks/authorizationoperations_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armlocks @@ -28,7 +27,7 @@ type AuthorizationOperationsClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewAuthorizationOperationsClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*AuthorizationOperationsClient, error) { - cl, err := arm.NewClient(moduleName+".AuthorizationOperationsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -49,25 +48,20 @@ func (client *AuthorizationOperationsClient) NewListPager(options *Authorization return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AuthorizationOperationsClientListResponse) (AuthorizationOperationsClientListResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AuthorizationOperationsClient.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 AuthorizationOperationsClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return AuthorizationOperationsClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return AuthorizationOperationsClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armlocks/autorest.md b/sdk/resourcemanager/resources/armlocks/autorest.md index 22fe3d8b5f33..7217053d37ca 100644 --- a/sdk/resourcemanager/resources/armlocks/autorest.md +++ b/sdk/resourcemanager/resources/armlocks/autorest.md @@ -8,6 +8,6 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/0cc5e2efd6ffccf30e80d1e150b488dd87198b94/specification/resources/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/0cc5e2efd6ffccf30e80d1e150b488dd87198b94/specification/resources/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 1.1.1 +module-version: 1.2.0 package-locks: true ``` \ No newline at end of file diff --git a/sdk/resourcemanager/resources/armlocks/client_factory.go b/sdk/resourcemanager/resources/armlocks/client_factory.go index 1063ee97b20d..ede49372b654 100644 --- a/sdk/resourcemanager/resources/armlocks/client_factory.go +++ b/sdk/resourcemanager/resources/armlocks/client_factory.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armlocks @@ -28,7 +27,7 @@ type ClientFactory struct { // - 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) { - _, err := arm.NewClient(moduleName+".ClientFactory", moduleVersion, credential, options) + _, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -38,11 +37,13 @@ func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, }, nil } +// NewAuthorizationOperationsClient creates a new instance of AuthorizationOperationsClient. func (c *ClientFactory) NewAuthorizationOperationsClient() *AuthorizationOperationsClient { subClient, _ := NewAuthorizationOperationsClient(c.credential, c.options) return subClient } +// NewManagementLocksClient creates a new instance of ManagementLocksClient. func (c *ClientFactory) NewManagementLocksClient() *ManagementLocksClient { subClient, _ := NewManagementLocksClient(c.subscriptionID, c.credential, c.options) return subClient diff --git a/sdk/resourcemanager/resources/armlocks/constants.go b/sdk/resourcemanager/resources/armlocks/constants.go index e666d4c519a2..f54d3758f0cd 100644 --- a/sdk/resourcemanager/resources/armlocks/constants.go +++ b/sdk/resourcemanager/resources/armlocks/constants.go @@ -3,15 +3,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armlocks const ( - moduleName = "armlocks" - moduleVersion = "v1.1.1" + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armlocks" + moduleVersion = "v1.2.0" ) // CreatedByType - The type of identity that created the resource. diff --git a/sdk/resourcemanager/resources/armlocks/fake/authorizationoperations_server.go b/sdk/resourcemanager/resources/armlocks/fake/authorizationoperations_server.go new file mode 100644 index 000000000000..e0f2f136ad2a --- /dev/null +++ b/sdk/resourcemanager/resources/armlocks/fake/authorizationoperations_server.go @@ -0,0 +1,96 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armlocks" + "net/http" +) + +// AuthorizationOperationsServer is a fake server for instances of the armlocks.AuthorizationOperationsClient type. +type AuthorizationOperationsServer struct { + // NewListPager is the fake for method AuthorizationOperationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armlocks.AuthorizationOperationsClientListOptions) (resp azfake.PagerResponder[armlocks.AuthorizationOperationsClientListResponse]) +} + +// NewAuthorizationOperationsServerTransport creates a new instance of AuthorizationOperationsServerTransport with the provided implementation. +// The returned AuthorizationOperationsServerTransport instance is connected to an instance of armlocks.AuthorizationOperationsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewAuthorizationOperationsServerTransport(srv *AuthorizationOperationsServer) *AuthorizationOperationsServerTransport { + return &AuthorizationOperationsServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[armlocks.AuthorizationOperationsClientListResponse]](), + } +} + +// AuthorizationOperationsServerTransport connects instances of armlocks.AuthorizationOperationsClient to instances of AuthorizationOperationsServer. +// Don't use this type directly, use NewAuthorizationOperationsServerTransport instead. +type AuthorizationOperationsServerTransport struct { + srv *AuthorizationOperationsServer + newListPager *tracker[azfake.PagerResponder[armlocks.AuthorizationOperationsClientListResponse]] +} + +// Do implements the policy.Transporter interface for AuthorizationOperationsServerTransport. +func (a *AuthorizationOperationsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "AuthorizationOperationsClient.NewListPager": + resp, err = a.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *AuthorizationOperationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := a.newListPager.get(req) + if newListPager == nil { + resp := a.srv.NewListPager(nil) + newListPager = &resp + a.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armlocks.AuthorizationOperationsClientListResponse, 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) { + a.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + a.newListPager.remove(req) + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armlocks/fake/internal.go b/sdk/resourcemanager/resources/armlocks/fake/internal.go new file mode 100644 index 000000000000..94e060e89dbd --- /dev/null +++ b/sdk/resourcemanager/resources/armlocks/fake/internal.go @@ -0,0 +1,72 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "net/http" + "reflect" + "sync" +) + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} + +func getOptional[T any](v T) *T { + if reflect.ValueOf(v).IsZero() { + return nil + } + return &v +} + +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/resources/armlocks/fake/managementlocks_server.go b/sdk/resourcemanager/resources/armlocks/fake/managementlocks_server.go new file mode 100644 index 000000000000..8141d36c4c4f --- /dev/null +++ b/sdk/resourcemanager/resources/armlocks/fake/managementlocks_server.go @@ -0,0 +1,824 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armlocks" + "net/http" + "net/url" + "regexp" +) + +// ManagementLocksServer is a fake server for instances of the armlocks.ManagementLocksClient type. +type ManagementLocksServer struct { + // CreateOrUpdateAtResourceGroupLevel is the fake for method ManagementLocksClient.CreateOrUpdateAtResourceGroupLevel + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdateAtResourceGroupLevel func(ctx context.Context, resourceGroupName string, lockName string, parameters armlocks.ManagementLockObject, options *armlocks.ManagementLocksClientCreateOrUpdateAtResourceGroupLevelOptions) (resp azfake.Responder[armlocks.ManagementLocksClientCreateOrUpdateAtResourceGroupLevelResponse], errResp azfake.ErrorResponder) + + // CreateOrUpdateAtResourceLevel is the fake for method ManagementLocksClient.CreateOrUpdateAtResourceLevel + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdateAtResourceLevel func(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, lockName string, parameters armlocks.ManagementLockObject, options *armlocks.ManagementLocksClientCreateOrUpdateAtResourceLevelOptions) (resp azfake.Responder[armlocks.ManagementLocksClientCreateOrUpdateAtResourceLevelResponse], errResp azfake.ErrorResponder) + + // CreateOrUpdateAtSubscriptionLevel is the fake for method ManagementLocksClient.CreateOrUpdateAtSubscriptionLevel + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdateAtSubscriptionLevel func(ctx context.Context, lockName string, parameters armlocks.ManagementLockObject, options *armlocks.ManagementLocksClientCreateOrUpdateAtSubscriptionLevelOptions) (resp azfake.Responder[armlocks.ManagementLocksClientCreateOrUpdateAtSubscriptionLevelResponse], errResp azfake.ErrorResponder) + + // CreateOrUpdateByScope is the fake for method ManagementLocksClient.CreateOrUpdateByScope + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdateByScope func(ctx context.Context, scope string, lockName string, parameters armlocks.ManagementLockObject, options *armlocks.ManagementLocksClientCreateOrUpdateByScopeOptions) (resp azfake.Responder[armlocks.ManagementLocksClientCreateOrUpdateByScopeResponse], errResp azfake.ErrorResponder) + + // DeleteAtResourceGroupLevel is the fake for method ManagementLocksClient.DeleteAtResourceGroupLevel + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + DeleteAtResourceGroupLevel func(ctx context.Context, resourceGroupName string, lockName string, options *armlocks.ManagementLocksClientDeleteAtResourceGroupLevelOptions) (resp azfake.Responder[armlocks.ManagementLocksClientDeleteAtResourceGroupLevelResponse], errResp azfake.ErrorResponder) + + // DeleteAtResourceLevel is the fake for method ManagementLocksClient.DeleteAtResourceLevel + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + DeleteAtResourceLevel func(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, lockName string, options *armlocks.ManagementLocksClientDeleteAtResourceLevelOptions) (resp azfake.Responder[armlocks.ManagementLocksClientDeleteAtResourceLevelResponse], errResp azfake.ErrorResponder) + + // DeleteAtSubscriptionLevel is the fake for method ManagementLocksClient.DeleteAtSubscriptionLevel + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + DeleteAtSubscriptionLevel func(ctx context.Context, lockName string, options *armlocks.ManagementLocksClientDeleteAtSubscriptionLevelOptions) (resp azfake.Responder[armlocks.ManagementLocksClientDeleteAtSubscriptionLevelResponse], errResp azfake.ErrorResponder) + + // DeleteByScope is the fake for method ManagementLocksClient.DeleteByScope + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + DeleteByScope func(ctx context.Context, scope string, lockName string, options *armlocks.ManagementLocksClientDeleteByScopeOptions) (resp azfake.Responder[armlocks.ManagementLocksClientDeleteByScopeResponse], errResp azfake.ErrorResponder) + + // GetAtResourceGroupLevel is the fake for method ManagementLocksClient.GetAtResourceGroupLevel + // HTTP status codes to indicate success: http.StatusOK + GetAtResourceGroupLevel func(ctx context.Context, resourceGroupName string, lockName string, options *armlocks.ManagementLocksClientGetAtResourceGroupLevelOptions) (resp azfake.Responder[armlocks.ManagementLocksClientGetAtResourceGroupLevelResponse], errResp azfake.ErrorResponder) + + // GetAtResourceLevel is the fake for method ManagementLocksClient.GetAtResourceLevel + // HTTP status codes to indicate success: http.StatusOK + GetAtResourceLevel func(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, lockName string, options *armlocks.ManagementLocksClientGetAtResourceLevelOptions) (resp azfake.Responder[armlocks.ManagementLocksClientGetAtResourceLevelResponse], errResp azfake.ErrorResponder) + + // GetAtSubscriptionLevel is the fake for method ManagementLocksClient.GetAtSubscriptionLevel + // HTTP status codes to indicate success: http.StatusOK + GetAtSubscriptionLevel func(ctx context.Context, lockName string, options *armlocks.ManagementLocksClientGetAtSubscriptionLevelOptions) (resp azfake.Responder[armlocks.ManagementLocksClientGetAtSubscriptionLevelResponse], errResp azfake.ErrorResponder) + + // GetByScope is the fake for method ManagementLocksClient.GetByScope + // HTTP status codes to indicate success: http.StatusOK + GetByScope func(ctx context.Context, scope string, lockName string, options *armlocks.ManagementLocksClientGetByScopeOptions) (resp azfake.Responder[armlocks.ManagementLocksClientGetByScopeResponse], errResp azfake.ErrorResponder) + + // NewListAtResourceGroupLevelPager is the fake for method ManagementLocksClient.NewListAtResourceGroupLevelPager + // HTTP status codes to indicate success: http.StatusOK + NewListAtResourceGroupLevelPager func(resourceGroupName string, options *armlocks.ManagementLocksClientListAtResourceGroupLevelOptions) (resp azfake.PagerResponder[armlocks.ManagementLocksClientListAtResourceGroupLevelResponse]) + + // NewListAtResourceLevelPager is the fake for method ManagementLocksClient.NewListAtResourceLevelPager + // HTTP status codes to indicate success: http.StatusOK + NewListAtResourceLevelPager func(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, options *armlocks.ManagementLocksClientListAtResourceLevelOptions) (resp azfake.PagerResponder[armlocks.ManagementLocksClientListAtResourceLevelResponse]) + + // NewListAtSubscriptionLevelPager is the fake for method ManagementLocksClient.NewListAtSubscriptionLevelPager + // HTTP status codes to indicate success: http.StatusOK + NewListAtSubscriptionLevelPager func(options *armlocks.ManagementLocksClientListAtSubscriptionLevelOptions) (resp azfake.PagerResponder[armlocks.ManagementLocksClientListAtSubscriptionLevelResponse]) + + // NewListByScopePager is the fake for method ManagementLocksClient.NewListByScopePager + // HTTP status codes to indicate success: http.StatusOK + NewListByScopePager func(scope string, options *armlocks.ManagementLocksClientListByScopeOptions) (resp azfake.PagerResponder[armlocks.ManagementLocksClientListByScopeResponse]) +} + +// NewManagementLocksServerTransport creates a new instance of ManagementLocksServerTransport with the provided implementation. +// The returned ManagementLocksServerTransport instance is connected to an instance of armlocks.ManagementLocksClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewManagementLocksServerTransport(srv *ManagementLocksServer) *ManagementLocksServerTransport { + return &ManagementLocksServerTransport{ + srv: srv, + newListAtResourceGroupLevelPager: newTracker[azfake.PagerResponder[armlocks.ManagementLocksClientListAtResourceGroupLevelResponse]](), + newListAtResourceLevelPager: newTracker[azfake.PagerResponder[armlocks.ManagementLocksClientListAtResourceLevelResponse]](), + newListAtSubscriptionLevelPager: newTracker[azfake.PagerResponder[armlocks.ManagementLocksClientListAtSubscriptionLevelResponse]](), + newListByScopePager: newTracker[azfake.PagerResponder[armlocks.ManagementLocksClientListByScopeResponse]](), + } +} + +// ManagementLocksServerTransport connects instances of armlocks.ManagementLocksClient to instances of ManagementLocksServer. +// Don't use this type directly, use NewManagementLocksServerTransport instead. +type ManagementLocksServerTransport struct { + srv *ManagementLocksServer + newListAtResourceGroupLevelPager *tracker[azfake.PagerResponder[armlocks.ManagementLocksClientListAtResourceGroupLevelResponse]] + newListAtResourceLevelPager *tracker[azfake.PagerResponder[armlocks.ManagementLocksClientListAtResourceLevelResponse]] + newListAtSubscriptionLevelPager *tracker[azfake.PagerResponder[armlocks.ManagementLocksClientListAtSubscriptionLevelResponse]] + newListByScopePager *tracker[azfake.PagerResponder[armlocks.ManagementLocksClientListByScopeResponse]] +} + +// Do implements the policy.Transporter interface for ManagementLocksServerTransport. +func (m *ManagementLocksServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "ManagementLocksClient.CreateOrUpdateAtResourceGroupLevel": + resp, err = m.dispatchCreateOrUpdateAtResourceGroupLevel(req) + case "ManagementLocksClient.CreateOrUpdateAtResourceLevel": + resp, err = m.dispatchCreateOrUpdateAtResourceLevel(req) + case "ManagementLocksClient.CreateOrUpdateAtSubscriptionLevel": + resp, err = m.dispatchCreateOrUpdateAtSubscriptionLevel(req) + case "ManagementLocksClient.CreateOrUpdateByScope": + resp, err = m.dispatchCreateOrUpdateByScope(req) + case "ManagementLocksClient.DeleteAtResourceGroupLevel": + resp, err = m.dispatchDeleteAtResourceGroupLevel(req) + case "ManagementLocksClient.DeleteAtResourceLevel": + resp, err = m.dispatchDeleteAtResourceLevel(req) + case "ManagementLocksClient.DeleteAtSubscriptionLevel": + resp, err = m.dispatchDeleteAtSubscriptionLevel(req) + case "ManagementLocksClient.DeleteByScope": + resp, err = m.dispatchDeleteByScope(req) + case "ManagementLocksClient.GetAtResourceGroupLevel": + resp, err = m.dispatchGetAtResourceGroupLevel(req) + case "ManagementLocksClient.GetAtResourceLevel": + resp, err = m.dispatchGetAtResourceLevel(req) + case "ManagementLocksClient.GetAtSubscriptionLevel": + resp, err = m.dispatchGetAtSubscriptionLevel(req) + case "ManagementLocksClient.GetByScope": + resp, err = m.dispatchGetByScope(req) + case "ManagementLocksClient.NewListAtResourceGroupLevelPager": + resp, err = m.dispatchNewListAtResourceGroupLevelPager(req) + case "ManagementLocksClient.NewListAtResourceLevelPager": + resp, err = m.dispatchNewListAtResourceLevelPager(req) + case "ManagementLocksClient.NewListAtSubscriptionLevelPager": + resp, err = m.dispatchNewListAtSubscriptionLevelPager(req) + case "ManagementLocksClient.NewListByScopePager": + resp, err = m.dispatchNewListByScopePager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchCreateOrUpdateAtResourceGroupLevel(req *http.Request) (*http.Response, error) { + if m.srv.CreateOrUpdateAtResourceGroupLevel == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdateAtResourceGroupLevel not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks/(?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[armlocks.ManagementLockObject](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + lockNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("lockName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.CreateOrUpdateAtResourceGroupLevel(req.Context(), resourceGroupNameParam, lockNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ManagementLockObject, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchCreateOrUpdateAtResourceLevel(req *http.Request) (*http.Response, error) { + if m.srv.CreateOrUpdateAtResourceLevel == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdateAtResourceLevel not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 7 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[armlocks.ManagementLockObject](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + parentResourcePathParam, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + if err != nil { + return nil, err + } + resourceTypeParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + if err != nil { + return nil, err + } + resourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + lockNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("lockName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.CreateOrUpdateAtResourceLevel(req.Context(), resourceGroupNameParam, resourceProviderNamespaceParam, parentResourcePathParam, resourceTypeParam, resourceNameParam, lockNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ManagementLockObject, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchCreateOrUpdateAtSubscriptionLevel(req *http.Request) (*http.Response, error) { + if m.srv.CreateOrUpdateAtSubscriptionLevel == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdateAtSubscriptionLevel not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armlocks.ManagementLockObject](req) + if err != nil { + return nil, err + } + lockNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("lockName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.CreateOrUpdateAtSubscriptionLevel(req.Context(), lockNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ManagementLockObject, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchCreateOrUpdateByScope(req *http.Request) (*http.Response, error) { + if m.srv.CreateOrUpdateByScope == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdateByScope not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armlocks.ManagementLockObject](req) + if err != nil { + return nil, err + } + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + lockNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("lockName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.CreateOrUpdateByScope(req.Context(), scopeParam, lockNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ManagementLockObject, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchDeleteAtResourceGroupLevel(req *http.Request) (*http.Response, error) { + if m.srv.DeleteAtResourceGroupLevel == nil { + return nil, &nonRetriableError{errors.New("fake for method DeleteAtResourceGroupLevel not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks/(?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 + } + lockNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("lockName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.DeleteAtResourceGroupLevel(req.Context(), resourceGroupNameParam, lockNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchDeleteAtResourceLevel(req *http.Request) (*http.Response, error) { + if m.srv.DeleteAtResourceLevel == nil { + return nil, &nonRetriableError{errors.New("fake for method DeleteAtResourceLevel not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 7 { + 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 + } + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + parentResourcePathParam, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + if err != nil { + return nil, err + } + resourceTypeParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + if err != nil { + return nil, err + } + resourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + lockNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("lockName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.DeleteAtResourceLevel(req.Context(), resourceGroupNameParam, resourceProviderNamespaceParam, parentResourcePathParam, resourceTypeParam, resourceNameParam, lockNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchDeleteAtSubscriptionLevel(req *http.Request) (*http.Response, error) { + if m.srv.DeleteAtSubscriptionLevel == nil { + return nil, &nonRetriableError{errors.New("fake for method DeleteAtSubscriptionLevel not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + lockNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("lockName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.DeleteAtSubscriptionLevel(req.Context(), lockNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchDeleteByScope(req *http.Request) (*http.Response, error) { + if m.srv.DeleteByScope == nil { + return nil, &nonRetriableError{errors.New("fake for method DeleteByScope not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + lockNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("lockName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.DeleteByScope(req.Context(), scopeParam, lockNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchGetAtResourceGroupLevel(req *http.Request) (*http.Response, error) { + if m.srv.GetAtResourceGroupLevel == nil { + return nil, &nonRetriableError{errors.New("fake for method GetAtResourceGroupLevel not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks/(?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 + } + lockNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("lockName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.GetAtResourceGroupLevel(req.Context(), resourceGroupNameParam, lockNameParam, 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).ManagementLockObject, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchGetAtResourceLevel(req *http.Request) (*http.Response, error) { + if m.srv.GetAtResourceLevel == nil { + return nil, &nonRetriableError{errors.New("fake for method GetAtResourceLevel not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 7 { + 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 + } + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + parentResourcePathParam, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + if err != nil { + return nil, err + } + resourceTypeParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + if err != nil { + return nil, err + } + resourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + lockNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("lockName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.GetAtResourceLevel(req.Context(), resourceGroupNameParam, resourceProviderNamespaceParam, parentResourcePathParam, resourceTypeParam, resourceNameParam, lockNameParam, 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).ManagementLockObject, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchGetAtSubscriptionLevel(req *http.Request) (*http.Response, error) { + if m.srv.GetAtSubscriptionLevel == nil { + return nil, &nonRetriableError{errors.New("fake for method GetAtSubscriptionLevel not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + lockNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("lockName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.GetAtSubscriptionLevel(req.Context(), lockNameParam, 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).ManagementLockObject, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchGetByScope(req *http.Request) (*http.Response, error) { + if m.srv.GetByScope == nil { + return nil, &nonRetriableError{errors.New("fake for method GetByScope not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + lockNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("lockName")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.GetByScope(req.Context(), scopeParam, lockNameParam, 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).ManagementLockObject, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchNewListAtResourceGroupLevelPager(req *http.Request) (*http.Response, error) { + if m.srv.NewListAtResourceGroupLevelPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAtResourceGroupLevelPager not implemented")} + } + newListAtResourceGroupLevelPager := m.newListAtResourceGroupLevelPager.get(req) + if newListAtResourceGroupLevelPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks` + 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) + } + qp := req.URL.Query() + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + var options *armlocks.ManagementLocksClientListAtResourceGroupLevelOptions + if filterParam != nil { + options = &armlocks.ManagementLocksClientListAtResourceGroupLevelOptions{ + Filter: filterParam, + } + } + resp := m.srv.NewListAtResourceGroupLevelPager(resourceGroupNameParam, options) + newListAtResourceGroupLevelPager = &resp + m.newListAtResourceGroupLevelPager.add(req, newListAtResourceGroupLevelPager) + server.PagerResponderInjectNextLinks(newListAtResourceGroupLevelPager, req, func(page *armlocks.ManagementLocksClientListAtResourceGroupLevelResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListAtResourceGroupLevelPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + m.newListAtResourceGroupLevelPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListAtResourceGroupLevelPager) { + m.newListAtResourceGroupLevelPager.remove(req) + } + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchNewListAtResourceLevelPager(req *http.Request) (*http.Response, error) { + if m.srv.NewListAtResourceLevelPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAtResourceLevelPager not implemented")} + } + newListAtResourceLevelPager := m.newListAtResourceLevelPager.get(req) + if newListAtResourceLevelPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 6 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + parentResourcePathParam, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + if err != nil { + return nil, err + } + resourceTypeParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + if err != nil { + return nil, err + } + resourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + var options *armlocks.ManagementLocksClientListAtResourceLevelOptions + if filterParam != nil { + options = &armlocks.ManagementLocksClientListAtResourceLevelOptions{ + Filter: filterParam, + } + } + resp := m.srv.NewListAtResourceLevelPager(resourceGroupNameParam, resourceProviderNamespaceParam, parentResourcePathParam, resourceTypeParam, resourceNameParam, options) + newListAtResourceLevelPager = &resp + m.newListAtResourceLevelPager.add(req, newListAtResourceLevelPager) + server.PagerResponderInjectNextLinks(newListAtResourceLevelPager, req, func(page *armlocks.ManagementLocksClientListAtResourceLevelResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListAtResourceLevelPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + m.newListAtResourceLevelPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListAtResourceLevelPager) { + m.newListAtResourceLevelPager.remove(req) + } + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchNewListAtSubscriptionLevelPager(req *http.Request) (*http.Response, error) { + if m.srv.NewListAtSubscriptionLevelPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListAtSubscriptionLevelPager not implemented")} + } + newListAtSubscriptionLevelPager := m.newListAtSubscriptionLevelPager.get(req) + if newListAtSubscriptionLevelPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks` + 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) + } + qp := req.URL.Query() + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + var options *armlocks.ManagementLocksClientListAtSubscriptionLevelOptions + if filterParam != nil { + options = &armlocks.ManagementLocksClientListAtSubscriptionLevelOptions{ + Filter: filterParam, + } + } + resp := m.srv.NewListAtSubscriptionLevelPager(options) + newListAtSubscriptionLevelPager = &resp + m.newListAtSubscriptionLevelPager.add(req, newListAtSubscriptionLevelPager) + server.PagerResponderInjectNextLinks(newListAtSubscriptionLevelPager, req, func(page *armlocks.ManagementLocksClientListAtSubscriptionLevelResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListAtSubscriptionLevelPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + m.newListAtSubscriptionLevelPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListAtSubscriptionLevelPager) { + m.newListAtSubscriptionLevelPager.remove(req) + } + return resp, nil +} + +func (m *ManagementLocksServerTransport) dispatchNewListByScopePager(req *http.Request) (*http.Response, error) { + if m.srv.NewListByScopePager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByScopePager not implemented")} + } + newListByScopePager := m.newListByScopePager.get(req) + if newListByScopePager == nil { + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/locks` + 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) + } + qp := req.URL.Query() + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + var options *armlocks.ManagementLocksClientListByScopeOptions + if filterParam != nil { + options = &armlocks.ManagementLocksClientListByScopeOptions{ + Filter: filterParam, + } + } + resp := m.srv.NewListByScopePager(scopeParam, options) + newListByScopePager = &resp + m.newListByScopePager.add(req, newListByScopePager) + server.PagerResponderInjectNextLinks(newListByScopePager, req, func(page *armlocks.ManagementLocksClientListByScopeResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListByScopePager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + m.newListByScopePager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListByScopePager) { + m.newListByScopePager.remove(req) + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armlocks/fake/server_factory.go b/sdk/resourcemanager/resources/armlocks/fake/server_factory.go new file mode 100644 index 000000000000..e6f9788dcf71 --- /dev/null +++ b/sdk/resourcemanager/resources/armlocks/fake/server_factory.go @@ -0,0 +1,84 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" + "sync" +) + +// ServerFactory is a fake server for instances of the armlocks.ClientFactory type. +type ServerFactory struct { + AuthorizationOperationsServer AuthorizationOperationsServer + ManagementLocksServer ManagementLocksServer +} + +// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. +// The returned ServerFactoryTransport instance is connected to an instance of armlocks.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 armlocks.ClientFactory to instances of ServerFactory. +// Don't use this type directly, use NewServerFactoryTransport instead. +type ServerFactoryTransport struct { + srv *ServerFactory + trMu sync.Mutex + trAuthorizationOperationsServer *AuthorizationOperationsServerTransport + trManagementLocksServer *ManagementLocksServerTransport +} + +// 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 "AuthorizationOperationsClient": + initServer(s, &s.trAuthorizationOperationsServer, func() *AuthorizationOperationsServerTransport { + return NewAuthorizationOperationsServerTransport(&s.srv.AuthorizationOperationsServer) + }) + resp, err = s.trAuthorizationOperationsServer.Do(req) + case "ManagementLocksClient": + initServer(s, &s.trManagementLocksServer, func() *ManagementLocksServerTransport { + return NewManagementLocksServerTransport(&s.srv.ManagementLocksServer) + }) + resp, err = s.trManagementLocksServer.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/resources/armlocks/fake/time_rfc3339.go b/sdk/resourcemanager/resources/armlocks/fake/time_rfc3339.go new file mode 100644 index 000000000000..b0535a7b63e6 --- /dev/null +++ b/sdk/resourcemanager/resources/armlocks/fake/time_rfc3339.go @@ -0,0 +1,86 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "regexp" + "strings" + "time" +) + +// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. +var tzOffsetRegex = regexp.MustCompile(`(Z|z|\+|-)(\d+:\d+)*"*$`) + +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +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 { + layout := utcDateTimeJSON + if tzOffsetRegex.Match(data) { + layout = dateTimeJSON + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime + if tzOffsetRegex.Match(data) { + layout = time.RFC3339Nano + } + 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 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 || strings.EqualFold(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/resources/armlocks/go.mod b/sdk/resourcemanager/resources/armlocks/go.mod index 0143ca903aae..32820e7deb4a 100644 --- a/sdk/resourcemanager/resources/armlocks/go.mod +++ b/sdk/resourcemanager/resources/armlocks/go.mod @@ -3,19 +3,19 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armlocks go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect - github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 // indirect - github.com/golang-jwt/jwt/v4 v4.5.0 // indirect - github.com/google/uuid v1.3.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect + github.com/golang-jwt/jwt/v5 v5.0.0 // indirect + github.com/google/uuid v1.3.1 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect - golang.org/x/crypto v0.6.0 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect ) diff --git a/sdk/resourcemanager/resources/armlocks/go.sum b/sdk/resourcemanager/resources/armlocks/go.sum index 8ba445a8c4da..7985f1da436f 100644 --- a/sdk/resourcemanager/resources/armlocks/go.sum +++ b/sdk/resourcemanager/resources/armlocks/go.sum @@ -1,31 +1,31 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 h1:rTnT/Jrcm+figWlYz4Ixzt0SJVR2cMC8lvZcimipiEY= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0/go.mod h1:ON4tFdPTwRcgWEaVDrN3584Ef+b7GgSJaXxe5fW9t4M= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 h1:uqM+VoHjVH6zdlkLF2b6O0ZANcHoj3rO0PoQ3jglUJA= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2/go.mod h1:twTKAa1E6hLmSDjLhaCkbTMQKc7p/rNLU40rLxGEOCI= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 h1:leh5DwKv6Ihwi+h60uHtn6UWAxBbZ0q8DwQVMzf61zw= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= -github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 h1:UE9n9rkJF62ArLb1F3DEjRt8O3jLwMWdSoypKV4f3MU= -github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 h1:fb8kj/Dh4CSwgsOzHeZY4Xh68cFVbzXx+ONXGMY//4w= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0/go.mod h1:uReU2sSxZExRPBAg3qKzmAucSi51+SP1OhohieR821Q= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 h1:BMAjVKJM0U/CYF27gA0ZMmXGkOcvfFtD0oHVZ1TIPRI= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0/go.mod h1:1fXstnBMas5kzG+S3q8UoJcmyU6nUeunJcMDHcRYHhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 h1:WpB/QDNLpMw72xHJc34BNNykqSOeEJDAWkhf0u12/Jk= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= -github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= -github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= +github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/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-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc= -golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/sdk/resourcemanager/resources/armlocks/managementlocks_client.go b/sdk/resourcemanager/resources/armlocks/managementlocks_client.go index 1c0547445fa5..18e526b25d0c 100644 --- a/sdk/resourcemanager/resources/armlocks/managementlocks_client.go +++ b/sdk/resourcemanager/resources/armlocks/managementlocks_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armlocks @@ -33,7 +32,7 @@ type ManagementLocksClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewManagementLocksClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ManagementLocksClient, error) { - cl, err := arm.NewClient(moduleName+".ManagementLocksClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -57,18 +56,25 @@ func NewManagementLocksClient(subscriptionID string, credential azcore.TokenCred // - options - ManagementLocksClientCreateOrUpdateAtResourceGroupLevelOptions contains the optional parameters for the ManagementLocksClient.CreateOrUpdateAtResourceGroupLevel // method. func (client *ManagementLocksClient) CreateOrUpdateAtResourceGroupLevel(ctx context.Context, resourceGroupName string, lockName string, parameters ManagementLockObject, options *ManagementLocksClientCreateOrUpdateAtResourceGroupLevelOptions) (ManagementLocksClientCreateOrUpdateAtResourceGroupLevelResponse, error) { + var err error + const operationName = "ManagementLocksClient.CreateOrUpdateAtResourceGroupLevel" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateAtResourceGroupLevelCreateRequest(ctx, resourceGroupName, lockName, parameters, options) if err != nil { return ManagementLocksClientCreateOrUpdateAtResourceGroupLevelResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementLocksClientCreateOrUpdateAtResourceGroupLevelResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return ManagementLocksClientCreateOrUpdateAtResourceGroupLevelResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return ManagementLocksClientCreateOrUpdateAtResourceGroupLevelResponse{}, err } - return client.createOrUpdateAtResourceGroupLevelHandleResponse(resp) + resp, err := client.createOrUpdateAtResourceGroupLevelHandleResponse(httpResp) + return resp, err } // createOrUpdateAtResourceGroupLevelCreateRequest creates the CreateOrUpdateAtResourceGroupLevel request. @@ -94,7 +100,10 @@ func (client *ManagementLocksClient) createOrUpdateAtResourceGroupLevelCreateReq reqQP.Set("api-version", "2020-05-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // createOrUpdateAtResourceGroupLevelHandleResponse handles the CreateOrUpdateAtResourceGroupLevel response. @@ -123,18 +132,25 @@ func (client *ManagementLocksClient) createOrUpdateAtResourceGroupLevelHandleRes // - options - ManagementLocksClientCreateOrUpdateAtResourceLevelOptions contains the optional parameters for the ManagementLocksClient.CreateOrUpdateAtResourceLevel // method. func (client *ManagementLocksClient) CreateOrUpdateAtResourceLevel(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, lockName string, parameters ManagementLockObject, options *ManagementLocksClientCreateOrUpdateAtResourceLevelOptions) (ManagementLocksClientCreateOrUpdateAtResourceLevelResponse, error) { + var err error + const operationName = "ManagementLocksClient.CreateOrUpdateAtResourceLevel" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateAtResourceLevelCreateRequest(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, lockName, parameters, options) if err != nil { return ManagementLocksClientCreateOrUpdateAtResourceLevelResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementLocksClientCreateOrUpdateAtResourceLevelResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return ManagementLocksClientCreateOrUpdateAtResourceLevelResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return ManagementLocksClientCreateOrUpdateAtResourceLevelResponse{}, err } - return client.createOrUpdateAtResourceLevelHandleResponse(resp) + resp, err := client.createOrUpdateAtResourceLevelHandleResponse(httpResp) + return resp, err } // createOrUpdateAtResourceLevelCreateRequest creates the CreateOrUpdateAtResourceLevel request. @@ -170,7 +186,10 @@ func (client *ManagementLocksClient) createOrUpdateAtResourceLevelCreateRequest( reqQP.Set("api-version", "2020-05-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // createOrUpdateAtResourceLevelHandleResponse handles the CreateOrUpdateAtResourceLevel response. @@ -194,18 +213,25 @@ func (client *ManagementLocksClient) createOrUpdateAtResourceLevelHandleResponse // - options - ManagementLocksClientCreateOrUpdateAtSubscriptionLevelOptions contains the optional parameters for the ManagementLocksClient.CreateOrUpdateAtSubscriptionLevel // method. func (client *ManagementLocksClient) CreateOrUpdateAtSubscriptionLevel(ctx context.Context, lockName string, parameters ManagementLockObject, options *ManagementLocksClientCreateOrUpdateAtSubscriptionLevelOptions) (ManagementLocksClientCreateOrUpdateAtSubscriptionLevelResponse, error) { + var err error + const operationName = "ManagementLocksClient.CreateOrUpdateAtSubscriptionLevel" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateAtSubscriptionLevelCreateRequest(ctx, lockName, parameters, options) if err != nil { return ManagementLocksClientCreateOrUpdateAtSubscriptionLevelResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementLocksClientCreateOrUpdateAtSubscriptionLevelResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return ManagementLocksClientCreateOrUpdateAtSubscriptionLevelResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return ManagementLocksClientCreateOrUpdateAtSubscriptionLevelResponse{}, err } - return client.createOrUpdateAtSubscriptionLevelHandleResponse(resp) + resp, err := client.createOrUpdateAtSubscriptionLevelHandleResponse(httpResp) + return resp, err } // createOrUpdateAtSubscriptionLevelCreateRequest creates the CreateOrUpdateAtSubscriptionLevel request. @@ -227,7 +253,10 @@ func (client *ManagementLocksClient) createOrUpdateAtSubscriptionLevelCreateRequ reqQP.Set("api-version", "2020-05-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // createOrUpdateAtSubscriptionLevelHandleResponse handles the CreateOrUpdateAtSubscriptionLevel response. @@ -253,18 +282,25 @@ func (client *ManagementLocksClient) createOrUpdateAtSubscriptionLevelHandleResp // - options - ManagementLocksClientCreateOrUpdateByScopeOptions contains the optional parameters for the ManagementLocksClient.CreateOrUpdateByScope // method. func (client *ManagementLocksClient) CreateOrUpdateByScope(ctx context.Context, scope string, lockName string, parameters ManagementLockObject, options *ManagementLocksClientCreateOrUpdateByScopeOptions) (ManagementLocksClientCreateOrUpdateByScopeResponse, error) { + var err error + const operationName = "ManagementLocksClient.CreateOrUpdateByScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateByScopeCreateRequest(ctx, scope, lockName, parameters, options) if err != nil { return ManagementLocksClientCreateOrUpdateByScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementLocksClientCreateOrUpdateByScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return ManagementLocksClientCreateOrUpdateByScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return ManagementLocksClientCreateOrUpdateByScopeResponse{}, err } - return client.createOrUpdateByScopeHandleResponse(resp) + resp, err := client.createOrUpdateByScopeHandleResponse(httpResp) + return resp, err } // createOrUpdateByScopeCreateRequest creates the CreateOrUpdateByScope request. @@ -286,7 +322,10 @@ func (client *ManagementLocksClient) createOrUpdateByScopeCreateRequest(ctx cont reqQP.Set("api-version", "2020-05-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // createOrUpdateByScopeHandleResponse handles the CreateOrUpdateByScope response. @@ -309,16 +348,22 @@ func (client *ManagementLocksClient) createOrUpdateByScopeHandleResponse(resp *h // - options - ManagementLocksClientDeleteAtResourceGroupLevelOptions contains the optional parameters for the ManagementLocksClient.DeleteAtResourceGroupLevel // method. func (client *ManagementLocksClient) DeleteAtResourceGroupLevel(ctx context.Context, resourceGroupName string, lockName string, options *ManagementLocksClientDeleteAtResourceGroupLevelOptions) (ManagementLocksClientDeleteAtResourceGroupLevelResponse, error) { + var err error + const operationName = "ManagementLocksClient.DeleteAtResourceGroupLevel" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAtResourceGroupLevelCreateRequest(ctx, resourceGroupName, lockName, options) if err != nil { return ManagementLocksClientDeleteAtResourceGroupLevelResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementLocksClientDeleteAtResourceGroupLevelResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return ManagementLocksClientDeleteAtResourceGroupLevelResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return ManagementLocksClientDeleteAtResourceGroupLevelResponse{}, err } return ManagementLocksClientDeleteAtResourceGroupLevelResponse{}, nil } @@ -364,16 +409,22 @@ func (client *ManagementLocksClient) deleteAtResourceGroupLevelCreateRequest(ctx // - options - ManagementLocksClientDeleteAtResourceLevelOptions contains the optional parameters for the ManagementLocksClient.DeleteAtResourceLevel // method. func (client *ManagementLocksClient) DeleteAtResourceLevel(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, lockName string, options *ManagementLocksClientDeleteAtResourceLevelOptions) (ManagementLocksClientDeleteAtResourceLevelResponse, error) { + var err error + const operationName = "ManagementLocksClient.DeleteAtResourceLevel" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAtResourceLevelCreateRequest(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, lockName, options) if err != nil { return ManagementLocksClientDeleteAtResourceLevelResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementLocksClientDeleteAtResourceLevelResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return ManagementLocksClientDeleteAtResourceLevelResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return ManagementLocksClientDeleteAtResourceLevelResponse{}, err } return ManagementLocksClientDeleteAtResourceLevelResponse{}, nil } @@ -424,16 +475,22 @@ func (client *ManagementLocksClient) deleteAtResourceLevelCreateRequest(ctx cont // - options - ManagementLocksClientDeleteAtSubscriptionLevelOptions contains the optional parameters for the ManagementLocksClient.DeleteAtSubscriptionLevel // method. func (client *ManagementLocksClient) DeleteAtSubscriptionLevel(ctx context.Context, lockName string, options *ManagementLocksClientDeleteAtSubscriptionLevelOptions) (ManagementLocksClientDeleteAtSubscriptionLevelResponse, error) { + var err error + const operationName = "ManagementLocksClient.DeleteAtSubscriptionLevel" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAtSubscriptionLevelCreateRequest(ctx, lockName, options) if err != nil { return ManagementLocksClientDeleteAtSubscriptionLevelResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementLocksClientDeleteAtSubscriptionLevelResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return ManagementLocksClientDeleteAtSubscriptionLevelResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return ManagementLocksClientDeleteAtSubscriptionLevelResponse{}, err } return ManagementLocksClientDeleteAtSubscriptionLevelResponse{}, nil } @@ -469,16 +526,22 @@ func (client *ManagementLocksClient) deleteAtSubscriptionLevelCreateRequest(ctx // - options - ManagementLocksClientDeleteByScopeOptions contains the optional parameters for the ManagementLocksClient.DeleteByScope // method. func (client *ManagementLocksClient) DeleteByScope(ctx context.Context, scope string, lockName string, options *ManagementLocksClientDeleteByScopeOptions) (ManagementLocksClientDeleteByScopeResponse, error) { + var err error + const operationName = "ManagementLocksClient.DeleteByScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteByScopeCreateRequest(ctx, scope, lockName, options) if err != nil { return ManagementLocksClientDeleteByScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementLocksClientDeleteByScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return ManagementLocksClientDeleteByScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return ManagementLocksClientDeleteByScopeResponse{}, err } return ManagementLocksClientDeleteByScopeResponse{}, nil } @@ -514,18 +577,25 @@ func (client *ManagementLocksClient) deleteByScopeCreateRequest(ctx context.Cont // - options - ManagementLocksClientGetAtResourceGroupLevelOptions contains the optional parameters for the ManagementLocksClient.GetAtResourceGroupLevel // method. func (client *ManagementLocksClient) GetAtResourceGroupLevel(ctx context.Context, resourceGroupName string, lockName string, options *ManagementLocksClientGetAtResourceGroupLevelOptions) (ManagementLocksClientGetAtResourceGroupLevelResponse, error) { + var err error + const operationName = "ManagementLocksClient.GetAtResourceGroupLevel" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtResourceGroupLevelCreateRequest(ctx, resourceGroupName, lockName, options) if err != nil { return ManagementLocksClientGetAtResourceGroupLevelResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementLocksClientGetAtResourceGroupLevelResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementLocksClientGetAtResourceGroupLevelResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ManagementLocksClientGetAtResourceGroupLevelResponse{}, err } - return client.getAtResourceGroupLevelHandleResponse(resp) + resp, err := client.getAtResourceGroupLevelHandleResponse(httpResp) + return resp, err } // getAtResourceGroupLevelCreateRequest creates the GetAtResourceGroupLevel request. @@ -576,18 +646,25 @@ func (client *ManagementLocksClient) getAtResourceGroupLevelHandleResponse(resp // - options - ManagementLocksClientGetAtResourceLevelOptions contains the optional parameters for the ManagementLocksClient.GetAtResourceLevel // method. func (client *ManagementLocksClient) GetAtResourceLevel(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, lockName string, options *ManagementLocksClientGetAtResourceLevelOptions) (ManagementLocksClientGetAtResourceLevelResponse, error) { + var err error + const operationName = "ManagementLocksClient.GetAtResourceLevel" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtResourceLevelCreateRequest(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, lockName, options) if err != nil { return ManagementLocksClientGetAtResourceLevelResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementLocksClientGetAtResourceLevelResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementLocksClientGetAtResourceLevelResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ManagementLocksClientGetAtResourceLevelResponse{}, err } - return client.getAtResourceLevelHandleResponse(resp) + resp, err := client.getAtResourceLevelHandleResponse(httpResp) + return resp, err } // getAtResourceLevelCreateRequest creates the GetAtResourceLevel request. @@ -643,18 +720,25 @@ func (client *ManagementLocksClient) getAtResourceLevelHandleResponse(resp *http // - options - ManagementLocksClientGetAtSubscriptionLevelOptions contains the optional parameters for the ManagementLocksClient.GetAtSubscriptionLevel // method. func (client *ManagementLocksClient) GetAtSubscriptionLevel(ctx context.Context, lockName string, options *ManagementLocksClientGetAtSubscriptionLevelOptions) (ManagementLocksClientGetAtSubscriptionLevelResponse, error) { + var err error + const operationName = "ManagementLocksClient.GetAtSubscriptionLevel" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtSubscriptionLevelCreateRequest(ctx, lockName, options) if err != nil { return ManagementLocksClientGetAtSubscriptionLevelResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementLocksClientGetAtSubscriptionLevelResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementLocksClientGetAtSubscriptionLevelResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ManagementLocksClientGetAtSubscriptionLevelResponse{}, err } - return client.getAtSubscriptionLevelHandleResponse(resp) + resp, err := client.getAtSubscriptionLevelHandleResponse(httpResp) + return resp, err } // getAtSubscriptionLevelCreateRequest creates the GetAtSubscriptionLevel request. @@ -697,18 +781,25 @@ func (client *ManagementLocksClient) getAtSubscriptionLevelHandleResponse(resp * // - options - ManagementLocksClientGetByScopeOptions contains the optional parameters for the ManagementLocksClient.GetByScope // method. func (client *ManagementLocksClient) GetByScope(ctx context.Context, scope string, lockName string, options *ManagementLocksClientGetByScopeOptions) (ManagementLocksClientGetByScopeResponse, error) { + var err error + const operationName = "ManagementLocksClient.GetByScope" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getByScopeCreateRequest(ctx, scope, lockName, options) if err != nil { return ManagementLocksClientGetByScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ManagementLocksClientGetByScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementLocksClientGetByScopeResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ManagementLocksClientGetByScopeResponse{}, err } - return client.getByScopeHandleResponse(resp) + resp, err := client.getByScopeHandleResponse(httpResp) + return resp, err } // getByScopeCreateRequest creates the GetByScope request. @@ -754,25 +845,20 @@ func (client *ManagementLocksClient) NewListAtResourceGroupLevelPager(resourceGr return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ManagementLocksClientListAtResourceGroupLevelResponse) (ManagementLocksClientListAtResourceGroupLevelResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtResourceGroupLevelCreateRequest(ctx, resourceGroupName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return ManagementLocksClientListAtResourceGroupLevelResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ManagementLocksClient.NewListAtResourceGroupLevelPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listAtResourceGroupLevelCreateRequest(ctx, resourceGroupName, options) + }, nil) if err != nil { return ManagementLocksClientListAtResourceGroupLevelResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementLocksClientListAtResourceGroupLevelResponse{}, runtime.NewResponseError(resp) - } return client.listAtResourceGroupLevelHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -826,25 +912,20 @@ func (client *ManagementLocksClient) NewListAtResourceLevelPager(resourceGroupNa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ManagementLocksClientListAtResourceLevelResponse) (ManagementLocksClientListAtResourceLevelResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtResourceLevelCreateRequest(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return ManagementLocksClientListAtResourceLevelResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ManagementLocksClient.NewListAtResourceLevelPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listAtResourceLevelCreateRequest(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, options) + }, nil) if err != nil { return ManagementLocksClientListAtResourceLevelResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementLocksClientListAtResourceLevelResponse{}, runtime.NewResponseError(resp) - } return client.listAtResourceLevelHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -903,25 +984,20 @@ func (client *ManagementLocksClient) NewListAtSubscriptionLevelPager(options *Ma return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ManagementLocksClientListAtSubscriptionLevelResponse) (ManagementLocksClientListAtSubscriptionLevelResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtSubscriptionLevelCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return ManagementLocksClientListAtSubscriptionLevelResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ManagementLocksClient.NewListAtSubscriptionLevelPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listAtSubscriptionLevelCreateRequest(ctx, options) + }, nil) if err != nil { return ManagementLocksClientListAtSubscriptionLevelResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementLocksClientListAtSubscriptionLevelResponse{}, runtime.NewResponseError(resp) - } return client.listAtSubscriptionLevelHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -971,25 +1047,20 @@ func (client *ManagementLocksClient) NewListByScopePager(scope string, options * return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ManagementLocksClientListByScopeResponse) (ManagementLocksClientListByScopeResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listByScopeCreateRequest(ctx, scope, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ManagementLocksClient.NewListByScopePager") + 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.listByScopeCreateRequest(ctx, scope, options) + }, nil) if err != nil { return ManagementLocksClientListByScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ManagementLocksClientListByScopeResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ManagementLocksClientListByScopeResponse{}, runtime.NewResponseError(resp) - } return client.listByScopeHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armlocks/models.go b/sdk/resourcemanager/resources/armlocks/models.go index a8cdc4bf9873..59b3b07c7d91 100644 --- a/sdk/resourcemanager/resources/armlocks/models.go +++ b/sdk/resourcemanager/resources/armlocks/models.go @@ -3,20 +3,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armlocks import "time" -// AuthorizationOperationsClientListOptions contains the optional parameters for the AuthorizationOperationsClient.NewListPager -// method. -type AuthorizationOperationsClientListOptions struct { - // placeholder for future optional parameters -} - // ErrorAdditionalInfo - The resource management error additional info. type ErrorAdditionalInfo struct { // READ-ONLY; The additional info. @@ -98,105 +91,6 @@ type ManagementLockProperties struct { Owners []*ManagementLockOwner } -// ManagementLocksClientCreateOrUpdateAtResourceGroupLevelOptions contains the optional parameters for the ManagementLocksClient.CreateOrUpdateAtResourceGroupLevel -// method. -type ManagementLocksClientCreateOrUpdateAtResourceGroupLevelOptions struct { - // placeholder for future optional parameters -} - -// ManagementLocksClientCreateOrUpdateAtResourceLevelOptions contains the optional parameters for the ManagementLocksClient.CreateOrUpdateAtResourceLevel -// method. -type ManagementLocksClientCreateOrUpdateAtResourceLevelOptions struct { - // placeholder for future optional parameters -} - -// ManagementLocksClientCreateOrUpdateAtSubscriptionLevelOptions contains the optional parameters for the ManagementLocksClient.CreateOrUpdateAtSubscriptionLevel -// method. -type ManagementLocksClientCreateOrUpdateAtSubscriptionLevelOptions struct { - // placeholder for future optional parameters -} - -// ManagementLocksClientCreateOrUpdateByScopeOptions contains the optional parameters for the ManagementLocksClient.CreateOrUpdateByScope -// method. -type ManagementLocksClientCreateOrUpdateByScopeOptions struct { - // placeholder for future optional parameters -} - -// ManagementLocksClientDeleteAtResourceGroupLevelOptions contains the optional parameters for the ManagementLocksClient.DeleteAtResourceGroupLevel -// method. -type ManagementLocksClientDeleteAtResourceGroupLevelOptions struct { - // placeholder for future optional parameters -} - -// ManagementLocksClientDeleteAtResourceLevelOptions contains the optional parameters for the ManagementLocksClient.DeleteAtResourceLevel -// method. -type ManagementLocksClientDeleteAtResourceLevelOptions struct { - // placeholder for future optional parameters -} - -// ManagementLocksClientDeleteAtSubscriptionLevelOptions contains the optional parameters for the ManagementLocksClient.DeleteAtSubscriptionLevel -// method. -type ManagementLocksClientDeleteAtSubscriptionLevelOptions struct { - // placeholder for future optional parameters -} - -// ManagementLocksClientDeleteByScopeOptions contains the optional parameters for the ManagementLocksClient.DeleteByScope -// method. -type ManagementLocksClientDeleteByScopeOptions struct { - // placeholder for future optional parameters -} - -// ManagementLocksClientGetAtResourceGroupLevelOptions contains the optional parameters for the ManagementLocksClient.GetAtResourceGroupLevel -// method. -type ManagementLocksClientGetAtResourceGroupLevelOptions struct { - // placeholder for future optional parameters -} - -// ManagementLocksClientGetAtResourceLevelOptions contains the optional parameters for the ManagementLocksClient.GetAtResourceLevel -// method. -type ManagementLocksClientGetAtResourceLevelOptions struct { - // placeholder for future optional parameters -} - -// ManagementLocksClientGetAtSubscriptionLevelOptions contains the optional parameters for the ManagementLocksClient.GetAtSubscriptionLevel -// method. -type ManagementLocksClientGetAtSubscriptionLevelOptions struct { - // placeholder for future optional parameters -} - -// ManagementLocksClientGetByScopeOptions contains the optional parameters for the ManagementLocksClient.GetByScope method. -type ManagementLocksClientGetByScopeOptions struct { - // placeholder for future optional parameters -} - -// ManagementLocksClientListAtResourceGroupLevelOptions contains the optional parameters for the ManagementLocksClient.NewListAtResourceGroupLevelPager -// method. -type ManagementLocksClientListAtResourceGroupLevelOptions struct { - // The filter to apply on the operation. - Filter *string -} - -// ManagementLocksClientListAtResourceLevelOptions contains the optional parameters for the ManagementLocksClient.NewListAtResourceLevelPager -// method. -type ManagementLocksClientListAtResourceLevelOptions struct { - // The filter to apply on the operation. - Filter *string -} - -// ManagementLocksClientListAtSubscriptionLevelOptions contains the optional parameters for the ManagementLocksClient.NewListAtSubscriptionLevelPager -// method. -type ManagementLocksClientListAtSubscriptionLevelOptions struct { - // The filter to apply on the operation. - Filter *string -} - -// ManagementLocksClientListByScopeOptions contains the optional parameters for the ManagementLocksClient.NewListByScopePager -// method. -type ManagementLocksClientListByScopeOptions struct { - // The filter to apply on the operation. - Filter *string -} - // Operation - Microsoft.Authorization operation type Operation struct { // The object that represents the operation. diff --git a/sdk/resourcemanager/resources/armlocks/models_serde.go b/sdk/resourcemanager/resources/armlocks/models_serde.go index b6a3120a1472..238ddc6ac501 100644 --- a/sdk/resourcemanager/resources/armlocks/models_serde.go +++ b/sdk/resourcemanager/resources/armlocks/models_serde.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armlocks @@ -353,10 +352,10 @@ func (o *OperationListResult) UnmarshalJSON(data []byte) error { // MarshalJSON implements the json.Marshaller interface for type SystemData. func (s SystemData) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populateTimeRFC3339(objectMap, "createdAt", s.CreatedAt) + populateDateTimeRFC3339(objectMap, "createdAt", s.CreatedAt) populate(objectMap, "createdBy", s.CreatedBy) populate(objectMap, "createdByType", s.CreatedByType) - populateTimeRFC3339(objectMap, "lastModifiedAt", s.LastModifiedAt) + populateDateTimeRFC3339(objectMap, "lastModifiedAt", s.LastModifiedAt) populate(objectMap, "lastModifiedBy", s.LastModifiedBy) populate(objectMap, "lastModifiedByType", s.LastModifiedByType) return json.Marshal(objectMap) @@ -372,7 +371,7 @@ func (s *SystemData) UnmarshalJSON(data []byte) error { var err error switch key { case "createdAt": - err = unpopulateTimeRFC3339(val, "CreatedAt", &s.CreatedAt) + err = unpopulateDateTimeRFC3339(val, "CreatedAt", &s.CreatedAt) delete(rawMsg, key) case "createdBy": err = unpopulate(val, "CreatedBy", &s.CreatedBy) @@ -381,7 +380,7 @@ func (s *SystemData) UnmarshalJSON(data []byte) error { err = unpopulate(val, "CreatedByType", &s.CreatedByType) delete(rawMsg, key) case "lastModifiedAt": - err = unpopulateTimeRFC3339(val, "LastModifiedAt", &s.LastModifiedAt) + err = unpopulateDateTimeRFC3339(val, "LastModifiedAt", &s.LastModifiedAt) delete(rawMsg, key) case "lastModifiedBy": err = unpopulate(val, "LastModifiedBy", &s.LastModifiedBy) diff --git a/sdk/resourcemanager/resources/armlocks/options.go b/sdk/resourcemanager/resources/armlocks/options.go new file mode 100644 index 000000000000..2e4b37ceb684 --- /dev/null +++ b/sdk/resourcemanager/resources/armlocks/options.go @@ -0,0 +1,114 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armlocks + +// AuthorizationOperationsClientListOptions contains the optional parameters for the AuthorizationOperationsClient.NewListPager +// method. +type AuthorizationOperationsClientListOptions struct { + // placeholder for future optional parameters +} + +// ManagementLocksClientCreateOrUpdateAtResourceGroupLevelOptions contains the optional parameters for the ManagementLocksClient.CreateOrUpdateAtResourceGroupLevel +// method. +type ManagementLocksClientCreateOrUpdateAtResourceGroupLevelOptions struct { + // placeholder for future optional parameters +} + +// ManagementLocksClientCreateOrUpdateAtResourceLevelOptions contains the optional parameters for the ManagementLocksClient.CreateOrUpdateAtResourceLevel +// method. +type ManagementLocksClientCreateOrUpdateAtResourceLevelOptions struct { + // placeholder for future optional parameters +} + +// ManagementLocksClientCreateOrUpdateAtSubscriptionLevelOptions contains the optional parameters for the ManagementLocksClient.CreateOrUpdateAtSubscriptionLevel +// method. +type ManagementLocksClientCreateOrUpdateAtSubscriptionLevelOptions struct { + // placeholder for future optional parameters +} + +// ManagementLocksClientCreateOrUpdateByScopeOptions contains the optional parameters for the ManagementLocksClient.CreateOrUpdateByScope +// method. +type ManagementLocksClientCreateOrUpdateByScopeOptions struct { + // placeholder for future optional parameters +} + +// ManagementLocksClientDeleteAtResourceGroupLevelOptions contains the optional parameters for the ManagementLocksClient.DeleteAtResourceGroupLevel +// method. +type ManagementLocksClientDeleteAtResourceGroupLevelOptions struct { + // placeholder for future optional parameters +} + +// ManagementLocksClientDeleteAtResourceLevelOptions contains the optional parameters for the ManagementLocksClient.DeleteAtResourceLevel +// method. +type ManagementLocksClientDeleteAtResourceLevelOptions struct { + // placeholder for future optional parameters +} + +// ManagementLocksClientDeleteAtSubscriptionLevelOptions contains the optional parameters for the ManagementLocksClient.DeleteAtSubscriptionLevel +// method. +type ManagementLocksClientDeleteAtSubscriptionLevelOptions struct { + // placeholder for future optional parameters +} + +// ManagementLocksClientDeleteByScopeOptions contains the optional parameters for the ManagementLocksClient.DeleteByScope +// method. +type ManagementLocksClientDeleteByScopeOptions struct { + // placeholder for future optional parameters +} + +// ManagementLocksClientGetAtResourceGroupLevelOptions contains the optional parameters for the ManagementLocksClient.GetAtResourceGroupLevel +// method. +type ManagementLocksClientGetAtResourceGroupLevelOptions struct { + // placeholder for future optional parameters +} + +// ManagementLocksClientGetAtResourceLevelOptions contains the optional parameters for the ManagementLocksClient.GetAtResourceLevel +// method. +type ManagementLocksClientGetAtResourceLevelOptions struct { + // placeholder for future optional parameters +} + +// ManagementLocksClientGetAtSubscriptionLevelOptions contains the optional parameters for the ManagementLocksClient.GetAtSubscriptionLevel +// method. +type ManagementLocksClientGetAtSubscriptionLevelOptions struct { + // placeholder for future optional parameters +} + +// ManagementLocksClientGetByScopeOptions contains the optional parameters for the ManagementLocksClient.GetByScope method. +type ManagementLocksClientGetByScopeOptions struct { + // placeholder for future optional parameters +} + +// ManagementLocksClientListAtResourceGroupLevelOptions contains the optional parameters for the ManagementLocksClient.NewListAtResourceGroupLevelPager +// method. +type ManagementLocksClientListAtResourceGroupLevelOptions struct { + // The filter to apply on the operation. + Filter *string +} + +// ManagementLocksClientListAtResourceLevelOptions contains the optional parameters for the ManagementLocksClient.NewListAtResourceLevelPager +// method. +type ManagementLocksClientListAtResourceLevelOptions struct { + // The filter to apply on the operation. + Filter *string +} + +// ManagementLocksClientListAtSubscriptionLevelOptions contains the optional parameters for the ManagementLocksClient.NewListAtSubscriptionLevelPager +// method. +type ManagementLocksClientListAtSubscriptionLevelOptions struct { + // The filter to apply on the operation. + Filter *string +} + +// ManagementLocksClientListByScopeOptions contains the optional parameters for the ManagementLocksClient.NewListByScopePager +// method. +type ManagementLocksClientListByScopeOptions struct { + // The filter to apply on the operation. + Filter *string +} diff --git a/sdk/resourcemanager/resources/armlocks/response_types.go b/sdk/resourcemanager/resources/armlocks/response_types.go index 91d42f455b70..15ee181e7c0e 100644 --- a/sdk/resourcemanager/resources/armlocks/response_types.go +++ b/sdk/resourcemanager/resources/armlocks/response_types.go @@ -3,34 +3,39 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armlocks // AuthorizationOperationsClientListResponse contains the response from method AuthorizationOperationsClient.NewListPager. type AuthorizationOperationsClientListResponse struct { + // Result of the request to list Microsoft.Authorization operations. It contains a list of operations and a URL link to get + // the next set of results. OperationListResult } // ManagementLocksClientCreateOrUpdateAtResourceGroupLevelResponse contains the response from method ManagementLocksClient.CreateOrUpdateAtResourceGroupLevel. type ManagementLocksClientCreateOrUpdateAtResourceGroupLevelResponse struct { + // The lock information. ManagementLockObject } // ManagementLocksClientCreateOrUpdateAtResourceLevelResponse contains the response from method ManagementLocksClient.CreateOrUpdateAtResourceLevel. type ManagementLocksClientCreateOrUpdateAtResourceLevelResponse struct { + // The lock information. ManagementLockObject } // ManagementLocksClientCreateOrUpdateAtSubscriptionLevelResponse contains the response from method ManagementLocksClient.CreateOrUpdateAtSubscriptionLevel. type ManagementLocksClientCreateOrUpdateAtSubscriptionLevelResponse struct { + // The lock information. ManagementLockObject } // ManagementLocksClientCreateOrUpdateByScopeResponse contains the response from method ManagementLocksClient.CreateOrUpdateByScope. type ManagementLocksClientCreateOrUpdateByScopeResponse struct { + // The lock information. ManagementLockObject } @@ -56,40 +61,48 @@ type ManagementLocksClientDeleteByScopeResponse struct { // ManagementLocksClientGetAtResourceGroupLevelResponse contains the response from method ManagementLocksClient.GetAtResourceGroupLevel. type ManagementLocksClientGetAtResourceGroupLevelResponse struct { + // The lock information. ManagementLockObject } // ManagementLocksClientGetAtResourceLevelResponse contains the response from method ManagementLocksClient.GetAtResourceLevel. type ManagementLocksClientGetAtResourceLevelResponse struct { + // The lock information. ManagementLockObject } // ManagementLocksClientGetAtSubscriptionLevelResponse contains the response from method ManagementLocksClient.GetAtSubscriptionLevel. type ManagementLocksClientGetAtSubscriptionLevelResponse struct { + // The lock information. ManagementLockObject } // ManagementLocksClientGetByScopeResponse contains the response from method ManagementLocksClient.GetByScope. type ManagementLocksClientGetByScopeResponse struct { + // The lock information. ManagementLockObject } // ManagementLocksClientListAtResourceGroupLevelResponse contains the response from method ManagementLocksClient.NewListAtResourceGroupLevelPager. type ManagementLocksClientListAtResourceGroupLevelResponse struct { + // The list of locks. ManagementLockListResult } // ManagementLocksClientListAtResourceLevelResponse contains the response from method ManagementLocksClient.NewListAtResourceLevelPager. type ManagementLocksClientListAtResourceLevelResponse struct { + // The list of locks. ManagementLockListResult } // ManagementLocksClientListAtSubscriptionLevelResponse contains the response from method ManagementLocksClient.NewListAtSubscriptionLevelPager. type ManagementLocksClientListAtSubscriptionLevelResponse struct { + // The list of locks. ManagementLockListResult } // ManagementLocksClientListByScopeResponse contains the response from method ManagementLocksClient.NewListByScopePager. type ManagementLocksClientListByScopeResponse struct { + // The list of locks. ManagementLockListResult } diff --git a/sdk/resourcemanager/resources/armlocks/time_rfc3339.go b/sdk/resourcemanager/resources/armlocks/time_rfc3339.go index 631fbd0292d6..043a6952fc7a 100644 --- a/sdk/resourcemanager/resources/armlocks/time_rfc3339.go +++ b/sdk/resourcemanager/resources/armlocks/time_rfc3339.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armlocks @@ -19,50 +18,50 @@ import ( "time" ) -const ( - utcLayoutJSON = `"2006-01-02T15:04:05.999999999"` - utcLayout = "2006-01-02T15:04:05.999999999" - rfc3339JSON = `"` + time.RFC3339Nano + `"` -) - // 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+)*"*$`) -type timeRFC3339 time.Time +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +type dateTimeRFC3339 time.Time -func (t timeRFC3339) MarshalJSON() (json []byte, err error) { +func (t dateTimeRFC3339) MarshalJSON() ([]byte, error) { tt := time.Time(t) return tt.MarshalJSON() } -func (t timeRFC3339) MarshalText() (text []byte, err error) { +func (t dateTimeRFC3339) MarshalText() ([]byte, error) { tt := time.Time(t) return tt.MarshalText() } -func (t *timeRFC3339) UnmarshalJSON(data []byte) error { - layout := utcLayoutJSON +func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { + layout := utcDateTimeJSON if tzOffsetRegex.Match(data) { - layout = rfc3339JSON + layout = dateTimeJSON } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) UnmarshalText(data []byte) (err error) { - layout := utcLayout +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime if tzOffsetRegex.Match(data) { layout = time.RFC3339Nano } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) Parse(layout, value string) error { +func (t *dateTimeRFC3339) Parse(layout, value string) error { p, err := time.Parse(layout, strings.ToUpper(value)) - *t = timeRFC3339(p) + *t = dateTimeRFC3339(p) return err } -func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { +func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { if t == nil { return } else if azcore.IsNullValue(t) { @@ -71,14 +70,14 @@ func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { } else if reflect.ValueOf(t).IsNil() { return } - m[k] = (*timeRFC3339)(t) + m[k] = (*dateTimeRFC3339)(t) } -func unpopulateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { +func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { if data == nil || strings.EqualFold(string(data), "null") { return nil } - var aux timeRFC3339 + var aux dateTimeRFC3339 if err := json.Unmarshal(data, &aux); err != nil { return fmt.Errorf("struct field %s: %v", fn, err) } From 3611f6e25673c9f08baae222d5a20788429da28e Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 15:27:30 +0800 Subject: [PATCH 07/18] [Release] sdk/resourcemanager/resources/armmanagedapplications/1.2.0 generation from spec commit: bf204aab860f2eb58a9d346b00d44760f2a9b0a2 --- .../armmanagedapplications/CHANGELOG.md | 6 + .../armmanagedapplications/README.md | 7 + .../application_client.go | 26 +- .../applicationdefinitions_client.go | 158 ++++-- .../applications_client.go | 219 +++++--- .../armmanagedapplications/autorest.md | 2 +- .../armmanagedapplications/client_factory.go | 16 +- .../armmanagedapplications/constants.go | 15 +- .../fake/application_server.go | 96 ++++ .../fake/applicationdefinitions_server.go | 403 ++++++++++++++ .../fake/applications_server.go | 527 ++++++++++++++++++ .../armmanagedapplications/fake/internal.go | 64 +++ .../fake/server_factory.go | 87 +++ .../resources/armmanagedapplications/go.mod | 20 +- .../resources/armmanagedapplications/go.sum | 46 +- .../armmanagedapplications/models.go | 114 +--- .../armmanagedapplications/models_serde.go | 3 +- .../armmanagedapplications/options.go | 120 ++++ .../armmanagedapplications/response_types.go | 18 +- 19 files changed, 1642 insertions(+), 305 deletions(-) create mode 100644 sdk/resourcemanager/resources/armmanagedapplications/fake/application_server.go create mode 100644 sdk/resourcemanager/resources/armmanagedapplications/fake/applicationdefinitions_server.go create mode 100644 sdk/resourcemanager/resources/armmanagedapplications/fake/applications_server.go create mode 100644 sdk/resourcemanager/resources/armmanagedapplications/fake/internal.go create mode 100644 sdk/resourcemanager/resources/armmanagedapplications/fake/server_factory.go create mode 100644 sdk/resourcemanager/resources/armmanagedapplications/options.go diff --git a/sdk/resourcemanager/resources/armmanagedapplications/CHANGELOG.md b/sdk/resourcemanager/resources/armmanagedapplications/CHANGELOG.md index 18f569794de4..2bb309ae12ac 100644 --- a/sdk/resourcemanager/resources/armmanagedapplications/CHANGELOG.md +++ b/sdk/resourcemanager/resources/armmanagedapplications/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 1.2.0 (2023-11-24) +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + + ## 1.1.1 (2023-04-14) ### Bug Fixes diff --git a/sdk/resourcemanager/resources/armmanagedapplications/README.md b/sdk/resourcemanager/resources/armmanagedapplications/README.md index 3a15dda7e67d..1812126f3657 100644 --- a/sdk/resourcemanager/resources/armmanagedapplications/README.md +++ b/sdk/resourcemanager/resources/armmanagedapplications/README.md @@ -60,6 +60,13 @@ A client groups a set of related APIs, providing access to its functionality. C client := clientFactory.NewApplicationClient() ``` +## 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 diff --git a/sdk/resourcemanager/resources/armmanagedapplications/application_client.go b/sdk/resourcemanager/resources/armmanagedapplications/application_client.go index 7c745db1c0f9..97bb7ef77aec 100644 --- a/sdk/resourcemanager/resources/armmanagedapplications/application_client.go +++ b/sdk/resourcemanager/resources/armmanagedapplications/application_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armmanagedapplications @@ -28,7 +27,7 @@ type ApplicationClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewApplicationClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*ApplicationClient, error) { - cl, err := arm.NewClient(moduleName+".ApplicationClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -49,25 +48,20 @@ func (client *ApplicationClient) NewListOperationsPager(options *ApplicationClie return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ApplicationClientListOperationsResponse) (ApplicationClientListOperationsResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listOperationsCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ApplicationClient.NewListOperationsPager") + 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.listOperationsCreateRequest(ctx, options) + }, nil) if err != nil { return ApplicationClientListOperationsResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ApplicationClientListOperationsResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationClientListOperationsResponse{}, runtime.NewResponseError(resp) - } return client.listOperationsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armmanagedapplications/applicationdefinitions_client.go b/sdk/resourcemanager/resources/armmanagedapplications/applicationdefinitions_client.go index 70eb2716ff7d..35f9720d0ab7 100644 --- a/sdk/resourcemanager/resources/armmanagedapplications/applicationdefinitions_client.go +++ b/sdk/resourcemanager/resources/armmanagedapplications/applicationdefinitions_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armmanagedapplications @@ -33,7 +32,7 @@ type ApplicationDefinitionsClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewApplicationDefinitionsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ApplicationDefinitionsClient, error) { - cl, err := arm.NewClient(moduleName+".ApplicationDefinitionsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -59,9 +58,14 @@ func (client *ApplicationDefinitionsClient) BeginCreateOrUpdate(ctx context.Cont if err != nil { return nil, err } - return runtime.NewPoller[ApplicationDefinitionsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationDefinitionsClientCreateOrUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) + return poller, err } else { - return runtime.NewPollerFromResumeToken[ApplicationDefinitionsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ApplicationDefinitionsClientCreateOrUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -70,18 +74,24 @@ func (client *ApplicationDefinitionsClient) BeginCreateOrUpdate(ctx context.Cont // // Generated from API version 2018-06-01 func (client *ApplicationDefinitionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, applicationDefinitionName string, parameters ApplicationDefinition, options *ApplicationDefinitionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationDefinitionsClient.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, applicationDefinitionName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -107,7 +117,10 @@ func (client *ApplicationDefinitionsClient) createOrUpdateCreateRequest(ctx cont reqQP.Set("api-version", "2018-06-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginCreateOrUpdateByID - Creates a new managed application definition. @@ -125,9 +138,14 @@ func (client *ApplicationDefinitionsClient) BeginCreateOrUpdateByID(ctx context. if err != nil { return nil, err } - return runtime.NewPoller[ApplicationDefinitionsClientCreateOrUpdateByIDResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationDefinitionsClientCreateOrUpdateByIDResponse]{ + Tracer: client.internal.Tracer(), + }) + return poller, err } else { - return runtime.NewPollerFromResumeToken[ApplicationDefinitionsClientCreateOrUpdateByIDResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ApplicationDefinitionsClientCreateOrUpdateByIDResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -136,18 +154,24 @@ func (client *ApplicationDefinitionsClient) BeginCreateOrUpdateByID(ctx context. // // Generated from API version 2018-06-01 func (client *ApplicationDefinitionsClient) createOrUpdateByID(ctx context.Context, resourceGroupName string, applicationDefinitionName string, parameters ApplicationDefinition, options *ApplicationDefinitionsClientBeginCreateOrUpdateByIDOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationDefinitionsClient.BeginCreateOrUpdateByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateByIDCreateRequest(ctx, resourceGroupName, applicationDefinitionName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // createOrUpdateByIDCreateRequest creates the CreateOrUpdateByID request. @@ -173,7 +197,10 @@ func (client *ApplicationDefinitionsClient) createOrUpdateByIDCreateRequest(ctx reqQP.Set("api-version", "2018-06-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the managed application definition. @@ -190,9 +217,14 @@ func (client *ApplicationDefinitionsClient) BeginDelete(ctx context.Context, res if err != nil { return nil, err } - return runtime.NewPoller[ApplicationDefinitionsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationDefinitionsClientDeleteResponse]{ + Tracer: client.internal.Tracer(), + }) + return poller, err } else { - return runtime.NewPollerFromResumeToken[ApplicationDefinitionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ApplicationDefinitionsClientDeleteResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -201,18 +233,24 @@ func (client *ApplicationDefinitionsClient) BeginDelete(ctx context.Context, res // // Generated from API version 2018-06-01 func (client *ApplicationDefinitionsClient) deleteOperation(ctx context.Context, resourceGroupName string, applicationDefinitionName string, options *ApplicationDefinitionsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationDefinitionsClient.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, applicationDefinitionName, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteCreateRequest creates the Delete request. @@ -255,9 +293,14 @@ func (client *ApplicationDefinitionsClient) BeginDeleteByID(ctx context.Context, if err != nil { return nil, err } - return runtime.NewPoller[ApplicationDefinitionsClientDeleteByIDResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationDefinitionsClientDeleteByIDResponse]{ + Tracer: client.internal.Tracer(), + }) + return poller, err } else { - return runtime.NewPollerFromResumeToken[ApplicationDefinitionsClientDeleteByIDResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ApplicationDefinitionsClientDeleteByIDResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -266,18 +309,24 @@ func (client *ApplicationDefinitionsClient) BeginDeleteByID(ctx context.Context, // // Generated from API version 2018-06-01 func (client *ApplicationDefinitionsClient) deleteByID(ctx context.Context, resourceGroupName string, applicationDefinitionName string, options *ApplicationDefinitionsClientBeginDeleteByIDOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationDefinitionsClient.BeginDeleteByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteByIDCreateRequest(ctx, resourceGroupName, applicationDefinitionName, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteByIDCreateRequest creates the DeleteByID request. @@ -315,18 +364,25 @@ func (client *ApplicationDefinitionsClient) deleteByIDCreateRequest(ctx context. // - options - ApplicationDefinitionsClientGetOptions contains the optional parameters for the ApplicationDefinitionsClient.Get // method. func (client *ApplicationDefinitionsClient) Get(ctx context.Context, resourceGroupName string, applicationDefinitionName string, options *ApplicationDefinitionsClientGetOptions) (ApplicationDefinitionsClientGetResponse, error) { + var err error + const operationName = "ApplicationDefinitionsClient.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, applicationDefinitionName, options) if err != nil { return ApplicationDefinitionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationDefinitionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNotFound) { - return ApplicationDefinitionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNotFound) { + err = runtime.NewResponseError(httpResp) + return ApplicationDefinitionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -373,18 +429,25 @@ func (client *ApplicationDefinitionsClient) getHandleResponse(resp *http.Respons // - options - ApplicationDefinitionsClientGetByIDOptions contains the optional parameters for the ApplicationDefinitionsClient.GetByID // method. func (client *ApplicationDefinitionsClient) GetByID(ctx context.Context, resourceGroupName string, applicationDefinitionName string, options *ApplicationDefinitionsClientGetByIDOptions) (ApplicationDefinitionsClientGetByIDResponse, error) { + var err error + const operationName = "ApplicationDefinitionsClient.GetByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getByIDCreateRequest(ctx, resourceGroupName, applicationDefinitionName, options) if err != nil { return ApplicationDefinitionsClientGetByIDResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationDefinitionsClientGetByIDResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNotFound) { - return ApplicationDefinitionsClientGetByIDResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNotFound) { + err = runtime.NewResponseError(httpResp) + return ApplicationDefinitionsClientGetByIDResponse{}, err } - return client.getByIDHandleResponse(resp) + resp, err := client.getByIDHandleResponse(httpResp) + return resp, err } // getByIDCreateRequest creates the GetByID request. @@ -434,25 +497,20 @@ func (client *ApplicationDefinitionsClient) NewListByResourceGroupPager(resource return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ApplicationDefinitionsClientListByResourceGroupResponse) (ApplicationDefinitionsClientListByResourceGroupResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ApplicationDefinitionsClient.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 ApplicationDefinitionsClientListByResourceGroupResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ApplicationDefinitionsClientListByResourceGroupResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationDefinitionsClientListByResourceGroupResponse{}, runtime.NewResponseError(resp) - } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armmanagedapplications/applications_client.go b/sdk/resourcemanager/resources/armmanagedapplications/applications_client.go index eedbcb9f9930..f5d597d08b32 100644 --- a/sdk/resourcemanager/resources/armmanagedapplications/applications_client.go +++ b/sdk/resourcemanager/resources/armmanagedapplications/applications_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armmanagedapplications @@ -33,7 +32,7 @@ type ApplicationsClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewApplicationsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ApplicationsClient, error) { - cl, err := arm.NewClient(moduleName+".ApplicationsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -59,9 +58,14 @@ func (client *ApplicationsClient) BeginCreateOrUpdate(ctx context.Context, resou if err != nil { return nil, err } - return runtime.NewPoller[ApplicationsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationsClientCreateOrUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) + return poller, err } else { - return runtime.NewPollerFromResumeToken[ApplicationsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ApplicationsClientCreateOrUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -70,18 +74,24 @@ func (client *ApplicationsClient) BeginCreateOrUpdate(ctx context.Context, resou // // Generated from API version 2018-06-01 func (client *ApplicationsClient) createOrUpdate(ctx context.Context, resourceGroupName string, applicationName string, parameters Application, options *ApplicationsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationsClient.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, applicationName, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -107,7 +117,10 @@ func (client *ApplicationsClient) createOrUpdateCreateRequest(ctx context.Contex reqQP.Set("api-version", "2018-06-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginCreateOrUpdateByID - Creates a new managed application. @@ -126,9 +139,14 @@ func (client *ApplicationsClient) BeginCreateOrUpdateByID(ctx context.Context, a if err != nil { return nil, err } - return runtime.NewPoller[ApplicationsClientCreateOrUpdateByIDResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationsClientCreateOrUpdateByIDResponse]{ + Tracer: client.internal.Tracer(), + }) + return poller, err } else { - return runtime.NewPollerFromResumeToken[ApplicationsClientCreateOrUpdateByIDResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ApplicationsClientCreateOrUpdateByIDResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -137,18 +155,24 @@ func (client *ApplicationsClient) BeginCreateOrUpdateByID(ctx context.Context, a // // Generated from API version 2018-06-01 func (client *ApplicationsClient) createOrUpdateByID(ctx context.Context, applicationID string, parameters Application, options *ApplicationsClientBeginCreateOrUpdateByIDOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationsClient.BeginCreateOrUpdateByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateByIDCreateRequest(ctx, applicationID, parameters, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // createOrUpdateByIDCreateRequest creates the CreateOrUpdateByID request. @@ -163,7 +187,10 @@ func (client *ApplicationsClient) createOrUpdateByIDCreateRequest(ctx context.Co reqQP.Set("api-version", "2018-06-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, parameters) + if err := runtime.MarshalAsJSON(req, parameters); err != nil { + return nil, err + } + return req, nil } // BeginDelete - Deletes the managed application. @@ -180,9 +207,14 @@ func (client *ApplicationsClient) BeginDelete(ctx context.Context, resourceGroup if err != nil { return nil, err } - return runtime.NewPoller[ApplicationsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationsClientDeleteResponse]{ + Tracer: client.internal.Tracer(), + }) + return poller, err } else { - return runtime.NewPollerFromResumeToken[ApplicationsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ApplicationsClientDeleteResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -191,18 +223,24 @@ func (client *ApplicationsClient) BeginDelete(ctx context.Context, resourceGroup // // Generated from API version 2018-06-01 func (client *ApplicationsClient) deleteOperation(ctx context.Context, resourceGroupName string, applicationName string, options *ApplicationsClientBeginDeleteOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationsClient.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, applicationName, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteCreateRequest creates the Delete request. @@ -246,9 +284,14 @@ func (client *ApplicationsClient) BeginDeleteByID(ctx context.Context, applicati if err != nil { return nil, err } - return runtime.NewPoller[ApplicationsClientDeleteByIDResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationsClientDeleteByIDResponse]{ + Tracer: client.internal.Tracer(), + }) + return poller, err } else { - return runtime.NewPollerFromResumeToken[ApplicationsClientDeleteByIDResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ApplicationsClientDeleteByIDResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -257,18 +300,24 @@ func (client *ApplicationsClient) BeginDeleteByID(ctx context.Context, applicati // // Generated from API version 2018-06-01 func (client *ApplicationsClient) deleteByID(ctx context.Context, applicationID string, options *ApplicationsClientBeginDeleteByIDOptions) (*http.Response, error) { + var err error + const operationName = "ApplicationsClient.BeginDeleteByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteByIDCreateRequest(ctx, applicationID, options) if err != nil { return nil, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return nil, err } - if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { - return nil, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return nil, err } - return resp, nil + return httpResp, nil } // deleteByIDCreateRequest creates the DeleteByID request. @@ -294,18 +343,25 @@ func (client *ApplicationsClient) deleteByIDCreateRequest(ctx context.Context, a // - applicationName - The name of the managed application. // - options - ApplicationsClientGetOptions contains the optional parameters for the ApplicationsClient.Get method. func (client *ApplicationsClient) Get(ctx context.Context, resourceGroupName string, applicationName string, options *ApplicationsClientGetOptions) (ApplicationsClientGetResponse, error) { + var err error + const operationName = "ApplicationsClient.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, applicationName, options) if err != nil { return ApplicationsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNotFound) { - return ApplicationsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNotFound) { + err = runtime.NewResponseError(httpResp) + return ApplicationsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -352,18 +408,25 @@ func (client *ApplicationsClient) getHandleResponse(resp *http.Response) (Applic // /subscriptions/{guid}/resourceGroups/{resource-group-name}/Microsoft.Solutions/applications/{application-name} // - options - ApplicationsClientGetByIDOptions contains the optional parameters for the ApplicationsClient.GetByID method. func (client *ApplicationsClient) GetByID(ctx context.Context, applicationID string, options *ApplicationsClientGetByIDOptions) (ApplicationsClientGetByIDResponse, error) { + var err error + const operationName = "ApplicationsClient.GetByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getByIDCreateRequest(ctx, applicationID, options) if err != nil { return ApplicationsClientGetByIDResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationsClientGetByIDResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNotFound) { - return ApplicationsClientGetByIDResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNotFound) { + err = runtime.NewResponseError(httpResp) + return ApplicationsClientGetByIDResponse{}, err } - return client.getByIDHandleResponse(resp) + resp, err := client.getByIDHandleResponse(httpResp) + return resp, err } // getByIDCreateRequest creates the GetByID request. @@ -402,25 +465,20 @@ func (client *ApplicationsClient) NewListByResourceGroupPager(resourceGroupName return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ApplicationsClientListByResourceGroupResponse) (ApplicationsClientListByResourceGroupResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return ApplicationsClientListByResourceGroupResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ApplicationsClient.NewListByResourceGroupPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + 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 ApplicationsClientListByResourceGroupResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationsClientListByResourceGroupResponse{}, runtime.NewResponseError(resp) - } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -466,25 +524,20 @@ func (client *ApplicationsClient) NewListBySubscriptionPager(options *Applicatio return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ApplicationsClientListBySubscriptionResponse) (ApplicationsClientListBySubscriptionResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listBySubscriptionCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ApplicationsClient.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 ApplicationsClientListBySubscriptionResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ApplicationsClientListBySubscriptionResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationsClientListBySubscriptionResponse{}, runtime.NewResponseError(resp) - } return client.listBySubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -523,18 +576,25 @@ func (client *ApplicationsClient) listBySubscriptionHandleResponse(resp *http.Re // - applicationName - The name of the managed application. // - options - ApplicationsClientUpdateOptions contains the optional parameters for the ApplicationsClient.Update method. func (client *ApplicationsClient) Update(ctx context.Context, resourceGroupName string, applicationName string, options *ApplicationsClientUpdateOptions) (ApplicationsClientUpdateResponse, error) { + var err error + const operationName = "ApplicationsClient.Update" + 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, applicationName, options) if err != nil { return ApplicationsClientUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationsClientUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationsClientUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ApplicationsClientUpdateResponse{}, err } - return client.updateHandleResponse(resp) + resp, err := client.updateHandleResponse(httpResp) + return resp, err } // updateCreateRequest creates the Update request. @@ -561,7 +621,10 @@ func (client *ApplicationsClient) updateCreateRequest(ctx context.Context, resou req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.Parameters != nil { - return req, runtime.MarshalAsJSON(req, *options.Parameters) + if err := runtime.MarshalAsJSON(req, *options.Parameters); err != nil { + return nil, err + } + return req, nil } return req, nil } @@ -584,18 +647,25 @@ func (client *ApplicationsClient) updateHandleResponse(resp *http.Response) (App // /subscriptions/{guid}/resourceGroups/{resource-group-name}/Microsoft.Solutions/applications/{application-name} // - options - ApplicationsClientUpdateByIDOptions contains the optional parameters for the ApplicationsClient.UpdateByID method. func (client *ApplicationsClient) UpdateByID(ctx context.Context, applicationID string, options *ApplicationsClientUpdateByIDOptions) (ApplicationsClientUpdateByIDResponse, error) { + var err error + const operationName = "ApplicationsClient.UpdateByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateByIDCreateRequest(ctx, applicationID, options) if err != nil { return ApplicationsClientUpdateByIDResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ApplicationsClientUpdateByIDResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ApplicationsClientUpdateByIDResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ApplicationsClientUpdateByIDResponse{}, err } - return client.updateByIDHandleResponse(resp) + resp, err := client.updateByIDHandleResponse(httpResp) + return resp, err } // updateByIDCreateRequest creates the UpdateByID request. @@ -611,7 +681,10 @@ func (client *ApplicationsClient) updateByIDCreateRequest(ctx context.Context, a req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.Parameters != nil { - return req, runtime.MarshalAsJSON(req, *options.Parameters) + if err := runtime.MarshalAsJSON(req, *options.Parameters); err != nil { + return nil, err + } + return req, nil } return req, nil } diff --git a/sdk/resourcemanager/resources/armmanagedapplications/autorest.md b/sdk/resourcemanager/resources/armmanagedapplications/autorest.md index dc4d55881acf..24d811660b16 100644 --- a/sdk/resourcemanager/resources/armmanagedapplications/autorest.md +++ b/sdk/resourcemanager/resources/armmanagedapplications/autorest.md @@ -8,6 +8,6 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/0cc5e2efd6ffccf30e80d1e150b488dd87198b94/specification/resources/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/0cc5e2efd6ffccf30e80d1e150b488dd87198b94/specification/resources/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 1.1.1 +module-version: 1.2.0 package-managedapplications: true ``` \ No newline at end of file diff --git a/sdk/resourcemanager/resources/armmanagedapplications/client_factory.go b/sdk/resourcemanager/resources/armmanagedapplications/client_factory.go index e69a61f397c7..7dd85ca82e2b 100644 --- a/sdk/resourcemanager/resources/armmanagedapplications/client_factory.go +++ b/sdk/resourcemanager/resources/armmanagedapplications/client_factory.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armmanagedapplications @@ -28,7 +27,7 @@ type ClientFactory struct { // - 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) { - _, err := arm.NewClient(moduleName+".ClientFactory", moduleVersion, credential, options) + _, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -38,17 +37,20 @@ func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, }, nil } +// NewApplicationClient creates a new instance of ApplicationClient. func (c *ClientFactory) NewApplicationClient() *ApplicationClient { subClient, _ := NewApplicationClient(c.credential, c.options) return subClient } -func (c *ClientFactory) NewApplicationsClient() *ApplicationsClient { - subClient, _ := NewApplicationsClient(c.subscriptionID, c.credential, c.options) +// NewApplicationDefinitionsClient creates a new instance of ApplicationDefinitionsClient. +func (c *ClientFactory) NewApplicationDefinitionsClient() *ApplicationDefinitionsClient { + subClient, _ := NewApplicationDefinitionsClient(c.subscriptionID, c.credential, c.options) return subClient } -func (c *ClientFactory) NewApplicationDefinitionsClient() *ApplicationDefinitionsClient { - subClient, _ := NewApplicationDefinitionsClient(c.subscriptionID, c.credential, c.options) +// NewApplicationsClient creates a new instance of ApplicationsClient. +func (c *ClientFactory) NewApplicationsClient() *ApplicationsClient { + subClient, _ := NewApplicationsClient(c.subscriptionID, c.credential, c.options) return subClient } diff --git a/sdk/resourcemanager/resources/armmanagedapplications/constants.go b/sdk/resourcemanager/resources/armmanagedapplications/constants.go index f1134cea935b..0af828198ae9 100644 --- a/sdk/resourcemanager/resources/armmanagedapplications/constants.go +++ b/sdk/resourcemanager/resources/armmanagedapplications/constants.go @@ -3,30 +3,29 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armmanagedapplications const ( - moduleName = "armmanagedapplications" - moduleVersion = "v1.1.1" + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armmanagedapplications" + moduleVersion = "v1.2.0" ) // ApplicationArtifactType - The managed application artifact type. type ApplicationArtifactType string const ( - ApplicationArtifactTypeTemplate ApplicationArtifactType = "Template" ApplicationArtifactTypeCustom ApplicationArtifactType = "Custom" + ApplicationArtifactTypeTemplate ApplicationArtifactType = "Template" ) // PossibleApplicationArtifactTypeValues returns the possible values for the ApplicationArtifactType const type. func PossibleApplicationArtifactTypeValues() []ApplicationArtifactType { return []ApplicationArtifactType{ - ApplicationArtifactTypeTemplate, ApplicationArtifactTypeCustom, + ApplicationArtifactTypeTemplate, } } @@ -35,16 +34,16 @@ type ApplicationLockLevel string const ( ApplicationLockLevelCanNotDelete ApplicationLockLevel = "CanNotDelete" - ApplicationLockLevelReadOnly ApplicationLockLevel = "ReadOnly" ApplicationLockLevelNone ApplicationLockLevel = "None" + ApplicationLockLevelReadOnly ApplicationLockLevel = "ReadOnly" ) // PossibleApplicationLockLevelValues returns the possible values for the ApplicationLockLevel const type. func PossibleApplicationLockLevelValues() []ApplicationLockLevel { return []ApplicationLockLevel{ ApplicationLockLevelCanNotDelete, - ApplicationLockLevelReadOnly, ApplicationLockLevelNone, + ApplicationLockLevelReadOnly, } } diff --git a/sdk/resourcemanager/resources/armmanagedapplications/fake/application_server.go b/sdk/resourcemanager/resources/armmanagedapplications/fake/application_server.go new file mode 100644 index 000000000000..06be689b57d8 --- /dev/null +++ b/sdk/resourcemanager/resources/armmanagedapplications/fake/application_server.go @@ -0,0 +1,96 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armmanagedapplications" + "net/http" +) + +// ApplicationServer is a fake server for instances of the armmanagedapplications.ApplicationClient type. +type ApplicationServer struct { + // NewListOperationsPager is the fake for method ApplicationClient.NewListOperationsPager + // HTTP status codes to indicate success: http.StatusOK + NewListOperationsPager func(options *armmanagedapplications.ApplicationClientListOperationsOptions) (resp azfake.PagerResponder[armmanagedapplications.ApplicationClientListOperationsResponse]) +} + +// NewApplicationServerTransport creates a new instance of ApplicationServerTransport with the provided implementation. +// The returned ApplicationServerTransport instance is connected to an instance of armmanagedapplications.ApplicationClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewApplicationServerTransport(srv *ApplicationServer) *ApplicationServerTransport { + return &ApplicationServerTransport{ + srv: srv, + newListOperationsPager: newTracker[azfake.PagerResponder[armmanagedapplications.ApplicationClientListOperationsResponse]](), + } +} + +// ApplicationServerTransport connects instances of armmanagedapplications.ApplicationClient to instances of ApplicationServer. +// Don't use this type directly, use NewApplicationServerTransport instead. +type ApplicationServerTransport struct { + srv *ApplicationServer + newListOperationsPager *tracker[azfake.PagerResponder[armmanagedapplications.ApplicationClientListOperationsResponse]] +} + +// Do implements the policy.Transporter interface for ApplicationServerTransport. +func (a *ApplicationServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "ApplicationClient.NewListOperationsPager": + resp, err = a.dispatchNewListOperationsPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *ApplicationServerTransport) dispatchNewListOperationsPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListOperationsPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListOperationsPager not implemented")} + } + newListOperationsPager := a.newListOperationsPager.get(req) + if newListOperationsPager == nil { + resp := a.srv.NewListOperationsPager(nil) + newListOperationsPager = &resp + a.newListOperationsPager.add(req, newListOperationsPager) + server.PagerResponderInjectNextLinks(newListOperationsPager, req, func(page *armmanagedapplications.ApplicationClientListOperationsResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListOperationsPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + a.newListOperationsPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListOperationsPager) { + a.newListOperationsPager.remove(req) + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armmanagedapplications/fake/applicationdefinitions_server.go b/sdk/resourcemanager/resources/armmanagedapplications/fake/applicationdefinitions_server.go new file mode 100644 index 000000000000..07e47980ad55 --- /dev/null +++ b/sdk/resourcemanager/resources/armmanagedapplications/fake/applicationdefinitions_server.go @@ -0,0 +1,403 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armmanagedapplications" + "net/http" + "net/url" + "regexp" +) + +// ApplicationDefinitionsServer is a fake server for instances of the armmanagedapplications.ApplicationDefinitionsClient type. +type ApplicationDefinitionsServer struct { + // BeginCreateOrUpdate is the fake for method ApplicationDefinitionsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, applicationDefinitionName string, parameters armmanagedapplications.ApplicationDefinition, options *armmanagedapplications.ApplicationDefinitionsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armmanagedapplications.ApplicationDefinitionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdateByID is the fake for method ApplicationDefinitionsClient.BeginCreateOrUpdateByID + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdateByID func(ctx context.Context, resourceGroupName string, applicationDefinitionName string, parameters armmanagedapplications.ApplicationDefinition, options *armmanagedapplications.ApplicationDefinitionsClientBeginCreateOrUpdateByIDOptions) (resp azfake.PollerResponder[armmanagedapplications.ApplicationDefinitionsClientCreateOrUpdateByIDResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ApplicationDefinitionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, applicationDefinitionName string, options *armmanagedapplications.ApplicationDefinitionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armmanagedapplications.ApplicationDefinitionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // BeginDeleteByID is the fake for method ApplicationDefinitionsClient.BeginDeleteByID + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDeleteByID func(ctx context.Context, resourceGroupName string, applicationDefinitionName string, options *armmanagedapplications.ApplicationDefinitionsClientBeginDeleteByIDOptions) (resp azfake.PollerResponder[armmanagedapplications.ApplicationDefinitionsClientDeleteByIDResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ApplicationDefinitionsClient.Get + // HTTP status codes to indicate success: http.StatusOK, http.StatusNotFound + Get func(ctx context.Context, resourceGroupName string, applicationDefinitionName string, options *armmanagedapplications.ApplicationDefinitionsClientGetOptions) (resp azfake.Responder[armmanagedapplications.ApplicationDefinitionsClientGetResponse], errResp azfake.ErrorResponder) + + // GetByID is the fake for method ApplicationDefinitionsClient.GetByID + // HTTP status codes to indicate success: http.StatusOK, http.StatusNotFound + GetByID func(ctx context.Context, resourceGroupName string, applicationDefinitionName string, options *armmanagedapplications.ApplicationDefinitionsClientGetByIDOptions) (resp azfake.Responder[armmanagedapplications.ApplicationDefinitionsClientGetByIDResponse], errResp azfake.ErrorResponder) + + // NewListByResourceGroupPager is the fake for method ApplicationDefinitionsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armmanagedapplications.ApplicationDefinitionsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armmanagedapplications.ApplicationDefinitionsClientListByResourceGroupResponse]) +} + +// NewApplicationDefinitionsServerTransport creates a new instance of ApplicationDefinitionsServerTransport with the provided implementation. +// The returned ApplicationDefinitionsServerTransport instance is connected to an instance of armmanagedapplications.ApplicationDefinitionsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewApplicationDefinitionsServerTransport(srv *ApplicationDefinitionsServer) *ApplicationDefinitionsServerTransport { + return &ApplicationDefinitionsServerTransport{ + srv: srv, + beginCreateOrUpdate: newTracker[azfake.PollerResponder[armmanagedapplications.ApplicationDefinitionsClientCreateOrUpdateResponse]](), + beginCreateOrUpdateByID: newTracker[azfake.PollerResponder[armmanagedapplications.ApplicationDefinitionsClientCreateOrUpdateByIDResponse]](), + beginDelete: newTracker[azfake.PollerResponder[armmanagedapplications.ApplicationDefinitionsClientDeleteResponse]](), + beginDeleteByID: newTracker[azfake.PollerResponder[armmanagedapplications.ApplicationDefinitionsClientDeleteByIDResponse]](), + newListByResourceGroupPager: newTracker[azfake.PagerResponder[armmanagedapplications.ApplicationDefinitionsClientListByResourceGroupResponse]](), + } +} + +// ApplicationDefinitionsServerTransport connects instances of armmanagedapplications.ApplicationDefinitionsClient to instances of ApplicationDefinitionsServer. +// Don't use this type directly, use NewApplicationDefinitionsServerTransport instead. +type ApplicationDefinitionsServerTransport struct { + srv *ApplicationDefinitionsServer + beginCreateOrUpdate *tracker[azfake.PollerResponder[armmanagedapplications.ApplicationDefinitionsClientCreateOrUpdateResponse]] + beginCreateOrUpdateByID *tracker[azfake.PollerResponder[armmanagedapplications.ApplicationDefinitionsClientCreateOrUpdateByIDResponse]] + beginDelete *tracker[azfake.PollerResponder[armmanagedapplications.ApplicationDefinitionsClientDeleteResponse]] + beginDeleteByID *tracker[azfake.PollerResponder[armmanagedapplications.ApplicationDefinitionsClientDeleteByIDResponse]] + newListByResourceGroupPager *tracker[azfake.PagerResponder[armmanagedapplications.ApplicationDefinitionsClientListByResourceGroupResponse]] +} + +// Do implements the policy.Transporter interface for ApplicationDefinitionsServerTransport. +func (a *ApplicationDefinitionsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "ApplicationDefinitionsClient.BeginCreateOrUpdate": + resp, err = a.dispatchBeginCreateOrUpdate(req) + case "ApplicationDefinitionsClient.BeginCreateOrUpdateByID": + resp, err = a.dispatchBeginCreateOrUpdateByID(req) + case "ApplicationDefinitionsClient.BeginDelete": + resp, err = a.dispatchBeginDelete(req) + case "ApplicationDefinitionsClient.BeginDeleteByID": + resp, err = a.dispatchBeginDeleteByID(req) + case "ApplicationDefinitionsClient.Get": + resp, err = a.dispatchGet(req) + case "ApplicationDefinitionsClient.GetByID": + resp, err = a.dispatchGetByID(req) + case "ApplicationDefinitionsClient.NewListByResourceGroupPager": + resp, err = a.dispatchNewListByResourceGroupPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *ApplicationDefinitionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if a.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + beginCreateOrUpdate := a.beginCreateOrUpdate.get(req) + if beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Solutions/applicationDefinitions/(?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[armmanagedapplications.ApplicationDefinition](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, applicationDefinitionNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdate = &respr + a.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) { + a.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) { + a.beginCreateOrUpdate.remove(req) + } + + return resp, nil +} + +func (a *ApplicationDefinitionsServerTransport) dispatchBeginCreateOrUpdateByID(req *http.Request) (*http.Response, error) { + if a.srv.BeginCreateOrUpdateByID == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdateByID not implemented")} + } + beginCreateOrUpdateByID := a.beginCreateOrUpdateByID.get(req) + if beginCreateOrUpdateByID == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Solutions/applicationDefinitions/(?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[armmanagedapplications.ApplicationDefinition](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginCreateOrUpdateByID(req.Context(), resourceGroupNameParam, applicationDefinitionNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdateByID = &respr + a.beginCreateOrUpdateByID.add(req, beginCreateOrUpdateByID) + } + + resp, err := server.PollerResponderNext(beginCreateOrUpdateByID, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + a.beginCreateOrUpdateByID.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(beginCreateOrUpdateByID) { + a.beginCreateOrUpdateByID.remove(req) + } + + return resp, nil +} + +func (a *ApplicationDefinitionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if a.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + beginDelete := a.beginDelete.get(req) + if beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Solutions/applicationDefinitions/(?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 + } + applicationDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginDelete(req.Context(), resourceGroupNameParam, applicationDefinitionNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDelete = &respr + a.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) { + a.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) { + a.beginDelete.remove(req) + } + + return resp, nil +} + +func (a *ApplicationDefinitionsServerTransport) dispatchBeginDeleteByID(req *http.Request) (*http.Response, error) { + if a.srv.BeginDeleteByID == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDeleteByID not implemented")} + } + beginDeleteByID := a.beginDeleteByID.get(req) + if beginDeleteByID == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Solutions/applicationDefinitions/(?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 + } + applicationDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginDeleteByID(req.Context(), resourceGroupNameParam, applicationDefinitionNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDeleteByID = &respr + a.beginDeleteByID.add(req, beginDeleteByID) + } + + resp, err := server.PollerResponderNext(beginDeleteByID, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + a.beginDeleteByID.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(beginDeleteByID) { + a.beginDeleteByID.remove(req) + } + + return resp, nil +} + +func (a *ApplicationDefinitionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.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\.Solutions/applicationDefinitions/(?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 + } + applicationDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), resourceGroupNameParam, applicationDefinitionNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNotFound}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNotFound", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ApplicationDefinition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *ApplicationDefinitionsServerTransport) dispatchGetByID(req *http.Request) (*http.Response, error) { + if a.srv.GetByID == nil { + return nil, &nonRetriableError{errors.New("fake for method GetByID not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Solutions/applicationDefinitions/(?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 + } + applicationDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.GetByID(req.Context(), resourceGroupNameParam, applicationDefinitionNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNotFound}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNotFound", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ApplicationDefinition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *ApplicationDefinitionsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + newListByResourceGroupPager := a.newListByResourceGroupPager.get(req) + if newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Solutions/applicationDefinitions` + 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 := a.srv.NewListByResourceGroupPager(resourceGroupNameParam, nil) + newListByResourceGroupPager = &resp + a.newListByResourceGroupPager.add(req, newListByResourceGroupPager) + server.PagerResponderInjectNextLinks(newListByResourceGroupPager, req, func(page *armmanagedapplications.ApplicationDefinitionsClientListByResourceGroupResponse, 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) { + a.newListByResourceGroupPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListByResourceGroupPager) { + a.newListByResourceGroupPager.remove(req) + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armmanagedapplications/fake/applications_server.go b/sdk/resourcemanager/resources/armmanagedapplications/fake/applications_server.go new file mode 100644 index 000000000000..941da38a7af8 --- /dev/null +++ b/sdk/resourcemanager/resources/armmanagedapplications/fake/applications_server.go @@ -0,0 +1,527 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armmanagedapplications" + "net/http" + "net/url" + "reflect" + "regexp" +) + +// ApplicationsServer is a fake server for instances of the armmanagedapplications.ApplicationsClient type. +type ApplicationsServer struct { + // BeginCreateOrUpdate is the fake for method ApplicationsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, applicationName string, parameters armmanagedapplications.Application, options *armmanagedapplications.ApplicationsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armmanagedapplications.ApplicationsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginCreateOrUpdateByID is the fake for method ApplicationsClient.BeginCreateOrUpdateByID + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdateByID func(ctx context.Context, applicationID string, parameters armmanagedapplications.Application, options *armmanagedapplications.ApplicationsClientBeginCreateOrUpdateByIDOptions) (resp azfake.PollerResponder[armmanagedapplications.ApplicationsClientCreateOrUpdateByIDResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ApplicationsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, resourceGroupName string, applicationName string, options *armmanagedapplications.ApplicationsClientBeginDeleteOptions) (resp azfake.PollerResponder[armmanagedapplications.ApplicationsClientDeleteResponse], errResp azfake.ErrorResponder) + + // BeginDeleteByID is the fake for method ApplicationsClient.BeginDeleteByID + // HTTP status codes to indicate success: http.StatusAccepted, http.StatusNoContent + BeginDeleteByID func(ctx context.Context, applicationID string, options *armmanagedapplications.ApplicationsClientBeginDeleteByIDOptions) (resp azfake.PollerResponder[armmanagedapplications.ApplicationsClientDeleteByIDResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ApplicationsClient.Get + // HTTP status codes to indicate success: http.StatusOK, http.StatusNotFound + Get func(ctx context.Context, resourceGroupName string, applicationName string, options *armmanagedapplications.ApplicationsClientGetOptions) (resp azfake.Responder[armmanagedapplications.ApplicationsClientGetResponse], errResp azfake.ErrorResponder) + + // GetByID is the fake for method ApplicationsClient.GetByID + // HTTP status codes to indicate success: http.StatusOK, http.StatusNotFound + GetByID func(ctx context.Context, applicationID string, options *armmanagedapplications.ApplicationsClientGetByIDOptions) (resp azfake.Responder[armmanagedapplications.ApplicationsClientGetByIDResponse], errResp azfake.ErrorResponder) + + // NewListByResourceGroupPager is the fake for method ApplicationsClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armmanagedapplications.ApplicationsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armmanagedapplications.ApplicationsClientListByResourceGroupResponse]) + + // NewListBySubscriptionPager is the fake for method ApplicationsClient.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armmanagedapplications.ApplicationsClientListBySubscriptionOptions) (resp azfake.PagerResponder[armmanagedapplications.ApplicationsClientListBySubscriptionResponse]) + + // Update is the fake for method ApplicationsClient.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, resourceGroupName string, applicationName string, options *armmanagedapplications.ApplicationsClientUpdateOptions) (resp azfake.Responder[armmanagedapplications.ApplicationsClientUpdateResponse], errResp azfake.ErrorResponder) + + // UpdateByID is the fake for method ApplicationsClient.UpdateByID + // HTTP status codes to indicate success: http.StatusOK + UpdateByID func(ctx context.Context, applicationID string, options *armmanagedapplications.ApplicationsClientUpdateByIDOptions) (resp azfake.Responder[armmanagedapplications.ApplicationsClientUpdateByIDResponse], errResp azfake.ErrorResponder) +} + +// NewApplicationsServerTransport creates a new instance of ApplicationsServerTransport with the provided implementation. +// The returned ApplicationsServerTransport instance is connected to an instance of armmanagedapplications.ApplicationsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewApplicationsServerTransport(srv *ApplicationsServer) *ApplicationsServerTransport { + return &ApplicationsServerTransport{ + srv: srv, + beginCreateOrUpdate: newTracker[azfake.PollerResponder[armmanagedapplications.ApplicationsClientCreateOrUpdateResponse]](), + beginCreateOrUpdateByID: newTracker[azfake.PollerResponder[armmanagedapplications.ApplicationsClientCreateOrUpdateByIDResponse]](), + beginDelete: newTracker[azfake.PollerResponder[armmanagedapplications.ApplicationsClientDeleteResponse]](), + beginDeleteByID: newTracker[azfake.PollerResponder[armmanagedapplications.ApplicationsClientDeleteByIDResponse]](), + newListByResourceGroupPager: newTracker[azfake.PagerResponder[armmanagedapplications.ApplicationsClientListByResourceGroupResponse]](), + newListBySubscriptionPager: newTracker[azfake.PagerResponder[armmanagedapplications.ApplicationsClientListBySubscriptionResponse]](), + } +} + +// ApplicationsServerTransport connects instances of armmanagedapplications.ApplicationsClient to instances of ApplicationsServer. +// Don't use this type directly, use NewApplicationsServerTransport instead. +type ApplicationsServerTransport struct { + srv *ApplicationsServer + beginCreateOrUpdate *tracker[azfake.PollerResponder[armmanagedapplications.ApplicationsClientCreateOrUpdateResponse]] + beginCreateOrUpdateByID *tracker[azfake.PollerResponder[armmanagedapplications.ApplicationsClientCreateOrUpdateByIDResponse]] + beginDelete *tracker[azfake.PollerResponder[armmanagedapplications.ApplicationsClientDeleteResponse]] + beginDeleteByID *tracker[azfake.PollerResponder[armmanagedapplications.ApplicationsClientDeleteByIDResponse]] + newListByResourceGroupPager *tracker[azfake.PagerResponder[armmanagedapplications.ApplicationsClientListByResourceGroupResponse]] + newListBySubscriptionPager *tracker[azfake.PagerResponder[armmanagedapplications.ApplicationsClientListBySubscriptionResponse]] +} + +// Do implements the policy.Transporter interface for ApplicationsServerTransport. +func (a *ApplicationsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "ApplicationsClient.BeginCreateOrUpdate": + resp, err = a.dispatchBeginCreateOrUpdate(req) + case "ApplicationsClient.BeginCreateOrUpdateByID": + resp, err = a.dispatchBeginCreateOrUpdateByID(req) + case "ApplicationsClient.BeginDelete": + resp, err = a.dispatchBeginDelete(req) + case "ApplicationsClient.BeginDeleteByID": + resp, err = a.dispatchBeginDeleteByID(req) + case "ApplicationsClient.Get": + resp, err = a.dispatchGet(req) + case "ApplicationsClient.GetByID": + resp, err = a.dispatchGetByID(req) + case "ApplicationsClient.NewListByResourceGroupPager": + resp, err = a.dispatchNewListByResourceGroupPager(req) + case "ApplicationsClient.NewListBySubscriptionPager": + resp, err = a.dispatchNewListBySubscriptionPager(req) + case "ApplicationsClient.Update": + resp, err = a.dispatchUpdate(req) + case "ApplicationsClient.UpdateByID": + resp, err = a.dispatchUpdateByID(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *ApplicationsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if a.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + beginCreateOrUpdate := a.beginCreateOrUpdate.get(req) + if beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Solutions/applications/(?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[armmanagedapplications.Application](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, applicationNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdate = &respr + a.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) { + a.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) { + a.beginCreateOrUpdate.remove(req) + } + + return resp, nil +} + +func (a *ApplicationsServerTransport) dispatchBeginCreateOrUpdateByID(req *http.Request) (*http.Response, error) { + if a.srv.BeginCreateOrUpdateByID == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdateByID not implemented")} + } + beginCreateOrUpdateByID := a.beginCreateOrUpdateByID.get(req) + if beginCreateOrUpdateByID == nil { + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armmanagedapplications.Application](req) + if err != nil { + return nil, err + } + applicationIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationId")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginCreateOrUpdateByID(req.Context(), applicationIDParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdateByID = &respr + a.beginCreateOrUpdateByID.add(req, beginCreateOrUpdateByID) + } + + resp, err := server.PollerResponderNext(beginCreateOrUpdateByID, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + a.beginCreateOrUpdateByID.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(beginCreateOrUpdateByID) { + a.beginCreateOrUpdateByID.remove(req) + } + + return resp, nil +} + +func (a *ApplicationsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if a.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + beginDelete := a.beginDelete.get(req) + if beginDelete == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Solutions/applications/(?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 + } + applicationNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginDelete(req.Context(), resourceGroupNameParam, applicationNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDelete = &respr + a.beginDelete.add(req, beginDelete) + } + + resp, err := server.PollerResponderNext(beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + a.beginDelete.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(beginDelete) { + a.beginDelete.remove(req) + } + + return resp, nil +} + +func (a *ApplicationsServerTransport) dispatchBeginDeleteByID(req *http.Request) (*http.Response, error) { + if a.srv.BeginDeleteByID == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDeleteByID not implemented")} + } + beginDeleteByID := a.beginDeleteByID.get(req) + if beginDeleteByID == nil { + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + applicationIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationId")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginDeleteByID(req.Context(), applicationIDParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDeleteByID = &respr + a.beginDeleteByID.add(req, beginDeleteByID) + } + + resp, err := server.PollerResponderNext(beginDeleteByID, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + a.beginDeleteByID.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(beginDeleteByID) { + a.beginDeleteByID.remove(req) + } + + return resp, nil +} + +func (a *ApplicationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.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\.Solutions/applications/(?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 + } + applicationNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), resourceGroupNameParam, applicationNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNotFound}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNotFound", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Application, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *ApplicationsServerTransport) dispatchGetByID(req *http.Request) (*http.Response, error) { + if a.srv.GetByID == nil { + return nil, &nonRetriableError{errors.New("fake for method GetByID not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + applicationIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationId")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.GetByID(req.Context(), applicationIDParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNotFound}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNotFound", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Application, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *ApplicationsServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + newListByResourceGroupPager := a.newListByResourceGroupPager.get(req) + if newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Solutions/applications` + 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 := a.srv.NewListByResourceGroupPager(resourceGroupNameParam, nil) + newListByResourceGroupPager = &resp + a.newListByResourceGroupPager.add(req, newListByResourceGroupPager) + server.PagerResponderInjectNextLinks(newListByResourceGroupPager, req, func(page *armmanagedapplications.ApplicationsClientListByResourceGroupResponse, 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) { + a.newListByResourceGroupPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListByResourceGroupPager) { + a.newListByResourceGroupPager.remove(req) + } + return resp, nil +} + +func (a *ApplicationsServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListBySubscriptionPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListBySubscriptionPager not implemented")} + } + newListBySubscriptionPager := a.newListBySubscriptionPager.get(req) + if newListBySubscriptionPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Solutions/applications` + 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 := a.srv.NewListBySubscriptionPager(nil) + newListBySubscriptionPager = &resp + a.newListBySubscriptionPager.add(req, newListBySubscriptionPager) + server.PagerResponderInjectNextLinks(newListBySubscriptionPager, req, func(page *armmanagedapplications.ApplicationsClientListBySubscriptionResponse, 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) { + a.newListBySubscriptionPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListBySubscriptionPager) { + a.newListBySubscriptionPager.remove(req) + } + return resp, nil +} + +func (a *ApplicationsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if a.srv.Update == nil { + return nil, &nonRetriableError{errors.New("fake for method Update not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Solutions/applications/(?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[armmanagedapplications.ApplicationPatchable](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + applicationNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationName")]) + if err != nil { + return nil, err + } + var options *armmanagedapplications.ApplicationsClientUpdateOptions + if !reflect.ValueOf(body).IsZero() { + options = &armmanagedapplications.ApplicationsClientUpdateOptions{ + Parameters: &body, + } + } + respr, errRespr := a.srv.Update(req.Context(), resourceGroupNameParam, applicationNameParam, options) + 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).Application, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *ApplicationsServerTransport) dispatchUpdateByID(req *http.Request) (*http.Response, error) { + if a.srv.UpdateByID == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateByID not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armmanagedapplications.Application](req) + if err != nil { + return nil, err + } + applicationIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationId")]) + if err != nil { + return nil, err + } + var options *armmanagedapplications.ApplicationsClientUpdateByIDOptions + if !reflect.ValueOf(body).IsZero() { + options = &armmanagedapplications.ApplicationsClientUpdateByIDOptions{ + Parameters: &body, + } + } + respr, errRespr := a.srv.UpdateByID(req.Context(), applicationIDParam, options) + 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).Application, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armmanagedapplications/fake/internal.go b/sdk/resourcemanager/resources/armmanagedapplications/fake/internal.go new file mode 100644 index 000000000000..5f75802a569e --- /dev/null +++ b/sdk/resourcemanager/resources/armmanagedapplications/fake/internal.go @@ -0,0 +1,64 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "net/http" + "sync" +) + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} + +func newTracker[T any]() *tracker[T] { + return &tracker[T]{ + items: map[string]*T{}, + } +} + +type tracker[T any] struct { + items map[string]*T + mu sync.Mutex +} + +func (p *tracker[T]) get(req *http.Request) *T { + p.mu.Lock() + defer p.mu.Unlock() + if item, ok := p.items[server.SanitizePagerPollerPath(req.URL.Path)]; ok { + return item + } + return nil +} + +func (p *tracker[T]) add(req *http.Request, item *T) { + p.mu.Lock() + defer p.mu.Unlock() + p.items[server.SanitizePagerPollerPath(req.URL.Path)] = item +} + +func (p *tracker[T]) remove(req *http.Request) { + p.mu.Lock() + defer p.mu.Unlock() + delete(p.items, server.SanitizePagerPollerPath(req.URL.Path)) +} diff --git a/sdk/resourcemanager/resources/armmanagedapplications/fake/server_factory.go b/sdk/resourcemanager/resources/armmanagedapplications/fake/server_factory.go new file mode 100644 index 000000000000..338089490ef7 --- /dev/null +++ b/sdk/resourcemanager/resources/armmanagedapplications/fake/server_factory.go @@ -0,0 +1,87 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" + "sync" +) + +// ServerFactory is a fake server for instances of the armmanagedapplications.ClientFactory type. +type ServerFactory struct { + ApplicationServer ApplicationServer + ApplicationDefinitionsServer ApplicationDefinitionsServer + ApplicationsServer ApplicationsServer +} + +// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. +// The returned ServerFactoryTransport instance is connected to an instance of armmanagedapplications.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 armmanagedapplications.ClientFactory to instances of ServerFactory. +// Don't use this type directly, use NewServerFactoryTransport instead. +type ServerFactoryTransport struct { + srv *ServerFactory + trMu sync.Mutex + trApplicationServer *ApplicationServerTransport + trApplicationDefinitionsServer *ApplicationDefinitionsServerTransport + trApplicationsServer *ApplicationsServerTransport +} + +// 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 "ApplicationClient": + initServer(s, &s.trApplicationServer, func() *ApplicationServerTransport { return NewApplicationServerTransport(&s.srv.ApplicationServer) }) + resp, err = s.trApplicationServer.Do(req) + case "ApplicationDefinitionsClient": + initServer(s, &s.trApplicationDefinitionsServer, func() *ApplicationDefinitionsServerTransport { + return NewApplicationDefinitionsServerTransport(&s.srv.ApplicationDefinitionsServer) + }) + resp, err = s.trApplicationDefinitionsServer.Do(req) + case "ApplicationsClient": + initServer(s, &s.trApplicationsServer, func() *ApplicationsServerTransport { return NewApplicationsServerTransport(&s.srv.ApplicationsServer) }) + resp, err = s.trApplicationsServer.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/resources/armmanagedapplications/go.mod b/sdk/resourcemanager/resources/armmanagedapplications/go.mod index eb8afbb60516..06ad58f60645 100644 --- a/sdk/resourcemanager/resources/armmanagedapplications/go.mod +++ b/sdk/resourcemanager/resources/armmanagedapplications/go.mod @@ -3,19 +3,19 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armmanage go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect - github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 // indirect - github.com/golang-jwt/jwt/v4 v4.5.0 // indirect - github.com/google/uuid v1.3.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect + github.com/golang-jwt/jwt/v5 v5.0.0 // indirect + github.com/google/uuid v1.3.1 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect - golang.org/x/crypto v0.6.0 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect ) diff --git a/sdk/resourcemanager/resources/armmanagedapplications/go.sum b/sdk/resourcemanager/resources/armmanagedapplications/go.sum index 8ba445a8c4da..7985f1da436f 100644 --- a/sdk/resourcemanager/resources/armmanagedapplications/go.sum +++ b/sdk/resourcemanager/resources/armmanagedapplications/go.sum @@ -1,31 +1,31 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 h1:rTnT/Jrcm+figWlYz4Ixzt0SJVR2cMC8lvZcimipiEY= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0/go.mod h1:ON4tFdPTwRcgWEaVDrN3584Ef+b7GgSJaXxe5fW9t4M= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 h1:uqM+VoHjVH6zdlkLF2b6O0ZANcHoj3rO0PoQ3jglUJA= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2/go.mod h1:twTKAa1E6hLmSDjLhaCkbTMQKc7p/rNLU40rLxGEOCI= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 h1:leh5DwKv6Ihwi+h60uHtn6UWAxBbZ0q8DwQVMzf61zw= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= -github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 h1:UE9n9rkJF62ArLb1F3DEjRt8O3jLwMWdSoypKV4f3MU= -github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 h1:fb8kj/Dh4CSwgsOzHeZY4Xh68cFVbzXx+ONXGMY//4w= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0/go.mod h1:uReU2sSxZExRPBAg3qKzmAucSi51+SP1OhohieR821Q= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 h1:BMAjVKJM0U/CYF27gA0ZMmXGkOcvfFtD0oHVZ1TIPRI= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0/go.mod h1:1fXstnBMas5kzG+S3q8UoJcmyU6nUeunJcMDHcRYHhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 h1:WpB/QDNLpMw72xHJc34BNNykqSOeEJDAWkhf0u12/Jk= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= -github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= -github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= +github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/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-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc= -golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/sdk/resourcemanager/resources/armmanagedapplications/models.go b/sdk/resourcemanager/resources/armmanagedapplications/models.go index 39345d87aaad..cd94c10bef67 100644 --- a/sdk/resourcemanager/resources/armmanagedapplications/models.go +++ b/sdk/resourcemanager/resources/armmanagedapplications/models.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armmanagedapplications @@ -57,12 +56,6 @@ type ApplicationArtifact struct { URI *string } -// ApplicationClientListOperationsOptions contains the optional parameters for the ApplicationClient.NewListOperationsPager -// method. -type ApplicationClientListOperationsOptions struct { - // placeholder for future optional parameters -} - // ApplicationDefinition - Information about managed application definition. type ApplicationDefinition struct { // REQUIRED; The managed application definition properties. @@ -135,51 +128,6 @@ type ApplicationDefinitionProperties struct { PackageFileURI *string } -// ApplicationDefinitionsClientBeginCreateOrUpdateByIDOptions contains the optional parameters for the ApplicationDefinitionsClient.BeginCreateOrUpdateByID -// method. -type ApplicationDefinitionsClientBeginCreateOrUpdateByIDOptions struct { - // Resumes the LRO from the provided token. - ResumeToken string -} - -// ApplicationDefinitionsClientBeginCreateOrUpdateOptions contains the optional parameters for the ApplicationDefinitionsClient.BeginCreateOrUpdate -// method. -type ApplicationDefinitionsClientBeginCreateOrUpdateOptions struct { - // Resumes the LRO from the provided token. - ResumeToken string -} - -// ApplicationDefinitionsClientBeginDeleteByIDOptions contains the optional parameters for the ApplicationDefinitionsClient.BeginDeleteByID -// method. -type ApplicationDefinitionsClientBeginDeleteByIDOptions struct { - // Resumes the LRO from the provided token. - ResumeToken string -} - -// ApplicationDefinitionsClientBeginDeleteOptions contains the optional parameters for the ApplicationDefinitionsClient.BeginDelete -// method. -type ApplicationDefinitionsClientBeginDeleteOptions struct { - // Resumes the LRO from the provided token. - ResumeToken string -} - -// ApplicationDefinitionsClientGetByIDOptions contains the optional parameters for the ApplicationDefinitionsClient.GetByID -// method. -type ApplicationDefinitionsClientGetByIDOptions struct { - // placeholder for future optional parameters -} - -// ApplicationDefinitionsClientGetOptions contains the optional parameters for the ApplicationDefinitionsClient.Get method. -type ApplicationDefinitionsClientGetOptions struct { - // placeholder for future optional parameters -} - -// ApplicationDefinitionsClientListByResourceGroupOptions contains the optional parameters for the ApplicationDefinitionsClient.NewListByResourceGroupPager -// method. -type ApplicationDefinitionsClientListByResourceGroupOptions struct { - // placeholder for future optional parameters -} - // ApplicationListResult - List of managed applications. type ApplicationListResult struct { // The URL to use for getting the next set of results. @@ -273,66 +221,6 @@ type ApplicationProviderAuthorization struct { RoleDefinitionID *string } -// ApplicationsClientBeginCreateOrUpdateByIDOptions contains the optional parameters for the ApplicationsClient.BeginCreateOrUpdateByID -// method. -type ApplicationsClientBeginCreateOrUpdateByIDOptions struct { - // Resumes the LRO from the provided token. - ResumeToken string -} - -// ApplicationsClientBeginCreateOrUpdateOptions contains the optional parameters for the ApplicationsClient.BeginCreateOrUpdate -// method. -type ApplicationsClientBeginCreateOrUpdateOptions struct { - // Resumes the LRO from the provided token. - ResumeToken string -} - -// ApplicationsClientBeginDeleteByIDOptions contains the optional parameters for the ApplicationsClient.BeginDeleteByID method. -type ApplicationsClientBeginDeleteByIDOptions struct { - // Resumes the LRO from the provided token. - ResumeToken string -} - -// ApplicationsClientBeginDeleteOptions contains the optional parameters for the ApplicationsClient.BeginDelete method. -type ApplicationsClientBeginDeleteOptions struct { - // Resumes the LRO from the provided token. - ResumeToken string -} - -// ApplicationsClientGetByIDOptions contains the optional parameters for the ApplicationsClient.GetByID method. -type ApplicationsClientGetByIDOptions struct { - // placeholder for future optional parameters -} - -// ApplicationsClientGetOptions contains the optional parameters for the ApplicationsClient.Get method. -type ApplicationsClientGetOptions struct { - // placeholder for future optional parameters -} - -// ApplicationsClientListByResourceGroupOptions contains the optional parameters for the ApplicationsClient.NewListByResourceGroupPager -// method. -type ApplicationsClientListByResourceGroupOptions struct { - // placeholder for future optional parameters -} - -// ApplicationsClientListBySubscriptionOptions contains the optional parameters for the ApplicationsClient.NewListBySubscriptionPager -// method. -type ApplicationsClientListBySubscriptionOptions struct { - // placeholder for future optional parameters -} - -// ApplicationsClientUpdateByIDOptions contains the optional parameters for the ApplicationsClient.UpdateByID method. -type ApplicationsClientUpdateByIDOptions struct { - // Parameters supplied to update an existing managed application. - Parameters *Application -} - -// ApplicationsClientUpdateOptions contains the optional parameters for the ApplicationsClient.Update method. -type ApplicationsClientUpdateOptions struct { - // Parameters supplied to update an existing managed application. - Parameters *ApplicationPatchable -} - // ErrorResponse - Error response indicates managed application is not able to process the incoming request. The reason is // provided in the error message. type ErrorResponse struct { diff --git a/sdk/resourcemanager/resources/armmanagedapplications/models_serde.go b/sdk/resourcemanager/resources/armmanagedapplications/models_serde.go index 53d8f8694fdc..bf63041d30f9 100644 --- a/sdk/resourcemanager/resources/armmanagedapplications/models_serde.go +++ b/sdk/resourcemanager/resources/armmanagedapplications/models_serde.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armmanagedapplications diff --git a/sdk/resourcemanager/resources/armmanagedapplications/options.go b/sdk/resourcemanager/resources/armmanagedapplications/options.go new file mode 100644 index 000000000000..5c7cfd62992f --- /dev/null +++ b/sdk/resourcemanager/resources/armmanagedapplications/options.go @@ -0,0 +1,120 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmanagedapplications + +// ApplicationClientListOperationsOptions contains the optional parameters for the ApplicationClient.NewListOperationsPager +// method. +type ApplicationClientListOperationsOptions struct { + // placeholder for future optional parameters +} + +// ApplicationDefinitionsClientBeginCreateOrUpdateByIDOptions contains the optional parameters for the ApplicationDefinitionsClient.BeginCreateOrUpdateByID +// method. +type ApplicationDefinitionsClientBeginCreateOrUpdateByIDOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ApplicationDefinitionsClientBeginCreateOrUpdateOptions contains the optional parameters for the ApplicationDefinitionsClient.BeginCreateOrUpdate +// method. +type ApplicationDefinitionsClientBeginCreateOrUpdateOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ApplicationDefinitionsClientBeginDeleteByIDOptions contains the optional parameters for the ApplicationDefinitionsClient.BeginDeleteByID +// method. +type ApplicationDefinitionsClientBeginDeleteByIDOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ApplicationDefinitionsClientBeginDeleteOptions contains the optional parameters for the ApplicationDefinitionsClient.BeginDelete +// method. +type ApplicationDefinitionsClientBeginDeleteOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ApplicationDefinitionsClientGetByIDOptions contains the optional parameters for the ApplicationDefinitionsClient.GetByID +// method. +type ApplicationDefinitionsClientGetByIDOptions struct { + // placeholder for future optional parameters +} + +// ApplicationDefinitionsClientGetOptions contains the optional parameters for the ApplicationDefinitionsClient.Get method. +type ApplicationDefinitionsClientGetOptions struct { + // placeholder for future optional parameters +} + +// ApplicationDefinitionsClientListByResourceGroupOptions contains the optional parameters for the ApplicationDefinitionsClient.NewListByResourceGroupPager +// method. +type ApplicationDefinitionsClientListByResourceGroupOptions struct { + // placeholder for future optional parameters +} + +// ApplicationsClientBeginCreateOrUpdateByIDOptions contains the optional parameters for the ApplicationsClient.BeginCreateOrUpdateByID +// method. +type ApplicationsClientBeginCreateOrUpdateByIDOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ApplicationsClientBeginCreateOrUpdateOptions contains the optional parameters for the ApplicationsClient.BeginCreateOrUpdate +// method. +type ApplicationsClientBeginCreateOrUpdateOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ApplicationsClientBeginDeleteByIDOptions contains the optional parameters for the ApplicationsClient.BeginDeleteByID method. +type ApplicationsClientBeginDeleteByIDOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ApplicationsClientBeginDeleteOptions contains the optional parameters for the ApplicationsClient.BeginDelete method. +type ApplicationsClientBeginDeleteOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ApplicationsClientGetByIDOptions contains the optional parameters for the ApplicationsClient.GetByID method. +type ApplicationsClientGetByIDOptions struct { + // placeholder for future optional parameters +} + +// ApplicationsClientGetOptions contains the optional parameters for the ApplicationsClient.Get method. +type ApplicationsClientGetOptions struct { + // placeholder for future optional parameters +} + +// ApplicationsClientListByResourceGroupOptions contains the optional parameters for the ApplicationsClient.NewListByResourceGroupPager +// method. +type ApplicationsClientListByResourceGroupOptions struct { + // placeholder for future optional parameters +} + +// ApplicationsClientListBySubscriptionOptions contains the optional parameters for the ApplicationsClient.NewListBySubscriptionPager +// method. +type ApplicationsClientListBySubscriptionOptions struct { + // placeholder for future optional parameters +} + +// ApplicationsClientUpdateByIDOptions contains the optional parameters for the ApplicationsClient.UpdateByID method. +type ApplicationsClientUpdateByIDOptions struct { + // Parameters supplied to update an existing managed application. + Parameters *Application +} + +// ApplicationsClientUpdateOptions contains the optional parameters for the ApplicationsClient.Update method. +type ApplicationsClientUpdateOptions struct { + // Parameters supplied to update an existing managed application. + Parameters *ApplicationPatchable +} diff --git a/sdk/resourcemanager/resources/armmanagedapplications/response_types.go b/sdk/resourcemanager/resources/armmanagedapplications/response_types.go index 6bdea07f4a33..d23fd86392f3 100644 --- a/sdk/resourcemanager/resources/armmanagedapplications/response_types.go +++ b/sdk/resourcemanager/resources/armmanagedapplications/response_types.go @@ -3,24 +3,27 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armmanagedapplications // ApplicationClientListOperationsResponse contains the response from method ApplicationClient.NewListOperationsPager. type ApplicationClientListOperationsResponse struct { + // Result of the request to list Microsoft.Solutions operations. It contains a list of operations and a URL link to get the + // next set of results. OperationListResult } // ApplicationDefinitionsClientCreateOrUpdateByIDResponse contains the response from method ApplicationDefinitionsClient.BeginCreateOrUpdateByID. type ApplicationDefinitionsClientCreateOrUpdateByIDResponse struct { + // Information about managed application definition. ApplicationDefinition } // ApplicationDefinitionsClientCreateOrUpdateResponse contains the response from method ApplicationDefinitionsClient.BeginCreateOrUpdate. type ApplicationDefinitionsClientCreateOrUpdateResponse struct { + // Information about managed application definition. ApplicationDefinition } @@ -36,26 +39,31 @@ type ApplicationDefinitionsClientDeleteResponse struct { // ApplicationDefinitionsClientGetByIDResponse contains the response from method ApplicationDefinitionsClient.GetByID. type ApplicationDefinitionsClientGetByIDResponse struct { + // Information about managed application definition. ApplicationDefinition } // ApplicationDefinitionsClientGetResponse contains the response from method ApplicationDefinitionsClient.Get. type ApplicationDefinitionsClientGetResponse struct { + // Information about managed application definition. ApplicationDefinition } // ApplicationDefinitionsClientListByResourceGroupResponse contains the response from method ApplicationDefinitionsClient.NewListByResourceGroupPager. type ApplicationDefinitionsClientListByResourceGroupResponse struct { + // List of managed application definitions. ApplicationDefinitionListResult } // ApplicationsClientCreateOrUpdateByIDResponse contains the response from method ApplicationsClient.BeginCreateOrUpdateByID. type ApplicationsClientCreateOrUpdateByIDResponse struct { + // Information about managed application. Application } // ApplicationsClientCreateOrUpdateResponse contains the response from method ApplicationsClient.BeginCreateOrUpdate. type ApplicationsClientCreateOrUpdateResponse struct { + // Information about managed application. Application } @@ -71,30 +79,36 @@ type ApplicationsClientDeleteResponse struct { // ApplicationsClientGetByIDResponse contains the response from method ApplicationsClient.GetByID. type ApplicationsClientGetByIDResponse struct { + // Information about managed application. Application } // ApplicationsClientGetResponse contains the response from method ApplicationsClient.Get. type ApplicationsClientGetResponse struct { + // Information about managed application. Application } // ApplicationsClientListByResourceGroupResponse contains the response from method ApplicationsClient.NewListByResourceGroupPager. type ApplicationsClientListByResourceGroupResponse struct { + // List of managed applications. ApplicationListResult } // ApplicationsClientListBySubscriptionResponse contains the response from method ApplicationsClient.NewListBySubscriptionPager. type ApplicationsClientListBySubscriptionResponse struct { + // List of managed applications. ApplicationListResult } // ApplicationsClientUpdateByIDResponse contains the response from method ApplicationsClient.UpdateByID. type ApplicationsClientUpdateByIDResponse struct { + // Information about managed application. Application } // ApplicationsClientUpdateResponse contains the response from method ApplicationsClient.Update. type ApplicationsClientUpdateResponse struct { + // Information about managed application. Application } From 65237c745fb3a379fa91e8bf92309d7d54af3518 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 15:29:25 +0800 Subject: [PATCH 08/18] [Release] sdk/resourcemanager/resources/armpolicy/0.9.0 generation from spec commit: bf204aab860f2eb58a9d346b00d44760f2a9b0a2 --- .../resources/armpolicy/CHANGELOG.md | 6 + .../resources/armpolicy/README.md | 7 + .../resources/armpolicy/assignments_client.go | 118 +-- .../resources/armpolicy/autorest.md | 2 +- .../resources/armpolicy/client_factory.go | 9 +- .../resources/armpolicy/constants.go | 4 +- .../armpolicy/datapolicymanifests_client.go | 27 +- .../resources/armpolicy/definitions_client.go | 93 +-- .../resources/armpolicy/exemptions_client.go | 102 ++- .../exemptions_client_example_test.go | 52 +- .../armpolicy/fake/assignments_server.go | 677 ++++++++++++++++++ .../fake/datapolicymanifests_server.go | 146 ++++ .../armpolicy/fake/definitions_server.go | 532 ++++++++++++++ .../armpolicy/fake/exemptions_server.go | 468 ++++++++++++ .../resources/armpolicy/fake/internal.go | 83 +++ .../armpolicy/fake/server_factory.go | 111 +++ .../armpolicy/fake/setdefinitions_server.go | 532 ++++++++++++++ .../resources/armpolicy/fake/time_rfc3339.go | 86 +++ .../armpolicy/fake/variables_server.go | 380 ++++++++++ .../armpolicy/fake/variablevalues_server.go | 412 +++++++++++ .../resources/armpolicy/go.mod | 32 +- .../resources/armpolicy/go.sum | 70 +- .../resources/armpolicy/models_serde.go | 12 +- .../policydefinitions_client_live_test.go | 2 +- .../armpolicy/setdefinitions_client.go | 93 +-- .../resources/armpolicy/time_rfc3339.go | 40 +- .../resources/armpolicy/variables_client.go | 68 +- .../variables_client_example_test.go | 32 +- .../armpolicy/variablevalues_client.go | 68 +- .../variablevalues_client_example_test.go | 32 +- 30 files changed, 3902 insertions(+), 394 deletions(-) create mode 100644 sdk/resourcemanager/resources/armpolicy/fake/assignments_server.go create mode 100644 sdk/resourcemanager/resources/armpolicy/fake/datapolicymanifests_server.go create mode 100644 sdk/resourcemanager/resources/armpolicy/fake/definitions_server.go create mode 100644 sdk/resourcemanager/resources/armpolicy/fake/exemptions_server.go create mode 100644 sdk/resourcemanager/resources/armpolicy/fake/internal.go create mode 100644 sdk/resourcemanager/resources/armpolicy/fake/server_factory.go create mode 100644 sdk/resourcemanager/resources/armpolicy/fake/setdefinitions_server.go create mode 100644 sdk/resourcemanager/resources/armpolicy/fake/time_rfc3339.go create mode 100644 sdk/resourcemanager/resources/armpolicy/fake/variables_server.go create mode 100644 sdk/resourcemanager/resources/armpolicy/fake/variablevalues_server.go diff --git a/sdk/resourcemanager/resources/armpolicy/CHANGELOG.md b/sdk/resourcemanager/resources/armpolicy/CHANGELOG.md index 6e3226d6ecd9..8f90d906063f 100644 --- a/sdk/resourcemanager/resources/armpolicy/CHANGELOG.md +++ b/sdk/resourcemanager/resources/armpolicy/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 0.9.0 (2023-11-24) +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + + ## 0.8.0 (2023-10-27) ### Features Added diff --git a/sdk/resourcemanager/resources/armpolicy/README.md b/sdk/resourcemanager/resources/armpolicy/README.md index 145a56954259..0a39dd6a4699 100644 --- a/sdk/resourcemanager/resources/armpolicy/README.md +++ b/sdk/resourcemanager/resources/armpolicy/README.md @@ -60,6 +60,13 @@ A client groups a set of related APIs, providing access to its functionality. C client := clientFactory.NewDefinitionsClient() ``` +## 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 diff --git a/sdk/resourcemanager/resources/armpolicy/assignments_client.go b/sdk/resourcemanager/resources/armpolicy/assignments_client.go index 27ed9cf3bb29..1346bdc15c8a 100644 --- a/sdk/resourcemanager/resources/armpolicy/assignments_client.go +++ b/sdk/resourcemanager/resources/armpolicy/assignments_client.go @@ -33,7 +33,7 @@ type AssignmentsClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewAssignmentsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*AssignmentsClient, error) { - cl, err := arm.NewClient(moduleName+".AssignmentsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -60,6 +60,10 @@ func NewAssignmentsClient(subscriptionID string, credential azcore.TokenCredenti // - options - AssignmentsClientCreateOptions contains the optional parameters for the AssignmentsClient.Create method. func (client *AssignmentsClient) Create(ctx context.Context, scope string, policyAssignmentName string, parameters Assignment, options *AssignmentsClientCreateOptions) (AssignmentsClientCreateResponse, error) { var err error + const operationName = "AssignmentsClient.Create" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createCreateRequest(ctx, scope, policyAssignmentName, parameters, options) if err != nil { return AssignmentsClientCreateResponse{}, err @@ -123,6 +127,10 @@ func (client *AssignmentsClient) createHandleResponse(resp *http.Response) (Assi // - options - AssignmentsClientCreateByIDOptions contains the optional parameters for the AssignmentsClient.CreateByID method. func (client *AssignmentsClient) CreateByID(ctx context.Context, policyAssignmentID string, parameters Assignment, options *AssignmentsClientCreateByIDOptions) (AssignmentsClientCreateByIDResponse, error) { var err error + const operationName = "AssignmentsClient.CreateByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createByIDCreateRequest(ctx, policyAssignmentID, parameters, options) if err != nil { return AssignmentsClientCreateByIDResponse{}, err @@ -181,6 +189,10 @@ func (client *AssignmentsClient) createByIDHandleResponse(resp *http.Response) ( // - options - AssignmentsClientDeleteOptions contains the optional parameters for the AssignmentsClient.Delete method. func (client *AssignmentsClient) Delete(ctx context.Context, scope string, policyAssignmentName string, options *AssignmentsClientDeleteOptions) (AssignmentsClientDeleteResponse, error) { var err error + const operationName = "AssignmentsClient.Delete" + 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, scope, policyAssignmentName, options) if err != nil { return AssignmentsClientDeleteResponse{}, err @@ -239,6 +251,10 @@ func (client *AssignmentsClient) deleteHandleResponse(resp *http.Response) (Assi // - options - AssignmentsClientDeleteByIDOptions contains the optional parameters for the AssignmentsClient.DeleteByID method. func (client *AssignmentsClient) DeleteByID(ctx context.Context, policyAssignmentID string, options *AssignmentsClientDeleteByIDOptions) (AssignmentsClientDeleteByIDResponse, error) { var err error + const operationName = "AssignmentsClient.DeleteByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteByIDCreateRequest(ctx, policyAssignmentID, options) if err != nil { return AssignmentsClientDeleteByIDResponse{}, err @@ -292,6 +308,10 @@ func (client *AssignmentsClient) deleteByIDHandleResponse(resp *http.Response) ( // - options - AssignmentsClientGetOptions contains the optional parameters for the AssignmentsClient.Get method. func (client *AssignmentsClient) Get(ctx context.Context, scope string, policyAssignmentName string, options *AssignmentsClientGetOptions) (AssignmentsClientGetResponse, error) { var err error + const operationName = "AssignmentsClient.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, scope, policyAssignmentName, options) if err != nil { return AssignmentsClientGetResponse{}, err @@ -349,6 +369,10 @@ func (client *AssignmentsClient) getHandleResponse(resp *http.Response) (Assignm // - options - AssignmentsClientGetByIDOptions contains the optional parameters for the AssignmentsClient.GetByID method. func (client *AssignmentsClient) GetByID(ctx context.Context, policyAssignmentID string, options *AssignmentsClientGetByIDOptions) (AssignmentsClientGetByIDResponse, error) { var err error + const operationName = "AssignmentsClient.GetByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getByIDCreateRequest(ctx, policyAssignmentID, options) if err != nil { return AssignmentsClientGetByIDResponse{}, err @@ -409,25 +433,20 @@ func (client *AssignmentsClient) NewListPager(options *AssignmentsClientListOpti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AssignmentsClientListResponse) (AssignmentsClientListResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AssignmentsClient.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 AssignmentsClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return AssignmentsClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return AssignmentsClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -484,25 +503,20 @@ func (client *AssignmentsClient) NewListForManagementGroupPager(managementGroupI return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AssignmentsClientListForManagementGroupResponse) (AssignmentsClientListForManagementGroupResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listForManagementGroupCreateRequest(ctx, managementGroupID, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AssignmentsClient.NewListForManagementGroupPager") + 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.listForManagementGroupCreateRequest(ctx, managementGroupID, options) + }, nil) if err != nil { return AssignmentsClientListForManagementGroupResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return AssignmentsClientListForManagementGroupResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return AssignmentsClientListForManagementGroupResponse{}, runtime.NewResponseError(resp) - } return client.listForManagementGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -578,25 +592,20 @@ func (client *AssignmentsClient) NewListForResourcePager(resourceGroupName strin return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AssignmentsClientListForResourceResponse) (AssignmentsClientListForResourceResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listForResourceCreateRequest(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AssignmentsClient.NewListForResourcePager") + 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.listForResourceCreateRequest(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, options) + }, nil) if err != nil { return AssignmentsClientListForResourceResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return AssignmentsClientListForResourceResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return AssignmentsClientListForResourceResponse{}, runtime.NewResponseError(resp) - } return client.listForResourceHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -671,25 +680,20 @@ func (client *AssignmentsClient) NewListForResourceGroupPager(resourceGroupName return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AssignmentsClientListForResourceGroupResponse) (AssignmentsClientListForResourceGroupResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listForResourceGroupCreateRequest(ctx, resourceGroupName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AssignmentsClient.NewListForResourceGroupPager") + 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.listForResourceGroupCreateRequest(ctx, resourceGroupName, options) + }, nil) if err != nil { return AssignmentsClientListForResourceGroupResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return AssignmentsClientListForResourceGroupResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return AssignmentsClientListForResourceGroupResponse{}, runtime.NewResponseError(resp) - } return client.listForResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -748,6 +752,10 @@ func (client *AssignmentsClient) listForResourceGroupHandleResponse(resp *http.R // - options - AssignmentsClientUpdateOptions contains the optional parameters for the AssignmentsClient.Update method. func (client *AssignmentsClient) Update(ctx context.Context, scope string, policyAssignmentName string, parameters AssignmentUpdate, options *AssignmentsClientUpdateOptions) (AssignmentsClientUpdateResponse, error) { var err error + const operationName = "AssignmentsClient.Update" + 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, scope, policyAssignmentName, parameters, options) if err != nil { return AssignmentsClientUpdateResponse{}, err @@ -811,6 +819,10 @@ func (client *AssignmentsClient) updateHandleResponse(resp *http.Response) (Assi // - options - AssignmentsClientUpdateByIDOptions contains the optional parameters for the AssignmentsClient.UpdateByID method. func (client *AssignmentsClient) UpdateByID(ctx context.Context, policyAssignmentID string, parameters AssignmentUpdate, options *AssignmentsClientUpdateByIDOptions) (AssignmentsClientUpdateByIDResponse, error) { var err error + const operationName = "AssignmentsClient.UpdateByID" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.updateByIDCreateRequest(ctx, policyAssignmentID, parameters, options) if err != nil { return AssignmentsClientUpdateByIDResponse{}, err diff --git a/sdk/resourcemanager/resources/armpolicy/autorest.md b/sdk/resourcemanager/resources/armpolicy/autorest.md index 25815dcb08dd..f8b50d429714 100644 --- a/sdk/resourcemanager/resources/armpolicy/autorest.md +++ b/sdk/resourcemanager/resources/armpolicy/autorest.md @@ -8,7 +8,7 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/9ec0fcc278aa2128c4fbb2b8a1aa93432d72cce0/specification/resources/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/9ec0fcc278aa2128c4fbb2b8a1aa93432d72cce0/specification/resources/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 0.8.0 +module-version: 0.9.0 package-policy: true tag: package-policy-2022-06 ``` \ No newline at end of file diff --git a/sdk/resourcemanager/resources/armpolicy/client_factory.go b/sdk/resourcemanager/resources/armpolicy/client_factory.go index 0ba0b185a711..16ca41746025 100644 --- a/sdk/resourcemanager/resources/armpolicy/client_factory.go +++ b/sdk/resourcemanager/resources/armpolicy/client_factory.go @@ -27,7 +27,7 @@ type ClientFactory struct { // - 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) { - _, err := arm.NewClient(moduleName+".ClientFactory", moduleVersion, credential, options) + _, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -37,36 +37,43 @@ func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, }, nil } +// NewAssignmentsClient creates a new instance of AssignmentsClient. func (c *ClientFactory) NewAssignmentsClient() *AssignmentsClient { subClient, _ := NewAssignmentsClient(c.subscriptionID, c.credential, c.options) return subClient } +// NewDataPolicyManifestsClient creates a new instance of DataPolicyManifestsClient. func (c *ClientFactory) NewDataPolicyManifestsClient() *DataPolicyManifestsClient { subClient, _ := NewDataPolicyManifestsClient(c.credential, c.options) return subClient } +// NewDefinitionsClient creates a new instance of DefinitionsClient. func (c *ClientFactory) NewDefinitionsClient() *DefinitionsClient { subClient, _ := NewDefinitionsClient(c.subscriptionID, c.credential, c.options) return subClient } +// NewExemptionsClient creates a new instance of ExemptionsClient. func (c *ClientFactory) NewExemptionsClient() *ExemptionsClient { subClient, _ := NewExemptionsClient(c.subscriptionID, c.credential, c.options) return subClient } +// NewSetDefinitionsClient creates a new instance of SetDefinitionsClient. func (c *ClientFactory) NewSetDefinitionsClient() *SetDefinitionsClient { subClient, _ := NewSetDefinitionsClient(c.subscriptionID, c.credential, c.options) return subClient } +// NewVariableValuesClient creates a new instance of VariableValuesClient. func (c *ClientFactory) NewVariableValuesClient() *VariableValuesClient { subClient, _ := NewVariableValuesClient(c.subscriptionID, c.credential, c.options) return subClient } +// NewVariablesClient creates a new instance of VariablesClient. func (c *ClientFactory) NewVariablesClient() *VariablesClient { subClient, _ := NewVariablesClient(c.subscriptionID, c.credential, c.options) return subClient diff --git a/sdk/resourcemanager/resources/armpolicy/constants.go b/sdk/resourcemanager/resources/armpolicy/constants.go index 9e242c7b3f40..341a352cfd93 100644 --- a/sdk/resourcemanager/resources/armpolicy/constants.go +++ b/sdk/resourcemanager/resources/armpolicy/constants.go @@ -9,8 +9,8 @@ package armpolicy const ( - moduleName = "armpolicy" - moduleVersion = "v0.8.0" + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy" + moduleVersion = "v0.9.0" ) // AliasPathAttributes - The attributes of the token that the alias path is referring to. diff --git a/sdk/resourcemanager/resources/armpolicy/datapolicymanifests_client.go b/sdk/resourcemanager/resources/armpolicy/datapolicymanifests_client.go index eb85a599d8c7..998169d2761c 100644 --- a/sdk/resourcemanager/resources/armpolicy/datapolicymanifests_client.go +++ b/sdk/resourcemanager/resources/armpolicy/datapolicymanifests_client.go @@ -30,7 +30,7 @@ type DataPolicyManifestsClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewDataPolicyManifestsClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*DataPolicyManifestsClient, error) { - cl, err := arm.NewClient(moduleName+".DataPolicyManifestsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -49,6 +49,10 @@ func NewDataPolicyManifestsClient(credential azcore.TokenCredential, options *ar // method. func (client *DataPolicyManifestsClient) GetByPolicyMode(ctx context.Context, policyMode string, options *DataPolicyManifestsClientGetByPolicyModeOptions) (DataPolicyManifestsClientGetByPolicyModeResponse, error) { var err error + const operationName = "DataPolicyManifestsClient.GetByPolicyMode" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getByPolicyModeCreateRequest(ctx, policyMode, options) if err != nil { return DataPolicyManifestsClientGetByPolicyModeResponse{}, err @@ -107,25 +111,20 @@ func (client *DataPolicyManifestsClient) NewListPager(options *DataPolicyManifes return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DataPolicyManifestsClientListResponse) (DataPolicyManifestsClientListResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DataPolicyManifestsClient.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 DataPolicyManifestsClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return DataPolicyManifestsClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DataPolicyManifestsClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armpolicy/definitions_client.go b/sdk/resourcemanager/resources/armpolicy/definitions_client.go index bdb5f1f57654..02fdc7258b28 100644 --- a/sdk/resourcemanager/resources/armpolicy/definitions_client.go +++ b/sdk/resourcemanager/resources/armpolicy/definitions_client.go @@ -33,7 +33,7 @@ type DefinitionsClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewDefinitionsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*DefinitionsClient, error) { - cl, err := arm.NewClient(moduleName+".DefinitionsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -54,6 +54,10 @@ func NewDefinitionsClient(subscriptionID string, credential azcore.TokenCredenti // method. func (client *DefinitionsClient) CreateOrUpdate(ctx context.Context, policyDefinitionName string, parameters Definition, options *DefinitionsClientCreateOrUpdateOptions) (DefinitionsClientCreateOrUpdateResponse, error) { var err error + const operationName = "DefinitionsClient.CreateOrUpdate" + 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, policyDefinitionName, parameters, options) if err != nil { return DefinitionsClientCreateOrUpdateResponse{}, err @@ -116,6 +120,10 @@ func (client *DefinitionsClient) createOrUpdateHandleResponse(resp *http.Respons // method. func (client *DefinitionsClient) CreateOrUpdateAtManagementGroup(ctx context.Context, policyDefinitionName string, managementGroupID string, parameters Definition, options *DefinitionsClientCreateOrUpdateAtManagementGroupOptions) (DefinitionsClientCreateOrUpdateAtManagementGroupResponse, error) { var err error + const operationName = "DefinitionsClient.CreateOrUpdateAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateAtManagementGroupCreateRequest(ctx, policyDefinitionName, managementGroupID, parameters, options) if err != nil { return DefinitionsClientCreateOrUpdateAtManagementGroupResponse{}, err @@ -174,6 +182,10 @@ func (client *DefinitionsClient) createOrUpdateAtManagementGroupHandleResponse(r // - options - DefinitionsClientDeleteOptions contains the optional parameters for the DefinitionsClient.Delete method. func (client *DefinitionsClient) Delete(ctx context.Context, policyDefinitionName string, options *DefinitionsClientDeleteOptions) (DefinitionsClientDeleteResponse, error) { var err error + const operationName = "DefinitionsClient.Delete" + 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, policyDefinitionName, options) if err != nil { return DefinitionsClientDeleteResponse{}, err @@ -221,6 +233,10 @@ func (client *DefinitionsClient) deleteCreateRequest(ctx context.Context, policy // method. func (client *DefinitionsClient) DeleteAtManagementGroup(ctx context.Context, policyDefinitionName string, managementGroupID string, options *DefinitionsClientDeleteAtManagementGroupOptions) (DefinitionsClientDeleteAtManagementGroupResponse, error) { var err error + const operationName = "DefinitionsClient.DeleteAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAtManagementGroupCreateRequest(ctx, policyDefinitionName, managementGroupID, options) if err != nil { return DefinitionsClientDeleteAtManagementGroupResponse{}, err @@ -266,6 +282,10 @@ func (client *DefinitionsClient) deleteAtManagementGroupCreateRequest(ctx contex // - options - DefinitionsClientGetOptions contains the optional parameters for the DefinitionsClient.Get method. func (client *DefinitionsClient) Get(ctx context.Context, policyDefinitionName string, options *DefinitionsClientGetOptions) (DefinitionsClientGetResponse, error) { var err error + const operationName = "DefinitionsClient.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, policyDefinitionName, options) if err != nil { return DefinitionsClientGetResponse{}, err @@ -323,6 +343,10 @@ func (client *DefinitionsClient) getHandleResponse(resp *http.Response) (Definit // method. func (client *DefinitionsClient) GetAtManagementGroup(ctx context.Context, policyDefinitionName string, managementGroupID string, options *DefinitionsClientGetAtManagementGroupOptions) (DefinitionsClientGetAtManagementGroupResponse, error) { var err error + const operationName = "DefinitionsClient.GetAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtManagementGroupCreateRequest(ctx, policyDefinitionName, managementGroupID, options) if err != nil { return DefinitionsClientGetAtManagementGroupResponse{}, err @@ -378,6 +402,10 @@ func (client *DefinitionsClient) getAtManagementGroupHandleResponse(resp *http.R // - options - DefinitionsClientGetBuiltInOptions contains the optional parameters for the DefinitionsClient.GetBuiltIn method. func (client *DefinitionsClient) GetBuiltIn(ctx context.Context, policyDefinitionName string, options *DefinitionsClientGetBuiltInOptions) (DefinitionsClientGetBuiltInResponse, error) { var err error + const operationName = "DefinitionsClient.GetBuiltIn" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getBuiltInCreateRequest(ctx, policyDefinitionName, options) if err != nil { return DefinitionsClientGetBuiltInResponse{}, err @@ -439,25 +467,20 @@ func (client *DefinitionsClient) NewListPager(options *DefinitionsClientListOpti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DefinitionsClientListResponse) (DefinitionsClientListResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DefinitionsClient.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 DefinitionsClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return DefinitionsClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DefinitionsClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -511,25 +534,20 @@ func (client *DefinitionsClient) NewListBuiltInPager(options *DefinitionsClientL return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DefinitionsClientListBuiltInResponse) (DefinitionsClientListBuiltInResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listBuiltInCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return DefinitionsClientListBuiltInResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DefinitionsClient.NewListBuiltInPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listBuiltInCreateRequest(ctx, options) + }, nil) if err != nil { return DefinitionsClientListBuiltInResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DefinitionsClientListBuiltInResponse{}, runtime.NewResponseError(resp) - } return client.listBuiltInHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -585,25 +603,20 @@ func (client *DefinitionsClient) NewListByManagementGroupPager(managementGroupID return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *DefinitionsClientListByManagementGroupResponse) (DefinitionsClientListByManagementGroupResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listByManagementGroupCreateRequest(ctx, managementGroupID, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return DefinitionsClientListByManagementGroupResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DefinitionsClient.NewListByManagementGroupPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listByManagementGroupCreateRequest(ctx, managementGroupID, options) + }, nil) if err != nil { return DefinitionsClientListByManagementGroupResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DefinitionsClientListByManagementGroupResponse{}, runtime.NewResponseError(resp) - } return client.listByManagementGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armpolicy/exemptions_client.go b/sdk/resourcemanager/resources/armpolicy/exemptions_client.go index 26ff687e6b91..b0dead1ca36a 100644 --- a/sdk/resourcemanager/resources/armpolicy/exemptions_client.go +++ b/sdk/resourcemanager/resources/armpolicy/exemptions_client.go @@ -32,7 +32,7 @@ type ExemptionsClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewExemptionsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ExemptionsClient, error) { - cl, err := arm.NewClient(moduleName+".ExemptionsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -61,6 +61,10 @@ func NewExemptionsClient(subscriptionID string, credential azcore.TokenCredentia // method. func (client *ExemptionsClient) CreateOrUpdate(ctx context.Context, scope string, policyExemptionName string, parameters Exemption, options *ExemptionsClientCreateOrUpdateOptions) (ExemptionsClientCreateOrUpdateResponse, error) { var err error + const operationName = "ExemptionsClient.CreateOrUpdate" + 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, scope, policyExemptionName, parameters, options) if err != nil { return ExemptionsClientCreateOrUpdateResponse{}, err @@ -123,6 +127,10 @@ func (client *ExemptionsClient) createOrUpdateHandleResponse(resp *http.Response // - options - ExemptionsClientDeleteOptions contains the optional parameters for the ExemptionsClient.Delete method. func (client *ExemptionsClient) Delete(ctx context.Context, scope string, policyExemptionName string, options *ExemptionsClientDeleteOptions) (ExemptionsClientDeleteResponse, error) { var err error + const operationName = "ExemptionsClient.Delete" + 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, scope, policyExemptionName, options) if err != nil { return ExemptionsClientDeleteResponse{}, err @@ -170,6 +178,10 @@ func (client *ExemptionsClient) deleteCreateRequest(ctx context.Context, scope s // - options - ExemptionsClientGetOptions contains the optional parameters for the ExemptionsClient.Get method. func (client *ExemptionsClient) Get(ctx context.Context, scope string, policyExemptionName string, options *ExemptionsClientGetOptions) (ExemptionsClientGetResponse, error) { var err error + const operationName = "ExemptionsClient.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, scope, policyExemptionName, options) if err != nil { return ExemptionsClientGetResponse{}, err @@ -229,25 +241,20 @@ func (client *ExemptionsClient) NewListPager(options *ExemptionsClientListOption return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExemptionsClientListResponse) (ExemptionsClientListResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExemptionsClient.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 ExemptionsClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ExemptionsClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExemptionsClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -299,25 +306,20 @@ func (client *ExemptionsClient) NewListForManagementGroupPager(managementGroupID return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExemptionsClientListForManagementGroupResponse) (ExemptionsClientListForManagementGroupResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listForManagementGroupCreateRequest(ctx, managementGroupID, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExemptionsClient.NewListForManagementGroupPager") + 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.listForManagementGroupCreateRequest(ctx, managementGroupID, options) + }, nil) if err != nil { return ExemptionsClientListForManagementGroupResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ExemptionsClientListForManagementGroupResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExemptionsClientListForManagementGroupResponse{}, runtime.NewResponseError(resp) - } return client.listForManagementGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -385,25 +387,20 @@ func (client *ExemptionsClient) NewListForResourcePager(resourceGroupName string return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExemptionsClientListForResourceResponse) (ExemptionsClientListForResourceResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listForResourceCreateRequest(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExemptionsClient.NewListForResourcePager") + 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.listForResourceCreateRequest(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, options) + }, nil) if err != nil { return ExemptionsClientListForResourceResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ExemptionsClientListForResourceResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExemptionsClientListForResourceResponse{}, runtime.NewResponseError(resp) - } return client.listForResourceHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -470,25 +467,20 @@ func (client *ExemptionsClient) NewListForResourceGroupPager(resourceGroupName s return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ExemptionsClientListForResourceGroupResponse) (ExemptionsClientListForResourceGroupResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listForResourceGroupCreateRequest(ctx, resourceGroupName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExemptionsClient.NewListForResourceGroupPager") + 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.listForResourceGroupCreateRequest(ctx, resourceGroupName, options) + }, nil) if err != nil { return ExemptionsClientListForResourceGroupResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ExemptionsClientListForResourceGroupResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ExemptionsClientListForResourceGroupResponse{}, runtime.NewResponseError(resp) - } return client.listForResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -542,6 +534,10 @@ func (client *ExemptionsClient) listForResourceGroupHandleResponse(resp *http.Re // - options - ExemptionsClientUpdateOptions contains the optional parameters for the ExemptionsClient.Update method. func (client *ExemptionsClient) Update(ctx context.Context, scope string, policyExemptionName string, parameters ExemptionUpdate, options *ExemptionsClientUpdateOptions) (ExemptionsClientUpdateResponse, error) { var err error + const operationName = "ExemptionsClient.Update" + 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, scope, policyExemptionName, parameters, options) if err != nil { return ExemptionsClientUpdateResponse{}, err diff --git a/sdk/resourcemanager/resources/armpolicy/exemptions_client_example_test.go b/sdk/resourcemanager/resources/armpolicy/exemptions_client_example_test.go index d79997b78104..b73b15acc056 100644 --- a/sdk/resourcemanager/resources/armpolicy/exemptions_client_example_test.go +++ b/sdk/resourcemanager/resources/armpolicy/exemptions_client_example_test.go @@ -81,10 +81,10 @@ func ExampleExemptionsClient_CreateOrUpdate_createOrUpdateAPolicyExemption() { // to.Ptr("Limit_Skus")}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -161,10 +161,10 @@ func ExampleExemptionsClient_CreateOrUpdate_createOrUpdateAPolicyExemptionWithRe // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -205,10 +205,10 @@ func ExampleExemptionsClient_Get_retrieveAPolicyExemption() { // to.Ptr("Limit_Skus")}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -261,10 +261,10 @@ func ExampleExemptionsClient_Get_retrieveAPolicyExemptionWithResourceSelectors() // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -332,10 +332,10 @@ func ExampleExemptionsClient_Update() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -382,10 +382,10 @@ func ExampleExemptionsClient_NewListPager() { // to.Ptr("Limit_Skus")}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -404,10 +404,10 @@ func ExampleExemptionsClient_NewListPager() { // PolicyAssignmentID: to.Ptr("/providers/Microsoft.Management/managementGroups/DevOrg/providers/Microsoft.Authorization/policyAssignments/LimitPorts"), // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -456,10 +456,10 @@ func ExampleExemptionsClient_NewListForResourceGroupPager() { // to.Ptr("Limit_Skus")}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -478,10 +478,10 @@ func ExampleExemptionsClient_NewListForResourceGroupPager() { // PolicyAssignmentID: to.Ptr("/providers/Microsoft.Management/managementGroups/DevOrg/providers/Microsoft.Authorization/policyAssignments/LimitPorts"), // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -530,10 +530,10 @@ func ExampleExemptionsClient_NewListForResourcePager() { // to.Ptr("Limit_Skus")}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -552,10 +552,10 @@ func ExampleExemptionsClient_NewListForResourcePager() { // PolicyAssignmentID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyAssignments/LimitPorts"), // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -604,10 +604,10 @@ func ExampleExemptionsClient_NewListForManagementGroupPager() { // to.Ptr("Limit_Skus")}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -626,10 +626,10 @@ func ExampleExemptionsClient_NewListForManagementGroupPager() { // PolicyAssignmentID: to.Ptr("/providers/Microsoft.Management/managementGroups/HardwareDivision/providers/Microsoft.Authorization/policyAssignments/LimitPorts"), // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, diff --git a/sdk/resourcemanager/resources/armpolicy/fake/assignments_server.go b/sdk/resourcemanager/resources/armpolicy/fake/assignments_server.go new file mode 100644 index 000000000000..9f49acfd55f0 --- /dev/null +++ b/sdk/resourcemanager/resources/armpolicy/fake/assignments_server.go @@ -0,0 +1,677 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// AssignmentsServer is a fake server for instances of the armpolicy.AssignmentsClient type. +type AssignmentsServer struct { + // Create is the fake for method AssignmentsClient.Create + // HTTP status codes to indicate success: http.StatusCreated + Create func(ctx context.Context, scope string, policyAssignmentName string, parameters armpolicy.Assignment, options *armpolicy.AssignmentsClientCreateOptions) (resp azfake.Responder[armpolicy.AssignmentsClientCreateResponse], errResp azfake.ErrorResponder) + + // CreateByID is the fake for method AssignmentsClient.CreateByID + // HTTP status codes to indicate success: http.StatusCreated + CreateByID func(ctx context.Context, policyAssignmentID string, parameters armpolicy.Assignment, options *armpolicy.AssignmentsClientCreateByIDOptions) (resp azfake.Responder[armpolicy.AssignmentsClientCreateByIDResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method AssignmentsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, scope string, policyAssignmentName string, options *armpolicy.AssignmentsClientDeleteOptions) (resp azfake.Responder[armpolicy.AssignmentsClientDeleteResponse], errResp azfake.ErrorResponder) + + // DeleteByID is the fake for method AssignmentsClient.DeleteByID + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + DeleteByID func(ctx context.Context, policyAssignmentID string, options *armpolicy.AssignmentsClientDeleteByIDOptions) (resp azfake.Responder[armpolicy.AssignmentsClientDeleteByIDResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method AssignmentsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, scope string, policyAssignmentName string, options *armpolicy.AssignmentsClientGetOptions) (resp azfake.Responder[armpolicy.AssignmentsClientGetResponse], errResp azfake.ErrorResponder) + + // GetByID is the fake for method AssignmentsClient.GetByID + // HTTP status codes to indicate success: http.StatusOK + GetByID func(ctx context.Context, policyAssignmentID string, options *armpolicy.AssignmentsClientGetByIDOptions) (resp azfake.Responder[armpolicy.AssignmentsClientGetByIDResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method AssignmentsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armpolicy.AssignmentsClientListOptions) (resp azfake.PagerResponder[armpolicy.AssignmentsClientListResponse]) + + // NewListForManagementGroupPager is the fake for method AssignmentsClient.NewListForManagementGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListForManagementGroupPager func(managementGroupID string, options *armpolicy.AssignmentsClientListForManagementGroupOptions) (resp azfake.PagerResponder[armpolicy.AssignmentsClientListForManagementGroupResponse]) + + // NewListForResourcePager is the fake for method AssignmentsClient.NewListForResourcePager + // HTTP status codes to indicate success: http.StatusOK + NewListForResourcePager func(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, options *armpolicy.AssignmentsClientListForResourceOptions) (resp azfake.PagerResponder[armpolicy.AssignmentsClientListForResourceResponse]) + + // NewListForResourceGroupPager is the fake for method AssignmentsClient.NewListForResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListForResourceGroupPager func(resourceGroupName string, options *armpolicy.AssignmentsClientListForResourceGroupOptions) (resp azfake.PagerResponder[armpolicy.AssignmentsClientListForResourceGroupResponse]) + + // Update is the fake for method AssignmentsClient.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, scope string, policyAssignmentName string, parameters armpolicy.AssignmentUpdate, options *armpolicy.AssignmentsClientUpdateOptions) (resp azfake.Responder[armpolicy.AssignmentsClientUpdateResponse], errResp azfake.ErrorResponder) + + // UpdateByID is the fake for method AssignmentsClient.UpdateByID + // HTTP status codes to indicate success: http.StatusOK + UpdateByID func(ctx context.Context, policyAssignmentID string, parameters armpolicy.AssignmentUpdate, options *armpolicy.AssignmentsClientUpdateByIDOptions) (resp azfake.Responder[armpolicy.AssignmentsClientUpdateByIDResponse], errResp azfake.ErrorResponder) +} + +// NewAssignmentsServerTransport creates a new instance of AssignmentsServerTransport with the provided implementation. +// The returned AssignmentsServerTransport instance is connected to an instance of armpolicy.AssignmentsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewAssignmentsServerTransport(srv *AssignmentsServer) *AssignmentsServerTransport { + return &AssignmentsServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[armpolicy.AssignmentsClientListResponse]](), + newListForManagementGroupPager: newTracker[azfake.PagerResponder[armpolicy.AssignmentsClientListForManagementGroupResponse]](), + newListForResourcePager: newTracker[azfake.PagerResponder[armpolicy.AssignmentsClientListForResourceResponse]](), + newListForResourceGroupPager: newTracker[azfake.PagerResponder[armpolicy.AssignmentsClientListForResourceGroupResponse]](), + } +} + +// AssignmentsServerTransport connects instances of armpolicy.AssignmentsClient to instances of AssignmentsServer. +// Don't use this type directly, use NewAssignmentsServerTransport instead. +type AssignmentsServerTransport struct { + srv *AssignmentsServer + newListPager *tracker[azfake.PagerResponder[armpolicy.AssignmentsClientListResponse]] + newListForManagementGroupPager *tracker[azfake.PagerResponder[armpolicy.AssignmentsClientListForManagementGroupResponse]] + newListForResourcePager *tracker[azfake.PagerResponder[armpolicy.AssignmentsClientListForResourceResponse]] + newListForResourceGroupPager *tracker[azfake.PagerResponder[armpolicy.AssignmentsClientListForResourceGroupResponse]] +} + +// Do implements the policy.Transporter interface for AssignmentsServerTransport. +func (a *AssignmentsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "AssignmentsClient.Create": + resp, err = a.dispatchCreate(req) + case "AssignmentsClient.CreateByID": + resp, err = a.dispatchCreateByID(req) + case "AssignmentsClient.Delete": + resp, err = a.dispatchDelete(req) + case "AssignmentsClient.DeleteByID": + resp, err = a.dispatchDeleteByID(req) + case "AssignmentsClient.Get": + resp, err = a.dispatchGet(req) + case "AssignmentsClient.GetByID": + resp, err = a.dispatchGetByID(req) + case "AssignmentsClient.NewListPager": + resp, err = a.dispatchNewListPager(req) + case "AssignmentsClient.NewListForManagementGroupPager": + resp, err = a.dispatchNewListForManagementGroupPager(req) + case "AssignmentsClient.NewListForResourcePager": + resp, err = a.dispatchNewListForResourcePager(req) + case "AssignmentsClient.NewListForResourceGroupPager": + resp, err = a.dispatchNewListForResourceGroupPager(req) + case "AssignmentsClient.Update": + resp, err = a.dispatchUpdate(req) + case "AssignmentsClient.UpdateByID": + resp, err = a.dispatchUpdateByID(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (a *AssignmentsServerTransport) dispatchCreate(req *http.Request) (*http.Response, error) { + if a.srv.Create == nil { + return nil, &nonRetriableError{errors.New("fake for method Create not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyAssignments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armpolicy.Assignment](req) + if err != nil { + return nil, err + } + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + policyAssignmentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyAssignmentName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Create(req.Context(), scopeParam, policyAssignmentNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Assignment, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AssignmentsServerTransport) dispatchCreateByID(req *http.Request) (*http.Response, error) { + if a.srv.CreateByID == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateByID not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armpolicy.Assignment](req) + if err != nil { + return nil, err + } + policyAssignmentIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyAssignmentId")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.CreateByID(req.Context(), policyAssignmentIDParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Assignment, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AssignmentsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if a.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyAssignments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + policyAssignmentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyAssignmentName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Delete(req.Context(), scopeParam, policyAssignmentNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Assignment, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AssignmentsServerTransport) dispatchDeleteByID(req *http.Request) (*http.Response, error) { + if a.srv.DeleteByID == nil { + return nil, &nonRetriableError{errors.New("fake for method DeleteByID not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + policyAssignmentIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyAssignmentId")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.DeleteByID(req.Context(), policyAssignmentIDParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Assignment, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AssignmentsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyAssignments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + policyAssignmentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyAssignmentName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), scopeParam, policyAssignmentNameParam, 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).Assignment, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AssignmentsServerTransport) dispatchGetByID(req *http.Request) (*http.Response, error) { + if a.srv.GetByID == nil { + return nil, &nonRetriableError{errors.New("fake for method GetByID not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + policyAssignmentIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyAssignmentId")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.GetByID(req.Context(), policyAssignmentIDParam, 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).Assignment, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AssignmentsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := a.newListPager.get(req) + if newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyAssignments` + 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) + } + qp := req.URL.Query() + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armpolicy.AssignmentsClientListOptions + if filterParam != nil || topParam != nil { + options = &armpolicy.AssignmentsClientListOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := a.srv.NewListPager(options) + newListPager = &resp + a.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armpolicy.AssignmentsClientListResponse, 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) { + a.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + a.newListPager.remove(req) + } + return resp, nil +} + +func (a *AssignmentsServerTransport) dispatchNewListForManagementGroupPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListForManagementGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListForManagementGroupPager not implemented")} + } + newListForManagementGroupPager := a.newListForManagementGroupPager.get(req) + if newListForManagementGroupPager == nil { + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyAssignments` + 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) + } + qp := req.URL.Query() + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armpolicy.AssignmentsClientListForManagementGroupOptions + if filterParam != nil || topParam != nil { + options = &armpolicy.AssignmentsClientListForManagementGroupOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := a.srv.NewListForManagementGroupPager(managementGroupIDParam, options) + newListForManagementGroupPager = &resp + a.newListForManagementGroupPager.add(req, newListForManagementGroupPager) + server.PagerResponderInjectNextLinks(newListForManagementGroupPager, req, func(page *armpolicy.AssignmentsClientListForManagementGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListForManagementGroupPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + a.newListForManagementGroupPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListForManagementGroupPager) { + a.newListForManagementGroupPager.remove(req) + } + return resp, nil +} + +func (a *AssignmentsServerTransport) dispatchNewListForResourcePager(req *http.Request) (*http.Response, error) { + if a.srv.NewListForResourcePager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListForResourcePager not implemented")} + } + newListForResourcePager := a.newListForResourcePager.get(req) + if newListForResourcePager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyAssignments` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 6 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + parentResourcePathParam, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + if err != nil { + return nil, err + } + resourceTypeParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + if err != nil { + return nil, err + } + resourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armpolicy.AssignmentsClientListForResourceOptions + if filterParam != nil || topParam != nil { + options = &armpolicy.AssignmentsClientListForResourceOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := a.srv.NewListForResourcePager(resourceGroupNameParam, resourceProviderNamespaceParam, parentResourcePathParam, resourceTypeParam, resourceNameParam, options) + newListForResourcePager = &resp + a.newListForResourcePager.add(req, newListForResourcePager) + server.PagerResponderInjectNextLinks(newListForResourcePager, req, func(page *armpolicy.AssignmentsClientListForResourceResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListForResourcePager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + a.newListForResourcePager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListForResourcePager) { + a.newListForResourcePager.remove(req) + } + return resp, nil +} + +func (a *AssignmentsServerTransport) dispatchNewListForResourceGroupPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListForResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListForResourceGroupPager not implemented")} + } + newListForResourceGroupPager := a.newListForResourceGroupPager.get(req) + if newListForResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyAssignments` + 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) + } + qp := req.URL.Query() + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armpolicy.AssignmentsClientListForResourceGroupOptions + if filterParam != nil || topParam != nil { + options = &armpolicy.AssignmentsClientListForResourceGroupOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := a.srv.NewListForResourceGroupPager(resourceGroupNameParam, options) + newListForResourceGroupPager = &resp + a.newListForResourceGroupPager.add(req, newListForResourceGroupPager) + server.PagerResponderInjectNextLinks(newListForResourceGroupPager, req, func(page *armpolicy.AssignmentsClientListForResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListForResourceGroupPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + a.newListForResourceGroupPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListForResourceGroupPager) { + a.newListForResourceGroupPager.remove(req) + } + return resp, nil +} + +func (a *AssignmentsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if a.srv.Update == nil { + return nil, &nonRetriableError{errors.New("fake for method Update not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyAssignments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armpolicy.AssignmentUpdate](req) + if err != nil { + return nil, err + } + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + policyAssignmentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyAssignmentName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Update(req.Context(), scopeParam, policyAssignmentNameParam, body, 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).Assignment, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AssignmentsServerTransport) dispatchUpdateByID(req *http.Request) (*http.Response, error) { + if a.srv.UpdateByID == nil { + return nil, &nonRetriableError{errors.New("fake for method UpdateByID not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armpolicy.AssignmentUpdate](req) + if err != nil { + return nil, err + } + policyAssignmentIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyAssignmentId")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.UpdateByID(req.Context(), policyAssignmentIDParam, body, 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).Assignment, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armpolicy/fake/datapolicymanifests_server.go b/sdk/resourcemanager/resources/armpolicy/fake/datapolicymanifests_server.go new file mode 100644 index 000000000000..982133638f68 --- /dev/null +++ b/sdk/resourcemanager/resources/armpolicy/fake/datapolicymanifests_server.go @@ -0,0 +1,146 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy" + "net/http" + "net/url" + "regexp" +) + +// DataPolicyManifestsServer is a fake server for instances of the armpolicy.DataPolicyManifestsClient type. +type DataPolicyManifestsServer struct { + // GetByPolicyMode is the fake for method DataPolicyManifestsClient.GetByPolicyMode + // HTTP status codes to indicate success: http.StatusOK + GetByPolicyMode func(ctx context.Context, policyMode string, options *armpolicy.DataPolicyManifestsClientGetByPolicyModeOptions) (resp azfake.Responder[armpolicy.DataPolicyManifestsClientGetByPolicyModeResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method DataPolicyManifestsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armpolicy.DataPolicyManifestsClientListOptions) (resp azfake.PagerResponder[armpolicy.DataPolicyManifestsClientListResponse]) +} + +// NewDataPolicyManifestsServerTransport creates a new instance of DataPolicyManifestsServerTransport with the provided implementation. +// The returned DataPolicyManifestsServerTransport instance is connected to an instance of armpolicy.DataPolicyManifestsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewDataPolicyManifestsServerTransport(srv *DataPolicyManifestsServer) *DataPolicyManifestsServerTransport { + return &DataPolicyManifestsServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[armpolicy.DataPolicyManifestsClientListResponse]](), + } +} + +// DataPolicyManifestsServerTransport connects instances of armpolicy.DataPolicyManifestsClient to instances of DataPolicyManifestsServer. +// Don't use this type directly, use NewDataPolicyManifestsServerTransport instead. +type DataPolicyManifestsServerTransport struct { + srv *DataPolicyManifestsServer + newListPager *tracker[azfake.PagerResponder[armpolicy.DataPolicyManifestsClientListResponse]] +} + +// Do implements the policy.Transporter interface for DataPolicyManifestsServerTransport. +func (d *DataPolicyManifestsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "DataPolicyManifestsClient.GetByPolicyMode": + resp, err = d.dispatchGetByPolicyMode(req) + case "DataPolicyManifestsClient.NewListPager": + resp, err = d.dispatchNewListPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (d *DataPolicyManifestsServerTransport) dispatchGetByPolicyMode(req *http.Request) (*http.Response, error) { + if d.srv.GetByPolicyMode == nil { + return nil, &nonRetriableError{errors.New("fake for method GetByPolicyMode not implemented")} + } + const regexStr = `/providers/Microsoft\.Authorization/dataPolicyManifests/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + policyModeParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyMode")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.GetByPolicyMode(req.Context(), policyModeParam, 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).DataPolicyManifest, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DataPolicyManifestsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := d.newListPager.get(req) + if newListPager == nil { + qp := req.URL.Query() + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + var options *armpolicy.DataPolicyManifestsClientListOptions + if filterParam != nil { + options = &armpolicy.DataPolicyManifestsClientListOptions{ + Filter: filterParam, + } + } + resp := d.srv.NewListPager(options) + newListPager = &resp + d.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armpolicy.DataPolicyManifestsClientListResponse, 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) { + d.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + d.newListPager.remove(req) + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armpolicy/fake/definitions_server.go b/sdk/resourcemanager/resources/armpolicy/fake/definitions_server.go new file mode 100644 index 000000000000..5b01c5054a6a --- /dev/null +++ b/sdk/resourcemanager/resources/armpolicy/fake/definitions_server.go @@ -0,0 +1,532 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// DefinitionsServer is a fake server for instances of the armpolicy.DefinitionsClient type. +type DefinitionsServer struct { + // CreateOrUpdate is the fake for method DefinitionsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusCreated + CreateOrUpdate func(ctx context.Context, policyDefinitionName string, parameters armpolicy.Definition, options *armpolicy.DefinitionsClientCreateOrUpdateOptions) (resp azfake.Responder[armpolicy.DefinitionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // CreateOrUpdateAtManagementGroup is the fake for method DefinitionsClient.CreateOrUpdateAtManagementGroup + // HTTP status codes to indicate success: http.StatusCreated + CreateOrUpdateAtManagementGroup func(ctx context.Context, policyDefinitionName string, managementGroupID string, parameters armpolicy.Definition, options *armpolicy.DefinitionsClientCreateOrUpdateAtManagementGroupOptions) (resp azfake.Responder[armpolicy.DefinitionsClientCreateOrUpdateAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method DefinitionsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, policyDefinitionName string, options *armpolicy.DefinitionsClientDeleteOptions) (resp azfake.Responder[armpolicy.DefinitionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // DeleteAtManagementGroup is the fake for method DefinitionsClient.DeleteAtManagementGroup + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + DeleteAtManagementGroup func(ctx context.Context, policyDefinitionName string, managementGroupID string, options *armpolicy.DefinitionsClientDeleteAtManagementGroupOptions) (resp azfake.Responder[armpolicy.DefinitionsClientDeleteAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method DefinitionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, policyDefinitionName string, options *armpolicy.DefinitionsClientGetOptions) (resp azfake.Responder[armpolicy.DefinitionsClientGetResponse], errResp azfake.ErrorResponder) + + // GetAtManagementGroup is the fake for method DefinitionsClient.GetAtManagementGroup + // HTTP status codes to indicate success: http.StatusOK + GetAtManagementGroup func(ctx context.Context, policyDefinitionName string, managementGroupID string, options *armpolicy.DefinitionsClientGetAtManagementGroupOptions) (resp azfake.Responder[armpolicy.DefinitionsClientGetAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // GetBuiltIn is the fake for method DefinitionsClient.GetBuiltIn + // HTTP status codes to indicate success: http.StatusOK + GetBuiltIn func(ctx context.Context, policyDefinitionName string, options *armpolicy.DefinitionsClientGetBuiltInOptions) (resp azfake.Responder[armpolicy.DefinitionsClientGetBuiltInResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method DefinitionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armpolicy.DefinitionsClientListOptions) (resp azfake.PagerResponder[armpolicy.DefinitionsClientListResponse]) + + // NewListBuiltInPager is the fake for method DefinitionsClient.NewListBuiltInPager + // HTTP status codes to indicate success: http.StatusOK + NewListBuiltInPager func(options *armpolicy.DefinitionsClientListBuiltInOptions) (resp azfake.PagerResponder[armpolicy.DefinitionsClientListBuiltInResponse]) + + // NewListByManagementGroupPager is the fake for method DefinitionsClient.NewListByManagementGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByManagementGroupPager func(managementGroupID string, options *armpolicy.DefinitionsClientListByManagementGroupOptions) (resp azfake.PagerResponder[armpolicy.DefinitionsClientListByManagementGroupResponse]) +} + +// NewDefinitionsServerTransport creates a new instance of DefinitionsServerTransport with the provided implementation. +// The returned DefinitionsServerTransport instance is connected to an instance of armpolicy.DefinitionsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewDefinitionsServerTransport(srv *DefinitionsServer) *DefinitionsServerTransport { + return &DefinitionsServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[armpolicy.DefinitionsClientListResponse]](), + newListBuiltInPager: newTracker[azfake.PagerResponder[armpolicy.DefinitionsClientListBuiltInResponse]](), + newListByManagementGroupPager: newTracker[azfake.PagerResponder[armpolicy.DefinitionsClientListByManagementGroupResponse]](), + } +} + +// DefinitionsServerTransport connects instances of armpolicy.DefinitionsClient to instances of DefinitionsServer. +// Don't use this type directly, use NewDefinitionsServerTransport instead. +type DefinitionsServerTransport struct { + srv *DefinitionsServer + newListPager *tracker[azfake.PagerResponder[armpolicy.DefinitionsClientListResponse]] + newListBuiltInPager *tracker[azfake.PagerResponder[armpolicy.DefinitionsClientListBuiltInResponse]] + newListByManagementGroupPager *tracker[azfake.PagerResponder[armpolicy.DefinitionsClientListByManagementGroupResponse]] +} + +// Do implements the policy.Transporter interface for DefinitionsServerTransport. +func (d *DefinitionsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "DefinitionsClient.CreateOrUpdate": + resp, err = d.dispatchCreateOrUpdate(req) + case "DefinitionsClient.CreateOrUpdateAtManagementGroup": + resp, err = d.dispatchCreateOrUpdateAtManagementGroup(req) + case "DefinitionsClient.Delete": + resp, err = d.dispatchDelete(req) + case "DefinitionsClient.DeleteAtManagementGroup": + resp, err = d.dispatchDeleteAtManagementGroup(req) + case "DefinitionsClient.Get": + resp, err = d.dispatchGet(req) + case "DefinitionsClient.GetAtManagementGroup": + resp, err = d.dispatchGetAtManagementGroup(req) + case "DefinitionsClient.GetBuiltIn": + resp, err = d.dispatchGetBuiltIn(req) + case "DefinitionsClient.NewListPager": + resp, err = d.dispatchNewListPager(req) + case "DefinitionsClient.NewListBuiltInPager": + resp, err = d.dispatchNewListBuiltInPager(req) + case "DefinitionsClient.NewListByManagementGroupPager": + resp, err = d.dispatchNewListByManagementGroupPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (d *DefinitionsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if d.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armpolicy.Definition](req) + if err != nil { + return nil, err + } + policyDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.CreateOrUpdate(req.Context(), policyDefinitionNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Definition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DefinitionsServerTransport) dispatchCreateOrUpdateAtManagementGroup(req *http.Request) (*http.Response, error) { + if d.srv.CreateOrUpdateAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdateAtManagementGroup not implemented")} + } + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armpolicy.Definition](req) + if err != nil { + return nil, err + } + policyDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyDefinitionName")]) + if err != nil { + return nil, err + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.CreateOrUpdateAtManagementGroup(req.Context(), policyDefinitionNameParam, managementGroupIDParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Definition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DefinitionsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if d.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + policyDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Delete(req.Context(), policyDefinitionNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DefinitionsServerTransport) dispatchDeleteAtManagementGroup(req *http.Request) (*http.Response, error) { + if d.srv.DeleteAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method DeleteAtManagementGroup not implemented")} + } + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + policyDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyDefinitionName")]) + if err != nil { + return nil, err + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.DeleteAtManagementGroup(req.Context(), policyDefinitionNameParam, managementGroupIDParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DefinitionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if d.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + policyDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.Get(req.Context(), policyDefinitionNameParam, 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).Definition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DefinitionsServerTransport) dispatchGetAtManagementGroup(req *http.Request) (*http.Response, error) { + if d.srv.GetAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method GetAtManagementGroup not implemented")} + } + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + policyDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyDefinitionName")]) + if err != nil { + return nil, err + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.GetAtManagementGroup(req.Context(), policyDefinitionNameParam, managementGroupIDParam, 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).Definition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DefinitionsServerTransport) dispatchGetBuiltIn(req *http.Request) (*http.Response, error) { + if d.srv.GetBuiltIn == nil { + return nil, &nonRetriableError{errors.New("fake for method GetBuiltIn not implemented")} + } + const regexStr = `/providers/Microsoft\.Authorization/policyDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + policyDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := d.srv.GetBuiltIn(req.Context(), policyDefinitionNameParam, 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).Definition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (d *DefinitionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := d.newListPager.get(req) + if newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyDefinitions` + 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) + } + qp := req.URL.Query() + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armpolicy.DefinitionsClientListOptions + if filterParam != nil || topParam != nil { + options = &armpolicy.DefinitionsClientListOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := d.srv.NewListPager(options) + newListPager = &resp + d.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armpolicy.DefinitionsClientListResponse, 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) { + d.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + d.newListPager.remove(req) + } + return resp, nil +} + +func (d *DefinitionsServerTransport) dispatchNewListBuiltInPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListBuiltInPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListBuiltInPager not implemented")} + } + newListBuiltInPager := d.newListBuiltInPager.get(req) + if newListBuiltInPager == nil { + qp := req.URL.Query() + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armpolicy.DefinitionsClientListBuiltInOptions + if filterParam != nil || topParam != nil { + options = &armpolicy.DefinitionsClientListBuiltInOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := d.srv.NewListBuiltInPager(options) + newListBuiltInPager = &resp + d.newListBuiltInPager.add(req, newListBuiltInPager) + server.PagerResponderInjectNextLinks(newListBuiltInPager, req, func(page *armpolicy.DefinitionsClientListBuiltInResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListBuiltInPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + d.newListBuiltInPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListBuiltInPager) { + d.newListBuiltInPager.remove(req) + } + return resp, nil +} + +func (d *DefinitionsServerTransport) dispatchNewListByManagementGroupPager(req *http.Request) (*http.Response, error) { + if d.srv.NewListByManagementGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByManagementGroupPager not implemented")} + } + newListByManagementGroupPager := d.newListByManagementGroupPager.get(req) + if newListByManagementGroupPager == nil { + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyDefinitions` + 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) + } + qp := req.URL.Query() + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armpolicy.DefinitionsClientListByManagementGroupOptions + if filterParam != nil || topParam != nil { + options = &armpolicy.DefinitionsClientListByManagementGroupOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := d.srv.NewListByManagementGroupPager(managementGroupIDParam, options) + newListByManagementGroupPager = &resp + d.newListByManagementGroupPager.add(req, newListByManagementGroupPager) + server.PagerResponderInjectNextLinks(newListByManagementGroupPager, req, func(page *armpolicy.DefinitionsClientListByManagementGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListByManagementGroupPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + d.newListByManagementGroupPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListByManagementGroupPager) { + d.newListByManagementGroupPager.remove(req) + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armpolicy/fake/exemptions_server.go b/sdk/resourcemanager/resources/armpolicy/fake/exemptions_server.go new file mode 100644 index 000000000000..484ed861a636 --- /dev/null +++ b/sdk/resourcemanager/resources/armpolicy/fake/exemptions_server.go @@ -0,0 +1,468 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy" + "net/http" + "net/url" + "regexp" +) + +// ExemptionsServer is a fake server for instances of the armpolicy.ExemptionsClient type. +type ExemptionsServer struct { + // CreateOrUpdate is the fake for method ExemptionsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, scope string, policyExemptionName string, parameters armpolicy.Exemption, options *armpolicy.ExemptionsClientCreateOrUpdateOptions) (resp azfake.Responder[armpolicy.ExemptionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method ExemptionsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, scope string, policyExemptionName string, options *armpolicy.ExemptionsClientDeleteOptions) (resp azfake.Responder[armpolicy.ExemptionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ExemptionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, scope string, policyExemptionName string, options *armpolicy.ExemptionsClientGetOptions) (resp azfake.Responder[armpolicy.ExemptionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ExemptionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armpolicy.ExemptionsClientListOptions) (resp azfake.PagerResponder[armpolicy.ExemptionsClientListResponse]) + + // NewListForManagementGroupPager is the fake for method ExemptionsClient.NewListForManagementGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListForManagementGroupPager func(managementGroupID string, options *armpolicy.ExemptionsClientListForManagementGroupOptions) (resp azfake.PagerResponder[armpolicy.ExemptionsClientListForManagementGroupResponse]) + + // NewListForResourcePager is the fake for method ExemptionsClient.NewListForResourcePager + // HTTP status codes to indicate success: http.StatusOK + NewListForResourcePager func(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, options *armpolicy.ExemptionsClientListForResourceOptions) (resp azfake.PagerResponder[armpolicy.ExemptionsClientListForResourceResponse]) + + // NewListForResourceGroupPager is the fake for method ExemptionsClient.NewListForResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListForResourceGroupPager func(resourceGroupName string, options *armpolicy.ExemptionsClientListForResourceGroupOptions) (resp azfake.PagerResponder[armpolicy.ExemptionsClientListForResourceGroupResponse]) + + // Update is the fake for method ExemptionsClient.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, scope string, policyExemptionName string, parameters armpolicy.ExemptionUpdate, options *armpolicy.ExemptionsClientUpdateOptions) (resp azfake.Responder[armpolicy.ExemptionsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewExemptionsServerTransport creates a new instance of ExemptionsServerTransport with the provided implementation. +// The returned ExemptionsServerTransport instance is connected to an instance of armpolicy.ExemptionsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewExemptionsServerTransport(srv *ExemptionsServer) *ExemptionsServerTransport { + return &ExemptionsServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[armpolicy.ExemptionsClientListResponse]](), + newListForManagementGroupPager: newTracker[azfake.PagerResponder[armpolicy.ExemptionsClientListForManagementGroupResponse]](), + newListForResourcePager: newTracker[azfake.PagerResponder[armpolicy.ExemptionsClientListForResourceResponse]](), + newListForResourceGroupPager: newTracker[azfake.PagerResponder[armpolicy.ExemptionsClientListForResourceGroupResponse]](), + } +} + +// ExemptionsServerTransport connects instances of armpolicy.ExemptionsClient to instances of ExemptionsServer. +// Don't use this type directly, use NewExemptionsServerTransport instead. +type ExemptionsServerTransport struct { + srv *ExemptionsServer + newListPager *tracker[azfake.PagerResponder[armpolicy.ExemptionsClientListResponse]] + newListForManagementGroupPager *tracker[azfake.PagerResponder[armpolicy.ExemptionsClientListForManagementGroupResponse]] + newListForResourcePager *tracker[azfake.PagerResponder[armpolicy.ExemptionsClientListForResourceResponse]] + newListForResourceGroupPager *tracker[azfake.PagerResponder[armpolicy.ExemptionsClientListForResourceGroupResponse]] +} + +// Do implements the policy.Transporter interface for ExemptionsServerTransport. +func (e *ExemptionsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "ExemptionsClient.CreateOrUpdate": + resp, err = e.dispatchCreateOrUpdate(req) + case "ExemptionsClient.Delete": + resp, err = e.dispatchDelete(req) + case "ExemptionsClient.Get": + resp, err = e.dispatchGet(req) + case "ExemptionsClient.NewListPager": + resp, err = e.dispatchNewListPager(req) + case "ExemptionsClient.NewListForManagementGroupPager": + resp, err = e.dispatchNewListForManagementGroupPager(req) + case "ExemptionsClient.NewListForResourcePager": + resp, err = e.dispatchNewListForResourcePager(req) + case "ExemptionsClient.NewListForResourceGroupPager": + resp, err = e.dispatchNewListForResourceGroupPager(req) + case "ExemptionsClient.Update": + resp, err = e.dispatchUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (e *ExemptionsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if e.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyExemptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armpolicy.Exemption](req) + if err != nil { + return nil, err + } + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + policyExemptionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyExemptionName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.CreateOrUpdate(req.Context(), scopeParam, policyExemptionNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Exemption, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExemptionsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if e.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyExemptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + policyExemptionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyExemptionName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Delete(req.Context(), scopeParam, policyExemptionNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExemptionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if e.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyExemptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + policyExemptionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyExemptionName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Get(req.Context(), scopeParam, policyExemptionNameParam, 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).Exemption, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (e *ExemptionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := e.newListPager.get(req) + if newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyExemptions` + 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) + } + qp := req.URL.Query() + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + var options *armpolicy.ExemptionsClientListOptions + if filterParam != nil { + options = &armpolicy.ExemptionsClientListOptions{ + Filter: filterParam, + } + } + resp := e.srv.NewListPager(options) + newListPager = &resp + e.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armpolicy.ExemptionsClientListResponse, 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) { + e.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + e.newListPager.remove(req) + } + return resp, nil +} + +func (e *ExemptionsServerTransport) dispatchNewListForManagementGroupPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListForManagementGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListForManagementGroupPager not implemented")} + } + newListForManagementGroupPager := e.newListForManagementGroupPager.get(req) + if newListForManagementGroupPager == nil { + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyExemptions` + 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) + } + qp := req.URL.Query() + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + var options *armpolicy.ExemptionsClientListForManagementGroupOptions + if filterParam != nil { + options = &armpolicy.ExemptionsClientListForManagementGroupOptions{ + Filter: filterParam, + } + } + resp := e.srv.NewListForManagementGroupPager(managementGroupIDParam, options) + newListForManagementGroupPager = &resp + e.newListForManagementGroupPager.add(req, newListForManagementGroupPager) + server.PagerResponderInjectNextLinks(newListForManagementGroupPager, req, func(page *armpolicy.ExemptionsClientListForManagementGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListForManagementGroupPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + e.newListForManagementGroupPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListForManagementGroupPager) { + e.newListForManagementGroupPager.remove(req) + } + return resp, nil +} + +func (e *ExemptionsServerTransport) dispatchNewListForResourcePager(req *http.Request) (*http.Response, error) { + if e.srv.NewListForResourcePager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListForResourcePager not implemented")} + } + newListForResourcePager := e.newListForResourcePager.get(req) + if newListForResourcePager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyExemptions` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 6 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + if err != nil { + return nil, err + } + parentResourcePathParam, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + if err != nil { + return nil, err + } + resourceTypeParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + if err != nil { + return nil, err + } + resourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + var options *armpolicy.ExemptionsClientListForResourceOptions + if filterParam != nil { + options = &armpolicy.ExemptionsClientListForResourceOptions{ + Filter: filterParam, + } + } + resp := e.srv.NewListForResourcePager(resourceGroupNameParam, resourceProviderNamespaceParam, parentResourcePathParam, resourceTypeParam, resourceNameParam, options) + newListForResourcePager = &resp + e.newListForResourcePager.add(req, newListForResourcePager) + server.PagerResponderInjectNextLinks(newListForResourcePager, req, func(page *armpolicy.ExemptionsClientListForResourceResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListForResourcePager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + e.newListForResourcePager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListForResourcePager) { + e.newListForResourcePager.remove(req) + } + return resp, nil +} + +func (e *ExemptionsServerTransport) dispatchNewListForResourceGroupPager(req *http.Request) (*http.Response, error) { + if e.srv.NewListForResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListForResourceGroupPager not implemented")} + } + newListForResourceGroupPager := e.newListForResourceGroupPager.get(req) + if newListForResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyExemptions` + 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) + } + qp := req.URL.Query() + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + var options *armpolicy.ExemptionsClientListForResourceGroupOptions + if filterParam != nil { + options = &armpolicy.ExemptionsClientListForResourceGroupOptions{ + Filter: filterParam, + } + } + resp := e.srv.NewListForResourceGroupPager(resourceGroupNameParam, options) + newListForResourceGroupPager = &resp + e.newListForResourceGroupPager.add(req, newListForResourceGroupPager) + server.PagerResponderInjectNextLinks(newListForResourceGroupPager, req, func(page *armpolicy.ExemptionsClientListForResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListForResourceGroupPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + e.newListForResourceGroupPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListForResourceGroupPager) { + e.newListForResourceGroupPager.remove(req) + } + return resp, nil +} + +func (e *ExemptionsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if e.srv.Update == nil { + return nil, &nonRetriableError{errors.New("fake for method Update not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policyExemptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armpolicy.ExemptionUpdate](req) + if err != nil { + return nil, err + } + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + if err != nil { + return nil, err + } + policyExemptionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyExemptionName")]) + if err != nil { + return nil, err + } + respr, errRespr := e.srv.Update(req.Context(), scopeParam, policyExemptionNameParam, body, 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).Exemption, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armpolicy/fake/internal.go b/sdk/resourcemanager/resources/armpolicy/fake/internal.go new file mode 100644 index 000000000000..7d2f89ba4bb2 --- /dev/null +++ b/sdk/resourcemanager/resources/armpolicy/fake/internal.go @@ -0,0 +1,83 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "net/http" + "reflect" + "sync" +) + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} + +func getOptional[T any](v T) *T { + if reflect.ValueOf(v).IsZero() { + return nil + } + return &v +} + +func parseOptional[T any](v string, parse func(v string) (T, error)) (*T, error) { + if v == "" { + return nil, nil + } + t, err := parse(v) + if err != nil { + return nil, err + } + return &t, err +} + +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/resources/armpolicy/fake/server_factory.go b/sdk/resourcemanager/resources/armpolicy/fake/server_factory.go new file mode 100644 index 000000000000..243f08d91d25 --- /dev/null +++ b/sdk/resourcemanager/resources/armpolicy/fake/server_factory.go @@ -0,0 +1,111 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" + "sync" +) + +// ServerFactory is a fake server for instances of the armpolicy.ClientFactory type. +type ServerFactory struct { + AssignmentsServer AssignmentsServer + DataPolicyManifestsServer DataPolicyManifestsServer + DefinitionsServer DefinitionsServer + ExemptionsServer ExemptionsServer + SetDefinitionsServer SetDefinitionsServer + VariableValuesServer VariableValuesServer + VariablesServer VariablesServer +} + +// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. +// The returned ServerFactoryTransport instance is connected to an instance of armpolicy.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 armpolicy.ClientFactory to instances of ServerFactory. +// Don't use this type directly, use NewServerFactoryTransport instead. +type ServerFactoryTransport struct { + srv *ServerFactory + trMu sync.Mutex + trAssignmentsServer *AssignmentsServerTransport + trDataPolicyManifestsServer *DataPolicyManifestsServerTransport + trDefinitionsServer *DefinitionsServerTransport + trExemptionsServer *ExemptionsServerTransport + trSetDefinitionsServer *SetDefinitionsServerTransport + trVariableValuesServer *VariableValuesServerTransport + trVariablesServer *VariablesServerTransport +} + +// 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 "AssignmentsClient": + initServer(s, &s.trAssignmentsServer, func() *AssignmentsServerTransport { return NewAssignmentsServerTransport(&s.srv.AssignmentsServer) }) + resp, err = s.trAssignmentsServer.Do(req) + case "DataPolicyManifestsClient": + initServer(s, &s.trDataPolicyManifestsServer, func() *DataPolicyManifestsServerTransport { + return NewDataPolicyManifestsServerTransport(&s.srv.DataPolicyManifestsServer) + }) + resp, err = s.trDataPolicyManifestsServer.Do(req) + case "DefinitionsClient": + initServer(s, &s.trDefinitionsServer, func() *DefinitionsServerTransport { return NewDefinitionsServerTransport(&s.srv.DefinitionsServer) }) + resp, err = s.trDefinitionsServer.Do(req) + case "ExemptionsClient": + initServer(s, &s.trExemptionsServer, func() *ExemptionsServerTransport { return NewExemptionsServerTransport(&s.srv.ExemptionsServer) }) + resp, err = s.trExemptionsServer.Do(req) + case "SetDefinitionsClient": + initServer(s, &s.trSetDefinitionsServer, func() *SetDefinitionsServerTransport { + return NewSetDefinitionsServerTransport(&s.srv.SetDefinitionsServer) + }) + resp, err = s.trSetDefinitionsServer.Do(req) + case "VariableValuesClient": + initServer(s, &s.trVariableValuesServer, func() *VariableValuesServerTransport { + return NewVariableValuesServerTransport(&s.srv.VariableValuesServer) + }) + resp, err = s.trVariableValuesServer.Do(req) + case "VariablesClient": + initServer(s, &s.trVariablesServer, func() *VariablesServerTransport { return NewVariablesServerTransport(&s.srv.VariablesServer) }) + resp, err = s.trVariablesServer.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/resources/armpolicy/fake/setdefinitions_server.go b/sdk/resourcemanager/resources/armpolicy/fake/setdefinitions_server.go new file mode 100644 index 000000000000..fc89147e3008 --- /dev/null +++ b/sdk/resourcemanager/resources/armpolicy/fake/setdefinitions_server.go @@ -0,0 +1,532 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// SetDefinitionsServer is a fake server for instances of the armpolicy.SetDefinitionsClient type. +type SetDefinitionsServer struct { + // CreateOrUpdate is the fake for method SetDefinitionsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, policySetDefinitionName string, parameters armpolicy.SetDefinition, options *armpolicy.SetDefinitionsClientCreateOrUpdateOptions) (resp azfake.Responder[armpolicy.SetDefinitionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // CreateOrUpdateAtManagementGroup is the fake for method SetDefinitionsClient.CreateOrUpdateAtManagementGroup + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdateAtManagementGroup func(ctx context.Context, policySetDefinitionName string, managementGroupID string, parameters armpolicy.SetDefinition, options *armpolicy.SetDefinitionsClientCreateOrUpdateAtManagementGroupOptions) (resp azfake.Responder[armpolicy.SetDefinitionsClientCreateOrUpdateAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method SetDefinitionsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, policySetDefinitionName string, options *armpolicy.SetDefinitionsClientDeleteOptions) (resp azfake.Responder[armpolicy.SetDefinitionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // DeleteAtManagementGroup is the fake for method SetDefinitionsClient.DeleteAtManagementGroup + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + DeleteAtManagementGroup func(ctx context.Context, policySetDefinitionName string, managementGroupID string, options *armpolicy.SetDefinitionsClientDeleteAtManagementGroupOptions) (resp azfake.Responder[armpolicy.SetDefinitionsClientDeleteAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method SetDefinitionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, policySetDefinitionName string, options *armpolicy.SetDefinitionsClientGetOptions) (resp azfake.Responder[armpolicy.SetDefinitionsClientGetResponse], errResp azfake.ErrorResponder) + + // GetAtManagementGroup is the fake for method SetDefinitionsClient.GetAtManagementGroup + // HTTP status codes to indicate success: http.StatusOK + GetAtManagementGroup func(ctx context.Context, policySetDefinitionName string, managementGroupID string, options *armpolicy.SetDefinitionsClientGetAtManagementGroupOptions) (resp azfake.Responder[armpolicy.SetDefinitionsClientGetAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // GetBuiltIn is the fake for method SetDefinitionsClient.GetBuiltIn + // HTTP status codes to indicate success: http.StatusOK + GetBuiltIn func(ctx context.Context, policySetDefinitionName string, options *armpolicy.SetDefinitionsClientGetBuiltInOptions) (resp azfake.Responder[armpolicy.SetDefinitionsClientGetBuiltInResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method SetDefinitionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armpolicy.SetDefinitionsClientListOptions) (resp azfake.PagerResponder[armpolicy.SetDefinitionsClientListResponse]) + + // NewListBuiltInPager is the fake for method SetDefinitionsClient.NewListBuiltInPager + // HTTP status codes to indicate success: http.StatusOK + NewListBuiltInPager func(options *armpolicy.SetDefinitionsClientListBuiltInOptions) (resp azfake.PagerResponder[armpolicy.SetDefinitionsClientListBuiltInResponse]) + + // NewListByManagementGroupPager is the fake for method SetDefinitionsClient.NewListByManagementGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByManagementGroupPager func(managementGroupID string, options *armpolicy.SetDefinitionsClientListByManagementGroupOptions) (resp azfake.PagerResponder[armpolicy.SetDefinitionsClientListByManagementGroupResponse]) +} + +// NewSetDefinitionsServerTransport creates a new instance of SetDefinitionsServerTransport with the provided implementation. +// The returned SetDefinitionsServerTransport instance is connected to an instance of armpolicy.SetDefinitionsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewSetDefinitionsServerTransport(srv *SetDefinitionsServer) *SetDefinitionsServerTransport { + return &SetDefinitionsServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[armpolicy.SetDefinitionsClientListResponse]](), + newListBuiltInPager: newTracker[azfake.PagerResponder[armpolicy.SetDefinitionsClientListBuiltInResponse]](), + newListByManagementGroupPager: newTracker[azfake.PagerResponder[armpolicy.SetDefinitionsClientListByManagementGroupResponse]](), + } +} + +// SetDefinitionsServerTransport connects instances of armpolicy.SetDefinitionsClient to instances of SetDefinitionsServer. +// Don't use this type directly, use NewSetDefinitionsServerTransport instead. +type SetDefinitionsServerTransport struct { + srv *SetDefinitionsServer + newListPager *tracker[azfake.PagerResponder[armpolicy.SetDefinitionsClientListResponse]] + newListBuiltInPager *tracker[azfake.PagerResponder[armpolicy.SetDefinitionsClientListBuiltInResponse]] + newListByManagementGroupPager *tracker[azfake.PagerResponder[armpolicy.SetDefinitionsClientListByManagementGroupResponse]] +} + +// Do implements the policy.Transporter interface for SetDefinitionsServerTransport. +func (s *SetDefinitionsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "SetDefinitionsClient.CreateOrUpdate": + resp, err = s.dispatchCreateOrUpdate(req) + case "SetDefinitionsClient.CreateOrUpdateAtManagementGroup": + resp, err = s.dispatchCreateOrUpdateAtManagementGroup(req) + case "SetDefinitionsClient.Delete": + resp, err = s.dispatchDelete(req) + case "SetDefinitionsClient.DeleteAtManagementGroup": + resp, err = s.dispatchDeleteAtManagementGroup(req) + case "SetDefinitionsClient.Get": + resp, err = s.dispatchGet(req) + case "SetDefinitionsClient.GetAtManagementGroup": + resp, err = s.dispatchGetAtManagementGroup(req) + case "SetDefinitionsClient.GetBuiltIn": + resp, err = s.dispatchGetBuiltIn(req) + case "SetDefinitionsClient.NewListPager": + resp, err = s.dispatchNewListPager(req) + case "SetDefinitionsClient.NewListBuiltInPager": + resp, err = s.dispatchNewListBuiltInPager(req) + case "SetDefinitionsClient.NewListByManagementGroupPager": + resp, err = s.dispatchNewListByManagementGroupPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *SetDefinitionsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armpolicy.SetDefinition](req) + if err != nil { + return nil, err + } + policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.CreateOrUpdate(req.Context(), policySetDefinitionNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).SetDefinition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SetDefinitionsServerTransport) dispatchCreateOrUpdateAtManagementGroup(req *http.Request) (*http.Response, error) { + if s.srv.CreateOrUpdateAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdateAtManagementGroup not implemented")} + } + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armpolicy.SetDefinition](req) + if err != nil { + return nil, err + } + policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")]) + if err != nil { + return nil, err + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.CreateOrUpdateAtManagementGroup(req.Context(), policySetDefinitionNameParam, managementGroupIDParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).SetDefinition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SetDefinitionsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if s.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Delete(req.Context(), policySetDefinitionNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SetDefinitionsServerTransport) dispatchDeleteAtManagementGroup(req *http.Request) (*http.Response, error) { + if s.srv.DeleteAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method DeleteAtManagementGroup not implemented")} + } + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")]) + if err != nil { + return nil, err + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.DeleteAtManagementGroup(req.Context(), policySetDefinitionNameParam, managementGroupIDParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SetDefinitionsServerTransport) 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~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Get(req.Context(), policySetDefinitionNameParam, 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).SetDefinition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SetDefinitionsServerTransport) dispatchGetAtManagementGroup(req *http.Request) (*http.Response, error) { + if s.srv.GetAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method GetAtManagementGroup not implemented")} + } + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")]) + if err != nil { + return nil, err + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.GetAtManagementGroup(req.Context(), policySetDefinitionNameParam, managementGroupIDParam, 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).SetDefinition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SetDefinitionsServerTransport) dispatchGetBuiltIn(req *http.Request) (*http.Response, error) { + if s.srv.GetBuiltIn == nil { + return nil, &nonRetriableError{errors.New("fake for method GetBuiltIn not implemented")} + } + const regexStr = `/providers/Microsoft\.Authorization/policySetDefinitions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.GetBuiltIn(req.Context(), policySetDefinitionNameParam, 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).SetDefinition, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SetDefinitionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := s.newListPager.get(req) + if newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions` + 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) + } + qp := req.URL.Query() + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armpolicy.SetDefinitionsClientListOptions + if filterParam != nil || topParam != nil { + options = &armpolicy.SetDefinitionsClientListOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := s.srv.NewListPager(options) + newListPager = &resp + s.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armpolicy.SetDefinitionsClientListResponse, 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) { + s.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + s.newListPager.remove(req) + } + return resp, nil +} + +func (s *SetDefinitionsServerTransport) dispatchNewListBuiltInPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListBuiltInPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListBuiltInPager not implemented")} + } + newListBuiltInPager := s.newListBuiltInPager.get(req) + if newListBuiltInPager == nil { + qp := req.URL.Query() + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armpolicy.SetDefinitionsClientListBuiltInOptions + if filterParam != nil || topParam != nil { + options = &armpolicy.SetDefinitionsClientListBuiltInOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := s.srv.NewListBuiltInPager(options) + newListBuiltInPager = &resp + s.newListBuiltInPager.add(req, newListBuiltInPager) + server.PagerResponderInjectNextLinks(newListBuiltInPager, req, func(page *armpolicy.SetDefinitionsClientListBuiltInResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListBuiltInPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + s.newListBuiltInPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListBuiltInPager) { + s.newListBuiltInPager.remove(req) + } + return resp, nil +} + +func (s *SetDefinitionsServerTransport) dispatchNewListByManagementGroupPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListByManagementGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByManagementGroupPager not implemented")} + } + newListByManagementGroupPager := s.newListByManagementGroupPager.get(req) + if newListByManagementGroupPager == nil { + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions` + 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) + } + qp := req.URL.Query() + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + topUnescaped, err := url.QueryUnescape(qp.Get("$top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + var options *armpolicy.SetDefinitionsClientListByManagementGroupOptions + if filterParam != nil || topParam != nil { + options = &armpolicy.SetDefinitionsClientListByManagementGroupOptions{ + Filter: filterParam, + Top: topParam, + } + } + resp := s.srv.NewListByManagementGroupPager(managementGroupIDParam, options) + newListByManagementGroupPager = &resp + s.newListByManagementGroupPager.add(req, newListByManagementGroupPager) + server.PagerResponderInjectNextLinks(newListByManagementGroupPager, req, func(page *armpolicy.SetDefinitionsClientListByManagementGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListByManagementGroupPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + s.newListByManagementGroupPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListByManagementGroupPager) { + s.newListByManagementGroupPager.remove(req) + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armpolicy/fake/time_rfc3339.go b/sdk/resourcemanager/resources/armpolicy/fake/time_rfc3339.go new file mode 100644 index 000000000000..b0535a7b63e6 --- /dev/null +++ b/sdk/resourcemanager/resources/armpolicy/fake/time_rfc3339.go @@ -0,0 +1,86 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "regexp" + "strings" + "time" +) + +// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. +var tzOffsetRegex = regexp.MustCompile(`(Z|z|\+|-)(\d+:\d+)*"*$`) + +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +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 { + layout := utcDateTimeJSON + if tzOffsetRegex.Match(data) { + layout = dateTimeJSON + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime + if tzOffsetRegex.Match(data) { + layout = time.RFC3339Nano + } + 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 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 || strings.EqualFold(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/resources/armpolicy/fake/variables_server.go b/sdk/resourcemanager/resources/armpolicy/fake/variables_server.go new file mode 100644 index 000000000000..05fbf5ea665d --- /dev/null +++ b/sdk/resourcemanager/resources/armpolicy/fake/variables_server.go @@ -0,0 +1,380 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy" + "net/http" + "net/url" + "regexp" +) + +// VariablesServer is a fake server for instances of the armpolicy.VariablesClient type. +type VariablesServer struct { + // CreateOrUpdate is the fake for method VariablesClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, variableName string, parameters armpolicy.Variable, options *armpolicy.VariablesClientCreateOrUpdateOptions) (resp azfake.Responder[armpolicy.VariablesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // CreateOrUpdateAtManagementGroup is the fake for method VariablesClient.CreateOrUpdateAtManagementGroup + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdateAtManagementGroup func(ctx context.Context, managementGroupID string, variableName string, parameters armpolicy.Variable, options *armpolicy.VariablesClientCreateOrUpdateAtManagementGroupOptions) (resp azfake.Responder[armpolicy.VariablesClientCreateOrUpdateAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method VariablesClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, variableName string, options *armpolicy.VariablesClientDeleteOptions) (resp azfake.Responder[armpolicy.VariablesClientDeleteResponse], errResp azfake.ErrorResponder) + + // DeleteAtManagementGroup is the fake for method VariablesClient.DeleteAtManagementGroup + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + DeleteAtManagementGroup func(ctx context.Context, managementGroupID string, variableName string, options *armpolicy.VariablesClientDeleteAtManagementGroupOptions) (resp azfake.Responder[armpolicy.VariablesClientDeleteAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VariablesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, variableName string, options *armpolicy.VariablesClientGetOptions) (resp azfake.Responder[armpolicy.VariablesClientGetResponse], errResp azfake.ErrorResponder) + + // GetAtManagementGroup is the fake for method VariablesClient.GetAtManagementGroup + // HTTP status codes to indicate success: http.StatusOK + GetAtManagementGroup func(ctx context.Context, managementGroupID string, variableName string, options *armpolicy.VariablesClientGetAtManagementGroupOptions) (resp azfake.Responder[armpolicy.VariablesClientGetAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VariablesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armpolicy.VariablesClientListOptions) (resp azfake.PagerResponder[armpolicy.VariablesClientListResponse]) + + // NewListForManagementGroupPager is the fake for method VariablesClient.NewListForManagementGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListForManagementGroupPager func(managementGroupID string, options *armpolicy.VariablesClientListForManagementGroupOptions) (resp azfake.PagerResponder[armpolicy.VariablesClientListForManagementGroupResponse]) +} + +// NewVariablesServerTransport creates a new instance of VariablesServerTransport with the provided implementation. +// The returned VariablesServerTransport instance is connected to an instance of armpolicy.VariablesClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewVariablesServerTransport(srv *VariablesServer) *VariablesServerTransport { + return &VariablesServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[armpolicy.VariablesClientListResponse]](), + newListForManagementGroupPager: newTracker[azfake.PagerResponder[armpolicy.VariablesClientListForManagementGroupResponse]](), + } +} + +// VariablesServerTransport connects instances of armpolicy.VariablesClient to instances of VariablesServer. +// Don't use this type directly, use NewVariablesServerTransport instead. +type VariablesServerTransport struct { + srv *VariablesServer + newListPager *tracker[azfake.PagerResponder[armpolicy.VariablesClientListResponse]] + newListForManagementGroupPager *tracker[azfake.PagerResponder[armpolicy.VariablesClientListForManagementGroupResponse]] +} + +// Do implements the policy.Transporter interface for VariablesServerTransport. +func (v *VariablesServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "VariablesClient.CreateOrUpdate": + resp, err = v.dispatchCreateOrUpdate(req) + case "VariablesClient.CreateOrUpdateAtManagementGroup": + resp, err = v.dispatchCreateOrUpdateAtManagementGroup(req) + case "VariablesClient.Delete": + resp, err = v.dispatchDelete(req) + case "VariablesClient.DeleteAtManagementGroup": + resp, err = v.dispatchDeleteAtManagementGroup(req) + case "VariablesClient.Get": + resp, err = v.dispatchGet(req) + case "VariablesClient.GetAtManagementGroup": + resp, err = v.dispatchGetAtManagementGroup(req) + case "VariablesClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VariablesClient.NewListForManagementGroupPager": + resp, err = v.dispatchNewListForManagementGroupPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VariablesServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armpolicy.Variable](req) + if err != nil { + return nil, err + } + variableNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.CreateOrUpdate(req.Context(), variableNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Variable, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VariablesServerTransport) dispatchCreateOrUpdateAtManagementGroup(req *http.Request) (*http.Response, error) { + if v.srv.CreateOrUpdateAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdateAtManagementGroup not implemented")} + } + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armpolicy.Variable](req) + if err != nil { + return nil, err + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + variableNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.CreateOrUpdateAtManagementGroup(req.Context(), managementGroupIDParam, variableNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Variable, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VariablesServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if v.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + variableNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Delete(req.Context(), variableNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VariablesServerTransport) dispatchDeleteAtManagementGroup(req *http.Request) (*http.Response, error) { + if v.srv.DeleteAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method DeleteAtManagementGroup not implemented")} + } + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + variableNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.DeleteAtManagementGroup(req.Context(), managementGroupIDParam, variableNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VariablesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + variableNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), variableNameParam, 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).Variable, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VariablesServerTransport) dispatchGetAtManagementGroup(req *http.Request) (*http.Response, error) { + if v.srv.GetAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method GetAtManagementGroup not implemented")} + } + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + variableNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.GetAtManagementGroup(req.Context(), managementGroupIDParam, variableNameParam, 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).Variable, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VariablesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := v.newListPager.get(req) + if newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables` + 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 := v.srv.NewListPager(nil) + newListPager = &resp + v.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armpolicy.VariablesClientListResponse, 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) { + v.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + v.newListPager.remove(req) + } + return resp, nil +} + +func (v *VariablesServerTransport) dispatchNewListForManagementGroupPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListForManagementGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListForManagementGroupPager not implemented")} + } + newListForManagementGroupPager := v.newListForManagementGroupPager.get(req) + if newListForManagementGroupPager == nil { + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables` + 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) + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListForManagementGroupPager(managementGroupIDParam, nil) + newListForManagementGroupPager = &resp + v.newListForManagementGroupPager.add(req, newListForManagementGroupPager) + server.PagerResponderInjectNextLinks(newListForManagementGroupPager, req, func(page *armpolicy.VariablesClientListForManagementGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListForManagementGroupPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + v.newListForManagementGroupPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListForManagementGroupPager) { + v.newListForManagementGroupPager.remove(req) + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armpolicy/fake/variablevalues_server.go b/sdk/resourcemanager/resources/armpolicy/fake/variablevalues_server.go new file mode 100644 index 000000000000..f63f4ae48ac8 --- /dev/null +++ b/sdk/resourcemanager/resources/armpolicy/fake/variablevalues_server.go @@ -0,0 +1,412 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy" + "net/http" + "net/url" + "regexp" +) + +// VariableValuesServer is a fake server for instances of the armpolicy.VariableValuesClient type. +type VariableValuesServer struct { + // CreateOrUpdate is the fake for method VariableValuesClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, variableName string, variableValueName string, parameters armpolicy.VariableValue, options *armpolicy.VariableValuesClientCreateOrUpdateOptions) (resp azfake.Responder[armpolicy.VariableValuesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // CreateOrUpdateAtManagementGroup is the fake for method VariableValuesClient.CreateOrUpdateAtManagementGroup + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdateAtManagementGroup func(ctx context.Context, managementGroupID string, variableName string, variableValueName string, parameters armpolicy.VariableValue, options *armpolicy.VariableValuesClientCreateOrUpdateAtManagementGroupOptions) (resp azfake.Responder[armpolicy.VariableValuesClientCreateOrUpdateAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method VariableValuesClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, variableName string, variableValueName string, options *armpolicy.VariableValuesClientDeleteOptions) (resp azfake.Responder[armpolicy.VariableValuesClientDeleteResponse], errResp azfake.ErrorResponder) + + // DeleteAtManagementGroup is the fake for method VariableValuesClient.DeleteAtManagementGroup + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + DeleteAtManagementGroup func(ctx context.Context, managementGroupID string, variableName string, variableValueName string, options *armpolicy.VariableValuesClientDeleteAtManagementGroupOptions) (resp azfake.Responder[armpolicy.VariableValuesClientDeleteAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method VariableValuesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, variableName string, variableValueName string, options *armpolicy.VariableValuesClientGetOptions) (resp azfake.Responder[armpolicy.VariableValuesClientGetResponse], errResp azfake.ErrorResponder) + + // GetAtManagementGroup is the fake for method VariableValuesClient.GetAtManagementGroup + // HTTP status codes to indicate success: http.StatusOK + GetAtManagementGroup func(ctx context.Context, managementGroupID string, variableName string, variableValueName string, options *armpolicy.VariableValuesClientGetAtManagementGroupOptions) (resp azfake.Responder[armpolicy.VariableValuesClientGetAtManagementGroupResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method VariableValuesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(variableName string, options *armpolicy.VariableValuesClientListOptions) (resp azfake.PagerResponder[armpolicy.VariableValuesClientListResponse]) + + // NewListForManagementGroupPager is the fake for method VariableValuesClient.NewListForManagementGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListForManagementGroupPager func(managementGroupID string, variableName string, options *armpolicy.VariableValuesClientListForManagementGroupOptions) (resp azfake.PagerResponder[armpolicy.VariableValuesClientListForManagementGroupResponse]) +} + +// NewVariableValuesServerTransport creates a new instance of VariableValuesServerTransport with the provided implementation. +// The returned VariableValuesServerTransport instance is connected to an instance of armpolicy.VariableValuesClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewVariableValuesServerTransport(srv *VariableValuesServer) *VariableValuesServerTransport { + return &VariableValuesServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[armpolicy.VariableValuesClientListResponse]](), + newListForManagementGroupPager: newTracker[azfake.PagerResponder[armpolicy.VariableValuesClientListForManagementGroupResponse]](), + } +} + +// VariableValuesServerTransport connects instances of armpolicy.VariableValuesClient to instances of VariableValuesServer. +// Don't use this type directly, use NewVariableValuesServerTransport instead. +type VariableValuesServerTransport struct { + srv *VariableValuesServer + newListPager *tracker[azfake.PagerResponder[armpolicy.VariableValuesClientListResponse]] + newListForManagementGroupPager *tracker[azfake.PagerResponder[armpolicy.VariableValuesClientListForManagementGroupResponse]] +} + +// Do implements the policy.Transporter interface for VariableValuesServerTransport. +func (v *VariableValuesServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "VariableValuesClient.CreateOrUpdate": + resp, err = v.dispatchCreateOrUpdate(req) + case "VariableValuesClient.CreateOrUpdateAtManagementGroup": + resp, err = v.dispatchCreateOrUpdateAtManagementGroup(req) + case "VariableValuesClient.Delete": + resp, err = v.dispatchDelete(req) + case "VariableValuesClient.DeleteAtManagementGroup": + resp, err = v.dispatchDeleteAtManagementGroup(req) + case "VariableValuesClient.Get": + resp, err = v.dispatchGet(req) + case "VariableValuesClient.GetAtManagementGroup": + resp, err = v.dispatchGetAtManagementGroup(req) + case "VariableValuesClient.NewListPager": + resp, err = v.dispatchNewListPager(req) + case "VariableValuesClient.NewListForManagementGroupPager": + resp, err = v.dispatchNewListForManagementGroupPager(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (v *VariableValuesServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if v.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/values/(?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[armpolicy.VariableValue](req) + if err != nil { + return nil, err + } + variableNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableName")]) + if err != nil { + return nil, err + } + variableValueNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableValueName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.CreateOrUpdate(req.Context(), variableNameParam, variableValueNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).VariableValue, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VariableValuesServerTransport) dispatchCreateOrUpdateAtManagementGroup(req *http.Request) (*http.Response, error) { + if v.srv.CreateOrUpdateAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdateAtManagementGroup not implemented")} + } + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/values/(?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[armpolicy.VariableValue](req) + if err != nil { + return nil, err + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + variableNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableName")]) + if err != nil { + return nil, err + } + variableValueNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableValueName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.CreateOrUpdateAtManagementGroup(req.Context(), managementGroupIDParam, variableNameParam, variableValueNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).VariableValue, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VariableValuesServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if v.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/values/(?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) + } + variableNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableName")]) + if err != nil { + return nil, err + } + variableValueNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableValueName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Delete(req.Context(), variableNameParam, variableValueNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VariableValuesServerTransport) dispatchDeleteAtManagementGroup(req *http.Request) (*http.Response, error) { + if v.srv.DeleteAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method DeleteAtManagementGroup not implemented")} + } + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/values/(?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) + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + variableNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableName")]) + if err != nil { + return nil, err + } + variableValueNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableValueName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.DeleteAtManagementGroup(req.Context(), managementGroupIDParam, variableNameParam, variableValueNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VariableValuesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if v.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/values/(?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) + } + variableNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableName")]) + if err != nil { + return nil, err + } + variableValueNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableValueName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.Get(req.Context(), variableNameParam, variableValueNameParam, 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).VariableValue, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VariableValuesServerTransport) dispatchGetAtManagementGroup(req *http.Request) (*http.Response, error) { + if v.srv.GetAtManagementGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method GetAtManagementGroup not implemented")} + } + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/values/(?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) + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + variableNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableName")]) + if err != nil { + return nil, err + } + variableValueNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableValueName")]) + if err != nil { + return nil, err + } + respr, errRespr := v.srv.GetAtManagementGroup(req.Context(), managementGroupIDParam, variableNameParam, variableValueNameParam, 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).VariableValue, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (v *VariableValuesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := v.newListPager.get(req) + if newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/values` + 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) + } + variableNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListPager(variableNameParam, nil) + newListPager = &resp + v.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armpolicy.VariableValuesClientListResponse, 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) { + v.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + v.newListPager.remove(req) + } + return resp, nil +} + +func (v *VariableValuesServerTransport) dispatchNewListForManagementGroupPager(req *http.Request) (*http.Response, error) { + if v.srv.NewListForManagementGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListForManagementGroupPager not implemented")} + } + newListForManagementGroupPager := v.newListForManagementGroupPager.get(req) + if newListForManagementGroupPager == nil { + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/variables/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/values` + 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) + } + managementGroupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupId")]) + if err != nil { + return nil, err + } + variableNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("variableName")]) + if err != nil { + return nil, err + } + resp := v.srv.NewListForManagementGroupPager(managementGroupIDParam, variableNameParam, nil) + newListForManagementGroupPager = &resp + v.newListForManagementGroupPager.add(req, newListForManagementGroupPager) + server.PagerResponderInjectNextLinks(newListForManagementGroupPager, req, func(page *armpolicy.VariableValuesClientListForManagementGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListForManagementGroupPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + v.newListForManagementGroupPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListForManagementGroupPager) { + v.newListForManagementGroupPager.remove(req) + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armpolicy/go.mod b/sdk/resourcemanager/resources/armpolicy/go.mod index 24cd8514702e..c94089008a8b 100644 --- a/sdk/resourcemanager/resources/armpolicy/go.mod +++ b/sdk/resourcemanager/resources/armpolicy/go.mod @@ -3,27 +3,27 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 - github.com/stretchr/testify v1.7.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 + github.com/stretchr/testify v1.8.4 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 // indirect - github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dnaeon/go-vcr v1.1.0 // indirect - github.com/golang-jwt/jwt/v4 v4.4.2 // indirect - github.com/google/uuid v1.1.1 // indirect + github.com/dnaeon/go-vcr v1.2.0 // indirect + github.com/golang-jwt/jwt/v5 v5.0.0 // indirect + github.com/google/uuid v1.3.1 // indirect github.com/kylelemons/godebug v1.1.0 // indirect - github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect + github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 // indirect - golang.org/x/net v0.8.0 // indirect - golang.org/x/sys v0.6.0 // indirect - golang.org/x/text v0.8.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/sdk/resourcemanager/resources/armpolicy/go.sum b/sdk/resourcemanager/resources/armpolicy/go.sum index 592e81cc36bb..88bb72abf2ba 100644 --- a/sdk/resourcemanager/resources/armpolicy/go.sum +++ b/sdk/resourcemanager/resources/armpolicy/go.sum @@ -1,47 +1,47 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1 h1:SEy2xmstIphdPwNBUi7uhvjyjhVKISfwjfOJmuy7kg4= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 h1:t/W5MYAuQy81cvM8VUNfRLzhtKpXhVUAN7Cd7KVbTyc= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0/go.mod h1:NBanQUfSWiWn3QEpWDTCU0IjBECKOYvl2R8xdRtMtiM= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 h1:fb8kj/Dh4CSwgsOzHeZY4Xh68cFVbzXx+ONXGMY//4w= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0/go.mod h1:uReU2sSxZExRPBAg3qKzmAucSi51+SP1OhohieR821Q= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 h1:BMAjVKJM0U/CYF27gA0ZMmXGkOcvfFtD0oHVZ1TIPRI= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0/go.mod h1:1fXstnBMas5kzG+S3q8UoJcmyU6nUeunJcMDHcRYHhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 h1:ECsQtyERDVz3NP3kvDOTLvbQhqWp/x9EsGKtb4ogUr8= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0/go.mod h1:s1tW/At+xHqjNFvWU4G0c0Qv33KOhvbGNj0RCTQDV8s= -github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 h1:VgSJlZH5u0k2qxSpqyghcFQKmvYckj46uymKK5XzkBM= -github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0/go.mod h1:BDJ5qMFKx9DugEg3+uQSDCdbYPr5s9vBTrL9P8TpqOU= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 h1:PTFGRSlMKCQelWwxUyYVEUqseBJVemLyqWJjvMyt0do= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0/go.mod h1:LRr2FzBTQlONPPa5HREE5+RjSCTXl7BwOvYOaWTqCaI= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 h1:pPvTJ1dY0sA35JOeFq6TsY2xj6Z85Yo23Pj4wCCvu4o= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 h1:7CBQ+Ei8SP2c6ydQTGCCrS35bDxgTMfoP2miAwK++OU= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1/go.mod h1:c/wcGeGx5FUPbM/JltUYHZcKmigwyVLJlDq+4HdtXaw= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 h1:WpB/QDNLpMw72xHJc34BNNykqSOeEJDAWkhf0u12/Jk= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= -github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= -github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs= -github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= +github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= +github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/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/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= -github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 h1:Qj1ukM4GlMWXNdMBuXcXfz/Kw9s1qm0CLY32QxuSImI= -github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 h1:Tgea0cVUD0ivh5ADBX4WwuI12DUd2to3nCYe2eayMIw= -golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/resourcemanager/resources/armpolicy/models_serde.go b/sdk/resourcemanager/resources/armpolicy/models_serde.go index d381359681dc..74cb09e1e08b 100644 --- a/sdk/resourcemanager/resources/armpolicy/models_serde.go +++ b/sdk/resourcemanager/resources/armpolicy/models_serde.go @@ -892,7 +892,7 @@ func (e ExemptionProperties) MarshalJSON() ([]byte, error) { populate(objectMap, "description", e.Description) populate(objectMap, "displayName", e.DisplayName) populate(objectMap, "exemptionCategory", e.ExemptionCategory) - populateTimeRFC3339(objectMap, "expiresOn", e.ExpiresOn) + populateDateTimeRFC3339(objectMap, "expiresOn", e.ExpiresOn) populateAny(objectMap, "metadata", e.Metadata) populate(objectMap, "policyAssignmentId", e.PolicyAssignmentID) populate(objectMap, "policyDefinitionReferenceIds", e.PolicyDefinitionReferenceIDs) @@ -922,7 +922,7 @@ func (e *ExemptionProperties) UnmarshalJSON(data []byte) error { err = unpopulate(val, "ExemptionCategory", &e.ExemptionCategory) delete(rawMsg, key) case "expiresOn": - err = unpopulateTimeRFC3339(val, "ExpiresOn", &e.ExpiresOn) + err = unpopulateDateTimeRFC3339(val, "ExpiresOn", &e.ExpiresOn) delete(rawMsg, key) case "metadata": err = unpopulate(val, "Metadata", &e.Metadata) @@ -1452,10 +1452,10 @@ func (s *SetDefinitionProperties) UnmarshalJSON(data []byte) error { // MarshalJSON implements the json.Marshaller interface for type SystemData. func (s SystemData) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populateTimeRFC3339(objectMap, "createdAt", s.CreatedAt) + populateDateTimeRFC3339(objectMap, "createdAt", s.CreatedAt) populate(objectMap, "createdBy", s.CreatedBy) populate(objectMap, "createdByType", s.CreatedByType) - populateTimeRFC3339(objectMap, "lastModifiedAt", s.LastModifiedAt) + populateDateTimeRFC3339(objectMap, "lastModifiedAt", s.LastModifiedAt) populate(objectMap, "lastModifiedBy", s.LastModifiedBy) populate(objectMap, "lastModifiedByType", s.LastModifiedByType) return json.Marshal(objectMap) @@ -1471,7 +1471,7 @@ func (s *SystemData) UnmarshalJSON(data []byte) error { var err error switch key { case "createdAt": - err = unpopulateTimeRFC3339(val, "CreatedAt", &s.CreatedAt) + err = unpopulateDateTimeRFC3339(val, "CreatedAt", &s.CreatedAt) delete(rawMsg, key) case "createdBy": err = unpopulate(val, "CreatedBy", &s.CreatedBy) @@ -1480,7 +1480,7 @@ func (s *SystemData) UnmarshalJSON(data []byte) error { err = unpopulate(val, "CreatedByType", &s.CreatedByType) delete(rawMsg, key) case "lastModifiedAt": - err = unpopulateTimeRFC3339(val, "LastModifiedAt", &s.LastModifiedAt) + err = unpopulateDateTimeRFC3339(val, "LastModifiedAt", &s.LastModifiedAt) delete(rawMsg, key) case "lastModifiedBy": err = unpopulate(val, "LastModifiedBy", &s.LastModifiedBy) diff --git a/sdk/resourcemanager/resources/armpolicy/policydefinitions_client_live_test.go b/sdk/resourcemanager/resources/armpolicy/policydefinitions_client_live_test.go index c4fc515c06ee..3f2a02070b41 100644 --- a/sdk/resourcemanager/resources/armpolicy/policydefinitions_client_live_test.go +++ b/sdk/resourcemanager/resources/armpolicy/policydefinitions_client_live_test.go @@ -14,7 +14,7 @@ import ( "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/to" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy" "github.com/stretchr/testify/suite" ) diff --git a/sdk/resourcemanager/resources/armpolicy/setdefinitions_client.go b/sdk/resourcemanager/resources/armpolicy/setdefinitions_client.go index 2a9e2e19e681..457a89d51f08 100644 --- a/sdk/resourcemanager/resources/armpolicy/setdefinitions_client.go +++ b/sdk/resourcemanager/resources/armpolicy/setdefinitions_client.go @@ -33,7 +33,7 @@ type SetDefinitionsClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewSetDefinitionsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*SetDefinitionsClient, error) { - cl, err := arm.NewClient(moduleName+".SetDefinitionsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -54,6 +54,10 @@ func NewSetDefinitionsClient(subscriptionID string, credential azcore.TokenCrede // method. func (client *SetDefinitionsClient) CreateOrUpdate(ctx context.Context, policySetDefinitionName string, parameters SetDefinition, options *SetDefinitionsClientCreateOrUpdateOptions) (SetDefinitionsClientCreateOrUpdateResponse, error) { var err error + const operationName = "SetDefinitionsClient.CreateOrUpdate" + 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, policySetDefinitionName, parameters, options) if err != nil { return SetDefinitionsClientCreateOrUpdateResponse{}, err @@ -116,6 +120,10 @@ func (client *SetDefinitionsClient) createOrUpdateHandleResponse(resp *http.Resp // method. func (client *SetDefinitionsClient) CreateOrUpdateAtManagementGroup(ctx context.Context, policySetDefinitionName string, managementGroupID string, parameters SetDefinition, options *SetDefinitionsClientCreateOrUpdateAtManagementGroupOptions) (SetDefinitionsClientCreateOrUpdateAtManagementGroupResponse, error) { var err error + const operationName = "SetDefinitionsClient.CreateOrUpdateAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateAtManagementGroupCreateRequest(ctx, policySetDefinitionName, managementGroupID, parameters, options) if err != nil { return SetDefinitionsClientCreateOrUpdateAtManagementGroupResponse{}, err @@ -174,6 +182,10 @@ func (client *SetDefinitionsClient) createOrUpdateAtManagementGroupHandleRespons // - options - SetDefinitionsClientDeleteOptions contains the optional parameters for the SetDefinitionsClient.Delete method. func (client *SetDefinitionsClient) Delete(ctx context.Context, policySetDefinitionName string, options *SetDefinitionsClientDeleteOptions) (SetDefinitionsClientDeleteResponse, error) { var err error + const operationName = "SetDefinitionsClient.Delete" + 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, policySetDefinitionName, options) if err != nil { return SetDefinitionsClientDeleteResponse{}, err @@ -222,6 +234,10 @@ func (client *SetDefinitionsClient) deleteCreateRequest(ctx context.Context, pol // method. func (client *SetDefinitionsClient) DeleteAtManagementGroup(ctx context.Context, policySetDefinitionName string, managementGroupID string, options *SetDefinitionsClientDeleteAtManagementGroupOptions) (SetDefinitionsClientDeleteAtManagementGroupResponse, error) { var err error + const operationName = "SetDefinitionsClient.DeleteAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAtManagementGroupCreateRequest(ctx, policySetDefinitionName, managementGroupID, options) if err != nil { return SetDefinitionsClientDeleteAtManagementGroupResponse{}, err @@ -267,6 +283,10 @@ func (client *SetDefinitionsClient) deleteAtManagementGroupCreateRequest(ctx con // - options - SetDefinitionsClientGetOptions contains the optional parameters for the SetDefinitionsClient.Get method. func (client *SetDefinitionsClient) Get(ctx context.Context, policySetDefinitionName string, options *SetDefinitionsClientGetOptions) (SetDefinitionsClientGetResponse, error) { var err error + const operationName = "SetDefinitionsClient.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, policySetDefinitionName, options) if err != nil { return SetDefinitionsClientGetResponse{}, err @@ -325,6 +345,10 @@ func (client *SetDefinitionsClient) getHandleResponse(resp *http.Response) (SetD // method. func (client *SetDefinitionsClient) GetAtManagementGroup(ctx context.Context, policySetDefinitionName string, managementGroupID string, options *SetDefinitionsClientGetAtManagementGroupOptions) (SetDefinitionsClientGetAtManagementGroupResponse, error) { var err error + const operationName = "SetDefinitionsClient.GetAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtManagementGroupCreateRequest(ctx, policySetDefinitionName, managementGroupID, options) if err != nil { return SetDefinitionsClientGetAtManagementGroupResponse{}, err @@ -381,6 +405,10 @@ func (client *SetDefinitionsClient) getAtManagementGroupHandleResponse(resp *htt // method. func (client *SetDefinitionsClient) GetBuiltIn(ctx context.Context, policySetDefinitionName string, options *SetDefinitionsClientGetBuiltInOptions) (SetDefinitionsClientGetBuiltInResponse, error) { var err error + const operationName = "SetDefinitionsClient.GetBuiltIn" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getBuiltInCreateRequest(ctx, policySetDefinitionName, options) if err != nil { return SetDefinitionsClientGetBuiltInResponse{}, err @@ -443,25 +471,20 @@ func (client *SetDefinitionsClient) NewListPager(options *SetDefinitionsClientLi return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SetDefinitionsClientListResponse) (SetDefinitionsClientListResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SetDefinitionsClient.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 SetDefinitionsClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return SetDefinitionsClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SetDefinitionsClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -513,25 +536,20 @@ func (client *SetDefinitionsClient) NewListBuiltInPager(options *SetDefinitionsC return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SetDefinitionsClientListBuiltInResponse) (SetDefinitionsClientListBuiltInResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listBuiltInCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return SetDefinitionsClientListBuiltInResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SetDefinitionsClient.NewListBuiltInPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listBuiltInCreateRequest(ctx, options) + }, nil) if err != nil { return SetDefinitionsClientListBuiltInResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SetDefinitionsClientListBuiltInResponse{}, runtime.NewResponseError(resp) - } return client.listBuiltInHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -587,25 +605,20 @@ func (client *SetDefinitionsClient) NewListByManagementGroupPager(managementGrou return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *SetDefinitionsClientListByManagementGroupResponse) (SetDefinitionsClientListByManagementGroupResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listByManagementGroupCreateRequest(ctx, managementGroupID, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return SetDefinitionsClientListByManagementGroupResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SetDefinitionsClient.NewListByManagementGroupPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listByManagementGroupCreateRequest(ctx, managementGroupID, options) + }, nil) if err != nil { return SetDefinitionsClientListByManagementGroupResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return SetDefinitionsClientListByManagementGroupResponse{}, runtime.NewResponseError(resp) - } return client.listByManagementGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armpolicy/time_rfc3339.go b/sdk/resourcemanager/resources/armpolicy/time_rfc3339.go index fc0590d74830..b5e151c43800 100644 --- a/sdk/resourcemanager/resources/armpolicy/time_rfc3339.go +++ b/sdk/resourcemanager/resources/armpolicy/time_rfc3339.go @@ -18,50 +18,50 @@ import ( "time" ) -const ( - utcLayoutJSON = `"2006-01-02T15:04:05.999999999"` - utcLayout = "2006-01-02T15:04:05.999999999" - rfc3339JSON = `"` + time.RFC3339Nano + `"` -) - // 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+)*"*$`) -type timeRFC3339 time.Time +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +type dateTimeRFC3339 time.Time -func (t timeRFC3339) MarshalJSON() (json []byte, err error) { +func (t dateTimeRFC3339) MarshalJSON() ([]byte, error) { tt := time.Time(t) return tt.MarshalJSON() } -func (t timeRFC3339) MarshalText() (text []byte, err error) { +func (t dateTimeRFC3339) MarshalText() ([]byte, error) { tt := time.Time(t) return tt.MarshalText() } -func (t *timeRFC3339) UnmarshalJSON(data []byte) error { - layout := utcLayoutJSON +func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { + layout := utcDateTimeJSON if tzOffsetRegex.Match(data) { - layout = rfc3339JSON + layout = dateTimeJSON } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) UnmarshalText(data []byte) (err error) { - layout := utcLayout +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime if tzOffsetRegex.Match(data) { layout = time.RFC3339Nano } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) Parse(layout, value string) error { +func (t *dateTimeRFC3339) Parse(layout, value string) error { p, err := time.Parse(layout, strings.ToUpper(value)) - *t = timeRFC3339(p) + *t = dateTimeRFC3339(p) return err } -func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { +func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { if t == nil { return } else if azcore.IsNullValue(t) { @@ -70,14 +70,14 @@ func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { } else if reflect.ValueOf(t).IsNil() { return } - m[k] = (*timeRFC3339)(t) + m[k] = (*dateTimeRFC3339)(t) } -func unpopulateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { +func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { if data == nil || strings.EqualFold(string(data), "null") { return nil } - var aux timeRFC3339 + var aux dateTimeRFC3339 if err := json.Unmarshal(data, &aux); err != nil { return fmt.Errorf("struct field %s: %v", fn, err) } diff --git a/sdk/resourcemanager/resources/armpolicy/variables_client.go b/sdk/resourcemanager/resources/armpolicy/variables_client.go index d5d75464a5ee..40efd8d8c4dc 100644 --- a/sdk/resourcemanager/resources/armpolicy/variables_client.go +++ b/sdk/resourcemanager/resources/armpolicy/variables_client.go @@ -32,7 +32,7 @@ type VariablesClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewVariablesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*VariablesClient, error) { - cl, err := arm.NewClient(moduleName+".VariablesClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -54,6 +54,10 @@ func NewVariablesClient(subscriptionID string, credential azcore.TokenCredential // method. func (client *VariablesClient) CreateOrUpdate(ctx context.Context, variableName string, parameters Variable, options *VariablesClientCreateOrUpdateOptions) (VariablesClientCreateOrUpdateResponse, error) { var err error + const operationName = "VariablesClient.CreateOrUpdate" + 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, variableName, parameters, options) if err != nil { return VariablesClientCreateOrUpdateResponse{}, err @@ -116,6 +120,10 @@ func (client *VariablesClient) createOrUpdateHandleResponse(resp *http.Response) // method. func (client *VariablesClient) CreateOrUpdateAtManagementGroup(ctx context.Context, managementGroupID string, variableName string, parameters Variable, options *VariablesClientCreateOrUpdateAtManagementGroupOptions) (VariablesClientCreateOrUpdateAtManagementGroupResponse, error) { var err error + const operationName = "VariablesClient.CreateOrUpdateAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateAtManagementGroupCreateRequest(ctx, managementGroupID, variableName, parameters, options) if err != nil { return VariablesClientCreateOrUpdateAtManagementGroupResponse{}, err @@ -176,6 +184,10 @@ func (client *VariablesClient) createOrUpdateAtManagementGroupHandleResponse(res // - options - VariablesClientDeleteOptions contains the optional parameters for the VariablesClient.Delete method. func (client *VariablesClient) Delete(ctx context.Context, variableName string, options *VariablesClientDeleteOptions) (VariablesClientDeleteResponse, error) { var err error + const operationName = "VariablesClient.Delete" + 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, variableName, options) if err != nil { return VariablesClientDeleteResponse{}, err @@ -225,6 +237,10 @@ func (client *VariablesClient) deleteCreateRequest(ctx context.Context, variable // method. func (client *VariablesClient) DeleteAtManagementGroup(ctx context.Context, managementGroupID string, variableName string, options *VariablesClientDeleteAtManagementGroupOptions) (VariablesClientDeleteAtManagementGroupResponse, error) { var err error + const operationName = "VariablesClient.DeleteAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAtManagementGroupCreateRequest(ctx, managementGroupID, variableName, options) if err != nil { return VariablesClientDeleteAtManagementGroupResponse{}, err @@ -270,6 +286,10 @@ func (client *VariablesClient) deleteAtManagementGroupCreateRequest(ctx context. // - options - VariablesClientGetOptions contains the optional parameters for the VariablesClient.Get method. func (client *VariablesClient) Get(ctx context.Context, variableName string, options *VariablesClientGetOptions) (VariablesClientGetResponse, error) { var err error + const operationName = "VariablesClient.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, variableName, options) if err != nil { return VariablesClientGetResponse{}, err @@ -328,6 +348,10 @@ func (client *VariablesClient) getHandleResponse(resp *http.Response) (Variables // method. func (client *VariablesClient) GetAtManagementGroup(ctx context.Context, managementGroupID string, variableName string, options *VariablesClientGetAtManagementGroupOptions) (VariablesClientGetAtManagementGroupResponse, error) { var err error + const operationName = "VariablesClient.GetAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtManagementGroupCreateRequest(ctx, managementGroupID, variableName, options) if err != nil { return VariablesClientGetAtManagementGroupResponse{}, err @@ -385,25 +409,20 @@ func (client *VariablesClient) NewListPager(options *VariablesClientListOptions) return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VariablesClientListResponse) (VariablesClientListResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VariablesClient.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 VariablesClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return VariablesClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VariablesClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -446,25 +465,20 @@ func (client *VariablesClient) NewListForManagementGroupPager(managementGroupID return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VariablesClientListForManagementGroupResponse) (VariablesClientListForManagementGroupResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listForManagementGroupCreateRequest(ctx, managementGroupID, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VariablesClient.NewListForManagementGroupPager") + 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.listForManagementGroupCreateRequest(ctx, managementGroupID, options) + }, nil) if err != nil { return VariablesClientListForManagementGroupResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return VariablesClientListForManagementGroupResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VariablesClientListForManagementGroupResponse{}, runtime.NewResponseError(resp) - } return client.listForManagementGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armpolicy/variables_client_example_test.go b/sdk/resourcemanager/resources/armpolicy/variables_client_example_test.go index 8b2627074eb1..39726b6d8ebb 100644 --- a/sdk/resourcemanager/resources/armpolicy/variables_client_example_test.go +++ b/sdk/resourcemanager/resources/armpolicy/variables_client_example_test.go @@ -71,10 +71,10 @@ func ExampleVariablesClient_CreateOrUpdate() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -110,10 +110,10 @@ func ExampleVariablesClient_Get() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -173,10 +173,10 @@ func ExampleVariablesClient_CreateOrUpdateAtManagementGroup() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -212,10 +212,10 @@ func ExampleVariablesClient_GetAtManagementGroup() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -257,10 +257,10 @@ func ExampleVariablesClient_NewListPager() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -276,10 +276,10 @@ func ExampleVariablesClient_NewListPager() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -323,10 +323,10 @@ func ExampleVariablesClient_NewListForManagementGroupPager() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -342,10 +342,10 @@ func ExampleVariablesClient_NewListForManagementGroupPager() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, diff --git a/sdk/resourcemanager/resources/armpolicy/variablevalues_client.go b/sdk/resourcemanager/resources/armpolicy/variablevalues_client.go index 7c12d5e3c4f9..97ebe9c492d3 100644 --- a/sdk/resourcemanager/resources/armpolicy/variablevalues_client.go +++ b/sdk/resourcemanager/resources/armpolicy/variablevalues_client.go @@ -32,7 +32,7 @@ type VariableValuesClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewVariableValuesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*VariableValuesClient, error) { - cl, err := arm.NewClient(moduleName+".VariableValuesClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -55,6 +55,10 @@ func NewVariableValuesClient(subscriptionID string, credential azcore.TokenCrede // method. func (client *VariableValuesClient) CreateOrUpdate(ctx context.Context, variableName string, variableValueName string, parameters VariableValue, options *VariableValuesClientCreateOrUpdateOptions) (VariableValuesClientCreateOrUpdateResponse, error) { var err error + const operationName = "VariableValuesClient.CreateOrUpdate" + 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, variableName, variableValueName, parameters, options) if err != nil { return VariableValuesClientCreateOrUpdateResponse{}, err @@ -122,6 +126,10 @@ func (client *VariableValuesClient) createOrUpdateHandleResponse(resp *http.Resp // method. func (client *VariableValuesClient) CreateOrUpdateAtManagementGroup(ctx context.Context, managementGroupID string, variableName string, variableValueName string, parameters VariableValue, options *VariableValuesClientCreateOrUpdateAtManagementGroupOptions) (VariableValuesClientCreateOrUpdateAtManagementGroupResponse, error) { var err error + const operationName = "VariableValuesClient.CreateOrUpdateAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.createOrUpdateAtManagementGroupCreateRequest(ctx, managementGroupID, variableName, variableValueName, parameters, options) if err != nil { return VariableValuesClientCreateOrUpdateAtManagementGroupResponse{}, err @@ -187,6 +195,10 @@ func (client *VariableValuesClient) createOrUpdateAtManagementGroupHandleRespons // - options - VariableValuesClientDeleteOptions contains the optional parameters for the VariableValuesClient.Delete method. func (client *VariableValuesClient) Delete(ctx context.Context, variableName string, variableValueName string, options *VariableValuesClientDeleteOptions) (VariableValuesClientDeleteResponse, error) { var err error + const operationName = "VariableValuesClient.Delete" + 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, variableName, variableValueName, options) if err != nil { return VariableValuesClientDeleteResponse{}, err @@ -241,6 +253,10 @@ func (client *VariableValuesClient) deleteCreateRequest(ctx context.Context, var // method. func (client *VariableValuesClient) DeleteAtManagementGroup(ctx context.Context, managementGroupID string, variableName string, variableValueName string, options *VariableValuesClientDeleteAtManagementGroupOptions) (VariableValuesClientDeleteAtManagementGroupResponse, error) { var err error + const operationName = "VariableValuesClient.DeleteAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.deleteAtManagementGroupCreateRequest(ctx, managementGroupID, variableName, variableValueName, options) if err != nil { return VariableValuesClientDeleteAtManagementGroupResponse{}, err @@ -292,6 +308,10 @@ func (client *VariableValuesClient) deleteAtManagementGroupCreateRequest(ctx con // - options - VariableValuesClientGetOptions contains the optional parameters for the VariableValuesClient.Get method. func (client *VariableValuesClient) Get(ctx context.Context, variableName string, variableValueName string, options *VariableValuesClientGetOptions) (VariableValuesClientGetResponse, error) { var err error + const operationName = "VariableValuesClient.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, variableName, variableValueName, options) if err != nil { return VariableValuesClientGetResponse{}, err @@ -355,6 +375,10 @@ func (client *VariableValuesClient) getHandleResponse(resp *http.Response) (Vari // method. func (client *VariableValuesClient) GetAtManagementGroup(ctx context.Context, managementGroupID string, variableName string, variableValueName string, options *VariableValuesClientGetAtManagementGroupOptions) (VariableValuesClientGetAtManagementGroupResponse, error) { var err error + const operationName = "VariableValuesClient.GetAtManagementGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAtManagementGroupCreateRequest(ctx, managementGroupID, variableName, variableValueName, options) if err != nil { return VariableValuesClientGetAtManagementGroupResponse{}, err @@ -418,25 +442,20 @@ func (client *VariableValuesClient) NewListPager(variableName string, options *V return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VariableValuesClientListResponse) (VariableValuesClientListResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, variableName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VariableValuesClient.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, variableName, options) + }, nil) if err != nil { return VariableValuesClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return VariableValuesClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VariableValuesClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -485,25 +504,20 @@ func (client *VariableValuesClient) NewListForManagementGroupPager(managementGro return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *VariableValuesClientListForManagementGroupResponse) (VariableValuesClientListForManagementGroupResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listForManagementGroupCreateRequest(ctx, managementGroupID, variableName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VariableValuesClient.NewListForManagementGroupPager") + 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.listForManagementGroupCreateRequest(ctx, managementGroupID, variableName, options) + }, nil) if err != nil { return VariableValuesClientListForManagementGroupResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return VariableValuesClientListForManagementGroupResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return VariableValuesClientListForManagementGroupResponse{}, runtime.NewResponseError(resp) - } return client.listForManagementGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/resources/armpolicy/variablevalues_client_example_test.go b/sdk/resourcemanager/resources/armpolicy/variablevalues_client_example_test.go index 97074bfd5063..4c4cf8803e69 100644 --- a/sdk/resourcemanager/resources/armpolicy/variablevalues_client_example_test.go +++ b/sdk/resourcemanager/resources/armpolicy/variablevalues_client_example_test.go @@ -81,10 +81,10 @@ func ExampleVariableValuesClient_CreateOrUpdate() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -125,10 +125,10 @@ func ExampleVariableValuesClient_Get() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -175,10 +175,10 @@ func ExampleVariableValuesClient_NewListPager() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -194,10 +194,10 @@ func ExampleVariableValuesClient_NewListPager() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -246,10 +246,10 @@ func ExampleVariableValuesClient_NewListForManagementGroupPager() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -265,10 +265,10 @@ func ExampleVariableValuesClient_NewListForManagementGroupPager() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -340,10 +340,10 @@ func ExampleVariableValuesClient_CreateOrUpdateAtManagementGroup() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T02:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T02:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, @@ -384,10 +384,10 @@ func ExampleVariableValuesClient_GetAtManagementGroup() { // }}, // }, // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-07-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-08-01T01:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), // }, From b275e8512c72a4eb61ddf704b18bfba85594942a Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 15:31:27 +0800 Subject: [PATCH 09/18] [Release] sdk/resourcemanager/resources/armresources/1.2.0 generation from spec commit: bf204aab860f2eb58a9d346b00d44760f2a9b0a2 --- .../resources/armresources/CHANGELOG.md | 6 + .../resources/armresources/README.md | 28 +- .../resources/armresources/autorest.md | 6 +- .../resources/armresources/build.go | 2 +- .../resources/armresources/client.go | 104 +++--- .../resources/armresources/client_factory.go | 10 +- .../resources/armresources/constants.go | 4 +- .../deploymentoperations_client.go | 97 ++---- .../armresources/deployments_client.go | 237 ++++++++------ .../deployments_client_example_test.go | 16 +- .../deployments_client_live_test.go | 2 +- .../fake/deploymentoperations_server.go | 78 ++--- .../armresources/fake/deployments_server.go | 300 +++++++++--------- .../resources/armresources/fake/internal.go | 66 +--- .../fake/providerresourcetypes_server.go | 4 +- .../armresources/fake/providers_server.go | 28 +- .../fake/resourcegroups_server.go | 24 +- .../resources/armresources/fake/server.go | 112 +++---- .../armresources/fake/server_factory.go | 116 +++++++ .../armresources/fake/tags_server.go | 44 +-- .../armresources/fake/time_rfc3339.go | 40 +-- .../resources/armresources/go.mod | 26 +- .../resources/armresources/go.sum | 58 ++-- .../resources/armresources/models_serde.go | 16 +- .../armresources/operations_client.go | 21 +- .../providerresourcetypes_client.go | 2 +- .../armresources/providers_client.go | 40 +-- .../armresources/resourcegroups_client.go | 34 +- .../resourcegroups_client_live_test.go | 2 +- .../resources_client_live_test.go | 2 +- .../resources/armresources/tags_client.go | 21 +- .../armresources/tags_client_live_test.go | 2 +- .../resources/armresources/time_rfc3339.go | 40 +-- 33 files changed, 823 insertions(+), 765 deletions(-) create mode 100644 sdk/resourcemanager/resources/armresources/fake/server_factory.go diff --git a/sdk/resourcemanager/resources/armresources/CHANGELOG.md b/sdk/resourcemanager/resources/armresources/CHANGELOG.md index ce1ab8d64e8a..7186a65f14a3 100644 --- a/sdk/resourcemanager/resources/armresources/CHANGELOG.md +++ b/sdk/resourcemanager/resources/armresources/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 1.2.0 (2023-11-24) +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + + ## 1.2.0-beta.3 (2023-10-09) ### Other Changes diff --git a/sdk/resourcemanager/resources/armresources/README.md b/sdk/resourcemanager/resources/armresources/README.md index 3d7808ffa4d6..fbe11f6c642a 100644 --- a/sdk/resourcemanager/resources/armresources/README.md +++ b/sdk/resourcemanager/resources/armresources/README.md @@ -61,29 +61,11 @@ client := clientFactory.NewClient() ``` ## Fakes -The `fake` package provides implementations for fake servers that can be used for testing. -To create a fake server, declare an instance of the required fake server type(s). -```go -myFakeServer := fake.Server{} -``` -Next, provide func implementations for the methods you wish to fake. -The named return variables can be used to simplify return value construction. -```go -myFakeServer.CheckExistence = func(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, apiVersion string, options *armresources.ClientCheckExistenceOptions) (resp azfake.Responder[armresources.ClientCheckExistenceResponse], errResp azfake.ErrorResponder) { - // TODO: resp.SetResponse(/* your fake ClientCheckExistenceResponse response */) - return -} -``` -You connect the fake server to a client instance during construction through the optional transport. -Use `NewTokenCredential()` from `azcore/fake` to obtain a fake credential. -```go -import azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" -client, err := armresources.NewClient("subscriptionID", azfake.NewTokenCredential(), &arm.ClientOptions{ - ClientOptions: azcore.ClientOptions{ - Transport: fake.NewServerTransport(&myFakeServer), - }, -}) -``` + +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. ## More sample code diff --git a/sdk/resourcemanager/resources/armresources/autorest.md b/sdk/resourcemanager/resources/armresources/autorest.md index 8b913922c8c3..58dea419a422 100644 --- a/sdk/resourcemanager/resources/armresources/autorest.md +++ b/sdk/resourcemanager/resources/armresources/autorest.md @@ -8,10 +8,6 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/4fd842fb73656039ec94ce367bcedee25a57bd18/specification/resources/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/4fd842fb73656039ec94ce367bcedee25a57bd18/specification/resources/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources -module-version: 1.2.0-beta.3 +module-version: 1.2.0 package-resources: true -azcore-version: 1.9.0-beta.1 -generate-fakes: true -inject-spans: true ``` diff --git a/sdk/resourcemanager/resources/armresources/build.go b/sdk/resourcemanager/resources/armresources/build.go index c48b02b11e78..546b96f36c1c 100644 --- a/sdk/resourcemanager/resources/armresources/build.go +++ b/sdk/resourcemanager/resources/armresources/build.go @@ -2,6 +2,6 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // This file enables 'go generate' to regenerate this specific SDK -//go:generate pwsh ../../../../eng/scripts/build.ps1 -goExtension "@autorest/go@4.0.0-preview.54" -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/resources/armresources +//go:generate pwsh ../../../../eng/scripts/build.ps1 -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/resources/armresources package armresources diff --git a/sdk/resourcemanager/resources/armresources/client.go b/sdk/resourcemanager/resources/armresources/client.go index 8b984cbd51f8..46fde2c78cb7 100644 --- a/sdk/resourcemanager/resources/armresources/client.go +++ b/sdk/resourcemanager/resources/armresources/client.go @@ -33,7 +33,7 @@ type Client struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*Client, error) { - cl, err := arm.NewClient(moduleName+".Client", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -168,10 +168,14 @@ func (client *Client) BeginCreateOrUpdate(ctx context.Context, resourceGroupName if err != nil { return nil, err } - poller, err := runtime.NewPoller[ClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClientCreateOrUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ClientCreateOrUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -251,10 +255,14 @@ func (client *Client) BeginCreateOrUpdateByID(ctx context.Context, resourceID st if err != nil { return nil, err } - poller, err := runtime.NewPoller[ClientCreateOrUpdateByIDResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClientCreateOrUpdateByIDResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ClientCreateOrUpdateByIDResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ClientCreateOrUpdateByIDResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -318,10 +326,14 @@ func (client *Client) BeginDelete(ctx context.Context, resourceGroupName string, if err != nil { return nil, err } - poller, err := runtime.NewPoller[ClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClientDeleteResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ClientDeleteResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -396,10 +408,14 @@ func (client *Client) BeginDeleteByID(ctx context.Context, resourceID string, ap if err != nil { return nil, err } - poller, err := runtime.NewPoller[ClientDeleteByIDResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClientDeleteByIDResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ClientDeleteByIDResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ClientDeleteByIDResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -582,23 +598,16 @@ func (client *Client) NewListPager(options *ClientListOptions) *runtime.Pager[Cl }, Fetcher: func(ctx context.Context, page *ClientListResponse) (ClientListResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewListPager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + 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 ClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, Tracer: client.internal.Tracer(), @@ -654,23 +663,16 @@ func (client *Client) NewListByResourceGroupPager(resourceGroupName string, opti }, Fetcher: func(ctx context.Context, page *ClientListByResourceGroupResponse) (ClientListByResourceGroupResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewListByResourceGroupPager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + 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 ClientListByResourceGroupResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ClientListByResourceGroupResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListByResourceGroupResponse{}, runtime.NewResponseError(resp) - } return client.listByResourceGroupHandleResponse(resp) }, Tracer: client.internal.Tracer(), @@ -733,10 +735,14 @@ func (client *Client) BeginMoveResources(ctx context.Context, sourceResourceGrou if err != nil { return nil, err } - poller, err := runtime.NewPoller[ClientMoveResourcesResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClientMoveResourcesResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ClientMoveResourcesResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ClientMoveResourcesResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -811,10 +817,14 @@ func (client *Client) BeginUpdate(ctx context.Context, resourceGroupName string, if err != nil { return nil, err } - poller, err := runtime.NewPoller[ClientUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClientUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ClientUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -893,10 +903,14 @@ func (client *Client) BeginUpdateByID(ctx context.Context, resourceID string, ap if err != nil { return nil, err } - poller, err := runtime.NewPoller[ClientUpdateByIDResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClientUpdateByIDResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ClientUpdateByIDResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ClientUpdateByIDResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -962,10 +976,14 @@ func (client *Client) BeginValidateMoveResources(ctx context.Context, sourceReso if err != nil { return nil, err } - poller, err := runtime.NewPoller[ClientValidateMoveResourcesResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClientValidateMoveResourcesResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ClientValidateMoveResourcesResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ClientValidateMoveResourcesResponse]{ + Tracer: client.internal.Tracer(), + }) } } diff --git a/sdk/resourcemanager/resources/armresources/client_factory.go b/sdk/resourcemanager/resources/armresources/client_factory.go index b8c9f57170b3..bcd6487d6961 100644 --- a/sdk/resourcemanager/resources/armresources/client_factory.go +++ b/sdk/resourcemanager/resources/armresources/client_factory.go @@ -27,7 +27,7 @@ type ClientFactory struct { // - 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) { - _, err := arm.NewClient(moduleName+".ClientFactory", moduleVersion, credential, options) + _, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -37,41 +37,49 @@ func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, }, nil } +// NewClient creates a new instance of Client. func (c *ClientFactory) NewClient() *Client { subClient, _ := NewClient(c.subscriptionID, c.credential, c.options) return subClient } +// NewDeploymentOperationsClient creates a new instance of DeploymentOperationsClient. func (c *ClientFactory) NewDeploymentOperationsClient() *DeploymentOperationsClient { subClient, _ := NewDeploymentOperationsClient(c.subscriptionID, c.credential, c.options) return subClient } +// NewDeploymentsClient creates a new instance of DeploymentsClient. func (c *ClientFactory) NewDeploymentsClient() *DeploymentsClient { subClient, _ := NewDeploymentsClient(c.subscriptionID, c.credential, c.options) return subClient } +// NewOperationsClient creates a new instance of OperationsClient. func (c *ClientFactory) NewOperationsClient() *OperationsClient { subClient, _ := NewOperationsClient(c.credential, c.options) return subClient } +// NewProviderResourceTypesClient creates a new instance of ProviderResourceTypesClient. func (c *ClientFactory) NewProviderResourceTypesClient() *ProviderResourceTypesClient { subClient, _ := NewProviderResourceTypesClient(c.subscriptionID, c.credential, c.options) return subClient } +// NewProvidersClient creates a new instance of ProvidersClient. func (c *ClientFactory) NewProvidersClient() *ProvidersClient { subClient, _ := NewProvidersClient(c.subscriptionID, c.credential, c.options) return subClient } +// NewResourceGroupsClient creates a new instance of ResourceGroupsClient. func (c *ClientFactory) NewResourceGroupsClient() *ResourceGroupsClient { subClient, _ := NewResourceGroupsClient(c.subscriptionID, c.credential, c.options) return subClient } +// NewTagsClient creates a new instance of TagsClient. func (c *ClientFactory) NewTagsClient() *TagsClient { subClient, _ := NewTagsClient(c.subscriptionID, c.credential, c.options) return subClient diff --git a/sdk/resourcemanager/resources/armresources/constants.go b/sdk/resourcemanager/resources/armresources/constants.go index dbe415064705..6cf0f0dc33cb 100644 --- a/sdk/resourcemanager/resources/armresources/constants.go +++ b/sdk/resourcemanager/resources/armresources/constants.go @@ -9,8 +9,8 @@ package armresources const ( - moduleName = "armresources" - moduleVersion = "v1.2.0-beta.3" + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + moduleVersion = "v1.2.0" ) // AliasPathAttributes - The attributes of the token that the alias path is referring to. diff --git a/sdk/resourcemanager/resources/armresources/deploymentoperations_client.go b/sdk/resourcemanager/resources/armresources/deploymentoperations_client.go index 76fe51416b30..ec1e1ab800e4 100644 --- a/sdk/resourcemanager/resources/armresources/deploymentoperations_client.go +++ b/sdk/resourcemanager/resources/armresources/deploymentoperations_client.go @@ -33,7 +33,7 @@ type DeploymentOperationsClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewDeploymentOperationsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*DeploymentOperationsClient, error) { - cl, err := arm.NewClient(moduleName+".DeploymentOperationsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -383,23 +383,16 @@ func (client *DeploymentOperationsClient) NewListPager(resourceGroupName string, }, Fetcher: func(ctx context.Context, page *DeploymentOperationsClientListResponse) (DeploymentOperationsClientListResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentOperationsClient.NewListPager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, resourceGroupName, deploymentName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + 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, resourceGroupName, deploymentName, options) + }, nil) if err != nil { return DeploymentOperationsClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return DeploymentOperationsClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentOperationsClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, Tracer: client.internal.Tracer(), @@ -458,23 +451,16 @@ func (client *DeploymentOperationsClient) NewListAtManagementGroupScopePager(gro }, Fetcher: func(ctx context.Context, page *DeploymentOperationsClientListAtManagementGroupScopeResponse) (DeploymentOperationsClientListAtManagementGroupScopeResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentOperationsClient.NewListAtManagementGroupScopePager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtManagementGroupScopeCreateRequest(ctx, groupID, deploymentName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return DeploymentOperationsClientListAtManagementGroupScopeResponse{}, err + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listAtManagementGroupScopeCreateRequest(ctx, groupID, deploymentName, options) + }, nil) if err != nil { return DeploymentOperationsClientListAtManagementGroupScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentOperationsClientListAtManagementGroupScopeResponse{}, runtime.NewResponseError(resp) - } return client.listAtManagementGroupScopeHandleResponse(resp) }, Tracer: client.internal.Tracer(), @@ -529,23 +515,16 @@ func (client *DeploymentOperationsClient) NewListAtScopePager(scope string, depl }, Fetcher: func(ctx context.Context, page *DeploymentOperationsClientListAtScopeResponse) (DeploymentOperationsClientListAtScopeResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentOperationsClient.NewListAtScopePager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtScopeCreateRequest(ctx, scope, deploymentName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return DeploymentOperationsClientListAtScopeResponse{}, err + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listAtScopeCreateRequest(ctx, scope, deploymentName, options) + }, nil) if err != nil { return DeploymentOperationsClientListAtScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentOperationsClientListAtScopeResponse{}, runtime.NewResponseError(resp) - } return client.listAtScopeHandleResponse(resp) }, Tracer: client.internal.Tracer(), @@ -596,23 +575,16 @@ func (client *DeploymentOperationsClient) NewListAtSubscriptionScopePager(deploy }, Fetcher: func(ctx context.Context, page *DeploymentOperationsClientListAtSubscriptionScopeResponse) (DeploymentOperationsClientListAtSubscriptionScopeResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentOperationsClient.NewListAtSubscriptionScopePager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtSubscriptionScopeCreateRequest(ctx, deploymentName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return DeploymentOperationsClientListAtSubscriptionScopeResponse{}, err + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listAtSubscriptionScopeCreateRequest(ctx, deploymentName, options) + }, nil) if err != nil { return DeploymentOperationsClientListAtSubscriptionScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentOperationsClientListAtSubscriptionScopeResponse{}, runtime.NewResponseError(resp) - } return client.listAtSubscriptionScopeHandleResponse(resp) }, Tracer: client.internal.Tracer(), @@ -666,23 +638,16 @@ func (client *DeploymentOperationsClient) NewListAtTenantScopePager(deploymentNa }, Fetcher: func(ctx context.Context, page *DeploymentOperationsClientListAtTenantScopeResponse) (DeploymentOperationsClientListAtTenantScopeResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentOperationsClient.NewListAtTenantScopePager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtTenantScopeCreateRequest(ctx, deploymentName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + 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.listAtTenantScopeCreateRequest(ctx, deploymentName, options) + }, nil) if err != nil { return DeploymentOperationsClientListAtTenantScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return DeploymentOperationsClientListAtTenantScopeResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentOperationsClientListAtTenantScopeResponse{}, runtime.NewResponseError(resp) - } return client.listAtTenantScopeHandleResponse(resp) }, Tracer: client.internal.Tracer(), diff --git a/sdk/resourcemanager/resources/armresources/deployments_client.go b/sdk/resourcemanager/resources/armresources/deployments_client.go index 7350d1edefb2..2e9eff6b7792 100644 --- a/sdk/resourcemanager/resources/armresources/deployments_client.go +++ b/sdk/resourcemanager/resources/armresources/deployments_client.go @@ -33,7 +33,7 @@ type DeploymentsClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewDeploymentsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*DeploymentsClient, error) { - cl, err := arm.NewClient(moduleName+".DeploymentsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -619,10 +619,14 @@ func (client *DeploymentsClient) BeginCreateOrUpdate(ctx context.Context, resour if err != nil { return nil, err } - poller, err := runtime.NewPoller[DeploymentsClientCreateOrUpdateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientCreateOrUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientCreateOrUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -696,10 +700,14 @@ func (client *DeploymentsClient) BeginCreateOrUpdateAtManagementGroupScope(ctx c if err != nil { return nil, err } - poller, err := runtime.NewPoller[DeploymentsClientCreateOrUpdateAtManagementGroupScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientCreateOrUpdateAtManagementGroupScopeResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientCreateOrUpdateAtManagementGroupScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientCreateOrUpdateAtManagementGroupScopeResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -769,10 +777,14 @@ func (client *DeploymentsClient) BeginCreateOrUpdateAtScope(ctx context.Context, if err != nil { return nil, err } - poller, err := runtime.NewPoller[DeploymentsClientCreateOrUpdateAtScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientCreateOrUpdateAtScopeResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientCreateOrUpdateAtScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientCreateOrUpdateAtScopeResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -838,10 +850,14 @@ func (client *DeploymentsClient) BeginCreateOrUpdateAtSubscriptionScope(ctx cont if err != nil { return nil, err } - poller, err := runtime.NewPoller[DeploymentsClientCreateOrUpdateAtSubscriptionScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientCreateOrUpdateAtSubscriptionScopeResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientCreateOrUpdateAtSubscriptionScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientCreateOrUpdateAtSubscriptionScopeResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -911,10 +927,14 @@ func (client *DeploymentsClient) BeginCreateOrUpdateAtTenantScope(ctx context.Co if err != nil { return nil, err } - poller, err := runtime.NewPoller[DeploymentsClientCreateOrUpdateAtTenantScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientCreateOrUpdateAtTenantScopeResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientCreateOrUpdateAtTenantScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientCreateOrUpdateAtTenantScopeResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -984,10 +1004,14 @@ func (client *DeploymentsClient) BeginDelete(ctx context.Context, resourceGroupN if err != nil { return nil, err } - poller, err := runtime.NewPoller[DeploymentsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientDeleteResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientDeleteResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -1069,10 +1093,14 @@ func (client *DeploymentsClient) BeginDeleteAtManagementGroupScope(ctx context.C if err != nil { return nil, err } - poller, err := runtime.NewPoller[DeploymentsClientDeleteAtManagementGroupScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientDeleteAtManagementGroupScopeResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientDeleteAtManagementGroupScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientDeleteAtManagementGroupScopeResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -1149,10 +1177,14 @@ func (client *DeploymentsClient) BeginDeleteAtScope(ctx context.Context, scope s if err != nil { return nil, err } - poller, err := runtime.NewPoller[DeploymentsClientDeleteAtScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientDeleteAtScopeResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientDeleteAtScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientDeleteAtScopeResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -1225,10 +1257,14 @@ func (client *DeploymentsClient) BeginDeleteAtSubscriptionScope(ctx context.Cont if err != nil { return nil, err } - poller, err := runtime.NewPoller[DeploymentsClientDeleteAtSubscriptionScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientDeleteAtSubscriptionScopeResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientDeleteAtSubscriptionScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientDeleteAtSubscriptionScopeResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -1304,10 +1340,14 @@ func (client *DeploymentsClient) BeginDeleteAtTenantScope(ctx context.Context, d if err != nil { return nil, err } - poller, err := runtime.NewPoller[DeploymentsClientDeleteAtTenantScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientDeleteAtTenantScopeResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientDeleteAtTenantScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientDeleteAtTenantScopeResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -1971,23 +2011,16 @@ func (client *DeploymentsClient) NewListAtManagementGroupScopePager(groupID stri }, Fetcher: func(ctx context.Context, page *DeploymentsClientListAtManagementGroupScopeResponse) (DeploymentsClientListAtManagementGroupScopeResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentsClient.NewListAtManagementGroupScopePager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtManagementGroupScopeCreateRequest(ctx, groupID, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + 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.listAtManagementGroupScopeCreateRequest(ctx, groupID, options) + }, nil) if err != nil { return DeploymentsClientListAtManagementGroupScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return DeploymentsClientListAtManagementGroupScopeResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientListAtManagementGroupScopeResponse{}, runtime.NewResponseError(resp) - } return client.listAtManagementGroupScopeHandleResponse(resp) }, Tracer: client.internal.Tracer(), @@ -2040,23 +2073,16 @@ func (client *DeploymentsClient) NewListAtScopePager(scope string, options *Depl }, Fetcher: func(ctx context.Context, page *DeploymentsClientListAtScopeResponse) (DeploymentsClientListAtScopeResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentsClient.NewListAtScopePager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtScopeCreateRequest(ctx, scope, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return DeploymentsClientListAtScopeResponse{}, err + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listAtScopeCreateRequest(ctx, scope, options) + }, nil) if err != nil { return DeploymentsClientListAtScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientListAtScopeResponse{}, runtime.NewResponseError(resp) - } return client.listAtScopeHandleResponse(resp) }, Tracer: client.internal.Tracer(), @@ -2105,23 +2131,16 @@ func (client *DeploymentsClient) NewListAtSubscriptionScopePager(options *Deploy }, Fetcher: func(ctx context.Context, page *DeploymentsClientListAtSubscriptionScopeResponse) (DeploymentsClientListAtSubscriptionScopeResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentsClient.NewListAtSubscriptionScopePager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtSubscriptionScopeCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return DeploymentsClientListAtSubscriptionScopeResponse{}, err + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listAtSubscriptionScopeCreateRequest(ctx, options) + }, nil) if err != nil { return DeploymentsClientListAtSubscriptionScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientListAtSubscriptionScopeResponse{}, runtime.NewResponseError(resp) - } return client.listAtSubscriptionScopeHandleResponse(resp) }, Tracer: client.internal.Tracer(), @@ -2173,23 +2192,16 @@ func (client *DeploymentsClient) NewListAtTenantScopePager(options *DeploymentsC }, Fetcher: func(ctx context.Context, page *DeploymentsClientListAtTenantScopeResponse) (DeploymentsClientListAtTenantScopeResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentsClient.NewListAtTenantScopePager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtTenantScopeCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return DeploymentsClientListAtTenantScopeResponse{}, err + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listAtTenantScopeCreateRequest(ctx, options) + }, nil) if err != nil { return DeploymentsClientListAtTenantScopeResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientListAtTenantScopeResponse{}, runtime.NewResponseError(resp) - } return client.listAtTenantScopeHandleResponse(resp) }, Tracer: client.internal.Tracer(), @@ -2238,23 +2250,16 @@ func (client *DeploymentsClient) NewListByResourceGroupPager(resourceGroupName s }, Fetcher: func(ctx context.Context, page *DeploymentsClientListByResourceGroupResponse) (DeploymentsClientListByResourceGroupResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DeploymentsClient.NewListByResourceGroupPager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + 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 DeploymentsClientListByResourceGroupResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return DeploymentsClientListByResourceGroupResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return DeploymentsClientListByResourceGroupResponse{}, runtime.NewResponseError(resp) - } return client.listByResourceGroupHandleResponse(resp) }, Tracer: client.internal.Tracer(), @@ -2314,10 +2319,14 @@ func (client *DeploymentsClient) BeginValidate(ctx context.Context, resourceGrou if err != nil { return nil, err } - poller, err := runtime.NewPoller[DeploymentsClientValidateResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientValidateResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientValidateResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientValidateResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -2391,10 +2400,14 @@ func (client *DeploymentsClient) BeginValidateAtManagementGroupScope(ctx context if err != nil { return nil, err } - poller, err := runtime.NewPoller[DeploymentsClientValidateAtManagementGroupScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientValidateAtManagementGroupScopeResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientValidateAtManagementGroupScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientValidateAtManagementGroupScopeResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -2465,10 +2478,14 @@ func (client *DeploymentsClient) BeginValidateAtScope(ctx context.Context, scope if err != nil { return nil, err } - poller, err := runtime.NewPoller[DeploymentsClientValidateAtScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientValidateAtScopeResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientValidateAtScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientValidateAtScopeResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -2535,10 +2552,14 @@ func (client *DeploymentsClient) BeginValidateAtSubscriptionScope(ctx context.Co if err != nil { return nil, err } - poller, err := runtime.NewPoller[DeploymentsClientValidateAtSubscriptionScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientValidateAtSubscriptionScopeResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientValidateAtSubscriptionScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientValidateAtSubscriptionScopeResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -2608,10 +2629,14 @@ func (client *DeploymentsClient) BeginValidateAtTenantScope(ctx context.Context, if err != nil { return nil, err } - poller, err := runtime.NewPoller[DeploymentsClientValidateAtTenantScopeResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientValidateAtTenantScopeResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientValidateAtTenantScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientValidateAtTenantScopeResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -2678,10 +2703,13 @@ func (client *DeploymentsClient) BeginWhatIf(ctx context.Context, resourceGroupN } poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientWhatIfResponse]{ FinalStateVia: runtime.FinalStateViaLocation, + Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientWhatIfResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientWhatIfResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -2757,10 +2785,13 @@ func (client *DeploymentsClient) BeginWhatIfAtManagementGroupScope(ctx context.C } poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientWhatIfAtManagementGroupScopeResponse]{ FinalStateVia: runtime.FinalStateViaLocation, + Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientWhatIfAtManagementGroupScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientWhatIfAtManagementGroupScopeResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -2831,10 +2862,13 @@ func (client *DeploymentsClient) BeginWhatIfAtSubscriptionScope(ctx context.Cont } poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientWhatIfAtSubscriptionScopeResponse]{ FinalStateVia: runtime.FinalStateViaLocation, + Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientWhatIfAtSubscriptionScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientWhatIfAtSubscriptionScopeResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -2904,10 +2938,13 @@ func (client *DeploymentsClient) BeginWhatIfAtTenantScope(ctx context.Context, d } poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DeploymentsClientWhatIfAtTenantScopeResponse]{ FinalStateVia: runtime.FinalStateViaLocation, + Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken[DeploymentsClientWhatIfAtTenantScopeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DeploymentsClientWhatIfAtTenantScopeResponse]{ + Tracer: client.internal.Tracer(), + }) } } diff --git a/sdk/resourcemanager/resources/armresources/deployments_client_example_test.go b/sdk/resourcemanager/resources/armresources/deployments_client_example_test.go index 43d004201a10..8b34318d619b 100644 --- a/sdk/resourcemanager/resources/armresources/deployments_client_example_test.go +++ b/sdk/resourcemanager/resources/armresources/deployments_client_example_test.go @@ -101,7 +101,7 @@ func ExampleDeploymentsClient_BeginCreateOrUpdateAtScope() { // }}, // }}, // ProvisioningState: to.Ptr(armresources.ProvisioningStateSucceeded), - // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-04-24T22:52:38.7895563Z"); return t}()), + // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-04-24T22:52:38.789Z"); return t}()), // }, // Tags: map[string]*string{ // "tagKey1": to.Ptr("tag-value-1"), @@ -193,7 +193,7 @@ func ExampleDeploymentsClient_BeginCreateOrUpdateAtTenantScope() { // }}, // }}, // ProvisioningState: to.Ptr(armresources.ProvisioningStateSucceeded), - // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-04-24T22:52:38.7895563Z"); return t}()), + // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-04-24T22:52:38.789Z"); return t}()), // }, // Tags: map[string]*string{ // "tagKey1": to.Ptr("tag-value-1"), @@ -328,7 +328,7 @@ func ExampleDeploymentsClient_BeginCreateOrUpdateAtManagementGroupScope() { // }}, // }}, // ProvisioningState: to.Ptr(armresources.ProvisioningStateSucceeded), - // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-04-24T22:52:38.7895563Z"); return t}()), + // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-04-24T22:52:38.789Z"); return t}()), // }, // } } @@ -480,7 +480,7 @@ func ExampleDeploymentsClient_BeginCreateOrUpdateAtSubscriptionScope() { // ContentVersion: to.Ptr("1.0.0.0"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/my-resource-group/providers/Microsoft.Resources/TemplateSpecs/TemplateSpec-Name/versions/v1"), // }, - // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-06-05T01:51:58.6288067Z"); return t}()), + // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-06-05T01:51:58.628Z"); return t}()), // }, // } } @@ -637,7 +637,7 @@ func ExampleDeploymentsClient_BeginCreateOrUpdate_createADeploymentThatWillDeplo // ContentVersion: to.Ptr("1.0.0.0"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/my-resource-group/providers/Microsoft.Resources/TemplateSpecs/TemplateSpec-Name/versions/v1"), // }, - // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-06-05T01:20:01.723776Z"); return t}()), + // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-06-05T01:20:01.723Z"); return t}()), // }, // } } @@ -704,7 +704,7 @@ func ExampleDeploymentsClient_BeginCreateOrUpdate_createADeploymentThatWillDeplo // ContentVersion: to.Ptr("1.0.0.0"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/my-resource-group/providers/Microsoft.Resources/TemplateSpecs/TemplateSpec-Name/versions/v1"), // }, - // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-06-05T01:20:01.723776Z"); return t}()), + // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-06-05T01:20:01.723Z"); return t}()), // }, // } } @@ -805,7 +805,7 @@ func ExampleDeploymentsClient_BeginCreateOrUpdate_createADeploymentThatWillRedep // ContentVersion: to.Ptr("1.0.0.0"), // URI: to.Ptr("https://example.com/exampleTemplate.json"), // }, - // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-03-01T00:00:00.0000000Z"); return t}()), + // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-03-01T00:00:00.000Z"); return t}()), // }, // } } @@ -905,7 +905,7 @@ func ExampleDeploymentsClient_BeginCreateOrUpdate_createADeploymentThatWillRedep // ContentVersion: to.Ptr("1.0.0.0"), // URI: to.Ptr("https://example.com/exampleTemplate.json"), // }, - // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-03-01T00:00:00.0000000Z"); return t}()), + // Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-03-01T00:00:00.000Z"); return t}()), // }, // } } diff --git a/sdk/resourcemanager/resources/armresources/deployments_client_live_test.go b/sdk/resourcemanager/resources/armresources/deployments_client_live_test.go index 322f758b88c5..743f8170fa78 100644 --- a/sdk/resourcemanager/resources/armresources/deployments_client_live_test.go +++ b/sdk/resourcemanager/resources/armresources/deployments_client_live_test.go @@ -13,7 +13,7 @@ import ( "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/to" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "github.com/stretchr/testify/suite" diff --git a/sdk/resourcemanager/resources/armresources/fake/deploymentoperations_server.go b/sdk/resourcemanager/resources/armresources/fake/deploymentoperations_server.go index dda04d97e2b4..64d1dbf2ec2b 100644 --- a/sdk/resourcemanager/resources/armresources/fake/deploymentoperations_server.go +++ b/sdk/resourcemanager/resources/armresources/fake/deploymentoperations_server.go @@ -144,19 +144,19 @@ func (d *DeploymentOperationsServerTransport) dispatchGet(req *http.Request) (*h if matches == nil || len(matches) < 4 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - operationIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) + operationIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) if err != nil { return nil, err } - respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, operationIDUnescaped, nil) + respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameParam, deploymentNameParam, operationIDParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -175,25 +175,25 @@ func (d *DeploymentOperationsServerTransport) dispatchGetAtManagementGroupScope( if d.srv.GetAtManagementGroupScope == nil { return nil, &nonRetriableError{errors.New("fake for method GetAtManagementGroupScope not implemented")} } - const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?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) } - groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + groupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - operationIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) + operationIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) if err != nil { return nil, err } - respr, errRespr := d.srv.GetAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, operationIDUnescaped, nil) + respr, errRespr := d.srv.GetAtManagementGroupScope(req.Context(), groupIDParam, deploymentNameParam, operationIDParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -212,25 +212,25 @@ func (d *DeploymentOperationsServerTransport) dispatchGetAtScope(req *http.Reque if d.srv.GetAtScope == nil { return nil, &nonRetriableError{errors.New("fake for method GetAtScope not implemented")} } - const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?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) } - scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - operationIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) + operationIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) if err != nil { return nil, err } - respr, errRespr := d.srv.GetAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, operationIDUnescaped, nil) + respr, errRespr := d.srv.GetAtScope(req.Context(), scopeParam, deploymentNameParam, operationIDParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -249,21 +249,21 @@ func (d *DeploymentOperationsServerTransport) dispatchGetAtSubscriptionScope(req if d.srv.GetAtSubscriptionScope == nil { return nil, &nonRetriableError{errors.New("fake for method GetAtSubscriptionScope not implemented")} } - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?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) } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - operationIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) + operationIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) if err != nil { return nil, err } - respr, errRespr := d.srv.GetAtSubscriptionScope(req.Context(), deploymentNameUnescaped, operationIDUnescaped, nil) + respr, errRespr := d.srv.GetAtSubscriptionScope(req.Context(), deploymentNameParam, operationIDParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -282,21 +282,21 @@ func (d *DeploymentOperationsServerTransport) dispatchGetAtTenantScope(req *http if d.srv.GetAtTenantScope == nil { return nil, &nonRetriableError{errors.New("fake for method GetAtTenantScope not implemented")} } - const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 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) } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - operationIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) + operationIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) if err != nil { return nil, err } - respr, errRespr := d.srv.GetAtTenantScope(req.Context(), deploymentNameUnescaped, operationIDUnescaped, nil) + respr, errRespr := d.srv.GetAtTenantScope(req.Context(), deploymentNameParam, operationIDParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -324,11 +324,11 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListPager(req *http.Req return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } @@ -352,7 +352,7 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListPager(req *http.Req Top: topParam, } } - resp := d.srv.NewListPager(resourceGroupNameUnescaped, deploymentNameUnescaped, options) + resp := d.srv.NewListPager(resourceGroupNameParam, deploymentNameParam, options) newListPager = &resp d.newListPager.add(req, newListPager) server.PagerResponderInjectNextLinks(newListPager, req, func(page *armresources.DeploymentOperationsClientListResponse, createLink func() string) { @@ -379,18 +379,18 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListAtManagementGroupSc } newListAtManagementGroupScopePager := d.newListAtManagementGroupScopePager.get(req) if newListAtManagementGroupScopePager == nil { - const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations` + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations` 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) } qp := req.URL.Query() - groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + groupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } @@ -414,7 +414,7 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListAtManagementGroupSc Top: topParam, } } - resp := d.srv.NewListAtManagementGroupScopePager(groupIDUnescaped, deploymentNameUnescaped, options) + resp := d.srv.NewListAtManagementGroupScopePager(groupIDParam, deploymentNameParam, options) newListAtManagementGroupScopePager = &resp d.newListAtManagementGroupScopePager.add(req, newListAtManagementGroupScopePager) server.PagerResponderInjectNextLinks(newListAtManagementGroupScopePager, req, func(page *armresources.DeploymentOperationsClientListAtManagementGroupScopeResponse, createLink func() string) { @@ -441,18 +441,18 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListAtScopePager(req *h } newListAtScopePager := d.newListAtScopePager.get(req) if newListAtScopePager == nil { - const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations` + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations` 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) } qp := req.URL.Query() - scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } @@ -476,7 +476,7 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListAtScopePager(req *h Top: topParam, } } - resp := d.srv.NewListAtScopePager(scopeUnescaped, deploymentNameUnescaped, options) + resp := d.srv.NewListAtScopePager(scopeParam, deploymentNameParam, options) newListAtScopePager = &resp d.newListAtScopePager.add(req, newListAtScopePager) server.PagerResponderInjectNextLinks(newListAtScopePager, req, func(page *armresources.DeploymentOperationsClientListAtScopeResponse, createLink func() string) { @@ -503,14 +503,14 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListAtSubscriptionScope } newListAtSubscriptionScopePager := d.newListAtSubscriptionScopePager.get(req) if newListAtSubscriptionScopePager == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations` 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) } qp := req.URL.Query() - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } @@ -534,7 +534,7 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListAtSubscriptionScope Top: topParam, } } - resp := d.srv.NewListAtSubscriptionScopePager(deploymentNameUnescaped, options) + resp := d.srv.NewListAtSubscriptionScopePager(deploymentNameParam, options) newListAtSubscriptionScopePager = &resp d.newListAtSubscriptionScopePager.add(req, newListAtSubscriptionScopePager) server.PagerResponderInjectNextLinks(newListAtSubscriptionScopePager, req, func(page *armresources.DeploymentOperationsClientListAtSubscriptionScopeResponse, createLink func() string) { @@ -561,14 +561,14 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListAtTenantScopePager( } newListAtTenantScopePager := d.newListAtTenantScopePager.get(req) if newListAtTenantScopePager == nil { - const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations` + const regexStr = `/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations` 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) } qp := req.URL.Query() - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } @@ -592,7 +592,7 @@ func (d *DeploymentOperationsServerTransport) dispatchNewListAtTenantScopePager( Top: topParam, } } - resp := d.srv.NewListAtTenantScopePager(deploymentNameUnescaped, options) + resp := d.srv.NewListAtTenantScopePager(deploymentNameParam, options) newListAtTenantScopePager = &resp d.newListAtTenantScopePager.add(req, newListAtTenantScopePager) server.PagerResponderInjectNextLinks(newListAtTenantScopePager, req, func(page *armresources.DeploymentOperationsClientListAtTenantScopeResponse, createLink func() string) { diff --git a/sdk/resourcemanager/resources/armresources/fake/deployments_server.go b/sdk/resourcemanager/resources/armresources/fake/deployments_server.go index d8d119a96d80..4dbb81cdef51 100644 --- a/sdk/resourcemanager/resources/armresources/fake/deployments_server.go +++ b/sdk/resourcemanager/resources/armresources/fake/deployments_server.go @@ -409,21 +409,21 @@ func (d *DeploymentsServerTransport) dispatchCancel(req *http.Request) (*http.Re if d.srv.Cancel == nil { return nil, &nonRetriableError{errors.New("fake for method Cancel not implemented")} } - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` 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) } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.Cancel(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, nil) + respr, errRespr := d.srv.Cancel(req.Context(), resourceGroupNameParam, deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -442,21 +442,21 @@ func (d *DeploymentsServerTransport) dispatchCancelAtManagementGroupScope(req *h if d.srv.CancelAtManagementGroupScope == nil { return nil, &nonRetriableError{errors.New("fake for method CancelAtManagementGroupScope not implemented")} } - const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` 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) } - groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + groupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.CancelAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, nil) + respr, errRespr := d.srv.CancelAtManagementGroupScope(req.Context(), groupIDParam, deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -475,21 +475,21 @@ func (d *DeploymentsServerTransport) dispatchCancelAtScope(req *http.Request) (* if d.srv.CancelAtScope == nil { return nil, &nonRetriableError{errors.New("fake for method CancelAtScope not implemented")} } - const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` 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) } - scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.CancelAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, nil) + respr, errRespr := d.srv.CancelAtScope(req.Context(), scopeParam, deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -508,17 +508,17 @@ func (d *DeploymentsServerTransport) dispatchCancelAtSubscriptionScope(req *http if d.srv.CancelAtSubscriptionScope == nil { return nil, &nonRetriableError{errors.New("fake for method CancelAtSubscriptionScope not implemented")} } - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` 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) } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.CancelAtSubscriptionScope(req.Context(), deploymentNameUnescaped, nil) + respr, errRespr := d.srv.CancelAtSubscriptionScope(req.Context(), deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -537,17 +537,17 @@ func (d *DeploymentsServerTransport) dispatchCancelAtTenantScope(req *http.Reque if d.srv.CancelAtTenantScope == nil { return nil, &nonRetriableError{errors.New("fake for method CancelAtTenantScope not implemented")} } - const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` + const regexStr = `/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` 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) } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.CancelAtTenantScope(req.Context(), deploymentNameUnescaped, nil) + respr, errRespr := d.srv.CancelAtTenantScope(req.Context(), deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -566,21 +566,21 @@ func (d *DeploymentsServerTransport) dispatchCheckExistence(req *http.Request) ( if d.srv.CheckExistence == nil { return nil, &nonRetriableError{errors.New("fake for method CheckExistence not implemented")} } - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?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) } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.CheckExistence(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, nil) + respr, errRespr := d.srv.CheckExistence(req.Context(), resourceGroupNameParam, deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -599,21 +599,21 @@ func (d *DeploymentsServerTransport) dispatchCheckExistenceAtManagementGroupScop if d.srv.CheckExistenceAtManagementGroupScope == nil { return nil, &nonRetriableError{errors.New("fake for method CheckExistenceAtManagementGroupScope not implemented")} } - const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 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) } - groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + groupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.CheckExistenceAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, nil) + respr, errRespr := d.srv.CheckExistenceAtManagementGroupScope(req.Context(), groupIDParam, deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -632,21 +632,21 @@ func (d *DeploymentsServerTransport) dispatchCheckExistenceAtScope(req *http.Req if d.srv.CheckExistenceAtScope == nil { return nil, &nonRetriableError{errors.New("fake for method CheckExistenceAtScope not implemented")} } - const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 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) } - scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.CheckExistenceAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, nil) + respr, errRespr := d.srv.CheckExistenceAtScope(req.Context(), scopeParam, deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -665,17 +665,17 @@ func (d *DeploymentsServerTransport) dispatchCheckExistenceAtSubscriptionScope(r if d.srv.CheckExistenceAtSubscriptionScope == nil { return nil, &nonRetriableError{errors.New("fake for method CheckExistenceAtSubscriptionScope not implemented")} } - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 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) } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.CheckExistenceAtSubscriptionScope(req.Context(), deploymentNameUnescaped, nil) + respr, errRespr := d.srv.CheckExistenceAtSubscriptionScope(req.Context(), deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -694,17 +694,17 @@ func (d *DeploymentsServerTransport) dispatchCheckExistenceAtTenantScope(req *ht if d.srv.CheckExistenceAtTenantScope == nil { return nil, &nonRetriableError{errors.New("fake for method CheckExistenceAtTenantScope not implemented")} } - const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 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) } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.CheckExistenceAtTenantScope(req.Context(), deploymentNameUnescaped, nil) + respr, errRespr := d.srv.CheckExistenceAtTenantScope(req.Context(), deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -725,7 +725,7 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdate(req *http.Reque } beginCreateOrUpdate := d.beginCreateOrUpdate.get(req) if beginCreateOrUpdate == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { @@ -735,15 +735,15 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdate(req *http.Reque if err != nil { return nil, err } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, body, nil) + respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, deploymentNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -773,7 +773,7 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtManagementGrou } beginCreateOrUpdateAtManagementGroupScope := d.beginCreateOrUpdateAtManagementGroupScope.get(req) if beginCreateOrUpdateAtManagementGroupScope == nil { - const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { @@ -783,15 +783,15 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtManagementGrou if err != nil { return nil, err } - groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + groupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginCreateOrUpdateAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, body, nil) + respr, errRespr := d.srv.BeginCreateOrUpdateAtManagementGroupScope(req.Context(), groupIDParam, deploymentNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -821,7 +821,7 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtScope(req *htt } beginCreateOrUpdateAtScope := d.beginCreateOrUpdateAtScope.get(req) if beginCreateOrUpdateAtScope == nil { - const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { @@ -831,15 +831,15 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtScope(req *htt if err != nil { return nil, err } - scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginCreateOrUpdateAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, body, nil) + respr, errRespr := d.srv.BeginCreateOrUpdateAtScope(req.Context(), scopeParam, deploymentNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -869,7 +869,7 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtSubscriptionSc } beginCreateOrUpdateAtSubscriptionScope := d.beginCreateOrUpdateAtSubscriptionScope.get(req) if beginCreateOrUpdateAtSubscriptionScope == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { @@ -879,11 +879,11 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtSubscriptionSc if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginCreateOrUpdateAtSubscriptionScope(req.Context(), deploymentNameUnescaped, body, nil) + respr, errRespr := d.srv.BeginCreateOrUpdateAtSubscriptionScope(req.Context(), deploymentNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -913,7 +913,7 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtTenantScope(re } beginCreateOrUpdateAtTenantScope := d.beginCreateOrUpdateAtTenantScope.get(req) if beginCreateOrUpdateAtTenantScope == nil { - const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { @@ -923,11 +923,11 @@ func (d *DeploymentsServerTransport) dispatchBeginCreateOrUpdateAtTenantScope(re if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginCreateOrUpdateAtTenantScope(req.Context(), deploymentNameUnescaped, body, nil) + respr, errRespr := d.srv.BeginCreateOrUpdateAtTenantScope(req.Context(), deploymentNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -957,21 +957,21 @@ func (d *DeploymentsServerTransport) dispatchBeginDelete(req *http.Request) (*ht } beginDelete := d.beginDelete.get(req) if beginDelete == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?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) } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, nil) + respr, errRespr := d.srv.BeginDelete(req.Context(), resourceGroupNameParam, deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1001,21 +1001,21 @@ func (d *DeploymentsServerTransport) dispatchBeginDeleteAtManagementGroupScope(r } beginDeleteAtManagementGroupScope := d.beginDeleteAtManagementGroupScope.get(req) if beginDeleteAtManagementGroupScope == nil { - const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 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) } - groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + groupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginDeleteAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, nil) + respr, errRespr := d.srv.BeginDeleteAtManagementGroupScope(req.Context(), groupIDParam, deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1045,21 +1045,21 @@ func (d *DeploymentsServerTransport) dispatchBeginDeleteAtScope(req *http.Reques } beginDeleteAtScope := d.beginDeleteAtScope.get(req) if beginDeleteAtScope == nil { - const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 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) } - scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginDeleteAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, nil) + respr, errRespr := d.srv.BeginDeleteAtScope(req.Context(), scopeParam, deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1089,17 +1089,17 @@ func (d *DeploymentsServerTransport) dispatchBeginDeleteAtSubscriptionScope(req } beginDeleteAtSubscriptionScope := d.beginDeleteAtSubscriptionScope.get(req) if beginDeleteAtSubscriptionScope == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 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) } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginDeleteAtSubscriptionScope(req.Context(), deploymentNameUnescaped, nil) + respr, errRespr := d.srv.BeginDeleteAtSubscriptionScope(req.Context(), deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1129,17 +1129,17 @@ func (d *DeploymentsServerTransport) dispatchBeginDeleteAtTenantScope(req *http. } beginDeleteAtTenantScope := d.beginDeleteAtTenantScope.get(req) if beginDeleteAtTenantScope == nil { - const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 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) } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginDeleteAtTenantScope(req.Context(), deploymentNameUnescaped, nil) + respr, errRespr := d.srv.BeginDeleteAtTenantScope(req.Context(), deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1167,21 +1167,21 @@ func (d *DeploymentsServerTransport) dispatchExportTemplate(req *http.Request) ( if d.srv.ExportTemplate == nil { return nil, &nonRetriableError{errors.New("fake for method ExportTemplate not implemented")} } - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` 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) } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.ExportTemplate(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, nil) + respr, errRespr := d.srv.ExportTemplate(req.Context(), resourceGroupNameParam, deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1200,21 +1200,21 @@ func (d *DeploymentsServerTransport) dispatchExportTemplateAtManagementGroupScop if d.srv.ExportTemplateAtManagementGroupScope == nil { return nil, &nonRetriableError{errors.New("fake for method ExportTemplateAtManagementGroupScope not implemented")} } - const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` 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) } - groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + groupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.ExportTemplateAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, nil) + respr, errRespr := d.srv.ExportTemplateAtManagementGroupScope(req.Context(), groupIDParam, deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1233,21 +1233,21 @@ func (d *DeploymentsServerTransport) dispatchExportTemplateAtScope(req *http.Req if d.srv.ExportTemplateAtScope == nil { return nil, &nonRetriableError{errors.New("fake for method ExportTemplateAtScope not implemented")} } - const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` 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) } - scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.ExportTemplateAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, nil) + respr, errRespr := d.srv.ExportTemplateAtScope(req.Context(), scopeParam, deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1266,17 +1266,17 @@ func (d *DeploymentsServerTransport) dispatchExportTemplateAtSubscriptionScope(r if d.srv.ExportTemplateAtSubscriptionScope == nil { return nil, &nonRetriableError{errors.New("fake for method ExportTemplateAtSubscriptionScope not implemented")} } - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` 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) } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.ExportTemplateAtSubscriptionScope(req.Context(), deploymentNameUnescaped, nil) + respr, errRespr := d.srv.ExportTemplateAtSubscriptionScope(req.Context(), deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1295,17 +1295,17 @@ func (d *DeploymentsServerTransport) dispatchExportTemplateAtTenantScope(req *ht if d.srv.ExportTemplateAtTenantScope == nil { return nil, &nonRetriableError{errors.New("fake for method ExportTemplateAtTenantScope not implemented")} } - const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` + const regexStr = `/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/exportTemplate` 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) } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.ExportTemplateAtTenantScope(req.Context(), deploymentNameUnescaped, nil) + respr, errRespr := d.srv.ExportTemplateAtTenantScope(req.Context(), deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1324,21 +1324,21 @@ func (d *DeploymentsServerTransport) dispatchGet(req *http.Request) (*http.Respo if d.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.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?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) } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, nil) + respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameParam, deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1357,21 +1357,21 @@ func (d *DeploymentsServerTransport) dispatchGetAtManagementGroupScope(req *http if d.srv.GetAtManagementGroupScope == nil { return nil, &nonRetriableError{errors.New("fake for method GetAtManagementGroupScope not implemented")} } - const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 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) } - groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + groupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.GetAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, nil) + respr, errRespr := d.srv.GetAtManagementGroupScope(req.Context(), groupIDParam, deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1390,21 +1390,21 @@ func (d *DeploymentsServerTransport) dispatchGetAtScope(req *http.Request) (*htt if d.srv.GetAtScope == nil { return nil, &nonRetriableError{errors.New("fake for method GetAtScope not implemented")} } - const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 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) } - scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.GetAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, nil) + respr, errRespr := d.srv.GetAtScope(req.Context(), scopeParam, deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1423,17 +1423,17 @@ func (d *DeploymentsServerTransport) dispatchGetAtSubscriptionScope(req *http.Re if d.srv.GetAtSubscriptionScope == nil { return nil, &nonRetriableError{errors.New("fake for method GetAtSubscriptionScope not implemented")} } - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 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) } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.GetAtSubscriptionScope(req.Context(), deploymentNameUnescaped, nil) + respr, errRespr := d.srv.GetAtSubscriptionScope(req.Context(), deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1452,17 +1452,17 @@ func (d *DeploymentsServerTransport) dispatchGetAtTenantScope(req *http.Request) if d.srv.GetAtTenantScope == nil { return nil, &nonRetriableError{errors.New("fake for method GetAtTenantScope not implemented")} } - const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 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) } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.GetAtTenantScope(req.Context(), deploymentNameUnescaped, nil) + respr, errRespr := d.srv.GetAtTenantScope(req.Context(), deploymentNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1483,14 +1483,14 @@ func (d *DeploymentsServerTransport) dispatchNewListAtManagementGroupScopePager( } newListAtManagementGroupScopePager := d.newListAtManagementGroupScopePager.get(req) if newListAtManagementGroupScopePager == nil { - const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/` + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/` 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) } qp := req.URL.Query() - groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + groupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) if err != nil { return nil, err } @@ -1520,7 +1520,7 @@ func (d *DeploymentsServerTransport) dispatchNewListAtManagementGroupScopePager( Top: topParam, } } - resp := d.srv.NewListAtManagementGroupScopePager(groupIDUnescaped, options) + resp := d.srv.NewListAtManagementGroupScopePager(groupIDParam, options) newListAtManagementGroupScopePager = &resp d.newListAtManagementGroupScopePager.add(req, newListAtManagementGroupScopePager) server.PagerResponderInjectNextLinks(newListAtManagementGroupScopePager, req, func(page *armresources.DeploymentsClientListAtManagementGroupScopeResponse, createLink func() string) { @@ -1547,14 +1547,14 @@ func (d *DeploymentsServerTransport) dispatchNewListAtScopePager(req *http.Reque } newListAtScopePager := d.newListAtScopePager.get(req) if newListAtScopePager == nil { - const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/` + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/` 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) } qp := req.URL.Query() - scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) if err != nil { return nil, err } @@ -1584,7 +1584,7 @@ func (d *DeploymentsServerTransport) dispatchNewListAtScopePager(req *http.Reque Top: topParam, } } - resp := d.srv.NewListAtScopePager(scopeUnescaped, options) + resp := d.srv.NewListAtScopePager(scopeParam, options) newListAtScopePager = &resp d.newListAtScopePager.add(req, newListAtScopePager) server.PagerResponderInjectNextLinks(newListAtScopePager, req, func(page *armresources.DeploymentsClientListAtScopeResponse, createLink func() string) { @@ -1611,7 +1611,7 @@ func (d *DeploymentsServerTransport) dispatchNewListAtSubscriptionScopePager(req } newListAtSubscriptionScopePager := d.newListAtSubscriptionScopePager.get(req) if newListAtSubscriptionScopePager == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { @@ -1725,14 +1725,14 @@ func (d *DeploymentsServerTransport) dispatchNewListByResourceGroupPager(req *ht } newListByResourceGroupPager := d.newListByResourceGroupPager.get(req) if newListByResourceGroupPager == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/` 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) } qp := req.URL.Query() - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } @@ -1762,7 +1762,7 @@ func (d *DeploymentsServerTransport) dispatchNewListByResourceGroupPager(req *ht Top: topParam, } } - resp := d.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, options) + resp := d.srv.NewListByResourceGroupPager(resourceGroupNameParam, options) newListByResourceGroupPager = &resp d.newListByResourceGroupPager.add(req, newListByResourceGroupPager) server.PagerResponderInjectNextLinks(newListByResourceGroupPager, req, func(page *armresources.DeploymentsClientListByResourceGroupResponse, createLink func() string) { @@ -1789,7 +1789,7 @@ func (d *DeploymentsServerTransport) dispatchBeginValidate(req *http.Request) (* } beginValidate := d.beginValidate.get(req) if beginValidate == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validate` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validate` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { @@ -1799,15 +1799,15 @@ func (d *DeploymentsServerTransport) dispatchBeginValidate(req *http.Request) (* if err != nil { return nil, err } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginValidate(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, body, nil) + respr, errRespr := d.srv.BeginValidate(req.Context(), resourceGroupNameParam, deploymentNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1837,7 +1837,7 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtManagementGroupScope } beginValidateAtManagementGroupScope := d.beginValidateAtManagementGroupScope.get(req) if beginValidateAtManagementGroupScope == nil { - const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validate` + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validate` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { @@ -1847,15 +1847,15 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtManagementGroupScope if err != nil { return nil, err } - groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + groupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginValidateAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, body, nil) + respr, errRespr := d.srv.BeginValidateAtManagementGroupScope(req.Context(), groupIDParam, deploymentNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1885,7 +1885,7 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtScope(req *http.Requ } beginValidateAtScope := d.beginValidateAtScope.get(req) if beginValidateAtScope == nil { - const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validate` + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validate` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { @@ -1895,15 +1895,15 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtScope(req *http.Requ if err != nil { return nil, err } - scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginValidateAtScope(req.Context(), scopeUnescaped, deploymentNameUnescaped, body, nil) + respr, errRespr := d.srv.BeginValidateAtScope(req.Context(), scopeParam, deploymentNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1933,7 +1933,7 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtSubscriptionScope(re } beginValidateAtSubscriptionScope := d.beginValidateAtSubscriptionScope.get(req) if beginValidateAtSubscriptionScope == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validate` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validate` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { @@ -1943,11 +1943,11 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtSubscriptionScope(re if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginValidateAtSubscriptionScope(req.Context(), deploymentNameUnescaped, body, nil) + respr, errRespr := d.srv.BeginValidateAtSubscriptionScope(req.Context(), deploymentNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -1977,7 +1977,7 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtTenantScope(req *htt } beginValidateAtTenantScope := d.beginValidateAtTenantScope.get(req) if beginValidateAtTenantScope == nil { - const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validate` + const regexStr = `/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/validate` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { @@ -1987,11 +1987,11 @@ func (d *DeploymentsServerTransport) dispatchBeginValidateAtTenantScope(req *htt if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginValidateAtTenantScope(req.Context(), deploymentNameUnescaped, body, nil) + respr, errRespr := d.srv.BeginValidateAtTenantScope(req.Context(), deploymentNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -2021,7 +2021,7 @@ func (d *DeploymentsServerTransport) dispatchBeginWhatIf(req *http.Request) (*ht } beginWhatIf := d.beginWhatIf.get(req) if beginWhatIf == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/whatIf` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/whatIf` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { @@ -2031,15 +2031,15 @@ func (d *DeploymentsServerTransport) dispatchBeginWhatIf(req *http.Request) (*ht if err != nil { return nil, err } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginWhatIf(req.Context(), resourceGroupNameUnescaped, deploymentNameUnescaped, body, nil) + respr, errRespr := d.srv.BeginWhatIf(req.Context(), resourceGroupNameParam, deploymentNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -2069,7 +2069,7 @@ func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtManagementGroupScope(r } beginWhatIfAtManagementGroupScope := d.beginWhatIfAtManagementGroupScope.get(req) if beginWhatIfAtManagementGroupScope == nil { - const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/whatIf` + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/whatIf` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { @@ -2079,15 +2079,15 @@ func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtManagementGroupScope(r if err != nil { return nil, err } - groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + groupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginWhatIfAtManagementGroupScope(req.Context(), groupIDUnescaped, deploymentNameUnescaped, body, nil) + respr, errRespr := d.srv.BeginWhatIfAtManagementGroupScope(req.Context(), groupIDParam, deploymentNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -2117,7 +2117,7 @@ func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtSubscriptionScope(req } beginWhatIfAtSubscriptionScope := d.beginWhatIfAtSubscriptionScope.get(req) if beginWhatIfAtSubscriptionScope == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/whatIf` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/whatIf` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { @@ -2127,11 +2127,11 @@ func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtSubscriptionScope(req if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginWhatIfAtSubscriptionScope(req.Context(), deploymentNameUnescaped, body, nil) + respr, errRespr := d.srv.BeginWhatIfAtSubscriptionScope(req.Context(), deploymentNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -2161,7 +2161,7 @@ func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtTenantScope(req *http. } beginWhatIfAtTenantScope := d.beginWhatIfAtTenantScope.get(req) if beginWhatIfAtTenantScope == nil { - const regexStr = `/providers/Microsoft.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/whatIf` + const regexStr = `/providers/Microsoft\.Resources/deployments/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/whatIf` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { @@ -2171,11 +2171,11 @@ func (d *DeploymentsServerTransport) dispatchBeginWhatIfAtTenantScope(req *http. if err != nil { return nil, err } - deploymentNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) + deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")]) if err != nil { return nil, err } - respr, errRespr := d.srv.BeginWhatIfAtTenantScope(req.Context(), deploymentNameUnescaped, body, nil) + respr, errRespr := d.srv.BeginWhatIfAtTenantScope(req.Context(), deploymentNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/resources/armresources/fake/internal.go b/sdk/resourcemanager/resources/armresources/fake/internal.go index 03b635903572..7d2f89ba4bb2 100644 --- a/sdk/resourcemanager/resources/armresources/fake/internal.go +++ b/sdk/resourcemanager/resources/armresources/fake/internal.go @@ -9,11 +9,9 @@ package fake import ( - "io" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" "net/http" "reflect" - "regexp" - "strings" "sync" ) @@ -25,6 +23,15 @@ 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 getOptional[T any](v T) *T { if reflect.ValueOf(v).IsZero() { return nil @@ -32,14 +39,6 @@ func getOptional[T any](v T) *T { return &v } -func getHeaderValue(h http.Header, k string) string { - v := h[k] - if len(v) == 0 { - return "" - } - return v[0] -} - func parseOptional[T any](v string, parse func(v string) (T, error)) (*T, error) { if v == "" { return nil, nil @@ -51,35 +50,6 @@ func parseOptional[T any](v string, parse func(v string) (T, error)) (*T, error) return &t, err } -func parseWithCast[T any](v string, parse func(v string) (T, error)) (T, error) { - t, err := parse(v) - if err != nil { - return *new(T), err - } - return t, err -} - -func readRequestBody(req *http.Request) ([]byte, error) { - if req.Body == nil { - return nil, nil - } - body, err := io.ReadAll(req.Body) - if err != nil { - return nil, err - } - req.Body.Close() - return body, nil -} - -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{}, @@ -91,20 +61,10 @@ type tracker[T any] struct { mu sync.Mutex } -func (p *tracker[T]) key(req *http.Request) string { - path := req.URL.Path - if match, _ := regexp.Match(`/page_\d+$`, []byte(path)); match { - path = path[:strings.LastIndex(path, "/")] - } else if strings.HasSuffix(path, "/get/fake/status") { - path = path[:len(path)-16] - } - return path -} - func (p *tracker[T]) get(req *http.Request) *T { p.mu.Lock() defer p.mu.Unlock() - if item, ok := p.items[p.key(req)]; ok { + if item, ok := p.items[server.SanitizePagerPollerPath(req.URL.Path)]; ok { return item } return nil @@ -113,11 +73,11 @@ func (p *tracker[T]) get(req *http.Request) *T { func (p *tracker[T]) add(req *http.Request, item *T) { p.mu.Lock() defer p.mu.Unlock() - p.items[p.key(req)] = item + 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, p.key(req)) + delete(p.items, server.SanitizePagerPollerPath(req.URL.Path)) } diff --git a/sdk/resourcemanager/resources/armresources/fake/providerresourcetypes_server.go b/sdk/resourcemanager/resources/armresources/fake/providerresourcetypes_server.go index 907b98cea2cf..67c2e7e91685 100644 --- a/sdk/resourcemanager/resources/armresources/fake/providerresourcetypes_server.go +++ b/sdk/resourcemanager/resources/armresources/fake/providerresourcetypes_server.go @@ -82,7 +82,7 @@ func (p *ProviderResourceTypesServerTransport) dispatchList(req *http.Request) ( return nil, err } expandParam := getOptional(expandUnescaped) - resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) if err != nil { return nil, err } @@ -92,7 +92,7 @@ func (p *ProviderResourceTypesServerTransport) dispatchList(req *http.Request) ( Expand: expandParam, } } - respr, errRespr := p.srv.List(req.Context(), resourceProviderNamespaceUnescaped, options) + respr, errRespr := p.srv.List(req.Context(), resourceProviderNamespaceParam, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/resources/armresources/fake/providers_server.go b/sdk/resourcemanager/resources/armresources/fake/providers_server.go index 6ed17df0562a..5681c862236d 100644 --- a/sdk/resourcemanager/resources/armresources/fake/providers_server.go +++ b/sdk/resourcemanager/resources/armresources/fake/providers_server.go @@ -132,7 +132,7 @@ func (p *ProvidersServerTransport) dispatchGet(req *http.Request) (*http.Respons return nil, err } expandParam := getOptional(expandUnescaped) - resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) if err != nil { return nil, err } @@ -142,7 +142,7 @@ func (p *ProvidersServerTransport) dispatchGet(req *http.Request) (*http.Respons Expand: expandParam, } } - respr, errRespr := p.srv.Get(req.Context(), resourceProviderNamespaceUnescaped, options) + respr, errRespr := p.srv.Get(req.Context(), resourceProviderNamespaceParam, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -173,7 +173,7 @@ func (p *ProvidersServerTransport) dispatchGetAtTenantScope(req *http.Request) ( return nil, err } expandParam := getOptional(expandUnescaped) - resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) if err != nil { return nil, err } @@ -183,7 +183,7 @@ func (p *ProvidersServerTransport) dispatchGetAtTenantScope(req *http.Request) ( Expand: expandParam, } } - respr, errRespr := p.srv.GetAtTenantScope(req.Context(), resourceProviderNamespaceUnescaped, options) + respr, errRespr := p.srv.GetAtTenantScope(req.Context(), resourceProviderNamespaceParam, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -292,11 +292,11 @@ func (p *ProvidersServerTransport) dispatchProviderPermissions(req *http.Request if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) if err != nil { return nil, err } - respr, errRespr := p.srv.ProviderPermissions(req.Context(), resourceProviderNamespaceUnescaped, nil) + respr, errRespr := p.srv.ProviderPermissions(req.Context(), resourceProviderNamespaceParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -325,7 +325,7 @@ func (p *ProvidersServerTransport) dispatchRegister(req *http.Request) (*http.Re if err != nil { return nil, err } - resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) if err != nil { return nil, err } @@ -335,7 +335,7 @@ func (p *ProvidersServerTransport) dispatchRegister(req *http.Request) (*http.Re Properties: &body, } } - respr, errRespr := p.srv.Register(req.Context(), resourceProviderNamespaceUnescaped, options) + respr, errRespr := p.srv.Register(req.Context(), resourceProviderNamespaceParam, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -354,21 +354,21 @@ func (p *ProvidersServerTransport) dispatchRegisterAtManagementGroupScope(req *h if p.srv.RegisterAtManagementGroupScope == nil { return nil, &nonRetriableError{errors.New("fake for method RegisterAtManagementGroupScope not implemented")} } - const regexStr = `/providers/Microsoft.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/register` + const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/register` 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) } - resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) if err != nil { return nil, err } - groupIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) + groupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")]) if err != nil { return nil, err } - respr, errRespr := p.srv.RegisterAtManagementGroupScope(req.Context(), resourceProviderNamespaceUnescaped, groupIDUnescaped, nil) + respr, errRespr := p.srv.RegisterAtManagementGroupScope(req.Context(), resourceProviderNamespaceParam, groupIDParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -393,11 +393,11 @@ func (p *ProvidersServerTransport) dispatchUnregister(req *http.Request) (*http. if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) if err != nil { return nil, err } - respr, errRespr := p.srv.Unregister(req.Context(), resourceProviderNamespaceUnescaped, nil) + respr, errRespr := p.srv.Unregister(req.Context(), resourceProviderNamespaceParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/resources/armresources/fake/resourcegroups_server.go b/sdk/resourcemanager/resources/armresources/fake/resourcegroups_server.go index e16c5e5a7565..c44d076de850 100644 --- a/sdk/resourcemanager/resources/armresources/fake/resourcegroups_server.go +++ b/sdk/resourcemanager/resources/armresources/fake/resourcegroups_server.go @@ -122,11 +122,11 @@ func (r *ResourceGroupsServerTransport) dispatchCheckExistence(req *http.Request if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - respr, errRespr := r.srv.CheckExistence(req.Context(), resourceGroupNameUnescaped, nil) + respr, errRespr := r.srv.CheckExistence(req.Context(), resourceGroupNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -155,11 +155,11 @@ func (r *ResourceGroupsServerTransport) dispatchCreateOrUpdate(req *http.Request if err != nil { return nil, err } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - respr, errRespr := r.srv.CreateOrUpdate(req.Context(), resourceGroupNameUnescaped, body, nil) + respr, errRespr := r.srv.CreateOrUpdate(req.Context(), resourceGroupNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -187,7 +187,7 @@ func (r *ResourceGroupsServerTransport) dispatchBeginDelete(req *http.Request) ( return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } @@ -202,7 +202,7 @@ func (r *ResourceGroupsServerTransport) dispatchBeginDelete(req *http.Request) ( ForceDeletionTypes: forceDeletionTypesParam, } } - respr, errRespr := r.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, options) + respr, errRespr := r.srv.BeginDelete(req.Context(), resourceGroupNameParam, options) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -242,11 +242,11 @@ func (r *ResourceGroupsServerTransport) dispatchBeginExportTemplate(req *http.Re if err != nil { return nil, err } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - respr, errRespr := r.srv.BeginExportTemplate(req.Context(), resourceGroupNameUnescaped, body, nil) + respr, errRespr := r.srv.BeginExportTemplate(req.Context(), resourceGroupNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -280,11 +280,11 @@ func (r *ResourceGroupsServerTransport) dispatchGet(req *http.Request) (*http.Re if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - respr, errRespr := r.srv.Get(req.Context(), resourceGroupNameUnescaped, nil) + respr, errRespr := r.srv.Get(req.Context(), resourceGroupNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -373,11 +373,11 @@ func (r *ResourceGroupsServerTransport) dispatchUpdate(req *http.Request) (*http if err != nil { return nil, err } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - respr, errRespr := r.srv.Update(req.Context(), resourceGroupNameUnescaped, body, nil) + respr, errRespr := r.srv.Update(req.Context(), resourceGroupNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/resources/armresources/fake/server.go b/sdk/resourcemanager/resources/armresources/fake/server.go index df120d035ba5..e0706267a031 100644 --- a/sdk/resourcemanager/resources/armresources/fake/server.go +++ b/sdk/resourcemanager/resources/armresources/fake/server.go @@ -179,31 +179,31 @@ func (s *ServerTransport) dispatchCheckExistence(req *http.Request) (*http.Respo return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) if err != nil { return nil, err } - parentResourcePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + parentResourcePathParam, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) if err != nil { return nil, err } - resourceTypeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + resourceTypeParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) if err != nil { return nil, err } - resourceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + resourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) if err != nil { return nil, err } - apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + apiVersionParam, err := url.QueryUnescape(qp.Get("api-version")) if err != nil { return nil, err } - respr, errRespr := s.srv.CheckExistence(req.Context(), resourceGroupNameUnescaped, resourceProviderNamespaceUnescaped, parentResourcePathUnescaped, resourceTypeUnescaped, resourceNameUnescaped, apiVersionUnescaped, nil) + respr, errRespr := s.srv.CheckExistence(req.Context(), resourceGroupNameParam, resourceProviderNamespaceParam, parentResourcePathParam, resourceTypeParam, resourceNameParam, apiVersionParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -229,15 +229,15 @@ func (s *ServerTransport) dispatchCheckExistenceByID(req *http.Request) (*http.R return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - resourceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceId")]) + resourceIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceId")]) if err != nil { return nil, err } - apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + apiVersionParam, err := url.QueryUnescape(qp.Get("api-version")) if err != nil { return nil, err } - respr, errRespr := s.srv.CheckExistenceByID(req.Context(), resourceIDUnescaped, apiVersionUnescaped, nil) + respr, errRespr := s.srv.CheckExistenceByID(req.Context(), resourceIDParam, apiVersionParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -269,31 +269,31 @@ func (s *ServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http. if err != nil { return nil, err } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) if err != nil { return nil, err } - parentResourcePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + parentResourcePathParam, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) if err != nil { return nil, err } - resourceTypeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + resourceTypeParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) if err != nil { return nil, err } - resourceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + resourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) if err != nil { return nil, err } - apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + apiVersionParam, err := url.QueryUnescape(qp.Get("api-version")) if err != nil { return nil, err } - respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameUnescaped, resourceProviderNamespaceUnescaped, parentResourcePathUnescaped, resourceTypeUnescaped, resourceNameUnescaped, apiVersionUnescaped, body, nil) + respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, resourceProviderNamespaceParam, parentResourcePathParam, resourceTypeParam, resourceNameParam, apiVersionParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -334,15 +334,15 @@ func (s *ServerTransport) dispatchBeginCreateOrUpdateByID(req *http.Request) (*h if err != nil { return nil, err } - resourceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceId")]) + resourceIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceId")]) if err != nil { return nil, err } - apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + apiVersionParam, err := url.QueryUnescape(qp.Get("api-version")) if err != nil { return nil, err } - respr, errRespr := s.srv.BeginCreateOrUpdateByID(req.Context(), resourceIDUnescaped, apiVersionUnescaped, body, nil) + respr, errRespr := s.srv.BeginCreateOrUpdateByID(req.Context(), resourceIDParam, apiVersionParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -379,31 +379,31 @@ func (s *ServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) if err != nil { return nil, err } - parentResourcePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + parentResourcePathParam, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) if err != nil { return nil, err } - resourceTypeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + resourceTypeParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) if err != nil { return nil, err } - resourceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + resourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) if err != nil { return nil, err } - apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + apiVersionParam, err := url.QueryUnescape(qp.Get("api-version")) if err != nil { return nil, err } - respr, errRespr := s.srv.BeginDelete(req.Context(), resourceGroupNameUnescaped, resourceProviderNamespaceUnescaped, parentResourcePathUnescaped, resourceTypeUnescaped, resourceNameUnescaped, apiVersionUnescaped, nil) + respr, errRespr := s.srv.BeginDelete(req.Context(), resourceGroupNameParam, resourceProviderNamespaceParam, parentResourcePathParam, resourceTypeParam, resourceNameParam, apiVersionParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -440,15 +440,15 @@ func (s *ServerTransport) dispatchBeginDeleteByID(req *http.Request) (*http.Resp return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - resourceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceId")]) + resourceIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceId")]) if err != nil { return nil, err } - apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + apiVersionParam, err := url.QueryUnescape(qp.Get("api-version")) if err != nil { return nil, err } - respr, errRespr := s.srv.BeginDeleteByID(req.Context(), resourceIDUnescaped, apiVersionUnescaped, nil) + respr, errRespr := s.srv.BeginDeleteByID(req.Context(), resourceIDParam, apiVersionParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -483,31 +483,31 @@ func (s *ServerTransport) dispatchGet(req *http.Request) (*http.Response, error) return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) if err != nil { return nil, err } - parentResourcePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + parentResourcePathParam, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) if err != nil { return nil, err } - resourceTypeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + resourceTypeParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) if err != nil { return nil, err } - resourceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + resourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) if err != nil { return nil, err } - apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + apiVersionParam, err := url.QueryUnescape(qp.Get("api-version")) if err != nil { return nil, err } - respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameUnescaped, resourceProviderNamespaceUnescaped, parentResourcePathUnescaped, resourceTypeUnescaped, resourceNameUnescaped, apiVersionUnescaped, nil) + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameParam, resourceProviderNamespaceParam, parentResourcePathParam, resourceTypeParam, resourceNameParam, apiVersionParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -533,15 +533,15 @@ func (s *ServerTransport) dispatchGetByID(req *http.Request) (*http.Response, er return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - resourceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceId")]) + resourceIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceId")]) if err != nil { return nil, err } - apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + apiVersionParam, err := url.QueryUnescape(qp.Get("api-version")) if err != nil { return nil, err } - respr, errRespr := s.srv.GetByID(req.Context(), resourceIDUnescaped, apiVersionUnescaped, nil) + respr, errRespr := s.srv.GetByID(req.Context(), resourceIDParam, apiVersionParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -635,7 +635,7 @@ func (s *ServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } @@ -671,7 +671,7 @@ func (s *ServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) Top: topParam, } } - resp := s.srv.NewListByResourceGroupPager(resourceGroupNameUnescaped, options) + resp := s.srv.NewListByResourceGroupPager(resourceGroupNameParam, options) newListByResourceGroupPager = &resp s.newListByResourceGroupPager.add(req, newListByResourceGroupPager) server.PagerResponderInjectNextLinks(newListByResourceGroupPager, req, func(page *armresources.ClientListByResourceGroupResponse, createLink func() string) { @@ -708,11 +708,11 @@ func (s *ServerTransport) dispatchBeginMoveResources(req *http.Request) (*http.R if err != nil { return nil, err } - sourceResourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("sourceResourceGroupName")]) + sourceResourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("sourceResourceGroupName")]) if err != nil { return nil, err } - respr, errRespr := s.srv.BeginMoveResources(req.Context(), sourceResourceGroupNameUnescaped, body, nil) + respr, errRespr := s.srv.BeginMoveResources(req.Context(), sourceResourceGroupNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -753,31 +753,31 @@ func (s *ServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response if err != nil { return nil, err } - resourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) if err != nil { return nil, err } - resourceProviderNamespaceUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) + resourceProviderNamespaceParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderNamespace")]) if err != nil { return nil, err } - parentResourcePathUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) + parentResourcePathParam, err := url.PathUnescape(matches[regex.SubexpIndex("parentResourcePath")]) if err != nil { return nil, err } - resourceTypeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) + resourceTypeParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceType")]) if err != nil { return nil, err } - resourceNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) + resourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceName")]) if err != nil { return nil, err } - apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + apiVersionParam, err := url.QueryUnescape(qp.Get("api-version")) if err != nil { return nil, err } - respr, errRespr := s.srv.BeginUpdate(req.Context(), resourceGroupNameUnescaped, resourceProviderNamespaceUnescaped, parentResourcePathUnescaped, resourceTypeUnescaped, resourceNameUnescaped, apiVersionUnescaped, body, nil) + respr, errRespr := s.srv.BeginUpdate(req.Context(), resourceGroupNameParam, resourceProviderNamespaceParam, parentResourcePathParam, resourceTypeParam, resourceNameParam, apiVersionParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -818,15 +818,15 @@ func (s *ServerTransport) dispatchBeginUpdateByID(req *http.Request) (*http.Resp if err != nil { return nil, err } - resourceIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("resourceId")]) + resourceIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceId")]) if err != nil { return nil, err } - apiVersionUnescaped, err := url.QueryUnescape(qp.Get("api-version")) + apiVersionParam, err := url.QueryUnescape(qp.Get("api-version")) if err != nil { return nil, err } - respr, errRespr := s.srv.BeginUpdateByID(req.Context(), resourceIDUnescaped, apiVersionUnescaped, body, nil) + respr, errRespr := s.srv.BeginUpdateByID(req.Context(), resourceIDParam, apiVersionParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -866,11 +866,11 @@ func (s *ServerTransport) dispatchBeginValidateMoveResources(req *http.Request) if err != nil { return nil, err } - sourceResourceGroupNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("sourceResourceGroupName")]) + sourceResourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("sourceResourceGroupName")]) if err != nil { return nil, err } - respr, errRespr := s.srv.BeginValidateMoveResources(req.Context(), sourceResourceGroupNameUnescaped, body, nil) + respr, errRespr := s.srv.BeginValidateMoveResources(req.Context(), sourceResourceGroupNameParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/resources/armresources/fake/server_factory.go b/sdk/resourcemanager/resources/armresources/fake/server_factory.go new file mode 100644 index 000000000000..9b10cbd19f1d --- /dev/null +++ b/sdk/resourcemanager/resources/armresources/fake/server_factory.go @@ -0,0 +1,116 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" + "sync" +) + +// ServerFactory is a fake server for instances of the armresources.ClientFactory type. +type ServerFactory struct { + Server Server + DeploymentOperationsServer DeploymentOperationsServer + DeploymentsServer DeploymentsServer + OperationsServer OperationsServer + ProviderResourceTypesServer ProviderResourceTypesServer + ProvidersServer ProvidersServer + ResourceGroupsServer ResourceGroupsServer + TagsServer TagsServer +} + +// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. +// The returned ServerFactoryTransport instance is connected to an instance of armresources.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 armresources.ClientFactory to instances of ServerFactory. +// Don't use this type directly, use NewServerFactoryTransport instead. +type ServerFactoryTransport struct { + srv *ServerFactory + trMu sync.Mutex + trServer *ServerTransport + trDeploymentOperationsServer *DeploymentOperationsServerTransport + trDeploymentsServer *DeploymentsServerTransport + trOperationsServer *OperationsServerTransport + trProviderResourceTypesServer *ProviderResourceTypesServerTransport + trProvidersServer *ProvidersServerTransport + trResourceGroupsServer *ResourceGroupsServerTransport + trTagsServer *TagsServerTransport +} + +// 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 "Client": + initServer(s, &s.trServer, func() *ServerTransport { return NewServerTransport(&s.srv.Server) }) + resp, err = s.trServer.Do(req) + case "DeploymentOperationsClient": + initServer(s, &s.trDeploymentOperationsServer, func() *DeploymentOperationsServerTransport { + return NewDeploymentOperationsServerTransport(&s.srv.DeploymentOperationsServer) + }) + resp, err = s.trDeploymentOperationsServer.Do(req) + case "DeploymentsClient": + initServer(s, &s.trDeploymentsServer, func() *DeploymentsServerTransport { return NewDeploymentsServerTransport(&s.srv.DeploymentsServer) }) + resp, err = s.trDeploymentsServer.Do(req) + case "OperationsClient": + initServer(s, &s.trOperationsServer, func() *OperationsServerTransport { return NewOperationsServerTransport(&s.srv.OperationsServer) }) + resp, err = s.trOperationsServer.Do(req) + case "ProviderResourceTypesClient": + initServer(s, &s.trProviderResourceTypesServer, func() *ProviderResourceTypesServerTransport { + return NewProviderResourceTypesServerTransport(&s.srv.ProviderResourceTypesServer) + }) + resp, err = s.trProviderResourceTypesServer.Do(req) + case "ProvidersClient": + initServer(s, &s.trProvidersServer, func() *ProvidersServerTransport { return NewProvidersServerTransport(&s.srv.ProvidersServer) }) + resp, err = s.trProvidersServer.Do(req) + case "ResourceGroupsClient": + initServer(s, &s.trResourceGroupsServer, func() *ResourceGroupsServerTransport { + return NewResourceGroupsServerTransport(&s.srv.ResourceGroupsServer) + }) + resp, err = s.trResourceGroupsServer.Do(req) + case "TagsClient": + initServer(s, &s.trTagsServer, func() *TagsServerTransport { return NewTagsServerTransport(&s.srv.TagsServer) }) + resp, err = s.trTagsServer.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/resources/armresources/fake/tags_server.go b/sdk/resourcemanager/resources/armresources/fake/tags_server.go index 94d66494208a..91a1dfa51ce8 100644 --- a/sdk/resourcemanager/resources/armresources/fake/tags_server.go +++ b/sdk/resourcemanager/resources/armresources/fake/tags_server.go @@ -129,11 +129,11 @@ func (t *TagsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.R if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - tagNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tagName")]) + tagNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("tagName")]) if err != nil { return nil, err } - respr, errRespr := t.srv.CreateOrUpdate(req.Context(), tagNameUnescaped, nil) + respr, errRespr := t.srv.CreateOrUpdate(req.Context(), tagNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -152,7 +152,7 @@ func (t *TagsServerTransport) dispatchCreateOrUpdateAtScope(req *http.Request) ( if t.srv.CreateOrUpdateAtScope == nil { return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdateAtScope not implemented")} } - const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/tags/default` + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/tags/default` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { @@ -162,11 +162,11 @@ func (t *TagsServerTransport) dispatchCreateOrUpdateAtScope(req *http.Request) ( if err != nil { return nil, err } - scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) if err != nil { return nil, err } - respr, errRespr := t.srv.CreateOrUpdateAtScope(req.Context(), scopeUnescaped, body, nil) + respr, errRespr := t.srv.CreateOrUpdateAtScope(req.Context(), scopeParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -191,15 +191,15 @@ func (t *TagsServerTransport) dispatchCreateOrUpdateValue(req *http.Request) (*h if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - tagNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tagName")]) + tagNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("tagName")]) if err != nil { return nil, err } - tagValueUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tagValue")]) + tagValueParam, err := url.PathUnescape(matches[regex.SubexpIndex("tagValue")]) if err != nil { return nil, err } - respr, errRespr := t.srv.CreateOrUpdateValue(req.Context(), tagNameUnescaped, tagValueUnescaped, nil) + respr, errRespr := t.srv.CreateOrUpdateValue(req.Context(), tagNameParam, tagValueParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -224,11 +224,11 @@ func (t *TagsServerTransport) dispatchDelete(req *http.Request) (*http.Response, if matches == nil || len(matches) < 2 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - tagNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tagName")]) + tagNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("tagName")]) if err != nil { return nil, err } - respr, errRespr := t.srv.Delete(req.Context(), tagNameUnescaped, nil) + respr, errRespr := t.srv.Delete(req.Context(), tagNameParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -247,17 +247,17 @@ func (t *TagsServerTransport) dispatchDeleteAtScope(req *http.Request) (*http.Re if t.srv.DeleteAtScope == nil { return nil, &nonRetriableError{errors.New("fake for method DeleteAtScope not implemented")} } - const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/tags/default` + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/tags/default` 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) } - scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) if err != nil { return nil, err } - respr, errRespr := t.srv.DeleteAtScope(req.Context(), scopeUnescaped, nil) + respr, errRespr := t.srv.DeleteAtScope(req.Context(), scopeParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -282,15 +282,15 @@ func (t *TagsServerTransport) dispatchDeleteValue(req *http.Request) (*http.Resp if matches == nil || len(matches) < 3 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - tagNameUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tagName")]) + tagNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("tagName")]) if err != nil { return nil, err } - tagValueUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("tagValue")]) + tagValueParam, err := url.PathUnescape(matches[regex.SubexpIndex("tagValue")]) if err != nil { return nil, err } - respr, errRespr := t.srv.DeleteValue(req.Context(), tagNameUnescaped, tagValueUnescaped, nil) + respr, errRespr := t.srv.DeleteValue(req.Context(), tagNameParam, tagValueParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -309,17 +309,17 @@ func (t *TagsServerTransport) dispatchGetAtScope(req *http.Request) (*http.Respo if t.srv.GetAtScope == nil { return nil, &nonRetriableError{errors.New("fake for method GetAtScope not implemented")} } - const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/tags/default` + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/tags/default` 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) } - scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) if err != nil { return nil, err } - respr, errRespr := t.srv.GetAtScope(req.Context(), scopeUnescaped, nil) + respr, errRespr := t.srv.GetAtScope(req.Context(), scopeParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -371,7 +371,7 @@ func (t *TagsServerTransport) dispatchUpdateAtScope(req *http.Request) (*http.Re if t.srv.UpdateAtScope == nil { return nil, &nonRetriableError{errors.New("fake for method UpdateAtScope not implemented")} } - const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/tags/default` + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/tags/default` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { @@ -381,11 +381,11 @@ func (t *TagsServerTransport) dispatchUpdateAtScope(req *http.Request) (*http.Re if err != nil { return nil, err } - scopeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) + scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")]) if err != nil { return nil, err } - respr, errRespr := t.srv.UpdateAtScope(req.Context(), scopeUnescaped, body, nil) + respr, errRespr := t.srv.UpdateAtScope(req.Context(), scopeParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } diff --git a/sdk/resourcemanager/resources/armresources/fake/time_rfc3339.go b/sdk/resourcemanager/resources/armresources/fake/time_rfc3339.go index 45fe10cbc6df..b0535a7b63e6 100644 --- a/sdk/resourcemanager/resources/armresources/fake/time_rfc3339.go +++ b/sdk/resourcemanager/resources/armresources/fake/time_rfc3339.go @@ -18,50 +18,50 @@ import ( "time" ) -const ( - utcLayoutJSON = `"2006-01-02T15:04:05.999999999"` - utcLayout = "2006-01-02T15:04:05.999999999" - rfc3339JSON = `"` + time.RFC3339Nano + `"` -) - // 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+)*"*$`) -type timeRFC3339 time.Time +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +type dateTimeRFC3339 time.Time -func (t timeRFC3339) MarshalJSON() (json []byte, err error) { +func (t dateTimeRFC3339) MarshalJSON() ([]byte, error) { tt := time.Time(t) return tt.MarshalJSON() } -func (t timeRFC3339) MarshalText() (text []byte, err error) { +func (t dateTimeRFC3339) MarshalText() ([]byte, error) { tt := time.Time(t) return tt.MarshalText() } -func (t *timeRFC3339) UnmarshalJSON(data []byte) error { - layout := utcLayoutJSON +func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { + layout := utcDateTimeJSON if tzOffsetRegex.Match(data) { - layout = rfc3339JSON + layout = dateTimeJSON } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) UnmarshalText(data []byte) (err error) { - layout := utcLayout +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime if tzOffsetRegex.Match(data) { layout = time.RFC3339Nano } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) Parse(layout, value string) error { +func (t *dateTimeRFC3339) Parse(layout, value string) error { p, err := time.Parse(layout, strings.ToUpper(value)) - *t = timeRFC3339(p) + *t = dateTimeRFC3339(p) return err } -func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { +func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { if t == nil { return } else if azcore.IsNullValue(t) { @@ -70,14 +70,14 @@ func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { } else if reflect.ValueOf(t).IsNil() { return } - m[k] = (*timeRFC3339)(t) + m[k] = (*dateTimeRFC3339)(t) } -func unpopulateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { +func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { if data == nil || strings.EqualFold(string(data), "null") { return nil } - var aux timeRFC3339 + var aux dateTimeRFC3339 if err := json.Unmarshal(data, &aux); err != nil { return fmt.Errorf("struct field %s: %v", fn, err) } diff --git a/sdk/resourcemanager/resources/armresources/go.mod b/sdk/resourcemanager/resources/armresources/go.mod index 43b79559e5d6..d7b78d9a2d49 100644 --- a/sdk/resourcemanager/resources/armresources/go.mod +++ b/sdk/resourcemanager/resources/armresources/go.mod @@ -3,26 +3,26 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresour go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0-beta.1 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 - github.com/stretchr/testify v1.7.0 + github.com/stretchr/testify v1.8.4 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect - github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dnaeon/go-vcr v1.1.0 // indirect - github.com/golang-jwt/jwt/v4 v4.4.2 // indirect - github.com/google/uuid v1.1.1 // indirect + github.com/dnaeon/go-vcr v1.2.0 // indirect + github.com/golang-jwt/jwt/v5 v5.0.0 // indirect + github.com/google/uuid v1.3.1 // indirect github.com/kylelemons/godebug v1.1.0 // indirect - github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect + github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/crypto v0.13.0 // indirect - golang.org/x/net v0.15.0 // indirect - golang.org/x/sys v0.12.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/sdk/resourcemanager/resources/armresources/go.sum b/sdk/resourcemanager/resources/armresources/go.sum index 89c64d59459e..c28709506be2 100644 --- a/sdk/resourcemanager/resources/armresources/go.sum +++ b/sdk/resourcemanager/resources/armresources/go.sum @@ -1,47 +1,45 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0-beta.1 h1:ODs3brnqQM99Tq1PffODpAViYv3Bf8zOg464MU7p5ew= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0-beta.1/go.mod h1:3Ug6Qzto9anB6mGlEdgYMDF5zHQ+wwhEaYR4s17PHMw= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 h1:t/W5MYAuQy81cvM8VUNfRLzhtKpXhVUAN7Cd7KVbTyc= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0/go.mod h1:NBanQUfSWiWn3QEpWDTCU0IjBECKOYvl2R8xdRtMtiM= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 h1:fb8kj/Dh4CSwgsOzHeZY4Xh68cFVbzXx+ONXGMY//4w= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0/go.mod h1:uReU2sSxZExRPBAg3qKzmAucSi51+SP1OhohieR821Q= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 h1:BMAjVKJM0U/CYF27gA0ZMmXGkOcvfFtD0oHVZ1TIPRI= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0/go.mod h1:1fXstnBMas5kzG+S3q8UoJcmyU6nUeunJcMDHcRYHhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 h1:PTFGRSlMKCQelWwxUyYVEUqseBJVemLyqWJjvMyt0do= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0/go.mod h1:LRr2FzBTQlONPPa5HREE5+RjSCTXl7BwOvYOaWTqCaI= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 h1:pPvTJ1dY0sA35JOeFq6TsY2xj6Z85Yo23Pj4wCCvu4o= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0/go.mod h1:mLfWfj8v3jfWKsL9G4eoBoXVcsqcIUTapmdKy7uGOp0= -github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 h1:VgSJlZH5u0k2qxSpqyghcFQKmvYckj46uymKK5XzkBM= -github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0/go.mod h1:BDJ5qMFKx9DugEg3+uQSDCdbYPr5s9vBTrL9P8TpqOU= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 h1:WpB/QDNLpMw72xHJc34BNNykqSOeEJDAWkhf0u12/Jk= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= -github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= -github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs= -github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= +github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= +github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/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/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= -github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 h1:Qj1ukM4GlMWXNdMBuXcXfz/Kw9s1qm0CLY32QxuSImI= -github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= -golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/resourcemanager/resources/armresources/models_serde.go b/sdk/resourcemanager/resources/armresources/models_serde.go index fe07f1f2d807..5c6e3ac77c19 100644 --- a/sdk/resourcemanager/resources/armresources/models_serde.go +++ b/sdk/resourcemanager/resources/armresources/models_serde.go @@ -513,7 +513,7 @@ func (d DeploymentOperationProperties) MarshalJSON() ([]byte, error) { populate(objectMap, "statusCode", d.StatusCode) populate(objectMap, "statusMessage", d.StatusMessage) populate(objectMap, "targetResource", d.TargetResource) - populateTimeRFC3339(objectMap, "timestamp", d.Timestamp) + populateDateTimeRFC3339(objectMap, "timestamp", d.Timestamp) return json.Marshal(objectMap) } @@ -554,7 +554,7 @@ func (d *DeploymentOperationProperties) UnmarshalJSON(data []byte) error { err = unpopulate(val, "TargetResource", &d.TargetResource) delete(rawMsg, key) case "timestamp": - err = unpopulateTimeRFC3339(val, "Timestamp", &d.Timestamp) + err = unpopulateDateTimeRFC3339(val, "Timestamp", &d.Timestamp) delete(rawMsg, key) } if err != nil { @@ -668,7 +668,7 @@ func (d DeploymentPropertiesExtended) MarshalJSON() ([]byte, error) { populate(objectMap, "provisioningState", d.ProvisioningState) populate(objectMap, "templateHash", d.TemplateHash) populate(objectMap, "templateLink", d.TemplateLink) - populateTimeRFC3339(objectMap, "timestamp", d.Timestamp) + populateDateTimeRFC3339(objectMap, "timestamp", d.Timestamp) populate(objectMap, "validatedResources", d.ValidatedResources) return json.Marshal(objectMap) } @@ -728,7 +728,7 @@ func (d *DeploymentPropertiesExtended) UnmarshalJSON(data []byte) error { err = unpopulate(val, "TemplateLink", &d.TemplateLink) delete(rawMsg, key) case "timestamp": - err = unpopulateTimeRFC3339(val, "Timestamp", &d.Timestamp) + err = unpopulateDateTimeRFC3339(val, "Timestamp", &d.Timestamp) delete(rawMsg, key) case "validatedResources": err = unpopulate(val, "ValidatedResources", &d.ValidatedResources) @@ -1126,8 +1126,8 @@ func (g *GenericResource) UnmarshalJSON(data []byte) error { // MarshalJSON implements the json.Marshaller interface for type GenericResourceExpanded. func (g GenericResourceExpanded) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populateTimeRFC3339(objectMap, "changedTime", g.ChangedTime) - populateTimeRFC3339(objectMap, "createdTime", g.CreatedTime) + populateDateTimeRFC3339(objectMap, "changedTime", g.ChangedTime) + populateDateTimeRFC3339(objectMap, "createdTime", g.CreatedTime) populate(objectMap, "extendedLocation", g.ExtendedLocation) populate(objectMap, "id", g.ID) populate(objectMap, "identity", g.Identity) @@ -1154,10 +1154,10 @@ func (g *GenericResourceExpanded) UnmarshalJSON(data []byte) error { var err error switch key { case "changedTime": - err = unpopulateTimeRFC3339(val, "ChangedTime", &g.ChangedTime) + err = unpopulateDateTimeRFC3339(val, "ChangedTime", &g.ChangedTime) delete(rawMsg, key) case "createdTime": - err = unpopulateTimeRFC3339(val, "CreatedTime", &g.CreatedTime) + err = unpopulateDateTimeRFC3339(val, "CreatedTime", &g.CreatedTime) delete(rawMsg, key) case "extendedLocation": err = unpopulate(val, "ExtendedLocation", &g.ExtendedLocation) diff --git a/sdk/resourcemanager/resources/armresources/operations_client.go b/sdk/resourcemanager/resources/armresources/operations_client.go index 326aadab0f0f..e0fc6b961f4f 100644 --- a/sdk/resourcemanager/resources/armresources/operations_client.go +++ b/sdk/resourcemanager/resources/armresources/operations_client.go @@ -27,7 +27,7 @@ type OperationsClient struct { // - 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+".OperationsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -48,23 +48,16 @@ func (client *OperationsClient) NewListPager(options *OperationsClientListOption }, Fetcher: func(ctx context.Context, page *OperationsClientListResponse) (OperationsClientListResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "OperationsClient.NewListPager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + 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 } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return OperationsClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return OperationsClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, Tracer: client.internal.Tracer(), diff --git a/sdk/resourcemanager/resources/armresources/providerresourcetypes_client.go b/sdk/resourcemanager/resources/armresources/providerresourcetypes_client.go index 7f160860a0af..a64c08f0217d 100644 --- a/sdk/resourcemanager/resources/armresources/providerresourcetypes_client.go +++ b/sdk/resourcemanager/resources/armresources/providerresourcetypes_client.go @@ -32,7 +32,7 @@ type ProviderResourceTypesClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewProviderResourceTypesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ProviderResourceTypesClient, error) { - cl, err := arm.NewClient(moduleName+".ProviderResourceTypesClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } diff --git a/sdk/resourcemanager/resources/armresources/providers_client.go b/sdk/resourcemanager/resources/armresources/providers_client.go index 21c52166aea5..e1612d16090a 100644 --- a/sdk/resourcemanager/resources/armresources/providers_client.go +++ b/sdk/resourcemanager/resources/armresources/providers_client.go @@ -32,7 +32,7 @@ type ProvidersClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewProvidersClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ProvidersClient, error) { - cl, err := arm.NewClient(moduleName+".ProvidersClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -175,23 +175,16 @@ func (client *ProvidersClient) NewListPager(options *ProvidersClientListOptions) }, Fetcher: func(ctx context.Context, page *ProvidersClientListResponse) (ProvidersClientListResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ProvidersClient.NewListPager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + 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 ProvidersClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ProvidersClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ProvidersClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, Tracer: client.internal.Tracer(), @@ -240,23 +233,16 @@ func (client *ProvidersClient) NewListAtTenantScopePager(options *ProvidersClien }, Fetcher: func(ctx context.Context, page *ProvidersClientListAtTenantScopeResponse) (ProvidersClientListAtTenantScopeResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ProvidersClient.NewListAtTenantScopePager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listAtTenantScopeCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + 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.listAtTenantScopeCreateRequest(ctx, options) + }, nil) if err != nil { return ProvidersClientListAtTenantScopeResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ProvidersClientListAtTenantScopeResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ProvidersClientListAtTenantScopeResponse{}, runtime.NewResponseError(resp) - } return client.listAtTenantScopeHandleResponse(resp) }, Tracer: client.internal.Tracer(), diff --git a/sdk/resourcemanager/resources/armresources/resourcegroups_client.go b/sdk/resourcemanager/resources/armresources/resourcegroups_client.go index 123bf47a104f..b228d9f643c1 100644 --- a/sdk/resourcemanager/resources/armresources/resourcegroups_client.go +++ b/sdk/resourcemanager/resources/armresources/resourcegroups_client.go @@ -33,7 +33,7 @@ type ResourceGroupsClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewResourceGroupsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ResourceGroupsClient, error) { - cl, err := arm.NewClient(moduleName+".ResourceGroupsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -172,10 +172,14 @@ func (client *ResourceGroupsClient) BeginDelete(ctx context.Context, resourceGro if err != nil { return nil, err } - poller, err := runtime.NewPoller[ResourceGroupsClientDeleteResponse](resp, client.internal.Pipeline(), nil) + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ResourceGroupsClientDeleteResponse]{ + Tracer: client.internal.Tracer(), + }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ResourceGroupsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ResourceGroupsClientDeleteResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -246,10 +250,13 @@ func (client *ResourceGroupsClient) BeginExportTemplate(ctx context.Context, res } poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ResourceGroupsClientExportTemplateResponse]{ FinalStateVia: runtime.FinalStateViaLocation, + Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken[ResourceGroupsClientExportTemplateResponse](options.ResumeToken, client.internal.Pipeline(), nil) + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ResourceGroupsClientExportTemplateResponse]{ + Tracer: client.internal.Tracer(), + }) } } @@ -373,23 +380,16 @@ func (client *ResourceGroupsClient) NewListPager(options *ResourceGroupsClientLi }, Fetcher: func(ctx context.Context, page *ResourceGroupsClientListResponse) (ResourceGroupsClientListResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ResourceGroupsClient.NewListPager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + 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 ResourceGroupsClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ResourceGroupsClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ResourceGroupsClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, Tracer: client.internal.Tracer(), diff --git a/sdk/resourcemanager/resources/armresources/resourcegroups_client_live_test.go b/sdk/resourcemanager/resources/armresources/resourcegroups_client_live_test.go index 821539937367..5fdf6e22ddb7 100644 --- a/sdk/resourcemanager/resources/armresources/resourcegroups_client_live_test.go +++ b/sdk/resourcemanager/resources/armresources/resourcegroups_client_live_test.go @@ -12,7 +12,7 @@ import ( "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/to" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "github.com/stretchr/testify/suite" "testing" diff --git a/sdk/resourcemanager/resources/armresources/resources_client_live_test.go b/sdk/resourcemanager/resources/armresources/resources_client_live_test.go index b5529beab6f1..0d4e5329b022 100644 --- a/sdk/resourcemanager/resources/armresources/resources_client_live_test.go +++ b/sdk/resourcemanager/resources/armresources/resources_client_live_test.go @@ -15,7 +15,7 @@ import ( "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/to" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "github.com/stretchr/testify/suite" ) diff --git a/sdk/resourcemanager/resources/armresources/tags_client.go b/sdk/resourcemanager/resources/armresources/tags_client.go index caa54194a255..b6d0fc249279 100644 --- a/sdk/resourcemanager/resources/armresources/tags_client.go +++ b/sdk/resourcemanager/resources/armresources/tags_client.go @@ -32,7 +32,7 @@ type TagsClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewTagsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*TagsClient, error) { - cl, err := arm.NewClient(moduleName+".TagsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -441,23 +441,16 @@ func (client *TagsClient) NewListPager(options *TagsClientListOptions) *runtime. }, Fetcher: func(ctx context.Context, page *TagsClientListResponse) (TagsClientListResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "TagsClient.NewListPager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + 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 TagsClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return TagsClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return TagsClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, Tracer: client.internal.Tracer(), diff --git a/sdk/resourcemanager/resources/armresources/tags_client_live_test.go b/sdk/resourcemanager/resources/armresources/tags_client_live_test.go index fcdd862c54d6..4ffc8ed8d47d 100644 --- a/sdk/resourcemanager/resources/armresources/tags_client_live_test.go +++ b/sdk/resourcemanager/resources/armresources/tags_client_live_test.go @@ -14,7 +14,7 @@ import ( "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/to" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "github.com/stretchr/testify/suite" ) diff --git a/sdk/resourcemanager/resources/armresources/time_rfc3339.go b/sdk/resourcemanager/resources/armresources/time_rfc3339.go index b4726b97b180..5026e349b272 100644 --- a/sdk/resourcemanager/resources/armresources/time_rfc3339.go +++ b/sdk/resourcemanager/resources/armresources/time_rfc3339.go @@ -18,50 +18,50 @@ import ( "time" ) -const ( - utcLayoutJSON = `"2006-01-02T15:04:05.999999999"` - utcLayout = "2006-01-02T15:04:05.999999999" - rfc3339JSON = `"` + time.RFC3339Nano + `"` -) - // 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+)*"*$`) -type timeRFC3339 time.Time +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +type dateTimeRFC3339 time.Time -func (t timeRFC3339) MarshalJSON() (json []byte, err error) { +func (t dateTimeRFC3339) MarshalJSON() ([]byte, error) { tt := time.Time(t) return tt.MarshalJSON() } -func (t timeRFC3339) MarshalText() (text []byte, err error) { +func (t dateTimeRFC3339) MarshalText() ([]byte, error) { tt := time.Time(t) return tt.MarshalText() } -func (t *timeRFC3339) UnmarshalJSON(data []byte) error { - layout := utcLayoutJSON +func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { + layout := utcDateTimeJSON if tzOffsetRegex.Match(data) { - layout = rfc3339JSON + layout = dateTimeJSON } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) UnmarshalText(data []byte) (err error) { - layout := utcLayout +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime if tzOffsetRegex.Match(data) { layout = time.RFC3339Nano } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) Parse(layout, value string) error { +func (t *dateTimeRFC3339) Parse(layout, value string) error { p, err := time.Parse(layout, strings.ToUpper(value)) - *t = timeRFC3339(p) + *t = dateTimeRFC3339(p) return err } -func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { +func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { if t == nil { return } else if azcore.IsNullValue(t) { @@ -70,14 +70,14 @@ func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { } else if reflect.ValueOf(t).IsNil() { return } - m[k] = (*timeRFC3339)(t) + m[k] = (*dateTimeRFC3339)(t) } -func unpopulateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { +func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { if data == nil || strings.EqualFold(string(data), "null") { return nil } - var aux timeRFC3339 + var aux dateTimeRFC3339 if err := json.Unmarshal(data, &aux); err != nil { return fmt.Errorf("struct field %s: %v", fn, err) } From 70c128a3056f55852a84e314fdead43160cd3e29 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 15:33:30 +0800 Subject: [PATCH 10/18] [Release] sdk/resourcemanager/resources/armsubscriptions/1.3.0 generation from spec commit: bf204aab860f2eb58a9d346b00d44760f2a9b0a2 --- .../resources/armsubscriptions/CHANGELOG.md | 6 ++ .../resources/armsubscriptions/README.md | 28 ++---- .../resources/armsubscriptions/autorest.md | 6 +- .../resources/armsubscriptions/build.go | 2 +- .../resources/armsubscriptions/client.go | 21 ++--- .../armsubscriptions/client_factory.go | 6 +- .../resources/armsubscriptions/constants.go | 4 +- .../armsubscriptions/fake/internal.go | 68 +++----------- .../resources/armsubscriptions/fake/server.go | 14 +-- .../armsubscriptions/fake/server_factory.go | 90 +++++++++++++++++++ .../resources/armsubscriptions/go.mod | 28 +++--- .../resources/armsubscriptions/go.sum | 62 ++++++------- .../armsubscriptions/operations_client.go | 21 ++--- .../armsubscriptions/subscription_client.go | 2 +- .../subscriptions_client_live_test.go | 2 +- .../armsubscriptions/tenants_client.go | 21 ++--- .../tenants_client_live_test.go | 2 +- 17 files changed, 196 insertions(+), 187 deletions(-) create mode 100644 sdk/resourcemanager/resources/armsubscriptions/fake/server_factory.go diff --git a/sdk/resourcemanager/resources/armsubscriptions/CHANGELOG.md b/sdk/resourcemanager/resources/armsubscriptions/CHANGELOG.md index afc5b112f5a8..560cd95d6568 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/CHANGELOG.md +++ b/sdk/resourcemanager/resources/armsubscriptions/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 1.3.0 (2023-11-24) +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + + ## 1.3.0-beta.3 (2023-10-09) ### Other Changes diff --git a/sdk/resourcemanager/resources/armsubscriptions/README.md b/sdk/resourcemanager/resources/armsubscriptions/README.md index 34b06be02c94..23edfb54ca7a 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/README.md +++ b/sdk/resourcemanager/resources/armsubscriptions/README.md @@ -61,29 +61,11 @@ client := clientFactory.NewClient() ``` ## Fakes -The `fake` package provides implementations for fake servers that can be used for testing. -To create a fake server, declare an instance of the required fake server type(s). -```go -myFakeServer := fake.Server{} -``` -Next, provide func implementations for the methods you wish to fake. -The named return variables can be used to simplify return value construction. -```go -myFakeServer.Get = func(ctx context.Context, subscriptionID string, options *armsubscriptions.ClientGetOptions) (resp azfake.Responder[armsubscriptions.ClientGetResponse], errResp azfake.ErrorResponder) { - // TODO: resp.SetResponse(/* your fake ClientGetResponse response */) - return -} -``` -You connect the fake server to a client instance during construction through the optional transport. -Use `NewTokenCredential()` from `azcore/fake` to obtain a fake credential. -```go -import azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" -client, err := armsubscriptions.NewClient("subscriptionID", azfake.NewTokenCredential(), &arm.ClientOptions{ - ClientOptions: azcore.ClientOptions{ - Transport: fake.NewServerTransport(&myFakeServer), - }, -}) -``` + +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. See [creating a fake](https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/resourcemanager/resources/armsubscriptions/fake_example_test.go) for a complete example. diff --git a/sdk/resourcemanager/resources/armsubscriptions/autorest.md b/sdk/resourcemanager/resources/armsubscriptions/autorest.md index 475a3f85ecb1..77616e287acf 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/autorest.md +++ b/sdk/resourcemanager/resources/armsubscriptions/autorest.md @@ -8,11 +8,7 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/4f4073bdb028bc84bc3e6405c1cbaf8e89b83caf/specification/resources/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/4f4073bdb028bc84bc3e6405c1cbaf8e89b83caf/specification/resources/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions -module-version: 1.3.0-beta.3 +module-version: 1.3.0 package-subscriptions: true tag: package-subscriptions-2022-12 -azcore-version: 1.9.0-beta.1 -generate-fakes: true -inject-spans: true ``` diff --git a/sdk/resourcemanager/resources/armsubscriptions/build.go b/sdk/resourcemanager/resources/armsubscriptions/build.go index 06fdf0746448..6fd15000800a 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/build.go +++ b/sdk/resourcemanager/resources/armsubscriptions/build.go @@ -2,6 +2,6 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // This file enables 'go generate' to regenerate this specific SDK -//go:generate pwsh ../../../../eng/scripts/build.ps1 -goExtension "@autorest/go@4.0.0-preview.54" -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/resources/armsubscriptions +//go:generate pwsh ../../../../eng/scripts/build.ps1 -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/resources/armsubscriptions package armsubscriptions diff --git a/sdk/resourcemanager/resources/armsubscriptions/client.go b/sdk/resourcemanager/resources/armsubscriptions/client.go index 35bf6a12e427..8c8b99a0cc7d 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/client.go +++ b/sdk/resourcemanager/resources/armsubscriptions/client.go @@ -31,7 +31,7 @@ type Client struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*Client, error) { - cl, err := arm.NewClient(moduleName+".Client", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -166,23 +166,16 @@ func (client *Client) NewListPager(options *ClientListOptions) *runtime.Pager[Cl }, Fetcher: func(ctx context.Context, page *ClientListResponse) (ClientListResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewListPager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + 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 ClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, Tracer: client.internal.Tracer(), diff --git a/sdk/resourcemanager/resources/armsubscriptions/client_factory.go b/sdk/resourcemanager/resources/armsubscriptions/client_factory.go index a4d1cb194e3b..a6c5e5a37a85 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/client_factory.go +++ b/sdk/resourcemanager/resources/armsubscriptions/client_factory.go @@ -25,7 +25,7 @@ type ClientFactory struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewClientFactory(credential azcore.TokenCredential, options *arm.ClientOptions) (*ClientFactory, error) { - _, err := arm.NewClient(moduleName+".ClientFactory", moduleVersion, credential, options) + _, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -35,21 +35,25 @@ func NewClientFactory(credential azcore.TokenCredential, options *arm.ClientOpti }, nil } +// NewClient creates a new instance of Client. func (c *ClientFactory) NewClient() *Client { subClient, _ := NewClient(c.credential, c.options) return subClient } +// NewOperationsClient creates a new instance of OperationsClient. func (c *ClientFactory) NewOperationsClient() *OperationsClient { subClient, _ := NewOperationsClient(c.credential, c.options) return subClient } +// NewSubscriptionClient creates a new instance of SubscriptionClient. func (c *ClientFactory) NewSubscriptionClient() *SubscriptionClient { subClient, _ := NewSubscriptionClient(c.credential, c.options) return subClient } +// NewTenantsClient creates a new instance of TenantsClient. func (c *ClientFactory) NewTenantsClient() *TenantsClient { subClient, _ := NewTenantsClient(c.credential, c.options) return subClient diff --git a/sdk/resourcemanager/resources/armsubscriptions/constants.go b/sdk/resourcemanager/resources/armsubscriptions/constants.go index 7704bcb92a85..a8a453259982 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/constants.go +++ b/sdk/resourcemanager/resources/armsubscriptions/constants.go @@ -9,8 +9,8 @@ package armsubscriptions const ( - moduleName = "armsubscriptions" - moduleVersion = "v1.3.0-beta.3" + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions" + moduleVersion = "v1.3.0" ) // ActionType - Enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. diff --git a/sdk/resourcemanager/resources/armsubscriptions/fake/internal.go b/sdk/resourcemanager/resources/armsubscriptions/fake/internal.go index 03b635903572..4d8bd36394ec 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/fake/internal.go +++ b/sdk/resourcemanager/resources/armsubscriptions/fake/internal.go @@ -9,11 +9,8 @@ package fake import ( - "io" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" "net/http" - "reflect" - "regexp" - "strings" "sync" ) @@ -25,19 +22,13 @@ func (nonRetriableError) NonRetriable() { // marker method } -func getOptional[T any](v T) *T { - if reflect.ValueOf(v).IsZero() { - return nil - } - return &v -} - -func getHeaderValue(h http.Header, k string) string { - v := h[k] - if len(v) == 0 { - return "" +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } } - return v[0] + return false } func parseOptional[T any](v string, parse func(v string) (T, error)) (*T, error) { @@ -51,35 +42,6 @@ func parseOptional[T any](v string, parse func(v string) (T, error)) (*T, error) return &t, err } -func parseWithCast[T any](v string, parse func(v string) (T, error)) (T, error) { - t, err := parse(v) - if err != nil { - return *new(T), err - } - return t, err -} - -func readRequestBody(req *http.Request) ([]byte, error) { - if req.Body == nil { - return nil, nil - } - body, err := io.ReadAll(req.Body) - if err != nil { - return nil, err - } - req.Body.Close() - return body, nil -} - -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{}, @@ -91,20 +53,10 @@ type tracker[T any] struct { mu sync.Mutex } -func (p *tracker[T]) key(req *http.Request) string { - path := req.URL.Path - if match, _ := regexp.Match(`/page_\d+$`, []byte(path)); match { - path = path[:strings.LastIndex(path, "/")] - } else if strings.HasSuffix(path, "/get/fake/status") { - path = path[:len(path)-16] - } - return path -} - func (p *tracker[T]) get(req *http.Request) *T { p.mu.Lock() defer p.mu.Unlock() - if item, ok := p.items[p.key(req)]; ok { + if item, ok := p.items[server.SanitizePagerPollerPath(req.URL.Path)]; ok { return item } return nil @@ -113,11 +65,11 @@ func (p *tracker[T]) get(req *http.Request) *T { func (p *tracker[T]) add(req *http.Request, item *T) { p.mu.Lock() defer p.mu.Unlock() - p.items[p.key(req)] = item + 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, p.key(req)) + delete(p.items, server.SanitizePagerPollerPath(req.URL.Path)) } diff --git a/sdk/resourcemanager/resources/armsubscriptions/fake/server.go b/sdk/resourcemanager/resources/armsubscriptions/fake/server.go index 155d983374b4..c4a6d7f96f9c 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/fake/server.go +++ b/sdk/resourcemanager/resources/armsubscriptions/fake/server.go @@ -96,7 +96,7 @@ func (s *ServerTransport) dispatchCheckZonePeers(req *http.Request) (*http.Respo if s.srv.CheckZonePeers == nil { return nil, &nonRetriableError{errors.New("fake for method CheckZonePeers not implemented")} } - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.Resources/checkZonePeers/` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/checkZonePeers/` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { @@ -106,11 +106,11 @@ func (s *ServerTransport) dispatchCheckZonePeers(req *http.Request) (*http.Respo if err != nil { return nil, err } - subscriptionIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("subscriptionId")]) + subscriptionIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("subscriptionId")]) if err != nil { return nil, err } - respr, errRespr := s.srv.CheckZonePeers(req.Context(), subscriptionIDUnescaped, body, nil) + respr, errRespr := s.srv.CheckZonePeers(req.Context(), subscriptionIDParam, body, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -135,11 +135,11 @@ func (s *ServerTransport) dispatchGet(req *http.Request) (*http.Response, error) if matches == nil || len(matches) < 1 { return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } - subscriptionIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("subscriptionId")]) + subscriptionIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("subscriptionId")]) if err != nil { return nil, err } - respr, errRespr := s.srv.Get(req.Context(), subscriptionIDUnescaped, nil) + respr, errRespr := s.srv.Get(req.Context(), subscriptionIDParam, nil) if respErr := server.GetError(errRespr, req); respErr != nil { return nil, respErr } @@ -194,7 +194,7 @@ func (s *ServerTransport) dispatchNewListLocationsPager(req *http.Request) (*htt return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) } qp := req.URL.Query() - subscriptionIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("subscriptionId")]) + subscriptionIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("subscriptionId")]) if err != nil { return nil, err } @@ -212,7 +212,7 @@ func (s *ServerTransport) dispatchNewListLocationsPager(req *http.Request) (*htt IncludeExtendedLocations: includeExtendedLocationsParam, } } - resp := s.srv.NewListLocationsPager(subscriptionIDUnescaped, options) + resp := s.srv.NewListLocationsPager(subscriptionIDParam, options) newListLocationsPager = &resp s.newListLocationsPager.add(req, newListLocationsPager) } diff --git a/sdk/resourcemanager/resources/armsubscriptions/fake/server_factory.go b/sdk/resourcemanager/resources/armsubscriptions/fake/server_factory.go new file mode 100644 index 000000000000..cffaf2c95c9a --- /dev/null +++ b/sdk/resourcemanager/resources/armsubscriptions/fake/server_factory.go @@ -0,0 +1,90 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" + "sync" +) + +// ServerFactory is a fake server for instances of the armsubscriptions.ClientFactory type. +type ServerFactory struct { + Server Server + OperationsServer OperationsServer + SubscriptionServer SubscriptionServer + TenantsServer TenantsServer +} + +// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. +// The returned ServerFactoryTransport instance is connected to an instance of armsubscriptions.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 armsubscriptions.ClientFactory to instances of ServerFactory. +// Don't use this type directly, use NewServerFactoryTransport instead. +type ServerFactoryTransport struct { + srv *ServerFactory + trMu sync.Mutex + trServer *ServerTransport + trOperationsServer *OperationsServerTransport + trSubscriptionServer *SubscriptionServerTransport + trTenantsServer *TenantsServerTransport +} + +// 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 "Client": + initServer(s, &s.trServer, func() *ServerTransport { return NewServerTransport(&s.srv.Server) }) + resp, err = s.trServer.Do(req) + case "OperationsClient": + initServer(s, &s.trOperationsServer, func() *OperationsServerTransport { return NewOperationsServerTransport(&s.srv.OperationsServer) }) + resp, err = s.trOperationsServer.Do(req) + case "SubscriptionClient": + initServer(s, &s.trSubscriptionServer, func() *SubscriptionServerTransport { return NewSubscriptionServerTransport(&s.srv.SubscriptionServer) }) + resp, err = s.trSubscriptionServer.Do(req) + case "TenantsClient": + initServer(s, &s.trTenantsServer, func() *TenantsServerTransport { return NewTenantsServerTransport(&s.srv.TenantsServer) }) + resp, err = s.trTenantsServer.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/resources/armsubscriptions/go.mod b/sdk/resourcemanager/resources/armsubscriptions/go.mod index c09f3dd31280..e114f13047c2 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/go.mod +++ b/sdk/resourcemanager/resources/armsubscriptions/go.mod @@ -3,26 +3,26 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscr go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0-beta.1 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 - github.com/stretchr/testify v1.7.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 + github.com/stretchr/testify v1.8.4 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 // indirect - github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dnaeon/go-vcr v1.1.0 // indirect - github.com/golang-jwt/jwt/v4 v4.4.2 // indirect - github.com/google/uuid v1.1.1 // indirect + github.com/dnaeon/go-vcr v1.2.0 // indirect + github.com/golang-jwt/jwt/v5 v5.0.0 // indirect + github.com/google/uuid v1.3.1 // indirect github.com/kylelemons/godebug v1.1.0 // indirect - github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect + github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/crypto v0.13.0 // indirect - golang.org/x/net v0.15.0 // indirect - golang.org/x/sys v0.12.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/sdk/resourcemanager/resources/armsubscriptions/go.sum b/sdk/resourcemanager/resources/armsubscriptions/go.sum index 817c919b2270..88bb72abf2ba 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/go.sum +++ b/sdk/resourcemanager/resources/armsubscriptions/go.sum @@ -1,47 +1,47 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0-beta.1 h1:ODs3brnqQM99Tq1PffODpAViYv3Bf8zOg464MU7p5ew= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0-beta.1/go.mod h1:3Ug6Qzto9anB6mGlEdgYMDF5zHQ+wwhEaYR4s17PHMw= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 h1:t/W5MYAuQy81cvM8VUNfRLzhtKpXhVUAN7Cd7KVbTyc= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0/go.mod h1:NBanQUfSWiWn3QEpWDTCU0IjBECKOYvl2R8xdRtMtiM= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 h1:fb8kj/Dh4CSwgsOzHeZY4Xh68cFVbzXx+ONXGMY//4w= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0/go.mod h1:uReU2sSxZExRPBAg3qKzmAucSi51+SP1OhohieR821Q= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 h1:BMAjVKJM0U/CYF27gA0ZMmXGkOcvfFtD0oHVZ1TIPRI= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0/go.mod h1:1fXstnBMas5kzG+S3q8UoJcmyU6nUeunJcMDHcRYHhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 h1:ECsQtyERDVz3NP3kvDOTLvbQhqWp/x9EsGKtb4ogUr8= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0/go.mod h1:s1tW/At+xHqjNFvWU4G0c0Qv33KOhvbGNj0RCTQDV8s= -github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 h1:VgSJlZH5u0k2qxSpqyghcFQKmvYckj46uymKK5XzkBM= -github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0/go.mod h1:BDJ5qMFKx9DugEg3+uQSDCdbYPr5s9vBTrL9P8TpqOU= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 h1:PTFGRSlMKCQelWwxUyYVEUqseBJVemLyqWJjvMyt0do= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0/go.mod h1:LRr2FzBTQlONPPa5HREE5+RjSCTXl7BwOvYOaWTqCaI= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 h1:pPvTJ1dY0sA35JOeFq6TsY2xj6Z85Yo23Pj4wCCvu4o= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 h1:7CBQ+Ei8SP2c6ydQTGCCrS35bDxgTMfoP2miAwK++OU= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1/go.mod h1:c/wcGeGx5FUPbM/JltUYHZcKmigwyVLJlDq+4HdtXaw= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 h1:WpB/QDNLpMw72xHJc34BNNykqSOeEJDAWkhf0u12/Jk= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= -github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= -github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs= -github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= +github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= +github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/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/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= -github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 h1:Qj1ukM4GlMWXNdMBuXcXfz/Kw9s1qm0CLY32QxuSImI= -github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= -golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/resourcemanager/resources/armsubscriptions/operations_client.go b/sdk/resourcemanager/resources/armsubscriptions/operations_client.go index 06764f306671..39522167634c 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/operations_client.go +++ b/sdk/resourcemanager/resources/armsubscriptions/operations_client.go @@ -27,7 +27,7 @@ type OperationsClient struct { // - 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+".OperationsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -48,23 +48,16 @@ func (client *OperationsClient) NewListPager(options *OperationsClientListOption }, Fetcher: func(ctx context.Context, page *OperationsClientListResponse) (OperationsClientListResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "OperationsClient.NewListPager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + 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 } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return OperationsClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return OperationsClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, Tracer: client.internal.Tracer(), diff --git a/sdk/resourcemanager/resources/armsubscriptions/subscription_client.go b/sdk/resourcemanager/resources/armsubscriptions/subscription_client.go index 23621c5c7745..b45d6a248c3b 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/subscription_client.go +++ b/sdk/resourcemanager/resources/armsubscriptions/subscription_client.go @@ -27,7 +27,7 @@ type SubscriptionClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewSubscriptionClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*SubscriptionClient, error) { - cl, err := arm.NewClient(moduleName+".SubscriptionClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } diff --git a/sdk/resourcemanager/resources/armsubscriptions/subscriptions_client_live_test.go b/sdk/resourcemanager/resources/armsubscriptions/subscriptions_client_live_test.go index c9f2416fc92b..908b17b0d9d5 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/subscriptions_client_live_test.go +++ b/sdk/resourcemanager/resources/armsubscriptions/subscriptions_client_live_test.go @@ -14,7 +14,7 @@ import ( "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/to" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions" "github.com/stretchr/testify/suite" ) diff --git a/sdk/resourcemanager/resources/armsubscriptions/tenants_client.go b/sdk/resourcemanager/resources/armsubscriptions/tenants_client.go index 814b72feffc6..2ee5b85a9298 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/tenants_client.go +++ b/sdk/resourcemanager/resources/armsubscriptions/tenants_client.go @@ -27,7 +27,7 @@ type TenantsClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewTenantsClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*TenantsClient, error) { - cl, err := arm.NewClient(moduleName+".TenantsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -48,23 +48,16 @@ func (client *TenantsClient) NewListPager(options *TenantsClientListOptions) *ru }, Fetcher: func(ctx context.Context, page *TenantsClientListResponse) (TenantsClientListResponse, error) { ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "TenantsClient.NewListPager") - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + 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 TenantsClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return TenantsClientListResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return TenantsClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, Tracer: client.internal.Tracer(), diff --git a/sdk/resourcemanager/resources/armsubscriptions/tenants_client_live_test.go b/sdk/resourcemanager/resources/armsubscriptions/tenants_client_live_test.go index 1979df70a48d..083193c61d14 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/tenants_client_live_test.go +++ b/sdk/resourcemanager/resources/armsubscriptions/tenants_client_live_test.go @@ -13,7 +13,7 @@ import ( "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/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions" "github.com/stretchr/testify/suite" ) From e317ac614659b48ef02643dbbfcc5837ac2992c2 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 15:34:55 +0800 Subject: [PATCH 11/18] [Release] sdk/resourcemanager/resources/armtemplatespecs/1.2.0 generation from spec commit: bf204aab860f2eb58a9d346b00d44760f2a9b0a2 --- .../resources/armtemplatespecs/CHANGELOG.md | 6 + .../resources/armtemplatespecs/README.md | 7 + .../resources/armtemplatespecs/autorest.md | 2 +- .../resources/armtemplatespecs/client.go | 150 +++--- .../armtemplatespecs/client_example_test.go | 40 +- .../armtemplatespecs/client_factory.go | 7 +- .../resources/armtemplatespecs/constants.go | 7 +- .../armtemplatespecs/fake/internal.go | 72 +++ .../resources/armtemplatespecs/fake/server.go | 451 ++++++++++++++++++ .../armtemplatespecs/fake/server_factory.go | 82 ++++ .../fake/templatespecversions_server.go | 384 +++++++++++++++ .../armtemplatespecs/fake/time_rfc3339.go | 86 ++++ .../resources/armtemplatespecs/go.mod | 32 +- .../resources/armtemplatespecs/go.sum | 70 +-- .../resources/armtemplatespecs/models.go | 89 +--- .../armtemplatespecs/models_serde.go | 19 +- .../resources/armtemplatespecs/options.go | 95 ++++ .../armtemplatespecs/response_types.go | 16 +- .../templatespecs_client_live_test.go | 2 +- .../templatespecversions_client.go | 129 +++-- ...emplatespecversions_client_example_test.go | 32 +- .../templatespecversions_client_live_test.go | 2 +- .../armtemplatespecs/time_rfc3339.go | 43 +- 23 files changed, 1491 insertions(+), 332 deletions(-) create mode 100644 sdk/resourcemanager/resources/armtemplatespecs/fake/internal.go create mode 100644 sdk/resourcemanager/resources/armtemplatespecs/fake/server.go create mode 100644 sdk/resourcemanager/resources/armtemplatespecs/fake/server_factory.go create mode 100644 sdk/resourcemanager/resources/armtemplatespecs/fake/templatespecversions_server.go create mode 100644 sdk/resourcemanager/resources/armtemplatespecs/fake/time_rfc3339.go create mode 100644 sdk/resourcemanager/resources/armtemplatespecs/options.go diff --git a/sdk/resourcemanager/resources/armtemplatespecs/CHANGELOG.md b/sdk/resourcemanager/resources/armtemplatespecs/CHANGELOG.md index fe114fb624e9..77d85f2008c5 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/CHANGELOG.md +++ b/sdk/resourcemanager/resources/armtemplatespecs/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 1.2.0 (2023-11-24) +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + + ## 1.1.1 (2023-04-14) ### Bug Fixes diff --git a/sdk/resourcemanager/resources/armtemplatespecs/README.md b/sdk/resourcemanager/resources/armtemplatespecs/README.md index 3f42af0f1a3a..fb9eb5280fcb 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/README.md +++ b/sdk/resourcemanager/resources/armtemplatespecs/README.md @@ -60,6 +60,13 @@ A client groups a set of related APIs, providing access to its functionality. C client := clientFactory.NewClient() ``` +## 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 diff --git a/sdk/resourcemanager/resources/armtemplatespecs/autorest.md b/sdk/resourcemanager/resources/armtemplatespecs/autorest.md index e75f3b81761e..60f48c4e22ef 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/autorest.md +++ b/sdk/resourcemanager/resources/armtemplatespecs/autorest.md @@ -8,6 +8,6 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/0cc5e2efd6ffccf30e80d1e150b488dd87198b94/specification/resources/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/0cc5e2efd6ffccf30e80d1e150b488dd87198b94/specification/resources/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 1.1.1 +module-version: 1.2.0 package-templatespecs: true ``` \ No newline at end of file diff --git a/sdk/resourcemanager/resources/armtemplatespecs/client.go b/sdk/resourcemanager/resources/armtemplatespecs/client.go index 686aae12a55a..cb8598647334 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/client.go +++ b/sdk/resourcemanager/resources/armtemplatespecs/client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armtemplatespecs @@ -33,7 +32,7 @@ type Client struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*Client, error) { - cl, err := arm.NewClient(moduleName+".Client", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -53,18 +52,25 @@ func NewClient(subscriptionID string, credential azcore.TokenCredential, options // - templateSpec - Template Spec supplied to the operation. // - options - ClientCreateOrUpdateOptions contains the optional parameters for the Client.CreateOrUpdate method. func (client *Client) CreateOrUpdate(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpec TemplateSpec, options *ClientCreateOrUpdateOptions) (ClientCreateOrUpdateResponse, error) { + var err error + const operationName = "Client.CreateOrUpdate" + 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, templateSpecName, templateSpec, options) if err != nil { return ClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return ClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return ClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -90,7 +96,10 @@ func (client *Client) createOrUpdateCreateRequest(ctx context.Context, resourceG reqQP.Set("api-version", "2022-02-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, templateSpec) + if err := runtime.MarshalAsJSON(req, templateSpec); err != nil { + return nil, err + } + return req, nil } // createOrUpdateHandleResponse handles the CreateOrUpdate response. @@ -110,16 +119,22 @@ func (client *Client) createOrUpdateHandleResponse(resp *http.Response) (ClientC // - templateSpecName - Name of the Template Spec. // - options - ClientDeleteOptions contains the optional parameters for the Client.Delete method. func (client *Client) Delete(ctx context.Context, resourceGroupName string, templateSpecName string, options *ClientDeleteOptions) (ClientDeleteResponse, error) { + var err error + const operationName = "Client.Delete" + 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, templateSpecName, options) if err != nil { return ClientDeleteResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientDeleteResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return ClientDeleteResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return ClientDeleteResponse{}, err } return ClientDeleteResponse{}, nil } @@ -158,18 +173,25 @@ func (client *Client) deleteCreateRequest(ctx context.Context, resourceGroupName // - templateSpecName - Name of the Template Spec. // - options - ClientGetOptions contains the optional parameters for the Client.Get method. func (client *Client) Get(ctx context.Context, resourceGroupName string, templateSpecName string, options *ClientGetOptions) (ClientGetResponse, error) { + var err error + const operationName = "Client.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, templateSpecName, options) if err != nil { return ClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -217,18 +239,25 @@ func (client *Client) getHandleResponse(resp *http.Response) (ClientGetResponse, // - templateSpecName - Name of the Template Spec. // - options - ClientGetBuiltInOptions contains the optional parameters for the Client.GetBuiltIn method. func (client *Client) GetBuiltIn(ctx context.Context, templateSpecName string, options *ClientGetBuiltInOptions) (ClientGetBuiltInResponse, error) { + var err error + const operationName = "Client.GetBuiltIn" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getBuiltInCreateRequest(ctx, templateSpecName, options) if err != nil { return ClientGetBuiltInResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientGetBuiltInResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientGetBuiltInResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientGetBuiltInResponse{}, err } - return client.getBuiltInHandleResponse(resp) + resp, err := client.getBuiltInHandleResponse(httpResp) + return resp, err } // getBuiltInCreateRequest creates the GetBuiltIn request. @@ -271,25 +300,20 @@ func (client *Client) NewListBuiltInsPager(options *ClientListBuiltInsOptions) * return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ClientListBuiltInsResponse) (ClientListBuiltInsResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listBuiltInsCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return ClientListBuiltInsResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewListBuiltInsPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listBuiltInsCreateRequest(ctx, options) + }, nil) if err != nil { return ClientListBuiltInsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListBuiltInsResponse{}, runtime.NewResponseError(resp) - } return client.listBuiltInsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -331,25 +355,20 @@ func (client *Client) NewListByResourceGroupPager(resourceGroupName string, opti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ClientListByResourceGroupResponse) (ClientListByResourceGroupResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.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 ClientListByResourceGroupResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ClientListByResourceGroupResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListByResourceGroupResponse{}, runtime.NewResponseError(resp) - } return client.listByResourceGroupHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -397,25 +416,20 @@ func (client *Client) NewListBySubscriptionPager(options *ClientListBySubscripti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ClientListBySubscriptionResponse) (ClientListBySubscriptionResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listBySubscriptionCreateRequest(ctx, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.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 ClientListBySubscriptionResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) - if err != nil { - return ClientListBySubscriptionResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListBySubscriptionResponse{}, runtime.NewResponseError(resp) - } return client.listBySubscriptionHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -457,18 +471,25 @@ func (client *Client) listBySubscriptionHandleResponse(resp *http.Response) (Cli // - templateSpecName - Name of the Template Spec. // - options - ClientUpdateOptions contains the optional parameters for the Client.Update method. func (client *Client) Update(ctx context.Context, resourceGroupName string, templateSpecName string, options *ClientUpdateOptions) (ClientUpdateResponse, error) { + var err error + const operationName = "Client.Update" + 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, templateSpecName, options) if err != nil { return ClientUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return ClientUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientUpdateResponse{}, err } - return client.updateHandleResponse(resp) + resp, err := client.updateHandleResponse(httpResp) + return resp, err } // updateCreateRequest creates the Update request. @@ -495,7 +516,10 @@ func (client *Client) updateCreateRequest(ctx context.Context, resourceGroupName req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.TemplateSpec != nil { - return req, runtime.MarshalAsJSON(req, *options.TemplateSpec) + if err := runtime.MarshalAsJSON(req, *options.TemplateSpec); err != nil { + return nil, err + } + return req, nil } return req, nil } diff --git a/sdk/resourcemanager/resources/armtemplatespecs/client_example_test.go b/sdk/resourcemanager/resources/armtemplatespecs/client_example_test.go index f1ce8cb77e78..608583e397a7 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/client_example_test.go +++ b/sdk/resourcemanager/resources/armtemplatespecs/client_example_test.go @@ -46,10 +46,10 @@ func ExampleClient_CreateOrUpdate() { // Type: to.Ptr("Microsoft.Resources/templateSpecs"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/templateSpecRG/providers/Microsoft.Resources/templateSpecs/simpleTemplateSpec"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), // }, @@ -88,10 +88,10 @@ func ExampleClient_Update() { // Type: to.Ptr("Microsoft.Resources/templateSpecs"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/templateSpecRG/providers/Microsoft.Resources/templateSpecs/simpleTemplateSpec"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), // }, @@ -128,10 +128,10 @@ func ExampleClient_Get() { // Type: to.Ptr("Microsoft.Resources/templateSpecs"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/templateSpecRG/providers/Microsoft.Resources/templateSpecs/simpleTemplateSpec"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), // }, @@ -188,10 +188,10 @@ func ExampleClient_NewListBySubscriptionPager() { // Type: to.Ptr("Microsoft.Resources/templateSpecs"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/templateSpecRG/providers/Microsoft.Resources/templateSpecs/simpleTemplateSpec"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), // }, @@ -205,10 +205,10 @@ func ExampleClient_NewListBySubscriptionPager() { // Type: to.Ptr("Microsoft.Resources/templateSpecs"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/templateSpecRG2/providers/Microsoft.Resources/templateSpecs/anotherSimpleTemplateSpec"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-03T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-03T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), // }, @@ -250,10 +250,10 @@ func ExampleClient_NewListByResourceGroupPager() { // Type: to.Ptr("Microsoft.Resources/templateSpecs"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/templateSpecRG/providers/Microsoft.Resources/templateSpecs/simpleTemplateSpec"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), // }, @@ -267,10 +267,10 @@ func ExampleClient_NewListByResourceGroupPager() { // Type: to.Ptr("Microsoft.Resources/templateSpecs"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/templateSpecRG/providers/Microsoft.Resources/templateSpecs/anotherSimpleTemplateSpec"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-03T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-03T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), // }, @@ -306,8 +306,8 @@ func ExampleClient_GetBuiltIn() { // Type: to.Ptr("Microsoft.Resources/builtInTemplateSpecs"), // ID: to.Ptr("/providers/Microsoft.Resources/builtInTemplateSpecs/nameOfTheBuiltIn"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-01T01:01:01.1075056Z"); return t}()), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-02T02:03:01.1974346Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-01T01:01:01.107Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-02T02:03:01.197Z"); return t}()), // }, // Location: to.Ptr("eastus"), // Properties: &armtemplatespecs.TemplateSpecProperties{ @@ -345,8 +345,8 @@ func ExampleClient_NewListBuiltInsPager() { // Type: to.Ptr("Microsoft.Resources/builtInTemplateSpecs"), // ID: to.Ptr("/providers/Microsoft.Resources/builtInTemplateSpecs/nameOfBuiltIn"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-01T01:01:01.1075056Z"); return t}()), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-02T02:03:01.1974346Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-01T01:01:01.107Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-02T02:03:01.197Z"); return t}()), // }, // Location: to.Ptr("eastus"), // Properties: &armtemplatespecs.TemplateSpecProperties{ @@ -358,8 +358,8 @@ func ExampleClient_NewListBuiltInsPager() { // Type: to.Ptr("Microsoft.Resources/builtInTemplateSpecs"), // ID: to.Ptr("/providers/Microsoft.Resources/builtInTemplateSpecs/nameOfAnotherBuiltIn"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-03T03:01:01.1282121Z"); return t}()), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-03T05:22:06.1974346Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-03T03:01:01.128Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-03T05:22:06.197Z"); return t}()), // }, // Location: to.Ptr("eastus"), // Properties: &armtemplatespecs.TemplateSpecProperties{ diff --git a/sdk/resourcemanager/resources/armtemplatespecs/client_factory.go b/sdk/resourcemanager/resources/armtemplatespecs/client_factory.go index cd6c34073142..eee0635c465c 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/client_factory.go +++ b/sdk/resourcemanager/resources/armtemplatespecs/client_factory.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armtemplatespecs @@ -28,7 +27,7 @@ type ClientFactory struct { // - 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) { - _, err := arm.NewClient(moduleName+".ClientFactory", moduleVersion, credential, options) + _, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -38,11 +37,13 @@ func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, }, nil } +// NewClient creates a new instance of Client. func (c *ClientFactory) NewClient() *Client { subClient, _ := NewClient(c.subscriptionID, c.credential, c.options) return subClient } +// NewTemplateSpecVersionsClient creates a new instance of TemplateSpecVersionsClient. func (c *ClientFactory) NewTemplateSpecVersionsClient() *TemplateSpecVersionsClient { subClient, _ := NewTemplateSpecVersionsClient(c.subscriptionID, c.credential, c.options) return subClient diff --git a/sdk/resourcemanager/resources/armtemplatespecs/constants.go b/sdk/resourcemanager/resources/armtemplatespecs/constants.go index 60cb638a9cd0..62aa26651d79 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/constants.go +++ b/sdk/resourcemanager/resources/armtemplatespecs/constants.go @@ -3,15 +3,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armtemplatespecs const ( - moduleName = "armtemplatespecs" - moduleVersion = "v1.1.1" + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armtemplatespecs" + moduleVersion = "v1.2.0" ) // CreatedByType - The type of identity that created the resource. diff --git a/sdk/resourcemanager/resources/armtemplatespecs/fake/internal.go b/sdk/resourcemanager/resources/armtemplatespecs/fake/internal.go new file mode 100644 index 000000000000..94e060e89dbd --- /dev/null +++ b/sdk/resourcemanager/resources/armtemplatespecs/fake/internal.go @@ -0,0 +1,72 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "net/http" + "reflect" + "sync" +) + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} + +func getOptional[T any](v T) *T { + if reflect.ValueOf(v).IsZero() { + return nil + } + return &v +} + +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/resources/armtemplatespecs/fake/server.go b/sdk/resourcemanager/resources/armtemplatespecs/fake/server.go new file mode 100644 index 000000000000..5374364c5cf8 --- /dev/null +++ b/sdk/resourcemanager/resources/armtemplatespecs/fake/server.go @@ -0,0 +1,451 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armtemplatespecs" + "net/http" + "net/url" + "reflect" + "regexp" +) + +// Server is a fake server for instances of the armtemplatespecs.Client type. +type Server struct { + // CreateOrUpdate is the fake for method Client.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpec armtemplatespecs.TemplateSpec, options *armtemplatespecs.ClientCreateOrUpdateOptions) (resp azfake.Responder[armtemplatespecs.ClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method Client.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, resourceGroupName string, templateSpecName string, options *armtemplatespecs.ClientDeleteOptions) (resp azfake.Responder[armtemplatespecs.ClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method Client.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, templateSpecName string, options *armtemplatespecs.ClientGetOptions) (resp azfake.Responder[armtemplatespecs.ClientGetResponse], errResp azfake.ErrorResponder) + + // GetBuiltIn is the fake for method Client.GetBuiltIn + // HTTP status codes to indicate success: http.StatusOK + GetBuiltIn func(ctx context.Context, templateSpecName string, options *armtemplatespecs.ClientGetBuiltInOptions) (resp azfake.Responder[armtemplatespecs.ClientGetBuiltInResponse], errResp azfake.ErrorResponder) + + // NewListBuiltInsPager is the fake for method Client.NewListBuiltInsPager + // HTTP status codes to indicate success: http.StatusOK + NewListBuiltInsPager func(options *armtemplatespecs.ClientListBuiltInsOptions) (resp azfake.PagerResponder[armtemplatespecs.ClientListBuiltInsResponse]) + + // NewListByResourceGroupPager is the fake for method Client.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *armtemplatespecs.ClientListByResourceGroupOptions) (resp azfake.PagerResponder[armtemplatespecs.ClientListByResourceGroupResponse]) + + // NewListBySubscriptionPager is the fake for method Client.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armtemplatespecs.ClientListBySubscriptionOptions) (resp azfake.PagerResponder[armtemplatespecs.ClientListBySubscriptionResponse]) + + // Update is the fake for method Client.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, resourceGroupName string, templateSpecName string, options *armtemplatespecs.ClientUpdateOptions) (resp azfake.Responder[armtemplatespecs.ClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewServerTransport creates a new instance of ServerTransport with the provided implementation. +// The returned ServerTransport instance is connected to an instance of armtemplatespecs.Client via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewServerTransport(srv *Server) *ServerTransport { + return &ServerTransport{ + srv: srv, + newListBuiltInsPager: newTracker[azfake.PagerResponder[armtemplatespecs.ClientListBuiltInsResponse]](), + newListByResourceGroupPager: newTracker[azfake.PagerResponder[armtemplatespecs.ClientListByResourceGroupResponse]](), + newListBySubscriptionPager: newTracker[azfake.PagerResponder[armtemplatespecs.ClientListBySubscriptionResponse]](), + } +} + +// ServerTransport connects instances of armtemplatespecs.Client to instances of Server. +// Don't use this type directly, use NewServerTransport instead. +type ServerTransport struct { + srv *Server + newListBuiltInsPager *tracker[azfake.PagerResponder[armtemplatespecs.ClientListBuiltInsResponse]] + newListByResourceGroupPager *tracker[azfake.PagerResponder[armtemplatespecs.ClientListByResourceGroupResponse]] + newListBySubscriptionPager *tracker[azfake.PagerResponder[armtemplatespecs.ClientListBySubscriptionResponse]] +} + +// Do implements the policy.Transporter interface for ServerTransport. +func (s *ServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "Client.CreateOrUpdate": + resp, err = s.dispatchCreateOrUpdate(req) + case "Client.Delete": + resp, err = s.dispatchDelete(req) + case "Client.Get": + resp, err = s.dispatchGet(req) + case "Client.GetBuiltIn": + resp, err = s.dispatchGetBuiltIn(req) + case "Client.NewListBuiltInsPager": + resp, err = s.dispatchNewListBuiltInsPager(req) + case "Client.NewListByResourceGroupPager": + resp, err = s.dispatchNewListByResourceGroupPager(req) + case "Client.NewListBySubscriptionPager": + resp, err = s.dispatchNewListBySubscriptionPager(req) + case "Client.Update": + resp, err = s.dispatchUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (s *ServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/templateSpecs/(?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[armtemplatespecs.TemplateSpec](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + templateSpecNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.CreateOrUpdate(req.Context(), resourceGroupNameParam, templateSpecNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).TemplateSpec, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if s.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/templateSpecs/(?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 + } + templateSpecNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Delete(req.Context(), resourceGroupNameParam, templateSpecNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) 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\.Resources/templateSpecs/(?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) + } + qp := req.URL.Query() + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + templateSpecNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armtemplatespecs.TemplateSpecExpandKind(expandUnescaped)) + var options *armtemplatespecs.ClientGetOptions + if expandParam != nil { + options = &armtemplatespecs.ClientGetOptions{ + Expand: expandParam, + } + } + respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameParam, templateSpecNameParam, options) + 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).TemplateSpec, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchGetBuiltIn(req *http.Request) (*http.Response, error) { + if s.srv.GetBuiltIn == nil { + return nil, &nonRetriableError{errors.New("fake for method GetBuiltIn not implemented")} + } + const regexStr = `/providers/Microsoft\.Resources/builtInTemplateSpecs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + qp := req.URL.Query() + templateSpecNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armtemplatespecs.TemplateSpecExpandKind(expandUnescaped)) + var options *armtemplatespecs.ClientGetBuiltInOptions + if expandParam != nil { + options = &armtemplatespecs.ClientGetBuiltInOptions{ + Expand: expandParam, + } + } + respr, errRespr := s.srv.GetBuiltIn(req.Context(), templateSpecNameParam, options) + 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).TemplateSpec, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *ServerTransport) dispatchNewListBuiltInsPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListBuiltInsPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListBuiltInsPager not implemented")} + } + newListBuiltInsPager := s.newListBuiltInsPager.get(req) + if newListBuiltInsPager == nil { + qp := req.URL.Query() + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armtemplatespecs.TemplateSpecExpandKind(expandUnescaped)) + var options *armtemplatespecs.ClientListBuiltInsOptions + if expandParam != nil { + options = &armtemplatespecs.ClientListBuiltInsOptions{ + Expand: expandParam, + } + } + resp := s.srv.NewListBuiltInsPager(options) + newListBuiltInsPager = &resp + s.newListBuiltInsPager.add(req, newListBuiltInsPager) + server.PagerResponderInjectNextLinks(newListBuiltInsPager, req, func(page *armtemplatespecs.ClientListBuiltInsResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListBuiltInsPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + s.newListBuiltInsPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListBuiltInsPager) { + s.newListBuiltInsPager.remove(req) + } + return resp, nil +} + +func (s *ServerTransport) 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\.Resources/templateSpecs/` + 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) + } + qp := req.URL.Query() + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armtemplatespecs.TemplateSpecExpandKind(expandUnescaped)) + var options *armtemplatespecs.ClientListByResourceGroupOptions + if expandParam != nil { + options = &armtemplatespecs.ClientListByResourceGroupOptions{ + Expand: expandParam, + } + } + resp := s.srv.NewListByResourceGroupPager(resourceGroupNameParam, options) + newListByResourceGroupPager = &resp + s.newListByResourceGroupPager.add(req, newListByResourceGroupPager) + server.PagerResponderInjectNextLinks(newListByResourceGroupPager, req, func(page *armtemplatespecs.ClientListByResourceGroupResponse, 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 *ServerTransport) 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\.Resources/templateSpecs/` + 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) + } + qp := req.URL.Query() + expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) + if err != nil { + return nil, err + } + expandParam := getOptional(armtemplatespecs.TemplateSpecExpandKind(expandUnescaped)) + var options *armtemplatespecs.ClientListBySubscriptionOptions + if expandParam != nil { + options = &armtemplatespecs.ClientListBySubscriptionOptions{ + Expand: expandParam, + } + } + resp := s.srv.NewListBySubscriptionPager(options) + newListBySubscriptionPager = &resp + s.newListBySubscriptionPager.add(req, newListBySubscriptionPager) + server.PagerResponderInjectNextLinks(newListBySubscriptionPager, req, func(page *armtemplatespecs.ClientListBySubscriptionResponse, 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 *ServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if s.srv.Update == nil { + return nil, &nonRetriableError{errors.New("fake for method Update not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/templateSpecs/(?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[armtemplatespecs.TemplateSpecUpdateModel](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + templateSpecNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecName")]) + if err != nil { + return nil, err + } + var options *armtemplatespecs.ClientUpdateOptions + if !reflect.ValueOf(body).IsZero() { + options = &armtemplatespecs.ClientUpdateOptions{ + TemplateSpec: &body, + } + } + respr, errRespr := s.srv.Update(req.Context(), resourceGroupNameParam, templateSpecNameParam, options) + 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).TemplateSpec, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armtemplatespecs/fake/server_factory.go b/sdk/resourcemanager/resources/armtemplatespecs/fake/server_factory.go new file mode 100644 index 000000000000..7f06ca23ace4 --- /dev/null +++ b/sdk/resourcemanager/resources/armtemplatespecs/fake/server_factory.go @@ -0,0 +1,82 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" + "sync" +) + +// ServerFactory is a fake server for instances of the armtemplatespecs.ClientFactory type. +type ServerFactory struct { + Server Server + TemplateSpecVersionsServer TemplateSpecVersionsServer +} + +// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. +// The returned ServerFactoryTransport instance is connected to an instance of armtemplatespecs.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 armtemplatespecs.ClientFactory to instances of ServerFactory. +// Don't use this type directly, use NewServerFactoryTransport instead. +type ServerFactoryTransport struct { + srv *ServerFactory + trMu sync.Mutex + trServer *ServerTransport + trTemplateSpecVersionsServer *TemplateSpecVersionsServerTransport +} + +// 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 "Client": + initServer(s, &s.trServer, func() *ServerTransport { return NewServerTransport(&s.srv.Server) }) + resp, err = s.trServer.Do(req) + case "TemplateSpecVersionsClient": + initServer(s, &s.trTemplateSpecVersionsServer, func() *TemplateSpecVersionsServerTransport { + return NewTemplateSpecVersionsServerTransport(&s.srv.TemplateSpecVersionsServer) + }) + resp, err = s.trTemplateSpecVersionsServer.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/resources/armtemplatespecs/fake/templatespecversions_server.go b/sdk/resourcemanager/resources/armtemplatespecs/fake/templatespecversions_server.go new file mode 100644 index 000000000000..8598c2a45c78 --- /dev/null +++ b/sdk/resourcemanager/resources/armtemplatespecs/fake/templatespecversions_server.go @@ -0,0 +1,384 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armtemplatespecs" + "net/http" + "net/url" + "reflect" + "regexp" +) + +// TemplateSpecVersionsServer is a fake server for instances of the armtemplatespecs.TemplateSpecVersionsClient type. +type TemplateSpecVersionsServer struct { + // CreateOrUpdate is the fake for method TemplateSpecVersionsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string, templateSpecVersionModel armtemplatespecs.TemplateSpecVersion, options *armtemplatespecs.TemplateSpecVersionsClientCreateOrUpdateOptions) (resp azfake.Responder[armtemplatespecs.TemplateSpecVersionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method TemplateSpecVersionsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string, options *armtemplatespecs.TemplateSpecVersionsClientDeleteOptions) (resp azfake.Responder[armtemplatespecs.TemplateSpecVersionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method TemplateSpecVersionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string, options *armtemplatespecs.TemplateSpecVersionsClientGetOptions) (resp azfake.Responder[armtemplatespecs.TemplateSpecVersionsClientGetResponse], errResp azfake.ErrorResponder) + + // GetBuiltIn is the fake for method TemplateSpecVersionsClient.GetBuiltIn + // HTTP status codes to indicate success: http.StatusOK + GetBuiltIn func(ctx context.Context, templateSpecName string, templateSpecVersion string, options *armtemplatespecs.TemplateSpecVersionsClientGetBuiltInOptions) (resp azfake.Responder[armtemplatespecs.TemplateSpecVersionsClientGetBuiltInResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method TemplateSpecVersionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceGroupName string, templateSpecName string, options *armtemplatespecs.TemplateSpecVersionsClientListOptions) (resp azfake.PagerResponder[armtemplatespecs.TemplateSpecVersionsClientListResponse]) + + // NewListBuiltInsPager is the fake for method TemplateSpecVersionsClient.NewListBuiltInsPager + // HTTP status codes to indicate success: http.StatusOK + NewListBuiltInsPager func(templateSpecName string, options *armtemplatespecs.TemplateSpecVersionsClientListBuiltInsOptions) (resp azfake.PagerResponder[armtemplatespecs.TemplateSpecVersionsClientListBuiltInsResponse]) + + // Update is the fake for method TemplateSpecVersionsClient.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string, options *armtemplatespecs.TemplateSpecVersionsClientUpdateOptions) (resp azfake.Responder[armtemplatespecs.TemplateSpecVersionsClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewTemplateSpecVersionsServerTransport creates a new instance of TemplateSpecVersionsServerTransport with the provided implementation. +// The returned TemplateSpecVersionsServerTransport instance is connected to an instance of armtemplatespecs.TemplateSpecVersionsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewTemplateSpecVersionsServerTransport(srv *TemplateSpecVersionsServer) *TemplateSpecVersionsServerTransport { + return &TemplateSpecVersionsServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[armtemplatespecs.TemplateSpecVersionsClientListResponse]](), + newListBuiltInsPager: newTracker[azfake.PagerResponder[armtemplatespecs.TemplateSpecVersionsClientListBuiltInsResponse]](), + } +} + +// TemplateSpecVersionsServerTransport connects instances of armtemplatespecs.TemplateSpecVersionsClient to instances of TemplateSpecVersionsServer. +// Don't use this type directly, use NewTemplateSpecVersionsServerTransport instead. +type TemplateSpecVersionsServerTransport struct { + srv *TemplateSpecVersionsServer + newListPager *tracker[azfake.PagerResponder[armtemplatespecs.TemplateSpecVersionsClientListResponse]] + newListBuiltInsPager *tracker[azfake.PagerResponder[armtemplatespecs.TemplateSpecVersionsClientListBuiltInsResponse]] +} + +// Do implements the policy.Transporter interface for TemplateSpecVersionsServerTransport. +func (t *TemplateSpecVersionsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "TemplateSpecVersionsClient.CreateOrUpdate": + resp, err = t.dispatchCreateOrUpdate(req) + case "TemplateSpecVersionsClient.Delete": + resp, err = t.dispatchDelete(req) + case "TemplateSpecVersionsClient.Get": + resp, err = t.dispatchGet(req) + case "TemplateSpecVersionsClient.GetBuiltIn": + resp, err = t.dispatchGetBuiltIn(req) + case "TemplateSpecVersionsClient.NewListPager": + resp, err = t.dispatchNewListPager(req) + case "TemplateSpecVersionsClient.NewListBuiltInsPager": + resp, err = t.dispatchNewListBuiltInsPager(req) + case "TemplateSpecVersionsClient.Update": + resp, err = t.dispatchUpdate(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (t *TemplateSpecVersionsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if t.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/templateSpecs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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[armtemplatespecs.TemplateSpecVersion](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + templateSpecNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecName")]) + if err != nil { + return nil, err + } + templateSpecVersionParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecVersion")]) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.CreateOrUpdate(req.Context(), resourceGroupNameParam, templateSpecNameParam, templateSpecVersionParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).TemplateSpecVersion, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (t *TemplateSpecVersionsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if t.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/templateSpecs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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 + } + templateSpecNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecName")]) + if err != nil { + return nil, err + } + templateSpecVersionParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecVersion")]) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.Delete(req.Context(), resourceGroupNameParam, templateSpecNameParam, templateSpecVersionParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (t *TemplateSpecVersionsServerTransport) 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\.Resources/templateSpecs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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 + } + templateSpecNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecName")]) + if err != nil { + return nil, err + } + templateSpecVersionParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecVersion")]) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.Get(req.Context(), resourceGroupNameParam, templateSpecNameParam, templateSpecVersionParam, 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).TemplateSpecVersion, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (t *TemplateSpecVersionsServerTransport) dispatchGetBuiltIn(req *http.Request) (*http.Response, error) { + if t.srv.GetBuiltIn == nil { + return nil, &nonRetriableError{errors.New("fake for method GetBuiltIn not implemented")} + } + const regexStr = `/providers/Microsoft\.Resources/builtInTemplateSpecs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + 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) + } + templateSpecNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecName")]) + if err != nil { + return nil, err + } + templateSpecVersionParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecVersion")]) + if err != nil { + return nil, err + } + respr, errRespr := t.srv.GetBuiltIn(req.Context(), templateSpecNameParam, templateSpecVersionParam, 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).TemplateSpecVersion, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (t *TemplateSpecVersionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if t.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := t.newListPager.get(req) + if newListPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/templateSpecs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions` + 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 + } + templateSpecNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecName")]) + if err != nil { + return nil, err + } + resp := t.srv.NewListPager(resourceGroupNameParam, templateSpecNameParam, nil) + newListPager = &resp + t.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armtemplatespecs.TemplateSpecVersionsClientListResponse, 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) { + t.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + t.newListPager.remove(req) + } + return resp, nil +} + +func (t *TemplateSpecVersionsServerTransport) dispatchNewListBuiltInsPager(req *http.Request) (*http.Response, error) { + if t.srv.NewListBuiltInsPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListBuiltInsPager not implemented")} + } + newListBuiltInsPager := t.newListBuiltInsPager.get(req) + if newListBuiltInsPager == nil { + const regexStr = `/providers/Microsoft\.Resources/builtInTemplateSpecs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions` + 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) + } + templateSpecNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecName")]) + if err != nil { + return nil, err + } + resp := t.srv.NewListBuiltInsPager(templateSpecNameParam, nil) + newListBuiltInsPager = &resp + t.newListBuiltInsPager.add(req, newListBuiltInsPager) + server.PagerResponderInjectNextLinks(newListBuiltInsPager, req, func(page *armtemplatespecs.TemplateSpecVersionsClientListBuiltInsResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListBuiltInsPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + t.newListBuiltInsPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListBuiltInsPager) { + t.newListBuiltInsPager.remove(req) + } + return resp, nil +} + +func (t *TemplateSpecVersionsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if t.srv.Update == nil { + return nil, &nonRetriableError{errors.New("fake for method Update not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/templateSpecs/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?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[armtemplatespecs.TemplateSpecVersionUpdateModel](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + templateSpecNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecName")]) + if err != nil { + return nil, err + } + templateSpecVersionParam, err := url.PathUnescape(matches[regex.SubexpIndex("templateSpecVersion")]) + if err != nil { + return nil, err + } + var options *armtemplatespecs.TemplateSpecVersionsClientUpdateOptions + if !reflect.ValueOf(body).IsZero() { + options = &armtemplatespecs.TemplateSpecVersionsClientUpdateOptions{ + TemplateSpecVersionUpdateModel: &body, + } + } + respr, errRespr := t.srv.Update(req.Context(), resourceGroupNameParam, templateSpecNameParam, templateSpecVersionParam, options) + 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).TemplateSpecVersion, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/resources/armtemplatespecs/fake/time_rfc3339.go b/sdk/resourcemanager/resources/armtemplatespecs/fake/time_rfc3339.go new file mode 100644 index 000000000000..b0535a7b63e6 --- /dev/null +++ b/sdk/resourcemanager/resources/armtemplatespecs/fake/time_rfc3339.go @@ -0,0 +1,86 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "regexp" + "strings" + "time" +) + +// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. +var tzOffsetRegex = regexp.MustCompile(`(Z|z|\+|-)(\d+:\d+)*"*$`) + +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +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 { + layout := utcDateTimeJSON + if tzOffsetRegex.Match(data) { + layout = dateTimeJSON + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime + if tzOffsetRegex.Match(data) { + layout = time.RFC3339Nano + } + 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 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 || strings.EqualFold(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/resources/armtemplatespecs/go.mod b/sdk/resourcemanager/resources/armtemplatespecs/go.mod index c232f8bffadf..e18f1c4e605a 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/go.mod +++ b/sdk/resourcemanager/resources/armtemplatespecs/go.mod @@ -3,27 +3,27 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armtempla go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 - github.com/stretchr/testify v1.7.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 + github.com/stretchr/testify v1.8.4 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 // indirect - github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dnaeon/go-vcr v1.1.0 // indirect - github.com/golang-jwt/jwt/v4 v4.4.2 // indirect - github.com/google/uuid v1.1.1 // indirect + github.com/dnaeon/go-vcr v1.2.0 // indirect + github.com/golang-jwt/jwt/v5 v5.0.0 // indirect + github.com/google/uuid v1.3.1 // indirect github.com/kylelemons/godebug v1.1.0 // indirect - github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect + github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/sdk/resourcemanager/resources/armtemplatespecs/go.sum b/sdk/resourcemanager/resources/armtemplatespecs/go.sum index b0f97586a165..88bb72abf2ba 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/go.sum +++ b/sdk/resourcemanager/resources/armtemplatespecs/go.sum @@ -1,47 +1,47 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 h1:rTnT/Jrcm+figWlYz4Ixzt0SJVR2cMC8lvZcimipiEY= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0/go.mod h1:ON4tFdPTwRcgWEaVDrN3584Ef+b7GgSJaXxe5fW9t4M= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 h1:t/W5MYAuQy81cvM8VUNfRLzhtKpXhVUAN7Cd7KVbTyc= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0/go.mod h1:NBanQUfSWiWn3QEpWDTCU0IjBECKOYvl2R8xdRtMtiM= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 h1:leh5DwKv6Ihwi+h60uHtn6UWAxBbZ0q8DwQVMzf61zw= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 h1:fb8kj/Dh4CSwgsOzHeZY4Xh68cFVbzXx+ONXGMY//4w= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0/go.mod h1:uReU2sSxZExRPBAg3qKzmAucSi51+SP1OhohieR821Q= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 h1:BMAjVKJM0U/CYF27gA0ZMmXGkOcvfFtD0oHVZ1TIPRI= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0/go.mod h1:1fXstnBMas5kzG+S3q8UoJcmyU6nUeunJcMDHcRYHhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 h1:ECsQtyERDVz3NP3kvDOTLvbQhqWp/x9EsGKtb4ogUr8= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0/go.mod h1:s1tW/At+xHqjNFvWU4G0c0Qv33KOhvbGNj0RCTQDV8s= -github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 h1:VgSJlZH5u0k2qxSpqyghcFQKmvYckj46uymKK5XzkBM= -github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0/go.mod h1:BDJ5qMFKx9DugEg3+uQSDCdbYPr5s9vBTrL9P8TpqOU= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 h1:PTFGRSlMKCQelWwxUyYVEUqseBJVemLyqWJjvMyt0do= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0/go.mod h1:LRr2FzBTQlONPPa5HREE5+RjSCTXl7BwOvYOaWTqCaI= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 h1:pPvTJ1dY0sA35JOeFq6TsY2xj6Z85Yo23Pj4wCCvu4o= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 h1:7CBQ+Ei8SP2c6ydQTGCCrS35bDxgTMfoP2miAwK++OU= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1/go.mod h1:c/wcGeGx5FUPbM/JltUYHZcKmigwyVLJlDq+4HdtXaw= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 h1:WpB/QDNLpMw72xHJc34BNNykqSOeEJDAWkhf0u12/Jk= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= -github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= -github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs= -github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= +github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= +github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/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/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= -github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 h1:Qj1ukM4GlMWXNdMBuXcXfz/Kw9s1qm0CLY32QxuSImI= -github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 h1:Tgea0cVUD0ivh5ADBX4WwuI12DUd2to3nCYe2eayMIw= -golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/resourcemanager/resources/armtemplatespecs/models.go b/sdk/resourcemanager/resources/armtemplatespecs/models.go index 34482f5c7b29..de01e85770fc 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/models.go +++ b/sdk/resourcemanager/resources/armtemplatespecs/models.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armtemplatespecs @@ -26,52 +25,6 @@ type AzureResourceBase struct { Type *string } -// ClientCreateOrUpdateOptions contains the optional parameters for the Client.CreateOrUpdate method. -type ClientCreateOrUpdateOptions struct { - // placeholder for future optional parameters -} - -// ClientDeleteOptions contains the optional parameters for the Client.Delete method. -type ClientDeleteOptions struct { - // placeholder for future optional parameters -} - -// ClientGetBuiltInOptions contains the optional parameters for the Client.GetBuiltIn method. -type ClientGetBuiltInOptions struct { - // Allows for expansion of additional Template Spec details in the response. Optional. - Expand *TemplateSpecExpandKind -} - -// ClientGetOptions contains the optional parameters for the Client.Get method. -type ClientGetOptions struct { - // Allows for expansion of additional Template Spec details in the response. Optional. - Expand *TemplateSpecExpandKind -} - -// ClientListBuiltInsOptions contains the optional parameters for the Client.NewListBuiltInsPager method. -type ClientListBuiltInsOptions struct { - // Allows for expansion of additional Template Spec details in the response. Optional. - Expand *TemplateSpecExpandKind -} - -// ClientListByResourceGroupOptions contains the optional parameters for the Client.NewListByResourceGroupPager method. -type ClientListByResourceGroupOptions struct { - // Allows for expansion of additional Template Spec details in the response. Optional. - Expand *TemplateSpecExpandKind -} - -// ClientListBySubscriptionOptions contains the optional parameters for the Client.NewListBySubscriptionPager method. -type ClientListBySubscriptionOptions struct { - // Allows for expansion of additional Template Spec details in the response. Optional. - Expand *TemplateSpecExpandKind -} - -// ClientUpdateOptions contains the optional parameters for the Client.Update method. -type ClientUpdateOptions struct { - // Template Spec resource with the tags to be updated. - TemplateSpec *TemplateSpecUpdateModel -} - // Error - Template Specs error response. type Error struct { // Common error response for all Azure Resource Manager APIs to return error details for failed operations. (This also follows @@ -278,46 +231,6 @@ type TemplateSpecVersionUpdateModel struct { Type *string } -// TemplateSpecVersionsClientCreateOrUpdateOptions contains the optional parameters for the TemplateSpecVersionsClient.CreateOrUpdate -// method. -type TemplateSpecVersionsClientCreateOrUpdateOptions struct { - // placeholder for future optional parameters -} - -// TemplateSpecVersionsClientDeleteOptions contains the optional parameters for the TemplateSpecVersionsClient.Delete method. -type TemplateSpecVersionsClientDeleteOptions struct { - // placeholder for future optional parameters -} - -// TemplateSpecVersionsClientGetBuiltInOptions contains the optional parameters for the TemplateSpecVersionsClient.GetBuiltIn -// method. -type TemplateSpecVersionsClientGetBuiltInOptions struct { - // placeholder for future optional parameters -} - -// TemplateSpecVersionsClientGetOptions contains the optional parameters for the TemplateSpecVersionsClient.Get method. -type TemplateSpecVersionsClientGetOptions struct { - // placeholder for future optional parameters -} - -// TemplateSpecVersionsClientListBuiltInsOptions contains the optional parameters for the TemplateSpecVersionsClient.NewListBuiltInsPager -// method. -type TemplateSpecVersionsClientListBuiltInsOptions struct { - // placeholder for future optional parameters -} - -// TemplateSpecVersionsClientListOptions contains the optional parameters for the TemplateSpecVersionsClient.NewListPager -// method. -type TemplateSpecVersionsClientListOptions struct { - // placeholder for future optional parameters -} - -// TemplateSpecVersionsClientUpdateOptions contains the optional parameters for the TemplateSpecVersionsClient.Update method. -type TemplateSpecVersionsClientUpdateOptions struct { - // Template Spec Version resource with the tags to be updated. - TemplateSpecVersionUpdateModel *TemplateSpecVersionUpdateModel -} - // TemplateSpecVersionsListResult - List of Template Specs versions type TemplateSpecVersionsListResult struct { // An array of Template Spec versions. diff --git a/sdk/resourcemanager/resources/armtemplatespecs/models_serde.go b/sdk/resourcemanager/resources/armtemplatespecs/models_serde.go index 691260439439..a0bc4a7fed16 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/models_serde.go +++ b/sdk/resourcemanager/resources/armtemplatespecs/models_serde.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armtemplatespecs @@ -221,10 +220,10 @@ func (l *ListResult) UnmarshalJSON(data []byte) error { // MarshalJSON implements the json.Marshaller interface for type SystemData. func (s SystemData) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populateTimeRFC3339(objectMap, "createdAt", s.CreatedAt) + populateDateTimeRFC3339(objectMap, "createdAt", s.CreatedAt) populate(objectMap, "createdBy", s.CreatedBy) populate(objectMap, "createdByType", s.CreatedByType) - populateTimeRFC3339(objectMap, "lastModifiedAt", s.LastModifiedAt) + populateDateTimeRFC3339(objectMap, "lastModifiedAt", s.LastModifiedAt) populate(objectMap, "lastModifiedBy", s.LastModifiedBy) populate(objectMap, "lastModifiedByType", s.LastModifiedByType) return json.Marshal(objectMap) @@ -240,7 +239,7 @@ func (s *SystemData) UnmarshalJSON(data []byte) error { var err error switch key { case "createdAt": - err = unpopulateTimeRFC3339(val, "CreatedAt", &s.CreatedAt) + err = unpopulateDateTimeRFC3339(val, "CreatedAt", &s.CreatedAt) delete(rawMsg, key) case "createdBy": err = unpopulate(val, "CreatedBy", &s.CreatedBy) @@ -249,7 +248,7 @@ func (s *SystemData) UnmarshalJSON(data []byte) error { err = unpopulate(val, "CreatedByType", &s.CreatedByType) delete(rawMsg, key) case "lastModifiedAt": - err = unpopulateTimeRFC3339(val, "LastModifiedAt", &s.LastModifiedAt) + err = unpopulateDateTimeRFC3339(val, "LastModifiedAt", &s.LastModifiedAt) delete(rawMsg, key) case "lastModifiedBy": err = unpopulate(val, "LastModifiedBy", &s.LastModifiedBy) @@ -453,8 +452,8 @@ func (t *TemplateSpecVersion) UnmarshalJSON(data []byte) error { func (t TemplateSpecVersionInfo) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) populate(objectMap, "description", t.Description) - populateTimeRFC3339(objectMap, "timeCreated", t.TimeCreated) - populateTimeRFC3339(objectMap, "timeModified", t.TimeModified) + populateDateTimeRFC3339(objectMap, "timeCreated", t.TimeCreated) + populateDateTimeRFC3339(objectMap, "timeModified", t.TimeModified) return json.Marshal(objectMap) } @@ -471,10 +470,10 @@ func (t *TemplateSpecVersionInfo) UnmarshalJSON(data []byte) error { err = unpopulate(val, "Description", &t.Description) delete(rawMsg, key) case "timeCreated": - err = unpopulateTimeRFC3339(val, "TimeCreated", &t.TimeCreated) + err = unpopulateDateTimeRFC3339(val, "TimeCreated", &t.TimeCreated) delete(rawMsg, key) case "timeModified": - err = unpopulateTimeRFC3339(val, "TimeModified", &t.TimeModified) + err = unpopulateDateTimeRFC3339(val, "TimeModified", &t.TimeModified) delete(rawMsg, key) } if err != nil { diff --git a/sdk/resourcemanager/resources/armtemplatespecs/options.go b/sdk/resourcemanager/resources/armtemplatespecs/options.go new file mode 100644 index 000000000000..b57a6f978956 --- /dev/null +++ b/sdk/resourcemanager/resources/armtemplatespecs/options.go @@ -0,0 +1,95 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armtemplatespecs + +// ClientCreateOrUpdateOptions contains the optional parameters for the Client.CreateOrUpdate method. +type ClientCreateOrUpdateOptions struct { + // placeholder for future optional parameters +} + +// ClientDeleteOptions contains the optional parameters for the Client.Delete method. +type ClientDeleteOptions struct { + // placeholder for future optional parameters +} + +// ClientGetBuiltInOptions contains the optional parameters for the Client.GetBuiltIn method. +type ClientGetBuiltInOptions struct { + // Allows for expansion of additional Template Spec details in the response. Optional. + Expand *TemplateSpecExpandKind +} + +// ClientGetOptions contains the optional parameters for the Client.Get method. +type ClientGetOptions struct { + // Allows for expansion of additional Template Spec details in the response. Optional. + Expand *TemplateSpecExpandKind +} + +// ClientListBuiltInsOptions contains the optional parameters for the Client.NewListBuiltInsPager method. +type ClientListBuiltInsOptions struct { + // Allows for expansion of additional Template Spec details in the response. Optional. + Expand *TemplateSpecExpandKind +} + +// ClientListByResourceGroupOptions contains the optional parameters for the Client.NewListByResourceGroupPager method. +type ClientListByResourceGroupOptions struct { + // Allows for expansion of additional Template Spec details in the response. Optional. + Expand *TemplateSpecExpandKind +} + +// ClientListBySubscriptionOptions contains the optional parameters for the Client.NewListBySubscriptionPager method. +type ClientListBySubscriptionOptions struct { + // Allows for expansion of additional Template Spec details in the response. Optional. + Expand *TemplateSpecExpandKind +} + +// ClientUpdateOptions contains the optional parameters for the Client.Update method. +type ClientUpdateOptions struct { + // Template Spec resource with the tags to be updated. + TemplateSpec *TemplateSpecUpdateModel +} + +// TemplateSpecVersionsClientCreateOrUpdateOptions contains the optional parameters for the TemplateSpecVersionsClient.CreateOrUpdate +// method. +type TemplateSpecVersionsClientCreateOrUpdateOptions struct { + // placeholder for future optional parameters +} + +// TemplateSpecVersionsClientDeleteOptions contains the optional parameters for the TemplateSpecVersionsClient.Delete method. +type TemplateSpecVersionsClientDeleteOptions struct { + // placeholder for future optional parameters +} + +// TemplateSpecVersionsClientGetBuiltInOptions contains the optional parameters for the TemplateSpecVersionsClient.GetBuiltIn +// method. +type TemplateSpecVersionsClientGetBuiltInOptions struct { + // placeholder for future optional parameters +} + +// TemplateSpecVersionsClientGetOptions contains the optional parameters for the TemplateSpecVersionsClient.Get method. +type TemplateSpecVersionsClientGetOptions struct { + // placeholder for future optional parameters +} + +// TemplateSpecVersionsClientListBuiltInsOptions contains the optional parameters for the TemplateSpecVersionsClient.NewListBuiltInsPager +// method. +type TemplateSpecVersionsClientListBuiltInsOptions struct { + // placeholder for future optional parameters +} + +// TemplateSpecVersionsClientListOptions contains the optional parameters for the TemplateSpecVersionsClient.NewListPager +// method. +type TemplateSpecVersionsClientListOptions struct { + // placeholder for future optional parameters +} + +// TemplateSpecVersionsClientUpdateOptions contains the optional parameters for the TemplateSpecVersionsClient.Update method. +type TemplateSpecVersionsClientUpdateOptions struct { + // Template Spec Version resource with the tags to be updated. + TemplateSpecVersionUpdateModel *TemplateSpecVersionUpdateModel +} diff --git a/sdk/resourcemanager/resources/armtemplatespecs/response_types.go b/sdk/resourcemanager/resources/armtemplatespecs/response_types.go index cf6c742478dd..0fb15d444b12 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/response_types.go +++ b/sdk/resourcemanager/resources/armtemplatespecs/response_types.go @@ -3,14 +3,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armtemplatespecs // ClientCreateOrUpdateResponse contains the response from method Client.CreateOrUpdate. type ClientCreateOrUpdateResponse struct { + // Template Spec object. TemplateSpec } @@ -21,36 +21,43 @@ type ClientDeleteResponse struct { // ClientGetBuiltInResponse contains the response from method Client.GetBuiltIn. type ClientGetBuiltInResponse struct { + // Template Spec object. TemplateSpec } // ClientGetResponse contains the response from method Client.Get. type ClientGetResponse struct { + // Template Spec object. TemplateSpec } // ClientListBuiltInsResponse contains the response from method Client.NewListBuiltInsPager. type ClientListBuiltInsResponse struct { + // List of Template Specs. ListResult } // ClientListByResourceGroupResponse contains the response from method Client.NewListByResourceGroupPager. type ClientListByResourceGroupResponse struct { + // List of Template Specs. ListResult } // ClientListBySubscriptionResponse contains the response from method Client.NewListBySubscriptionPager. type ClientListBySubscriptionResponse struct { + // List of Template Specs. ListResult } // ClientUpdateResponse contains the response from method Client.Update. type ClientUpdateResponse struct { + // Template Spec object. TemplateSpec } // TemplateSpecVersionsClientCreateOrUpdateResponse contains the response from method TemplateSpecVersionsClient.CreateOrUpdate. type TemplateSpecVersionsClientCreateOrUpdateResponse struct { + // Template Spec Version object. TemplateSpecVersion } @@ -61,25 +68,30 @@ type TemplateSpecVersionsClientDeleteResponse struct { // TemplateSpecVersionsClientGetBuiltInResponse contains the response from method TemplateSpecVersionsClient.GetBuiltIn. type TemplateSpecVersionsClientGetBuiltInResponse struct { + // Template Spec Version object. TemplateSpecVersion } // TemplateSpecVersionsClientGetResponse contains the response from method TemplateSpecVersionsClient.Get. type TemplateSpecVersionsClientGetResponse struct { + // Template Spec Version object. TemplateSpecVersion } // TemplateSpecVersionsClientListBuiltInsResponse contains the response from method TemplateSpecVersionsClient.NewListBuiltInsPager. type TemplateSpecVersionsClientListBuiltInsResponse struct { + // List of Template Specs versions TemplateSpecVersionsListResult } // TemplateSpecVersionsClientListResponse contains the response from method TemplateSpecVersionsClient.NewListPager. type TemplateSpecVersionsClientListResponse struct { + // List of Template Specs versions TemplateSpecVersionsListResult } // TemplateSpecVersionsClientUpdateResponse contains the response from method TemplateSpecVersionsClient.Update. type TemplateSpecVersionsClientUpdateResponse struct { + // Template Spec Version object. TemplateSpecVersion } diff --git a/sdk/resourcemanager/resources/armtemplatespecs/templatespecs_client_live_test.go b/sdk/resourcemanager/resources/armtemplatespecs/templatespecs_client_live_test.go index d475f6226529..202395f9326a 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/templatespecs_client_live_test.go +++ b/sdk/resourcemanager/resources/armtemplatespecs/templatespecs_client_live_test.go @@ -14,7 +14,7 @@ import ( "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/to" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armtemplatespecs" "github.com/stretchr/testify/suite" ) diff --git a/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client.go b/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client.go index 8a7dc82ab5e8..f2ebb2e04ab9 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client.go +++ b/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armtemplatespecs @@ -33,7 +32,7 @@ type TemplateSpecVersionsClient struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewTemplateSpecVersionsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*TemplateSpecVersionsClient, error) { - cl, err := arm.NewClient(moduleName+".TemplateSpecVersionsClient", moduleVersion, credential, options) + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } @@ -55,18 +54,25 @@ func NewTemplateSpecVersionsClient(subscriptionID string, credential azcore.Toke // - options - TemplateSpecVersionsClientCreateOrUpdateOptions contains the optional parameters for the TemplateSpecVersionsClient.CreateOrUpdate // method. func (client *TemplateSpecVersionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string, templateSpecVersionModel TemplateSpecVersion, options *TemplateSpecVersionsClientCreateOrUpdateOptions) (TemplateSpecVersionsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "TemplateSpecVersionsClient.CreateOrUpdate" + 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, templateSpecName, templateSpecVersion, templateSpecVersionModel, options) if err != nil { return TemplateSpecVersionsClientCreateOrUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return TemplateSpecVersionsClientCreateOrUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { - return TemplateSpecVersionsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return TemplateSpecVersionsClientCreateOrUpdateResponse{}, err } - return client.createOrUpdateHandleResponse(resp) + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err } // createOrUpdateCreateRequest creates the CreateOrUpdate request. @@ -96,7 +102,10 @@ func (client *TemplateSpecVersionsClient) createOrUpdateCreateRequest(ctx contex reqQP.Set("api-version", "2022-02-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} - return req, runtime.MarshalAsJSON(req, templateSpecVersionModel) + if err := runtime.MarshalAsJSON(req, templateSpecVersionModel); err != nil { + return nil, err + } + return req, nil } // createOrUpdateHandleResponse handles the CreateOrUpdate response. @@ -118,16 +127,22 @@ func (client *TemplateSpecVersionsClient) createOrUpdateHandleResponse(resp *htt // - options - TemplateSpecVersionsClientDeleteOptions contains the optional parameters for the TemplateSpecVersionsClient.Delete // method. func (client *TemplateSpecVersionsClient) Delete(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string, options *TemplateSpecVersionsClientDeleteOptions) (TemplateSpecVersionsClientDeleteResponse, error) { + var err error + const operationName = "TemplateSpecVersionsClient.Delete" + 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, templateSpecName, templateSpecVersion, options) if err != nil { return TemplateSpecVersionsClientDeleteResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return TemplateSpecVersionsClientDeleteResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { - return TemplateSpecVersionsClientDeleteResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return TemplateSpecVersionsClientDeleteResponse{}, err } return TemplateSpecVersionsClientDeleteResponse{}, nil } @@ -172,18 +187,25 @@ func (client *TemplateSpecVersionsClient) deleteCreateRequest(ctx context.Contex // - options - TemplateSpecVersionsClientGetOptions contains the optional parameters for the TemplateSpecVersionsClient.Get // method. func (client *TemplateSpecVersionsClient) Get(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string, options *TemplateSpecVersionsClientGetOptions) (TemplateSpecVersionsClientGetResponse, error) { + var err error + const operationName = "TemplateSpecVersionsClient.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, templateSpecName, templateSpecVersion, options) if err != nil { return TemplateSpecVersionsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return TemplateSpecVersionsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return TemplateSpecVersionsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return TemplateSpecVersionsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -234,18 +256,25 @@ func (client *TemplateSpecVersionsClient) getHandleResponse(resp *http.Response) // - options - TemplateSpecVersionsClientGetBuiltInOptions contains the optional parameters for the TemplateSpecVersionsClient.GetBuiltIn // method. func (client *TemplateSpecVersionsClient) GetBuiltIn(ctx context.Context, templateSpecName string, templateSpecVersion string, options *TemplateSpecVersionsClientGetBuiltInOptions) (TemplateSpecVersionsClientGetBuiltInResponse, error) { + var err error + const operationName = "TemplateSpecVersionsClient.GetBuiltIn" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getBuiltInCreateRequest(ctx, templateSpecName, templateSpecVersion, options) if err != nil { return TemplateSpecVersionsClientGetBuiltInResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return TemplateSpecVersionsClientGetBuiltInResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return TemplateSpecVersionsClientGetBuiltInResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return TemplateSpecVersionsClientGetBuiltInResponse{}, err } - return client.getBuiltInHandleResponse(resp) + resp, err := client.getBuiltInHandleResponse(httpResp) + return resp, err } // getBuiltInCreateRequest creates the GetBuiltIn request. @@ -292,25 +321,20 @@ func (client *TemplateSpecVersionsClient) NewListPager(resourceGroupName string, return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *TemplateSpecVersionsClientListResponse) (TemplateSpecVersionsClientListResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listCreateRequest(ctx, resourceGroupName, templateSpecName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return TemplateSpecVersionsClientListResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "TemplateSpecVersionsClient.NewListPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listCreateRequest(ctx, resourceGroupName, templateSpecName, options) + }, nil) if err != nil { return TemplateSpecVersionsClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return TemplateSpecVersionsClientListResponse{}, runtime.NewResponseError(resp) - } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -361,25 +385,20 @@ func (client *TemplateSpecVersionsClient) NewListBuiltInsPager(templateSpecName return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *TemplateSpecVersionsClientListBuiltInsResponse) (TemplateSpecVersionsClientListBuiltInsResponse, error) { - var req *policy.Request - var err error - if page == nil { - req, err = client.listBuiltInsCreateRequest(ctx, templateSpecName, options) - } else { - req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) - } - if err != nil { - return TemplateSpecVersionsClientListBuiltInsResponse{}, err + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "TemplateSpecVersionsClient.NewListBuiltInsPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink } - resp, err := client.internal.Pipeline().Do(req) + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listBuiltInsCreateRequest(ctx, templateSpecName, options) + }, nil) if err != nil { return TemplateSpecVersionsClientListBuiltInsResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return TemplateSpecVersionsClientListBuiltInsResponse{}, runtime.NewResponseError(resp) - } return client.listBuiltInsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -420,18 +439,25 @@ func (client *TemplateSpecVersionsClient) listBuiltInsHandleResponse(resp *http. // - options - TemplateSpecVersionsClientUpdateOptions contains the optional parameters for the TemplateSpecVersionsClient.Update // method. func (client *TemplateSpecVersionsClient) Update(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string, options *TemplateSpecVersionsClientUpdateOptions) (TemplateSpecVersionsClientUpdateResponse, error) { + var err error + const operationName = "TemplateSpecVersionsClient.Update" + 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, templateSpecName, templateSpecVersion, options) if err != nil { return TemplateSpecVersionsClientUpdateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return TemplateSpecVersionsClientUpdateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return TemplateSpecVersionsClientUpdateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return TemplateSpecVersionsClientUpdateResponse{}, err } - return client.updateHandleResponse(resp) + resp, err := client.updateHandleResponse(httpResp) + return resp, err } // updateCreateRequest creates the Update request. @@ -462,7 +488,10 @@ func (client *TemplateSpecVersionsClient) updateCreateRequest(ctx context.Contex req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} if options != nil && options.TemplateSpecVersionUpdateModel != nil { - return req, runtime.MarshalAsJSON(req, *options.TemplateSpecVersionUpdateModel) + if err := runtime.MarshalAsJSON(req, *options.TemplateSpecVersionUpdateModel); err != nil { + return nil, err + } + return req, nil } return req, nil } diff --git a/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client_example_test.go b/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client_example_test.go index d210a05c0f70..8bc288acc81b 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client_example_test.go +++ b/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client_example_test.go @@ -52,10 +52,10 @@ func ExampleTemplateSpecVersionsClient_CreateOrUpdate() { // Type: to.Ptr("Microsoft.Resources/templateSpecs/versions"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/templateSpecRG/providers/Microsoft.Resources/templateSpecs/simpleTemplateSpec/versions/v1.0"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), // }, @@ -102,10 +102,10 @@ func ExampleTemplateSpecVersionsClient_Update() { // Type: to.Ptr("Microsoft.Resources/templateSpecs/versions"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/templateSpecRG/providers/Microsoft.Resources/templateSpecs/simpleTemplateSpec/versions/v1.0"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), // }, @@ -150,10 +150,10 @@ func ExampleTemplateSpecVersionsClient_Get() { // Type: to.Ptr("Microsoft.Resources/templateSpecs/versions"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/templateSpecRG/providers/Microsoft.Resources/templateSpecs/simpleTemplateSpec/versions/v1.0"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), // }, @@ -218,10 +218,10 @@ func ExampleTemplateSpecVersionsClient_NewListPager() { // Type: to.Ptr("Microsoft.Resources/templateSpecs/versions"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/templateSpecRG/providers/Microsoft.Resources/templateSpecs/simpleTemplateSpec/versions/v1.0"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-01T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-02T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), // }, @@ -235,10 +235,10 @@ func ExampleTemplateSpecVersionsClient_NewListPager() { // Type: to.Ptr("Microsoft.Resources/templateSpecs/versions"), // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/templateSpecRG/providers/Microsoft.Resources/templateSpecs/simpleTemplateSpec/versions/v2.0"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-03T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-03T01:01:01.107Z"); return t}()), // CreatedBy: to.Ptr("string"), // CreatedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-04T02:03:01.1974346Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-02-04T02:03:01.197Z"); return t}()), // LastModifiedBy: to.Ptr("string"), // LastModifiedByType: to.Ptr(armtemplatespecs.CreatedByTypeApplication), // }, @@ -280,8 +280,8 @@ func ExampleTemplateSpecVersionsClient_NewListBuiltInsPager() { // Type: to.Ptr("Microsoft.Resources/builtInTemplateSpecs/versions"), // ID: to.Ptr("/providers/Microsoft.Resources/builtInTemplateSpecs/nameOfTheBuiltIn/versions/v1.0"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-01T01:01:01.1075056Z"); return t}()), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-01T01:01:01.107Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-01T01:01:01.107Z"); return t}()), // }, // Location: to.Ptr("eastus"), // Properties: &armtemplatespecs.TemplateSpecVersionProperties{ @@ -293,8 +293,8 @@ func ExampleTemplateSpecVersionsClient_NewListBuiltInsPager() { // Type: to.Ptr("Microsoft.Resources/builtInTemplateSpecs/versions"), // ID: to.Ptr("/providers/Microsoft.Resources/builtInTemplateSpecs/nameOfTheBuiltIn/versions/v2.0"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-02T02:03:01.1974346Z"); return t}()), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-02T02:03:01.1974346Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-02T02:03:01.197Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-02T02:03:01.197Z"); return t}()), // }, // Location: to.Ptr("eastus"), // Properties: &armtemplatespecs.TemplateSpecVersionProperties{ @@ -328,8 +328,8 @@ func ExampleTemplateSpecVersionsClient_GetBuiltIn() { // Type: to.Ptr("Microsoft.Resources/builtInTemplateSpecs/versions"), // ID: to.Ptr("/providers/Microsoft.Resources/builtInTemplateSpecs/nameOfTheBuiltIn/versions/v1.0"), // SystemData: &armtemplatespecs.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-01T01:01:01.1075056Z"); return t}()), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-01T01:01:01.1075056Z"); return t}()), + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-01T01:01:01.107Z"); return t}()), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-02-01T01:01:01.107Z"); return t}()), // }, // Location: to.Ptr("eastus"), // Properties: &armtemplatespecs.TemplateSpecVersionProperties{ diff --git a/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client_live_test.go b/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client_live_test.go index 5fccae8ee69d..269168e2c219 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client_live_test.go +++ b/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client_live_test.go @@ -14,7 +14,7 @@ import ( "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/to" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armtemplatespecs" "github.com/stretchr/testify/suite" ) diff --git a/sdk/resourcemanager/resources/armtemplatespecs/time_rfc3339.go b/sdk/resourcemanager/resources/armtemplatespecs/time_rfc3339.go index 5412efd677f8..444174807531 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/time_rfc3339.go +++ b/sdk/resourcemanager/resources/armtemplatespecs/time_rfc3339.go @@ -3,9 +3,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. // Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. package armtemplatespecs @@ -19,50 +18,50 @@ import ( "time" ) -const ( - utcLayoutJSON = `"2006-01-02T15:04:05.999999999"` - utcLayout = "2006-01-02T15:04:05.999999999" - rfc3339JSON = `"` + time.RFC3339Nano + `"` -) - // 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+)*"*$`) -type timeRFC3339 time.Time +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +type dateTimeRFC3339 time.Time -func (t timeRFC3339) MarshalJSON() (json []byte, err error) { +func (t dateTimeRFC3339) MarshalJSON() ([]byte, error) { tt := time.Time(t) return tt.MarshalJSON() } -func (t timeRFC3339) MarshalText() (text []byte, err error) { +func (t dateTimeRFC3339) MarshalText() ([]byte, error) { tt := time.Time(t) return tt.MarshalText() } -func (t *timeRFC3339) UnmarshalJSON(data []byte) error { - layout := utcLayoutJSON +func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { + layout := utcDateTimeJSON if tzOffsetRegex.Match(data) { - layout = rfc3339JSON + layout = dateTimeJSON } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) UnmarshalText(data []byte) (err error) { - layout := utcLayout +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime if tzOffsetRegex.Match(data) { layout = time.RFC3339Nano } return t.Parse(layout, string(data)) } -func (t *timeRFC3339) Parse(layout, value string) error { +func (t *dateTimeRFC3339) Parse(layout, value string) error { p, err := time.Parse(layout, strings.ToUpper(value)) - *t = timeRFC3339(p) + *t = dateTimeRFC3339(p) return err } -func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { +func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { if t == nil { return } else if azcore.IsNullValue(t) { @@ -71,14 +70,14 @@ func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { } else if reflect.ValueOf(t).IsNil() { return } - m[k] = (*timeRFC3339)(t) + m[k] = (*dateTimeRFC3339)(t) } -func unpopulateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { +func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { if data == nil || strings.EqualFold(string(data), "null") { return nil } - var aux timeRFC3339 + var aux dateTimeRFC3339 if err := json.Unmarshal(data, &aux); err != nil { return fmt.Errorf("struct field %s: %v", fn, err) } From 19e6dc02cb5e73479c1adf218a806663085768d2 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 16:33:42 +0800 Subject: [PATCH 12/18] armresources --- .../armresources/deployments_client_live_test.go | 8 +++++--- .../resources/armresources/fake_example_test.go | 2 +- sdk/resourcemanager/resources/armresources/go.mod | 2 +- .../armresources/resourcegroups_client_live_test.go | 8 +++++--- .../resources/armresources/resources_client_live_test.go | 5 +++-- .../resources/armresources/tags_client_live_test.go | 5 +++-- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/sdk/resourcemanager/resources/armresources/deployments_client_live_test.go b/sdk/resourcemanager/resources/armresources/deployments_client_live_test.go index 743f8170fa78..576784c22965 100644 --- a/sdk/resourcemanager/resources/armresources/deployments_client_live_test.go +++ b/sdk/resourcemanager/resources/armresources/deployments_client_live_test.go @@ -10,14 +10,16 @@ import ( "context" "encoding/json" "fmt" + "testing" + "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/to" + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "github.com/stretchr/testify/suite" - "testing" ) type DeploymentsClientTestSuite struct { @@ -34,8 +36,8 @@ type DeploymentsClientTestSuite struct { func (testsuite *DeploymentsClientTestSuite) SetupSuite() { testsuite.ctx = context.Background() testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) - testsuite.location = testutil.GetEnv("LOCATION", "eastus") - testsuite.subscriptionID = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") + testsuite.subscriptionID = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/resources/armresources/testdata") resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.location) testsuite.Require().NoError(err) diff --git a/sdk/resourcemanager/resources/armresources/fake_example_test.go b/sdk/resourcemanager/resources/armresources/fake_example_test.go index 9c4d23e95339..61a42bd6499b 100644 --- a/sdk/resourcemanager/resources/armresources/fake_example_test.go +++ b/sdk/resourcemanager/resources/armresources/fake_example_test.go @@ -45,7 +45,7 @@ func ExampleServer() { } // now create the corresponding client, connecting the fake server via the client options - client, err := armresources.NewClient("subscriptionID", azfake.NewTokenCredential(), &arm.ClientOptions{ + client, err := armresources.NewClient("subscriptionID", &azfake.TokenCredential{}, &arm.ClientOptions{ ClientOptions: azcore.ClientOptions{ Transport: fake.NewServerTransport(&fakeServer), }, diff --git a/sdk/resourcemanager/resources/armresources/go.mod b/sdk/resourcemanager/resources/armresources/go.mod index d7b78d9a2d49..bef76d927938 100644 --- a/sdk/resourcemanager/resources/armresources/go.mod +++ b/sdk/resourcemanager/resources/armresources/go.mod @@ -5,13 +5,13 @@ go 1.18 require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 github.com/stretchr/testify v1.8.4 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dnaeon/go-vcr v1.2.0 // indirect diff --git a/sdk/resourcemanager/resources/armresources/resourcegroups_client_live_test.go b/sdk/resourcemanager/resources/armresources/resourcegroups_client_live_test.go index 5fdf6e22ddb7..8ca83b8660fd 100644 --- a/sdk/resourcemanager/resources/armresources/resourcegroups_client_live_test.go +++ b/sdk/resourcemanager/resources/armresources/resourcegroups_client_live_test.go @@ -9,13 +9,15 @@ package armresources_test import ( "context" "fmt" + "testing" + "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/to" + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "github.com/stretchr/testify/suite" - "testing" ) type ResourceGroupsClientTestSuite struct { @@ -32,8 +34,8 @@ type ResourceGroupsClientTestSuite struct { func (testsuite *ResourceGroupsClientTestSuite) SetupSuite() { testsuite.ctx = context.Background() testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) - testsuite.location = testutil.GetEnv("LOCATION", "eastus") - testsuite.subscriptionID = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") + testsuite.subscriptionID = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/resources/armresources/testdata") resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.location) testsuite.Require().NoError(err) diff --git a/sdk/resourcemanager/resources/armresources/resources_client_live_test.go b/sdk/resourcemanager/resources/armresources/resources_client_live_test.go index 0d4e5329b022..2543b4e39cdb 100644 --- a/sdk/resourcemanager/resources/armresources/resources_client_live_test.go +++ b/sdk/resourcemanager/resources/armresources/resources_client_live_test.go @@ -15,6 +15,7 @@ import ( "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/to" + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "github.com/stretchr/testify/suite" @@ -34,8 +35,8 @@ type ResourcesClientTestSuite struct { func (testsuite *ResourcesClientTestSuite) SetupSuite() { testsuite.ctx = context.Background() testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) - testsuite.location = testutil.GetEnv("LOCATION", "eastus") - testsuite.subscriptionID = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") + testsuite.subscriptionID = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/resources/armresources/testdata") resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.location) testsuite.Require().NoError(err) diff --git a/sdk/resourcemanager/resources/armresources/tags_client_live_test.go b/sdk/resourcemanager/resources/armresources/tags_client_live_test.go index 4ffc8ed8d47d..c6ead6806b6b 100644 --- a/sdk/resourcemanager/resources/armresources/tags_client_live_test.go +++ b/sdk/resourcemanager/resources/armresources/tags_client_live_test.go @@ -14,6 +14,7 @@ import ( "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/to" + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "github.com/stretchr/testify/suite" @@ -33,8 +34,8 @@ type TagsClientTestSuite struct { func (testsuite *TagsClientTestSuite) SetupSuite() { testsuite.ctx = context.Background() testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) - testsuite.location = testutil.GetEnv("LOCATION", "eastus") - testsuite.subscriptionID = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") + testsuite.subscriptionID = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/resources/armresources/testdata") resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.location) testsuite.Require().NoError(err) From 77b097ffa8da00ee0a7448a47e1de6ec3533228e Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 16:35:55 +0800 Subject: [PATCH 13/18] armpolicy --- sdk/resourcemanager/resources/armpolicy/go.mod | 2 +- .../armpolicy/policydefinitions_client_live_test.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sdk/resourcemanager/resources/armpolicy/go.mod b/sdk/resourcemanager/resources/armpolicy/go.mod index c94089008a8b..5a5ac3b55c91 100644 --- a/sdk/resourcemanager/resources/armpolicy/go.mod +++ b/sdk/resourcemanager/resources/armpolicy/go.mod @@ -5,12 +5,12 @@ go 1.18 require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 github.com/stretchr/testify v1.8.4 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/sdk/resourcemanager/resources/armpolicy/policydefinitions_client_live_test.go b/sdk/resourcemanager/resources/armpolicy/policydefinitions_client_live_test.go index 3f2a02070b41..a097ad35148c 100644 --- a/sdk/resourcemanager/resources/armpolicy/policydefinitions_client_live_test.go +++ b/sdk/resourcemanager/resources/armpolicy/policydefinitions_client_live_test.go @@ -14,6 +14,7 @@ import ( "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/to" + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy" "github.com/stretchr/testify/suite" @@ -33,8 +34,8 @@ type PolicyDefinitionsClientTestSuite struct { func (testsuite *PolicyDefinitionsClientTestSuite) SetupSuite() { testsuite.ctx = context.Background() testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) - testsuite.location = testutil.GetEnv("LOCATION", "eastus") - testsuite.subscriptionID = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") + testsuite.subscriptionID = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/resources/armpolicy/testdata") resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.location) testsuite.Require().NoError(err) From 23d12a8f243513224a92f93f8ea2a9fff5866cb9 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 16:37:12 +0800 Subject: [PATCH 14/18] armsubscriptions --- .../resources/armsubscriptions/fake_example_test.go | 2 +- sdk/resourcemanager/resources/armsubscriptions/go.mod | 2 +- .../armsubscriptions/subscriptions_client_live_test.go | 5 +++-- .../resources/armsubscriptions/tenants_client_live_test.go | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sdk/resourcemanager/resources/armsubscriptions/fake_example_test.go b/sdk/resourcemanager/resources/armsubscriptions/fake_example_test.go index a57b9b42522d..0e2a9e2e0d0e 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/fake_example_test.go +++ b/sdk/resourcemanager/resources/armsubscriptions/fake_example_test.go @@ -50,7 +50,7 @@ func ExampleServer() { } // now create the corresponding client, connecting the fake server via the client options - client, err := armsubscriptions.NewClient(azfake.NewTokenCredential(), &arm.ClientOptions{ + client, err := armsubscriptions.NewClient(&azfake.TokenCredential{}, &arm.ClientOptions{ ClientOptions: azcore.ClientOptions{ Transport: fake.NewServerTransport(&fakeServer), }, diff --git a/sdk/resourcemanager/resources/armsubscriptions/go.mod b/sdk/resourcemanager/resources/armsubscriptions/go.mod index e114f13047c2..1c0a792db4e4 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/go.mod +++ b/sdk/resourcemanager/resources/armsubscriptions/go.mod @@ -5,12 +5,12 @@ go 1.18 require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 github.com/stretchr/testify v1.8.4 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/sdk/resourcemanager/resources/armsubscriptions/subscriptions_client_live_test.go b/sdk/resourcemanager/resources/armsubscriptions/subscriptions_client_live_test.go index 908b17b0d9d5..fa94dc74a2f2 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/subscriptions_client_live_test.go +++ b/sdk/resourcemanager/resources/armsubscriptions/subscriptions_client_live_test.go @@ -14,6 +14,7 @@ import ( "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/to" + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions" "github.com/stretchr/testify/suite" @@ -33,8 +34,8 @@ type SubscriptionsClientTestSuite struct { func (testsuite *SubscriptionsClientTestSuite) SetupSuite() { testsuite.ctx = context.Background() testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) - testsuite.location = testutil.GetEnv("LOCATION", "eastus") - testsuite.subscriptionID = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") + testsuite.subscriptionID = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/resources/armsubscriptions/testdata") resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.location) testsuite.Require().NoError(err) diff --git a/sdk/resourcemanager/resources/armsubscriptions/tenants_client_live_test.go b/sdk/resourcemanager/resources/armsubscriptions/tenants_client_live_test.go index 083193c61d14..d43579e8af8f 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/tenants_client_live_test.go +++ b/sdk/resourcemanager/resources/armsubscriptions/tenants_client_live_test.go @@ -13,6 +13,7 @@ import ( "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/internal/recording" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions" "github.com/stretchr/testify/suite" @@ -32,8 +33,8 @@ type TenantsClientTestSuite struct { func (testsuite *TenantsClientTestSuite) SetupSuite() { testsuite.ctx = context.Background() testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) - testsuite.location = testutil.GetEnv("LOCATION", "eastus") - testsuite.subscriptionID = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") + testsuite.subscriptionID = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/resources/armsubscriptions/testdata") resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.location) testsuite.Require().NoError(err) From 1c347412a3a1d79a611879ab0cefcfe39ad3c677 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 16:38:32 +0800 Subject: [PATCH 15/18] armdeploymentscripts --- .../deploymentscripts_client_live_test.go | 5 +++-- sdk/resourcemanager/resources/armdeploymentscripts/go.mod | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/deploymentscripts_client_live_test.go b/sdk/resourcemanager/resources/armdeploymentscripts/deploymentscripts_client_live_test.go index cdfde4815ccc..f04e84efd686 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/deploymentscripts_client_live_test.go +++ b/sdk/resourcemanager/resources/armdeploymentscripts/deploymentscripts_client_live_test.go @@ -14,6 +14,7 @@ import ( "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/to" + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploymentscripts" @@ -34,8 +35,8 @@ type DeploymentScriptsClientTestSuite struct { func (testsuite *DeploymentScriptsClientTestSuite) SetupSuite() { testsuite.ctx = context.Background() testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) - testsuite.location = testutil.GetEnv("LOCATION", "eastus") - testsuite.subscriptionID = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") + testsuite.subscriptionID = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/resources/armdeploymentscripts/testdata") resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.location) testsuite.Require().NoError(err) diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/go.mod b/sdk/resourcemanager/resources/armdeploymentscripts/go.mod index bfe38a30a1a8..43784b0ce5ad 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/go.mod +++ b/sdk/resourcemanager/resources/armdeploymentscripts/go.mod @@ -5,6 +5,7 @@ go 1.18 require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v0.6.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploymentscripts v1.0.0 @@ -12,7 +13,6 @@ require ( ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect From 6f27ea3cf6f1759b342a1de8b4bfea3cc97a2548 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 16:39:21 +0800 Subject: [PATCH 16/18] armfeatures --- .../resources/armfeatures/features_client_live_test.go | 5 +++-- sdk/resourcemanager/resources/armfeatures/go.mod | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sdk/resourcemanager/resources/armfeatures/features_client_live_test.go b/sdk/resourcemanager/resources/armfeatures/features_client_live_test.go index 9a3dd68935c2..aa1d62ebbee4 100644 --- a/sdk/resourcemanager/resources/armfeatures/features_client_live_test.go +++ b/sdk/resourcemanager/resources/armfeatures/features_client_live_test.go @@ -13,6 +13,7 @@ import ( "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/internal/recording" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures" "github.com/stretchr/testify/suite" @@ -32,8 +33,8 @@ type FeaturesClientTestSuite struct { func (testsuite *FeaturesClientTestSuite) SetupSuite() { testsuite.ctx = context.Background() testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) - testsuite.location = testutil.GetEnv("LOCATION", "eastus") - testsuite.subscriptionID = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") + testsuite.subscriptionID = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/resources/armfeatures/testdata") resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.location) testsuite.Require().NoError(err) diff --git a/sdk/resourcemanager/resources/armfeatures/go.mod b/sdk/resourcemanager/resources/armfeatures/go.mod index 64441d55b66f..39e39d8ed169 100644 --- a/sdk/resourcemanager/resources/armfeatures/go.mod +++ b/sdk/resourcemanager/resources/armfeatures/go.mod @@ -5,12 +5,12 @@ go 1.18 require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 github.com/stretchr/testify v1.8.4 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect From a4f85fed9632cfee6f2506293ecb30ab3b425334 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 16:40:03 +0800 Subject: [PATCH 17/18] armtemplatespecs --- sdk/resourcemanager/resources/armtemplatespecs/go.mod | 2 +- .../armtemplatespecs/templatespecs_client_live_test.go | 5 +++-- .../templatespecversions_client_live_test.go | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sdk/resourcemanager/resources/armtemplatespecs/go.mod b/sdk/resourcemanager/resources/armtemplatespecs/go.mod index e18f1c4e605a..5f817c0fa2ec 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/go.mod +++ b/sdk/resourcemanager/resources/armtemplatespecs/go.mod @@ -5,12 +5,12 @@ go 1.18 require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 github.com/stretchr/testify v1.8.4 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/sdk/resourcemanager/resources/armtemplatespecs/templatespecs_client_live_test.go b/sdk/resourcemanager/resources/armtemplatespecs/templatespecs_client_live_test.go index 202395f9326a..4e77ea7a9cb3 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/templatespecs_client_live_test.go +++ b/sdk/resourcemanager/resources/armtemplatespecs/templatespecs_client_live_test.go @@ -14,6 +14,7 @@ import ( "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/to" + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armtemplatespecs" "github.com/stretchr/testify/suite" @@ -33,8 +34,8 @@ type TemplateSpecsClientTestSuite struct { func (testsuite *TemplateSpecsClientTestSuite) SetupSuite() { testsuite.ctx = context.Background() testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) - testsuite.location = testutil.GetEnv("LOCATION", "eastus") - testsuite.subscriptionID = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") + testsuite.subscriptionID = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/resources/armtemplatespecs/testdata") resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.location) testsuite.Require().NoError(err) diff --git a/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client_live_test.go b/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client_live_test.go index 269168e2c219..2bba65869a86 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client_live_test.go +++ b/sdk/resourcemanager/resources/armtemplatespecs/templatespecversions_client_live_test.go @@ -14,6 +14,7 @@ import ( "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/to" + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armtemplatespecs" "github.com/stretchr/testify/suite" @@ -33,8 +34,8 @@ type TemplateSpecVersionsClientTestSuite struct { func (testsuite *TemplateSpecVersionsClientTestSuite) SetupSuite() { testsuite.ctx = context.Background() testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) - testsuite.location = testutil.GetEnv("LOCATION", "eastus") - testsuite.subscriptionID = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") + testsuite.subscriptionID = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/resources/armtemplatespecs/testdata") resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.location) testsuite.Require().NoError(err) From 41a61d6f13be29cc8bedf6f65e8ef21b44394343 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 20 Nov 2023 17:19:20 +0800 Subject: [PATCH 18/18] assets --- sdk/resourcemanager/resources/armdeploymentscripts/assets.json | 2 +- sdk/resourcemanager/resources/armpolicy/assets.json | 2 +- sdk/resourcemanager/resources/armsubscriptions/assets.json | 2 +- sdk/resourcemanager/resources/armtemplatespecs/assets.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/resourcemanager/resources/armdeploymentscripts/assets.json b/sdk/resourcemanager/resources/armdeploymentscripts/assets.json index b6bf2dd74de2..0025276a09ce 100644 --- a/sdk/resourcemanager/resources/armdeploymentscripts/assets.json +++ b/sdk/resourcemanager/resources/armdeploymentscripts/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "go", "TagPrefix": "go/resourcemanager/resources/armdeploymentscripts", - "Tag": "go/resourcemanager/resources/armdeploymentscripts_778ff7f2a7" + "Tag": "go/resourcemanager/resources/armdeploymentscripts_aa387434cd" } diff --git a/sdk/resourcemanager/resources/armpolicy/assets.json b/sdk/resourcemanager/resources/armpolicy/assets.json index 82e03452e75e..296ec8353934 100644 --- a/sdk/resourcemanager/resources/armpolicy/assets.json +++ b/sdk/resourcemanager/resources/armpolicy/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "go", "TagPrefix": "go/resourcemanager/resources/armpolicy", - "Tag": "go/resourcemanager/resources/armpolicy_004957227c" + "Tag": "go/resourcemanager/resources/armpolicy_66f769ab98" } diff --git a/sdk/resourcemanager/resources/armsubscriptions/assets.json b/sdk/resourcemanager/resources/armsubscriptions/assets.json index 877580c36d3e..2cec2d9e366a 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/assets.json +++ b/sdk/resourcemanager/resources/armsubscriptions/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "go", "TagPrefix": "go/resourcemanager/resources/armsubscriptions", - "Tag": "go/resourcemanager/resources/armsubscriptions_2026935d28" + "Tag": "go/resourcemanager/resources/armsubscriptions_bda5929f0e" } diff --git a/sdk/resourcemanager/resources/armtemplatespecs/assets.json b/sdk/resourcemanager/resources/armtemplatespecs/assets.json index 4f920e29c5e0..bf00b07418c6 100644 --- a/sdk/resourcemanager/resources/armtemplatespecs/assets.json +++ b/sdk/resourcemanager/resources/armtemplatespecs/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "go", "TagPrefix": "go/resourcemanager/resources/armtemplatespecs", - "Tag": "go/resourcemanager/resources/armtemplatespecs_6c04adcf5f" + "Tag": "go/resourcemanager/resources/armtemplatespecs_9ab1992c31" }