diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/CHANGELOG.md b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/CHANGELOG.md index fc83cb3abcb1..68e79b3c61b1 100644 --- a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/CHANGELOG.md +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 1.2.0-beta.1 (2023-06-13) + +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + ## 1.1.0 (2023-03-31) ### Features Added @@ -12,4 +18,4 @@ The package of `github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/marketplac To migrate the existing applications to the latest version, please refer to [Migration Guide](https://aka.ms/azsdk/go/mgmt/migration). -To learn more, please refer to our documentation [Quick Start](https://aka.ms/azsdk/go/mgmt). \ No newline at end of file +To learn more, please refer to our documentation [Quick Start](https://aka.ms/azsdk/go/mgmt). diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/README.md b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/README.md index a97eb2615b92..0b9300d0b188 100644 --- a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/README.md +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/README.md @@ -60,6 +60,31 @@ A client groups a set of related APIs, providing access to its functionality. C client := clientFactory.NewMarketplaceAgreementsClient() ``` +## 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 +myFakeMarketplaceAgreementsServer := fake.MarketplaceAgreementsServer{} +``` +Next, provide func implementations for the methods you wish to fake. +The named return variables can be used to simplify return value construction. +```go +myFakeMarketplaceAgreementsServer.Get = func(ctx context.Context, offerType armmarketplaceordering.OfferType, publisherID string, offerID string, planID string, options *armmarketplaceordering.MarketplaceAgreementsClientGetOptions) (resp azfake.Responder[armmarketplaceordering.MarketplaceAgreementsClientGetResponse], errResp azfake.ErrorResponder) { + // TODO: resp.SetResponse(/* your fake MarketplaceAgreementsClientGetResponse 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 := armmarketplaceordering.NewMarketplaceAgreementsClient("subscriptionID", azfake.NewTokenCredential(), &arm.ClientOptions{ + ClientOptions: azcore.ClientOptions{ + Transport: fake.NewMarketplaceAgreementsServerTransport(&myFakeMarketplaceAgreementsServer), + }, +}) +``` + ## Provide Feedback If you encounter bugs or have suggestions, please @@ -82,4 +107,4 @@ This project has adopted the For more information, see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any -additional questions or comments. \ No newline at end of file +additional questions or comments. diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/autorest.md b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/autorest.md index 8e72c2721dd6..86c5acafb92d 100644 --- a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/autorest.md +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/autorest.md @@ -8,6 +8,9 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/marketplaceordering/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/marketplaceordering/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 1.1.0 - -``` \ No newline at end of file +module: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/marketplaceordering/armmarketplaceordering +module-version: 1.2.0-beta.1 +azcore-version: 1.7.0-beta.2 +generate-fakes: true +inject-spans: true +``` diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/build.go b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/build.go index 1c369f959776..8aaa8e4638e6 100644 --- a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/build.go +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/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 -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/marketplaceordering/armmarketplaceordering +//go:generate pwsh ../../../../eng/scripts/build.ps1 -goExtension "@autorest/go@4.0.0-preview.51" -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/marketplaceordering/armmarketplaceordering package armmarketplaceordering diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/client_factory.go b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/client_factory.go index e8aaa1ac1b69..d3037f304e63 100644 --- a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/client_factory.go +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/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 armmarketplaceordering diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/constants.go b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/constants.go index dc31f3bdd084..6714dc25c89c 100644 --- a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/constants.go +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/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 armmarketplaceordering const ( moduleName = "armmarketplaceordering" - moduleVersion = "v1.1.0" + moduleVersion = "v1.2.0-beta.1" ) // CreatedByType - The type of identity that created the resource. diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/fake/internal.go b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/fake/internal.go new file mode 100644 index 000000000000..e9c8222f2199 --- /dev/null +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/fake/internal.go @@ -0,0 +1,78 @@ +//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 ( + "io" + "net/http" + "reflect" +) + +type nonRetriableError struct { + error +} + +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 "" + } + return v[0] +} + +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 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 +} diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/fake/marketplaceagreements_server.go b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/fake/marketplaceagreements_server.go new file mode 100644 index 000000000000..002ab8e33055 --- /dev/null +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/fake/marketplaceagreements_server.go @@ -0,0 +1,319 @@ +//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/resourcemanager/marketplaceordering/armmarketplaceordering" + "net/http" + "net/url" + "regexp" +) + +// MarketplaceAgreementsServer is a fake server for instances of the armmarketplaceordering.MarketplaceAgreementsClient type. +type MarketplaceAgreementsServer struct { + // Cancel is the fake for method MarketplaceAgreementsClient.Cancel + // HTTP status codes to indicate success: http.StatusOK + Cancel func(ctx context.Context, publisherID string, offerID string, planID string, options *armmarketplaceordering.MarketplaceAgreementsClientCancelOptions) (resp azfake.Responder[armmarketplaceordering.MarketplaceAgreementsClientCancelResponse], errResp azfake.ErrorResponder) + + // Create is the fake for method MarketplaceAgreementsClient.Create + // HTTP status codes to indicate success: http.StatusOK + Create func(ctx context.Context, offerType armmarketplaceordering.OfferType, publisherID string, offerID string, planID string, parameters armmarketplaceordering.AgreementTerms, options *armmarketplaceordering.MarketplaceAgreementsClientCreateOptions) (resp azfake.Responder[armmarketplaceordering.MarketplaceAgreementsClientCreateResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method MarketplaceAgreementsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, offerType armmarketplaceordering.OfferType, publisherID string, offerID string, planID string, options *armmarketplaceordering.MarketplaceAgreementsClientGetOptions) (resp azfake.Responder[armmarketplaceordering.MarketplaceAgreementsClientGetResponse], errResp azfake.ErrorResponder) + + // GetAgreement is the fake for method MarketplaceAgreementsClient.GetAgreement + // HTTP status codes to indicate success: http.StatusOK + GetAgreement func(ctx context.Context, publisherID string, offerID string, planID string, options *armmarketplaceordering.MarketplaceAgreementsClientGetAgreementOptions) (resp azfake.Responder[armmarketplaceordering.MarketplaceAgreementsClientGetAgreementResponse], errResp azfake.ErrorResponder) + + // List is the fake for method MarketplaceAgreementsClient.List + // HTTP status codes to indicate success: http.StatusOK + List func(ctx context.Context, options *armmarketplaceordering.MarketplaceAgreementsClientListOptions) (resp azfake.Responder[armmarketplaceordering.MarketplaceAgreementsClientListResponse], errResp azfake.ErrorResponder) + + // Sign is the fake for method MarketplaceAgreementsClient.Sign + // HTTP status codes to indicate success: http.StatusOK + Sign func(ctx context.Context, publisherID string, offerID string, planID string, options *armmarketplaceordering.MarketplaceAgreementsClientSignOptions) (resp azfake.Responder[armmarketplaceordering.MarketplaceAgreementsClientSignResponse], errResp azfake.ErrorResponder) +} + +// NewMarketplaceAgreementsServerTransport creates a new instance of MarketplaceAgreementsServerTransport with the provided implementation. +// The returned MarketplaceAgreementsServerTransport instance is connected to an instance of armmarketplaceordering.MarketplaceAgreementsClient by way of the +// undefined.Transporter field. +func NewMarketplaceAgreementsServerTransport(srv *MarketplaceAgreementsServer) *MarketplaceAgreementsServerTransport { + return &MarketplaceAgreementsServerTransport{srv: srv} +} + +// MarketplaceAgreementsServerTransport connects instances of armmarketplaceordering.MarketplaceAgreementsClient to instances of MarketplaceAgreementsServer. +// Don't use this type directly, use NewMarketplaceAgreementsServerTransport instead. +type MarketplaceAgreementsServerTransport struct { + srv *MarketplaceAgreementsServer +} + +// Do implements the policy.Transporter interface for MarketplaceAgreementsServerTransport. +func (m *MarketplaceAgreementsServerTransport) 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 "MarketplaceAgreementsClient.Cancel": + resp, err = m.dispatchCancel(req) + case "MarketplaceAgreementsClient.Create": + resp, err = m.dispatchCreate(req) + case "MarketplaceAgreementsClient.Get": + resp, err = m.dispatchGet(req) + case "MarketplaceAgreementsClient.GetAgreement": + resp, err = m.dispatchGetAgreement(req) + case "MarketplaceAgreementsClient.List": + resp, err = m.dispatchList(req) + case "MarketplaceAgreementsClient.Sign": + resp, err = m.dispatchSign(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (m *MarketplaceAgreementsServerTransport) dispatchCancel(req *http.Request) (*http.Response, error) { + if m.srv.Cancel == nil { + return nil, &nonRetriableError{errors.New("fake for method Cancel not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.MarketplaceOrdering/agreements/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/offers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/plans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/cancel` + 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) + } + publisherIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherId")]) + if err != nil { + return nil, err + } + offerIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("offerId")]) + if err != nil { + return nil, err + } + planIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("planId")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.Cancel(req.Context(), publisherIDUnescaped, offerIDUnescaped, planIDUnescaped, 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).AgreementTerms, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *MarketplaceAgreementsServerTransport) dispatchCreate(req *http.Request) (*http.Response, error) { + if m.srv.Create == nil { + return nil, &nonRetriableError{errors.New("fake for method Create not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.MarketplaceOrdering/offerTypes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/offers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/plans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/agreements/current` + 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) + } + body, err := server.UnmarshalRequestAsJSON[armmarketplaceordering.AgreementTerms](req) + if err != nil { + return nil, err + } + offerTypeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("offerType")]) + if err != nil { + return nil, err + } + publisherIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherId")]) + if err != nil { + return nil, err + } + offerIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("offerId")]) + if err != nil { + return nil, err + } + planIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("planId")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.Create(req.Context(), armmarketplaceordering.OfferType(offerTypeUnescaped), publisherIDUnescaped, offerIDUnescaped, planIDUnescaped, 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).AgreementTerms, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *MarketplaceAgreementsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if m.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.MarketplaceOrdering/offerTypes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/offers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/plans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/agreements/current` + 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) + } + offerTypeUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("offerType")]) + if err != nil { + return nil, err + } + publisherIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherId")]) + if err != nil { + return nil, err + } + offerIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("offerId")]) + if err != nil { + return nil, err + } + planIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("planId")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.Get(req.Context(), armmarketplaceordering.OfferType(offerTypeUnescaped), publisherIDUnescaped, offerIDUnescaped, planIDUnescaped, 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).AgreementTerms, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *MarketplaceAgreementsServerTransport) dispatchGetAgreement(req *http.Request) (*http.Response, error) { + if m.srv.GetAgreement == nil { + return nil, &nonRetriableError{errors.New("fake for method GetAgreement not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.MarketplaceOrdering/agreements/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/offers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/plans/(?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) + } + publisherIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherId")]) + if err != nil { + return nil, err + } + offerIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("offerId")]) + if err != nil { + return nil, err + } + planIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("planId")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.GetAgreement(req.Context(), publisherIDUnescaped, offerIDUnescaped, planIDUnescaped, 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).AgreementTerms, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *MarketplaceAgreementsServerTransport) dispatchList(req *http.Request) (*http.Response, error) { + if m.srv.List == nil { + return nil, &nonRetriableError{errors.New("fake for method List not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.MarketplaceOrdering/agreements` + 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) + } + respr, errRespr := m.srv.List(req.Context(), 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).AgreementTermsArray, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (m *MarketplaceAgreementsServerTransport) dispatchSign(req *http.Request) (*http.Response, error) { + if m.srv.Sign == nil { + return nil, &nonRetriableError{errors.New("fake for method Sign not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft.MarketplaceOrdering/agreements/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/offers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/plans/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/sign` + 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) + } + publisherIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("publisherId")]) + if err != nil { + return nil, err + } + offerIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("offerId")]) + if err != nil { + return nil, err + } + planIDUnescaped, err := url.PathUnescape(matches[regex.SubexpIndex("planId")]) + if err != nil { + return nil, err + } + respr, errRespr := m.srv.Sign(req.Context(), publisherIDUnescaped, offerIDUnescaped, planIDUnescaped, 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).AgreementTerms, req) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/fake/operations_server.go b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/fake/operations_server.go new file mode 100644 index 000000000000..499f549ce625 --- /dev/null +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/fake/operations_server.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" + 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/marketplaceordering/armmarketplaceordering" + "net/http" +) + +// OperationsServer is a fake server for instances of the armmarketplaceordering.OperationsClient type. +type OperationsServer struct { + // NewListPager is the fake for method OperationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armmarketplaceordering.OperationsClientListOptions) (resp azfake.PagerResponder[armmarketplaceordering.OperationsClientListResponse]) +} + +// NewOperationsServerTransport creates a new instance of OperationsServerTransport with the provided implementation. +// The returned OperationsServerTransport instance is connected to an instance of armmarketplaceordering.OperationsClient by way of the +// undefined.Transporter field. +func NewOperationsServerTransport(srv *OperationsServer) *OperationsServerTransport { + return &OperationsServerTransport{srv: srv} +} + +// OperationsServerTransport connects instances of armmarketplaceordering.OperationsClient to instances of OperationsServer. +// Don't use this type directly, use NewOperationsServerTransport instead. +type OperationsServerTransport struct { + srv *OperationsServer + newListPager *azfake.PagerResponder[armmarketplaceordering.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")} + } + if o.newListPager == nil { + resp := o.srv.NewListPager(nil) + o.newListPager = &resp + server.PagerResponderInjectNextLinks(o.newListPager, req, func(page *armmarketplaceordering.OperationsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(o.newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(o.newListPager) { + o.newListPager = nil + } + return resp, nil +} diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/fake/time_rfc3339.go b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/fake/time_rfc3339.go new file mode 100644 index 000000000000..45fe10cbc6df --- /dev/null +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/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" +) + +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 + +func (t timeRFC3339) MarshalJSON() (json []byte, err error) { + tt := time.Time(t) + return tt.MarshalJSON() +} + +func (t timeRFC3339) MarshalText() (text []byte, err error) { + tt := time.Time(t) + return tt.MarshalText() +} + +func (t *timeRFC3339) UnmarshalJSON(data []byte) error { + layout := utcLayoutJSON + if tzOffsetRegex.Match(data) { + layout = rfc3339JSON + } + return t.Parse(layout, string(data)) +} + +func (t *timeRFC3339) UnmarshalText(data []byte) (err error) { + layout := utcLayout + if tzOffsetRegex.Match(data) { + layout = time.RFC3339Nano + } + return t.Parse(layout, string(data)) +} + +func (t *timeRFC3339) Parse(layout, value string) error { + p, err := time.Parse(layout, strings.ToUpper(value)) + *t = timeRFC3339(p) + return err +} + +func populateTimeRFC3339(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] = (*timeRFC3339)(t) +} + +func unpopulateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { + if data == nil || strings.EqualFold(string(data), "null") { + return nil + } + var aux timeRFC3339 + 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/marketplaceordering/armmarketplaceordering/fake_example_test.go b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/fake_example_test.go new file mode 100644 index 000000000000..980f5a94ae90 --- /dev/null +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/fake_example_test.go @@ -0,0 +1,77 @@ +//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. + +package armmarketplaceordering_test + +import ( + "context" + "fmt" + "log" + "net/http" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/marketplaceordering/armmarketplaceordering" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/fake" +) + +func ExampleMarketplaceAgreementsServer() { + // first, create an instance of the fake server for the client you wish to test. + // the type name of the server will be similar to the corresponding client, with + // the suffix "Server" instead of "Client". + fakeServer := fake.MarketplaceAgreementsServer{ + + // next, provide implementations for the APIs you wish to fake. + // this fake corresponds to the MarketplaceAgreementsClient.Get() API. + Get: func(ctx context.Context, offerType armmarketplaceordering.OfferType, publisherID string, offerID string, planID string, options *armmarketplaceordering.MarketplaceAgreementsClientGetOptions) (resp azfake.Responder[armmarketplaceordering.MarketplaceAgreementsClientGetResponse], errResp azfake.ErrorResponder) { + // the values of ctx, offerType, publisherID, offerID, planID, and options come from the API call. + + // the named return values resp and errResp are used to construct the response + // and are meant to be mutually exclusive. if both responses have been constructed, + // the error response is selected. + + // use resp to set the desired response + agreementResp := armmarketplaceordering.MarketplaceAgreementsClientGetResponse{} + agreementResp.ID = to.Ptr("/fake/resource/id") + resp.SetResponse(http.StatusOK, agreementResp, nil) + + // to simulate the failure case, use errResp + //errResp.SetResponseError(http.StatusBadRequest, "ThisIsASimulatedError") + + return + }, + } + + // now create the corresponding client, connecting the fake server via the client options + client, err := armmarketplaceordering.NewMarketplaceAgreementsClient("subscriptionID", azfake.NewTokenCredential(), &arm.ClientOptions{ + ClientOptions: azcore.ClientOptions{ + Transport: fake.NewMarketplaceAgreementsServerTransport(&fakeServer), + }, + }) + if err != nil { + log.Fatal(err) + } + + // call the API. the provided values will be passed to the fake's implementation. + // the response or error values returned by the API call are from the fake. + resp, err := client.Get(context.TODO(), armmarketplaceordering.OfferTypeVirtualmachine, "fakePublisherID", "fakeOfferID", "fakePlanID", nil) + if err != nil { + log.Fatal(err) + } + + fmt.Println(*resp.ID) + + // APIs that haven't been faked will return an error + _, err = client.Cancel(context.TODO(), "fakePublisherID", "fakeOfferID", "fakePlanID", nil) + + fmt.Println(err.Error()) + + // Output: + // /fake/resource/id + // fake for method Cancel not implemented +} diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/go.mod b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/go.mod index 1f7c1f7d10ea..6b3f0a19e671 100644 --- a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/go.mod +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/go.mod @@ -3,19 +3,19 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/marketplaceordering go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0-beta.2 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.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/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/net v0.8.0 // indirect + golang.org/x/sys v0.6.0 // indirect + golang.org/x/text v0.8.0 // indirect ) diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/go.sum b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/go.sum index 8ba445a8c4da..b9280dc6acaf 100644 --- a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/go.sum +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/go.sum @@ -1,9 +1,9 @@ -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/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/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/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 v0.9.0 h1:UE9n9rkJF62ArLb1F3DEjRt8O3jLwMWdSoypKV4f3MU= github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -20,12 +20,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb 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= +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.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.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= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/marketplaceagreements_client.go b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/marketplaceagreements_client.go index e7b0737a42eb..5cc1f977df8a 100644 --- a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/marketplaceagreements_client.go +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/marketplaceagreements_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 armmarketplaceordering @@ -54,18 +53,25 @@ func NewMarketplaceAgreementsClient(subscriptionID string, credential azcore.Tok // - options - MarketplaceAgreementsClientCancelOptions contains the optional parameters for the MarketplaceAgreementsClient.Cancel // method. func (client *MarketplaceAgreementsClient) Cancel(ctx context.Context, publisherID string, offerID string, planID string, options *MarketplaceAgreementsClientCancelOptions) (MarketplaceAgreementsClientCancelResponse, error) { + var err error + const operationName = "MarketplaceAgreementsClient.Cancel" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.cancelCreateRequest(ctx, publisherID, offerID, planID, options) if err != nil { return MarketplaceAgreementsClientCancelResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return MarketplaceAgreementsClientCancelResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return MarketplaceAgreementsClientCancelResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return MarketplaceAgreementsClientCancelResponse{}, err } - return client.cancelHandleResponse(resp) + resp, err := client.cancelHandleResponse(httpResp) + return resp, err } // cancelCreateRequest creates the Cancel request. @@ -119,18 +125,25 @@ func (client *MarketplaceAgreementsClient) cancelHandleResponse(resp *http.Respo // - options - MarketplaceAgreementsClientCreateOptions contains the optional parameters for the MarketplaceAgreementsClient.Create // method. func (client *MarketplaceAgreementsClient) Create(ctx context.Context, offerType OfferType, publisherID string, offerID string, planID string, parameters AgreementTerms, options *MarketplaceAgreementsClientCreateOptions) (MarketplaceAgreementsClientCreateResponse, error) { + var err error + const operationName = "MarketplaceAgreementsClient.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, offerType, publisherID, offerID, planID, parameters, options) if err != nil { return MarketplaceAgreementsClientCreateResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return MarketplaceAgreementsClientCreateResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return MarketplaceAgreementsClientCreateResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return MarketplaceAgreementsClientCreateResponse{}, err } - return client.createHandleResponse(resp) + resp, err := client.createHandleResponse(httpResp) + return resp, err } // createCreateRequest creates the Create request. @@ -164,7 +177,10 @@ func (client *MarketplaceAgreementsClient) createCreateRequest(ctx context.Conte reqQP.Set("api-version", "2021-01-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 } // createHandleResponse handles the Create response. @@ -187,18 +203,25 @@ func (client *MarketplaceAgreementsClient) createHandleResponse(resp *http.Respo // - options - MarketplaceAgreementsClientGetOptions contains the optional parameters for the MarketplaceAgreementsClient.Get // method. func (client *MarketplaceAgreementsClient) Get(ctx context.Context, offerType OfferType, publisherID string, offerID string, planID string, options *MarketplaceAgreementsClientGetOptions) (MarketplaceAgreementsClientGetResponse, error) { + var err error + const operationName = "MarketplaceAgreementsClient.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, offerType, publisherID, offerID, planID, options) if err != nil { return MarketplaceAgreementsClientGetResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return MarketplaceAgreementsClientGetResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return MarketplaceAgreementsClientGetResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return MarketplaceAgreementsClientGetResponse{}, err } - return client.getHandleResponse(resp) + resp, err := client.getHandleResponse(httpResp) + return resp, err } // getCreateRequest creates the Get request. @@ -254,18 +277,25 @@ func (client *MarketplaceAgreementsClient) getHandleResponse(resp *http.Response // - options - MarketplaceAgreementsClientGetAgreementOptions contains the optional parameters for the MarketplaceAgreementsClient.GetAgreement // method. func (client *MarketplaceAgreementsClient) GetAgreement(ctx context.Context, publisherID string, offerID string, planID string, options *MarketplaceAgreementsClientGetAgreementOptions) (MarketplaceAgreementsClientGetAgreementResponse, error) { + var err error + const operationName = "MarketplaceAgreementsClient.GetAgreement" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.getAgreementCreateRequest(ctx, publisherID, offerID, planID, options) if err != nil { return MarketplaceAgreementsClientGetAgreementResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return MarketplaceAgreementsClientGetAgreementResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return MarketplaceAgreementsClientGetAgreementResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return MarketplaceAgreementsClientGetAgreementResponse{}, err } - return client.getAgreementHandleResponse(resp) + resp, err := client.getAgreementHandleResponse(httpResp) + return resp, err } // getAgreementCreateRequest creates the GetAgreement request. @@ -314,18 +344,25 @@ func (client *MarketplaceAgreementsClient) getAgreementHandleResponse(resp *http // - options - MarketplaceAgreementsClientListOptions contains the optional parameters for the MarketplaceAgreementsClient.List // method. func (client *MarketplaceAgreementsClient) List(ctx context.Context, options *MarketplaceAgreementsClientListOptions) (MarketplaceAgreementsClientListResponse, error) { + var err error + const operationName = "MarketplaceAgreementsClient.List" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.listCreateRequest(ctx, options) if err != nil { return MarketplaceAgreementsClientListResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return MarketplaceAgreementsClientListResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return MarketplaceAgreementsClientListResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return MarketplaceAgreementsClientListResponse{}, err } - return client.listHandleResponse(resp) + resp, err := client.listHandleResponse(httpResp) + return resp, err } // listCreateRequest creates the List request. @@ -365,18 +402,25 @@ func (client *MarketplaceAgreementsClient) listHandleResponse(resp *http.Respons // - options - MarketplaceAgreementsClientSignOptions contains the optional parameters for the MarketplaceAgreementsClient.Sign // method. func (client *MarketplaceAgreementsClient) Sign(ctx context.Context, publisherID string, offerID string, planID string, options *MarketplaceAgreementsClientSignOptions) (MarketplaceAgreementsClientSignResponse, error) { + var err error + const operationName = "MarketplaceAgreementsClient.Sign" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.signCreateRequest(ctx, publisherID, offerID, planID, options) if err != nil { return MarketplaceAgreementsClientSignResponse{}, err } - resp, err := client.internal.Pipeline().Do(req) + httpResp, err := client.internal.Pipeline().Do(req) if err != nil { return MarketplaceAgreementsClientSignResponse{}, err } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return MarketplaceAgreementsClientSignResponse{}, runtime.NewResponseError(resp) + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return MarketplaceAgreementsClientSignResponse{}, err } - return client.signHandleResponse(resp) + resp, err := client.signHandleResponse(httpResp) + return resp, err } // signCreateRequest creates the Sign request. diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/models.go b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/models.go index 14e52ad41ff6..5d49977aa043 100644 --- a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/models.go +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/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 armmarketplaceordering @@ -14,65 +13,65 @@ import "time" // AgreementProperties - Agreement Terms definition type AgreementProperties struct { // If any version of the terms have been accepted, otherwise false. - Accepted *bool `json:"accepted,omitempty"` + Accepted *bool // Link to HTML with Microsoft and Publisher terms. - LicenseTextLink *string `json:"licenseTextLink,omitempty"` + LicenseTextLink *string // Link to HTML with Azure Marketplace terms. - MarketplaceTermsLink *string `json:"marketplaceTermsLink,omitempty"` + MarketplaceTermsLink *string // Plan identifier string of image being deployed. - Plan *string `json:"plan,omitempty"` + Plan *string // Link to the privacy policy of the publisher. - PrivacyPolicyLink *string `json:"privacyPolicyLink,omitempty"` + PrivacyPolicyLink *string // Offer identifier string of image being deployed. - Product *string `json:"product,omitempty"` + Product *string // Publisher identifier string of image being deployed. - Publisher *string `json:"publisher,omitempty"` + Publisher *string // Date and time in UTC of when the terms were accepted. This is empty if Accepted is false. - RetrieveDatetime *time.Time `json:"retrieveDatetime,omitempty"` + RetrieveDatetime *time.Time // Terms signature. - Signature *string `json:"signature,omitempty"` + Signature *string } // AgreementTerms - Terms properties for provided Publisher/Offer/Plan tuple type AgreementTerms struct { // Represents the properties of the resource. - Properties *AgreementProperties `json:"properties,omitempty"` + Properties *AgreementProperties // READ-ONLY; Resource ID. - ID *string `json:"id,omitempty" azure:"ro"` + ID *string // READ-ONLY; Resource name. - Name *string `json:"name,omitempty" azure:"ro"` + Name *string // READ-ONLY; The system meta data relating to this resource. - SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` + SystemData *SystemData // READ-ONLY; Resource type. - Type *string `json:"type,omitempty" azure:"ro"` + Type *string } // ErrorResponse - Error response indicates Microsoft.MarketplaceOrdering service is not able to process the incoming request. // The reason is provided in the error message. type ErrorResponse struct { // The details of the error. - Error *ErrorResponseError `json:"error,omitempty"` + Error *ErrorResponseError } // ErrorResponseError - The details of the error. type ErrorResponseError struct { // READ-ONLY; Error code. - Code *string `json:"code,omitempty" azure:"ro"` + Code *string // READ-ONLY; Error message indicating why the operation failed. - Message *string `json:"message,omitempty" azure:"ro"` + Message *string } // MarketplaceAgreementsClientCancelOptions contains the optional parameters for the MarketplaceAgreementsClient.Cancel method. @@ -109,35 +108,35 @@ type MarketplaceAgreementsClientSignOptions struct { // Operation - Microsoft.MarketplaceOrdering REST API 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 description. - Description *string `json:"description,omitempty"` + Description *string // Operation type: Get Agreement, Sign Agreement, Cancel Agreement etc. - Operation *string `json:"operation,omitempty"` + Operation *string // Service provider: Microsoft.MarketplaceOrdering - Provider *string `json:"provider,omitempty"` + Provider *string // Resource on which the operation is performed: Agreement, virtualmachine, etc. - Resource *string `json:"resource,omitempty"` + Resource *string } // OperationListResult - Result of the request to list MarketplaceOrdering operations. It contains a list of operations and // a URL link to get the next set of results. type OperationListResult struct { // List of Microsoft.MarketplaceOrdering operations supported by the Microsoft.MarketplaceOrdering resource provider. - Value []*Operation `json:"value,omitempty"` + Value []*Operation // READ-ONLY; URL to get the next set of operation list results if there are any. - NextLink *string `json:"nextLink,omitempty" azure:"ro"` + NextLink *string } // OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. @@ -148,32 +147,32 @@ type OperationsClientListOptions struct { // Resource - ARM resource. type Resource struct { // READ-ONLY; Resource ID. - ID *string `json:"id,omitempty" azure:"ro"` + ID *string // READ-ONLY; Resource name. - Name *string `json:"name,omitempty" azure:"ro"` + Name *string // READ-ONLY; Resource type. - Type *string `json:"type,omitempty" azure:"ro"` + Type *string } // SystemData - Metadata pertaining to creation and last modification of the resource. type SystemData struct { // The timestamp of resource creation (UTC). - CreatedAt *time.Time `json:"createdAt,omitempty"` + CreatedAt *time.Time // The identity that created the resource. - CreatedBy *string `json:"createdBy,omitempty"` + CreatedBy *string // The type of identity that created the resource. - CreatedByType *CreatedByType `json:"createdByType,omitempty"` + CreatedByType *CreatedByType // The timestamp of resource last modification (UTC) - LastModifiedAt *time.Time `json:"lastModifiedAt,omitempty"` + LastModifiedAt *time.Time // The identity that last modified the resource. - LastModifiedBy *string `json:"lastModifiedBy,omitempty"` + LastModifiedBy *string // The type of identity that last modified the resource. - LastModifiedByType *CreatedByType `json:"lastModifiedByType,omitempty"` + LastModifiedByType *CreatedByType } diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/models_serde.go b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/models_serde.go index f54d25952aa5..9069c5c67a53 100644 --- a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/models_serde.go +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/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 armmarketplaceordering diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/operations_client.go b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/operations_client.go index f028717f3130..95ab960792aa 100644 --- a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/operations_client.go +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/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 armmarketplaceordering @@ -48,6 +47,7 @@ func (client *OperationsClient) NewListPager(options *OperationsClientListOption return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *OperationsClientListResponse) (OperationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "OperationsClient.NewListPager") var req *policy.Request var err error if page == nil { @@ -67,6 +67,7 @@ func (client *OperationsClient) NewListPager(options *OperationsClientListOption } return client.listHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/response_types.go b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/response_types.go index 93e048ffaeb1..659b5eec26f1 100644 --- a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/response_types.go +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/response_types.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 armmarketplaceordering diff --git a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/time_rfc3339.go b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/time_rfc3339.go index 8133f962dc6a..9054f900901e 100644 --- a/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/time_rfc3339.go +++ b/sdk/resourcemanager/marketplaceordering/armmarketplaceordering/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 armmarketplaceordering