diff --git a/sdk/resourcemanager/resourcegraph/armresourcegraph/CHANGELOG.md b/sdk/resourcemanager/resourcegraph/armresourcegraph/CHANGELOG.md index a27deb574086..85ae2179d301 100644 --- a/sdk/resourcemanager/resourcegraph/armresourcegraph/CHANGELOG.md +++ b/sdk/resourcemanager/resourcegraph/armresourcegraph/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 0.8.1 (2023-07-19) + +### Bug Fixes + +- Fixed a potential panic in faked paged and long-running operations. + ## 0.8.0 (2023-06-13) ### Features Added diff --git a/sdk/resourcemanager/resourcegraph/armresourcegraph/autorest.md b/sdk/resourcemanager/resourcegraph/armresourcegraph/autorest.md index e887d72974fc..27b04f8fb7ae 100644 --- a/sdk/resourcemanager/resourcegraph/armresourcegraph/autorest.md +++ b/sdk/resourcemanager/resourcegraph/armresourcegraph/autorest.md @@ -9,8 +9,8 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resourcegraph/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION module: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph -module-version: 0.8.0 -azcore-version: 1.7.0-beta.2 +module-version: 0.8.1 +azcore-version: 1.8.0-beta.1 generate-fakes: true inject-spans: true ``` diff --git a/sdk/resourcemanager/resourcegraph/armresourcegraph/build.go b/sdk/resourcemanager/resourcegraph/armresourcegraph/build.go index 60a8b924c059..810aa2d6b7b7 100644 --- a/sdk/resourcemanager/resourcegraph/armresourcegraph/build.go +++ b/sdk/resourcemanager/resourcegraph/armresourcegraph/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.51" -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/resourcegraph/armresourcegraph +//go:generate pwsh ../../../../eng/scripts/build.ps1 -goExtension "@autorest/go@4.0.0-preview.53" -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/resourcegraph/armresourcegraph package armresourcegraph diff --git a/sdk/resourcemanager/resourcegraph/armresourcegraph/constants.go b/sdk/resourcemanager/resourcegraph/armresourcegraph/constants.go index d56b6438ebd8..01c7d228c228 100644 --- a/sdk/resourcemanager/resourcegraph/armresourcegraph/constants.go +++ b/sdk/resourcemanager/resourcegraph/armresourcegraph/constants.go @@ -10,7 +10,7 @@ package armresourcegraph const ( moduleName = "armresourcegraph" - moduleVersion = "v0.8.0" + moduleVersion = "v0.8.1" ) // AuthorizationScopeFilter - Defines what level of authorization resources should be returned based on the which subscriptions diff --git a/sdk/resourcemanager/resourcegraph/armresourcegraph/fake/internal.go b/sdk/resourcemanager/resourcegraph/armresourcegraph/fake/internal.go index e9c8222f2199..03b635903572 100644 --- a/sdk/resourcemanager/resourcegraph/armresourcegraph/fake/internal.go +++ b/sdk/resourcemanager/resourcegraph/armresourcegraph/fake/internal.go @@ -12,6 +12,9 @@ import ( "io" "net/http" "reflect" + "regexp" + "strings" + "sync" ) type nonRetriableError struct { @@ -76,3 +79,45 @@ func contains[T comparable](s []T, v T) bool { } 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]) 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 { + return item + } + return nil +} + +func (p *tracker[T]) add(req *http.Request, item *T) { + p.mu.Lock() + defer p.mu.Unlock() + p.items[p.key(req)] = item +} + +func (p *tracker[T]) remove(req *http.Request) { + p.mu.Lock() + defer p.mu.Unlock() + delete(p.items, p.key(req)) +} diff --git a/sdk/resourcemanager/resourcegraph/armresourcegraph/fake/operations_server.go b/sdk/resourcemanager/resourcegraph/armresourcegraph/fake/operations_server.go index 0cd2315cd0de..d9196b184358 100644 --- a/sdk/resourcemanager/resourcegraph/armresourcegraph/fake/operations_server.go +++ b/sdk/resourcemanager/resourcegraph/armresourcegraph/fake/operations_server.go @@ -26,17 +26,20 @@ type OperationsServer struct { } // NewOperationsServerTransport creates a new instance of OperationsServerTransport with the provided implementation. -// The returned OperationsServerTransport instance is connected to an instance of armresourcegraph.OperationsClient by way of the -// undefined.Transporter field. +// The returned OperationsServerTransport instance is connected to an instance of armresourcegraph.OperationsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. func NewOperationsServerTransport(srv *OperationsServer) *OperationsServerTransport { - return &OperationsServerTransport{srv: srv} + return &OperationsServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[armresourcegraph.OperationsClientListResponse]](), + } } // OperationsServerTransport connects instances of armresourcegraph.OperationsClient to instances of OperationsServer. // Don't use this type directly, use NewOperationsServerTransport instead. type OperationsServerTransport struct { srv *OperationsServer - newListPager *azfake.PagerResponder[armresourcegraph.OperationsClientListResponse] + newListPager *tracker[azfake.PagerResponder[armresourcegraph.OperationsClientListResponse]] } // Do implements the policy.Transporter interface for OperationsServerTransport. @@ -68,19 +71,22 @@ func (o *OperationsServerTransport) dispatchNewListPager(req *http.Request) (*ht if o.srv.NewListPager == nil { return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} } - if o.newListPager == nil { + newListPager := o.newListPager.get(req) + if newListPager == nil { resp := o.srv.NewListPager(nil) - o.newListPager = &resp + newListPager = &resp + o.newListPager.add(req, newListPager) } - resp, err := server.PagerResponderNext(o.newListPager, req) + 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(o.newListPager) { - o.newListPager = nil + if !server.PagerResponderMore(newListPager) { + o.newListPager.remove(req) } return resp, nil } diff --git a/sdk/resourcemanager/resourcegraph/armresourcegraph/fake/server.go b/sdk/resourcemanager/resourcegraph/armresourcegraph/fake/server.go index efaf008dc84c..9c3d9b6ec297 100644 --- a/sdk/resourcemanager/resourcegraph/armresourcegraph/fake/server.go +++ b/sdk/resourcemanager/resourcegraph/armresourcegraph/fake/server.go @@ -31,8 +31,8 @@ type Server struct { } // NewServerTransport creates a new instance of ServerTransport with the provided implementation. -// The returned ServerTransport instance is connected to an instance of armresourcegraph.Client by way of the -// undefined.Transporter field. +// The returned ServerTransport instance is connected to an instance of armresourcegraph.Client via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. func NewServerTransport(srv *Server) *ServerTransport { return &ServerTransport{srv: srv} } diff --git a/sdk/resourcemanager/resourcegraph/armresourcegraph/go.mod b/sdk/resourcemanager/resourcegraph/armresourcegraph/go.mod index 227155ebbf1a..fdb93d15018b 100644 --- a/sdk/resourcemanager/resourcegraph/armresourcegraph/go.mod +++ b/sdk/resourcemanager/resourcegraph/armresourcegraph/go.mod @@ -3,7 +3,7 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armre go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0-beta.2 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.8.0-beta.1 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 ) diff --git a/sdk/resourcemanager/resourcegraph/armresourcegraph/go.sum b/sdk/resourcemanager/resourcegraph/armresourcegraph/go.sum index b9280dc6acaf..3cb20742c931 100644 --- a/sdk/resourcemanager/resourcegraph/armresourcegraph/go.sum +++ b/sdk/resourcemanager/resourcegraph/armresourcegraph/go.sum @@ -1,5 +1,5 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0-beta.2 h1:C3zKsGguxcLd8a2uEytB8+TFtBGd75bXRxEs0QBwsv0= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0-beta.2/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.8.0-beta.1 h1:8t6ZZtkOCl+rx7uBn40Nj62ABVGkXK69U/En44wJIlE= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.8.0-beta.1/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= 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.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY= diff --git a/sdk/resourcemanager/resourcegraph/armresourcegraph/interfaces.go b/sdk/resourcemanager/resourcegraph/armresourcegraph/interfaces.go new file mode 100644 index 000000000000..25a4607f5e9a --- /dev/null +++ b/sdk/resourcemanager/resourcegraph/armresourcegraph/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 armresourcegraph + +// FacetClassification provides polymorphic access to related types. +// Call the interface's GetFacet() method to access the common type. +// Use a type switch to determine the concrete type. The possible types are: +// - *Facet, *FacetError, *FacetResult +type FacetClassification interface { + // GetFacet returns the Facet content of the underlying type. + GetFacet() *Facet +} diff --git a/sdk/resourcemanager/resourcegraph/armresourcegraph/models.go b/sdk/resourcemanager/resourcegraph/armresourcegraph/models.go index 8f7c54392e70..d7a29d9ac329 100644 --- a/sdk/resourcemanager/resourcegraph/armresourcegraph/models.go +++ b/sdk/resourcemanager/resourcegraph/armresourcegraph/models.go @@ -10,16 +10,6 @@ package armresourcegraph import "time" -// ClientResourcesHistoryOptions contains the optional parameters for the Client.ResourcesHistory method. -type ClientResourcesHistoryOptions struct { - // placeholder for future optional parameters -} - -// ClientResourcesOptions contains the optional parameters for the Client.Resources method. -type ClientResourcesOptions struct { - // placeholder for future optional parameters -} - // Column - Query result column descriptor. type Column struct { // REQUIRED; Column name. @@ -71,15 +61,6 @@ type ErrorResponse struct { Error *Error } -// FacetClassification provides polymorphic access to related types. -// Call the interface's GetFacet() method to access the common type. -// Use a type switch to determine the concrete type. The possible types are: -// - *Facet, *FacetError, *FacetResult -type FacetClassification interface { - // GetFacet returns the Facet content of the underlying type. - GetFacet() *Facet -} - // Facet - A facet containing additional statistics on the response of a query. Can be either FacetResult or FacetError. type Facet struct { // REQUIRED; Facet expression, same as in the corresponding facet request. @@ -197,11 +178,6 @@ type OperationListResult struct { Value []*Operation } -// OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. -type OperationsClientListOptions struct { - // placeholder for future optional parameters -} - // QueryRequest - Describes a query to be executed. type QueryRequest struct { // REQUIRED; The resources query. diff --git a/sdk/resourcemanager/resourcegraph/armresourcegraph/options.go b/sdk/resourcemanager/resourcegraph/armresourcegraph/options.go new file mode 100644 index 000000000000..43016398f4d0 --- /dev/null +++ b/sdk/resourcemanager/resourcegraph/armresourcegraph/options.go @@ -0,0 +1,24 @@ +//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 armresourcegraph + +// ClientResourcesHistoryOptions contains the optional parameters for the Client.ResourcesHistory method. +type ClientResourcesHistoryOptions struct { + // placeholder for future optional parameters +} + +// ClientResourcesOptions contains the optional parameters for the Client.Resources method. +type ClientResourcesOptions struct { + // placeholder for future optional parameters +} + +// OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. +type OperationsClientListOptions struct { + // placeholder for future optional parameters +} diff --git a/sdk/resourcemanager/resourcegraph/armresourcegraph/response_types.go b/sdk/resourcemanager/resourcegraph/armresourcegraph/response_types.go index 389220289d60..ce6fde39784e 100644 --- a/sdk/resourcemanager/resourcegraph/armresourcegraph/response_types.go +++ b/sdk/resourcemanager/resourcegraph/armresourcegraph/response_types.go @@ -16,10 +16,13 @@ type ClientResourcesHistoryResponse struct { // ClientResourcesResponse contains the response from method Client.Resources. type ClientResourcesResponse struct { + // Query result. QueryResponse } // OperationsClientListResponse contains the response from method OperationsClient.NewListPager. type OperationsClientListResponse struct { + // Result of the request to list Resource Graph operations. It contains a list of operations and a URL link to get the next + // set of results. OperationListResult }