diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/CHANGELOG.md b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/CHANGELOG.md new file mode 100644 index 000000000000..1541e973af70 --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/CHANGELOG.md @@ -0,0 +1,8 @@ +# Release History + +## 0.1.0 (2025-04-23) +### Other Changes + +The package of `github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/edgemarketplace/armedgemarketplace` is using our [next generation design principles](https://azure.github.io/azure-sdk/general_introduction.html). + +To learn more, please refer to our documentation [Quick Start](https://aka.ms/azsdk/go/mgmt). \ No newline at end of file diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/LICENSE.txt b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/LICENSE.txt new file mode 100644 index 000000000000..dc0c2ffb3dc1 --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Microsoft Corporation. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/README.md b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/README.md new file mode 100644 index 000000000000..c1b8e4fabbbb --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/README.md @@ -0,0 +1,90 @@ +# Azure Edgemarketplace Module for Go + +The `armedgemarketplace` module provides operations for working with Azure Edgemarketplace. + +[Source code](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/resourcemanager/edgemarketplace/armedgemarketplace) + +# Getting started + +## Prerequisites + +- an [Azure subscription](https://azure.microsoft.com/free/) +- Go 1.18 or above (You could download and install the latest version of Go from [here](https://go.dev/doc/install). It will replace the existing Go on your machine. If you want to install multiple Go versions on the same machine, you could refer this [doc](https://go.dev/doc/manage-install).) + +## Install the package + +This project uses [Go modules](https://github.com/golang/go/wiki/Modules) for versioning and dependency management. + +Install the Azure Edgemarketplace module: + +```sh +go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/edgemarketplace/armedgemarketplace +``` + +## Authorization + +When creating a client, you will need to provide a credential for authenticating with Azure Edgemarketplace. The `azidentity` module provides facilities for various ways of authenticating with Azure including client/secret, certificate, managed identity, and more. + +```go +cred, err := azidentity.NewDefaultAzureCredential(nil) +``` + +For more information on authentication, please see the documentation for `azidentity` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity). + +## Client Factory + +Azure Edgemarketplace module consists of one or more clients. We provide a client factory which could be used to create any client in this module. + +```go +clientFactory, err := armedgemarketplace.NewClientFactory(, cred, nil) +``` + +You can use `ClientOptions` in package `github.com/Azure/azure-sdk-for-go/sdk/azcore/arm` to set endpoint to connect with public and sovereign clouds as well as Azure Stack. For more information, please see the documentation for `azcore` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore). + +```go +options := arm.ClientOptions { + ClientOptions: azcore.ClientOptions { + Cloud: cloud.AzureChina, + }, +} +clientFactory, err := armedgemarketplace.NewClientFactory(, cred, &options) +``` + +## Clients + +A client groups a set of related APIs, providing access to its functionality. Create one or more clients to access the APIs you require using client factory. + +```go +client := clientFactory.NewOffersClient() +``` + +## Fakes + +The fake package contains types used for constructing in-memory fake servers used in unit tests. +This allows writing tests to cover various success/error conditions without the need for connecting to a live service. + +Please see https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/samples/fakes for details and examples on how to use fakes. + +## Provide Feedback + +If you encounter bugs or have suggestions, please +[open an issue](https://github.com/Azure/azure-sdk-for-go/issues) and assign the `Edgemarketplace` label. + +# Contributing + +This project welcomes contributions and suggestions. Most contributions require +you to agree to a Contributor License Agreement (CLA) declaring that you have +the right to, and actually do, grant us the rights to use your contribution. +For details, visit [https://cla.microsoft.com](https://cla.microsoft.com). + +When you submit a pull request, a CLA-bot will automatically determine whether +you need to provide a CLA and decorate the PR appropriately (e.g., label, +comment). Simply follow the instructions provided by the bot. You will only +need to do this once across all repos using our CLA. + +This project has adopted the +[Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information, see the +[Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) +or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any +additional questions or comments. \ No newline at end of file diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/autorest.md b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/autorest.md new file mode 100644 index 000000000000..744644ed90ff --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/autorest.md @@ -0,0 +1,13 @@ +### AutoRest Configuration + +> see https://aka.ms/autorest + +``` yaml +azure-arm: true +require: +- /mnt/vss/_work/1/s/azure-rest-api-specs/specification/edgemarketplace/resource-manager/readme.md +- /mnt/vss/_work/1/s/azure-rest-api-specs/specification/edgemarketplace/resource-manager/readme.go.md +license-header: MICROSOFT_MIT_NO_VERSION +module-version: 0.1.0 + +``` \ No newline at end of file diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/build.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/build.go new file mode 100644 index 000000000000..62702de00e5a --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/build.go @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +// This file enables 'go generate' to regenerate this specific SDK +//go:generate pwsh ../../../../eng/scripts/build.ps1 -skipBuild -cleanGenerated -format -tidy -generate -alwaysSetBodyParamRequired -removeUnreferencedTypes resourcemanager/edgemarketplace/armedgemarketplace + +package armedgemarketplace diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/ci.yml b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/ci.yml new file mode 100644 index 000000000000..74b502cd7c00 --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/ci.yml @@ -0,0 +1,27 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. +trigger: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/edgemarketplace/armedgemarketplace/ + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/edgemarketplace/armedgemarketplace/ + +extends: + template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml + parameters: + ServiceDirectory: 'resourcemanager/edgemarketplace/armedgemarketplace' diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/client_factory.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/client_factory.go new file mode 100644 index 000000000000..b6f2d714c566 --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/client_factory.go @@ -0,0 +1,57 @@ +// 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 armedgemarketplace + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" +) + +// ClientFactory is a client factory used to create any client in this module. +// Don't use this type directly, use NewClientFactory instead. +type ClientFactory struct { + subscriptionID string + internal *arm.Client +} + +// NewClientFactory creates a new instance of ClientFactory with the specified values. +// The parameter values will be propagated to any client created from this factory. +// - subscriptionID - The ID of the target subscription. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ClientFactory, error) { + internal, err := arm.NewClient(moduleName, moduleVersion, credential, options) + if err != nil { + return nil, err + } + return &ClientFactory{ + subscriptionID: subscriptionID, + internal: internal, + }, nil +} + +// NewOffersClient creates a new instance of OffersClient. +func (c *ClientFactory) NewOffersClient() *OffersClient { + return &OffersClient{ + subscriptionID: c.subscriptionID, + internal: c.internal, + } +} + +// NewOperationsClient creates a new instance of OperationsClient. +func (c *ClientFactory) NewOperationsClient() *OperationsClient { + return &OperationsClient{ + internal: c.internal, + } +} + +// NewPublishersClient creates a new instance of PublishersClient. +func (c *ClientFactory) NewPublishersClient() *PublishersClient { + return &PublishersClient{ + subscriptionID: c.subscriptionID, + internal: c.internal, + } +} diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/constants.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/constants.go new file mode 100644 index 000000000000..747248c6bb5f --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/constants.go @@ -0,0 +1,121 @@ +// 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 armedgemarketplace + +const ( + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/edgemarketplace/armedgemarketplace" + moduleVersion = "v0.1.0" +) + +// ActionType - Enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. +type ActionType string + +const ( + ActionTypeInternal ActionType = "Internal" +) + +// PossibleActionTypeValues returns the possible values for the ActionType const type. +func PossibleActionTypeValues() []ActionType { + return []ActionType{ + ActionTypeInternal, + } +} + +// CreatedByType - The type of identity that created the resource. +type CreatedByType string + +const ( + CreatedByTypeApplication CreatedByType = "Application" + CreatedByTypeKey CreatedByType = "Key" + CreatedByTypeManagedIdentity CreatedByType = "ManagedIdentity" + CreatedByTypeUser CreatedByType = "User" +) + +// PossibleCreatedByTypeValues returns the possible values for the CreatedByType const type. +func PossibleCreatedByTypeValues() []CreatedByType { + return []CreatedByType{ + CreatedByTypeApplication, + CreatedByTypeKey, + CreatedByTypeManagedIdentity, + CreatedByTypeUser, + } +} + +// OfferAvailability - Says if the offer is public/private +type OfferAvailability string + +const ( + // OfferAvailabilityPrivate - The offer availability is private + OfferAvailabilityPrivate OfferAvailability = "Private" + // OfferAvailabilityPublic - The offer availability is public + OfferAvailabilityPublic OfferAvailability = "Public" +) + +// PossibleOfferAvailabilityValues returns the possible values for the OfferAvailability const type. +func PossibleOfferAvailabilityValues() []OfferAvailability { + return []OfferAvailability{ + OfferAvailabilityPrivate, + OfferAvailabilityPublic, + } +} + +// OfferReleaseType - Offer release type +type OfferReleaseType string + +const ( + // OfferReleaseTypeGA - The offer in GA + OfferReleaseTypeGA OfferReleaseType = "GA" + // OfferReleaseTypePreview - The offer in preview + OfferReleaseTypePreview OfferReleaseType = "Preview" +) + +// PossibleOfferReleaseTypeValues returns the possible values for the OfferReleaseType const type. +func PossibleOfferReleaseTypeValues() []OfferReleaseType { + return []OfferReleaseType{ + OfferReleaseTypeGA, + OfferReleaseTypePreview, + } +} + +// Origin - The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default +// value is "user,system" +type Origin string + +const ( + OriginSystem Origin = "system" + OriginUser Origin = "user" + OriginUserSystem Origin = "user,system" +) + +// PossibleOriginValues returns the possible values for the Origin const type. +func PossibleOriginValues() []Origin { + return []Origin{ + OriginSystem, + OriginUser, + OriginUserSystem, + } +} + +// ResourceProvisioningState - The provisioning state of a resource type. +type ResourceProvisioningState string + +const ( + // ResourceProvisioningStateCanceled - Resource creation was canceled. + ResourceProvisioningStateCanceled ResourceProvisioningState = "Canceled" + // ResourceProvisioningStateFailed - Resource creation failed. + ResourceProvisioningStateFailed ResourceProvisioningState = "Failed" + // ResourceProvisioningStateSucceeded - Resource has been created. + ResourceProvisioningStateSucceeded ResourceProvisioningState = "Succeeded" +) + +// PossibleResourceProvisioningStateValues returns the possible values for the ResourceProvisioningState const type. +func PossibleResourceProvisioningStateValues() []ResourceProvisioningState { + return []ResourceProvisioningState{ + ResourceProvisioningStateCanceled, + ResourceProvisioningStateFailed, + ResourceProvisioningStateSucceeded, + } +} diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/fake/internal.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/fake/internal.go new file mode 100644 index 000000000000..c614f8d5643a --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/fake/internal.go @@ -0,0 +1,85 @@ +// 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 result struct { + resp *http.Response + err error +} + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} + +func 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/edgemarketplace/armedgemarketplace/fake/offers_server.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/fake/offers_server.go new file mode 100644 index 000000000000..7621eeca9953 --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/fake/offers_server.go @@ -0,0 +1,437 @@ +// 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/edgemarketplace/armedgemarketplace" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// OffersServer is a fake server for instances of the armedgemarketplace.OffersClient type. +type OffersServer struct { + // BeginGenerateAccessToken is the fake for method OffersClient.BeginGenerateAccessToken + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginGenerateAccessToken func(ctx context.Context, resourceURI string, offerID string, body armedgemarketplace.AccessTokenRequest, options *armedgemarketplace.OffersClientBeginGenerateAccessTokenOptions) (resp azfake.PollerResponder[armedgemarketplace.OffersClientGenerateAccessTokenResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method OffersClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceURI string, offerID string, options *armedgemarketplace.OffersClientGetOptions) (resp azfake.Responder[armedgemarketplace.OffersClientGetResponse], errResp azfake.ErrorResponder) + + // GetAccessToken is the fake for method OffersClient.GetAccessToken + // HTTP status codes to indicate success: http.StatusOK + GetAccessToken func(ctx context.Context, resourceURI string, offerID string, body armedgemarketplace.AccessTokenReadRequest, options *armedgemarketplace.OffersClientGetAccessTokenOptions) (resp azfake.Responder[armedgemarketplace.OffersClientGetAccessTokenResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method OffersClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceURI string, options *armedgemarketplace.OffersClientListOptions) (resp azfake.PagerResponder[armedgemarketplace.OffersClientListResponse]) + + // NewListBySubscriptionPager is the fake for method OffersClient.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armedgemarketplace.OffersClientListBySubscriptionOptions) (resp azfake.PagerResponder[armedgemarketplace.OffersClientListBySubscriptionResponse]) +} + +// NewOffersServerTransport creates a new instance of OffersServerTransport with the provided implementation. +// The returned OffersServerTransport instance is connected to an instance of armedgemarketplace.OffersClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewOffersServerTransport(srv *OffersServer) *OffersServerTransport { + return &OffersServerTransport{ + srv: srv, + beginGenerateAccessToken: newTracker[azfake.PollerResponder[armedgemarketplace.OffersClientGenerateAccessTokenResponse]](), + newListPager: newTracker[azfake.PagerResponder[armedgemarketplace.OffersClientListResponse]](), + newListBySubscriptionPager: newTracker[azfake.PagerResponder[armedgemarketplace.OffersClientListBySubscriptionResponse]](), + } +} + +// OffersServerTransport connects instances of armedgemarketplace.OffersClient to instances of OffersServer. +// Don't use this type directly, use NewOffersServerTransport instead. +type OffersServerTransport struct { + srv *OffersServer + beginGenerateAccessToken *tracker[azfake.PollerResponder[armedgemarketplace.OffersClientGenerateAccessTokenResponse]] + newListPager *tracker[azfake.PagerResponder[armedgemarketplace.OffersClientListResponse]] + newListBySubscriptionPager *tracker[azfake.PagerResponder[armedgemarketplace.OffersClientListBySubscriptionResponse]] +} + +// Do implements the policy.Transporter interface for OffersServerTransport. +func (o *OffersServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return o.dispatchToMethodFake(req, method) +} + +func (o *OffersServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if offersServerTransportInterceptor != nil { + res.resp, res.err, intercepted = offersServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "OffersClient.BeginGenerateAccessToken": + res.resp, res.err = o.dispatchBeginGenerateAccessToken(req) + case "OffersClient.Get": + res.resp, res.err = o.dispatchGet(req) + case "OffersClient.GetAccessToken": + res.resp, res.err = o.dispatchGetAccessToken(req) + case "OffersClient.NewListPager": + res.resp, res.err = o.dispatchNewListPager(req) + case "OffersClient.NewListBySubscriptionPager": + res.resp, res.err = o.dispatchNewListBySubscriptionPager(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (o *OffersServerTransport) dispatchBeginGenerateAccessToken(req *http.Request) (*http.Response, error) { + if o.srv.BeginGenerateAccessToken == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginGenerateAccessToken not implemented")} + } + beginGenerateAccessToken := o.beginGenerateAccessToken.get(req) + if beginGenerateAccessToken == nil { + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.EdgeMarketplace/offers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/generateAccessToken` + 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[armedgemarketplace.AccessTokenRequest](req) + if err != nil { + return nil, err + } + resourceURIParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceUri")]) + if err != nil { + return nil, err + } + offerIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("offerId")]) + if err != nil { + return nil, err + } + respr, errRespr := o.srv.BeginGenerateAccessToken(req.Context(), resourceURIParam, offerIDParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginGenerateAccessToken = &respr + o.beginGenerateAccessToken.add(req, beginGenerateAccessToken) + } + + resp, err := server.PollerResponderNext(beginGenerateAccessToken, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + o.beginGenerateAccessToken.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(beginGenerateAccessToken) { + o.beginGenerateAccessToken.remove(req) + } + + return resp, nil +} + +func (o *OffersServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if o.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.EdgeMarketplace/offers/(?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) + } + resourceURIParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceUri")]) + if err != nil { + return nil, err + } + offerIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("offerId")]) + if err != nil { + return nil, err + } + respr, errRespr := o.srv.Get(req.Context(), resourceURIParam, offerIDParam, 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).Offer, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (o *OffersServerTransport) dispatchGetAccessToken(req *http.Request) (*http.Response, error) { + if o.srv.GetAccessToken == nil { + return nil, &nonRetriableError{errors.New("fake for method GetAccessToken not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.EdgeMarketplace/offers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/getAccessToken` + 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[armedgemarketplace.AccessTokenReadRequest](req) + if err != nil { + return nil, err + } + resourceURIParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceUri")]) + if err != nil { + return nil, err + } + offerIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("offerId")]) + if err != nil { + return nil, err + } + respr, errRespr := o.srv.GetAccessToken(req.Context(), resourceURIParam, offerIDParam, 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).DiskAccessToken, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (o *OffersServerTransport) 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 { + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.EdgeMarketplace/offers` + 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() + resourceURIParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceUri")]) + 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) (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 + } + skipUnescaped, err := url.QueryUnescape(qp.Get("skip")) + if err != nil { + return nil, err + } + skipParam, err := parseOptional(skipUnescaped, 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 + } + maxpagesizeUnescaped, err := url.QueryUnescape(qp.Get("maxpagesize")) + if err != nil { + return nil, err + } + maxpagesizeParam, err := parseOptional(maxpagesizeUnescaped, 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 + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armedgemarketplace.OffersClientListOptions + if topParam != nil || skipParam != nil || maxpagesizeParam != nil || filterParam != nil || skipTokenParam != nil { + options = &armedgemarketplace.OffersClientListOptions{ + Top: topParam, + Skip: skipParam, + Maxpagesize: maxpagesizeParam, + Filter: filterParam, + SkipToken: skipTokenParam, + } + } + resp := o.srv.NewListPager(resourceURIParam, options) + newListPager = &resp + o.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armedgemarketplace.OffersClientListResponse, 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 +} + +func (o *OffersServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { + if o.srv.NewListBySubscriptionPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListBySubscriptionPager not implemented")} + } + newListBySubscriptionPager := o.newListBySubscriptionPager.get(req) + if newListBySubscriptionPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.EdgeMarketplace/offers` + 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() + 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 + } + skipUnescaped, err := url.QueryUnescape(qp.Get("skip")) + if err != nil { + return nil, err + } + skipParam, err := parseOptional(skipUnescaped, 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 + } + maxpagesizeUnescaped, err := url.QueryUnescape(qp.Get("maxpagesize")) + if err != nil { + return nil, err + } + maxpagesizeParam, err := parseOptional(maxpagesizeUnescaped, 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 + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armedgemarketplace.OffersClientListBySubscriptionOptions + if topParam != nil || skipParam != nil || maxpagesizeParam != nil || filterParam != nil || skipTokenParam != nil { + options = &armedgemarketplace.OffersClientListBySubscriptionOptions{ + Top: topParam, + Skip: skipParam, + Maxpagesize: maxpagesizeParam, + Filter: filterParam, + SkipToken: skipTokenParam, + } + } + resp := o.srv.NewListBySubscriptionPager(options) + newListBySubscriptionPager = &resp + o.newListBySubscriptionPager.add(req, newListBySubscriptionPager) + server.PagerResponderInjectNextLinks(newListBySubscriptionPager, req, func(page *armedgemarketplace.OffersClientListBySubscriptionResponse, 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) { + o.newListBySubscriptionPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListBySubscriptionPager) { + o.newListBySubscriptionPager.remove(req) + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to OffersServerTransport +var offersServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/fake/operations_server.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/fake/operations_server.go new file mode 100644 index 000000000000..7f222cee8e14 --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/fake/operations_server.go @@ -0,0 +1,118 @@ +// 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/edgemarketplace/armedgemarketplace" + "net/http" +) + +// OperationsServer is a fake server for instances of the armedgemarketplace.OperationsClient type. +type OperationsServer struct { + // NewListPager is the fake for method OperationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *armedgemarketplace.OperationsClientListOptions) (resp azfake.PagerResponder[armedgemarketplace.OperationsClientListResponse]) +} + +// NewOperationsServerTransport creates a new instance of OperationsServerTransport with the provided implementation. +// The returned OperationsServerTransport instance is connected to an instance of armedgemarketplace.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[armedgemarketplace.OperationsClientListResponse]](), + } +} + +// OperationsServerTransport connects instances of armedgemarketplace.OperationsClient to instances of OperationsServer. +// Don't use this type directly, use NewOperationsServerTransport instead. +type OperationsServerTransport struct { + srv *OperationsServer + newListPager *tracker[azfake.PagerResponder[armedgemarketplace.OperationsClientListResponse]] +} + +// Do implements the policy.Transporter interface for OperationsServerTransport. +func (o *OperationsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return o.dispatchToMethodFake(req, method) +} + +func (o *OperationsServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if operationsServerTransportInterceptor != nil { + res.resp, res.err, intercepted = operationsServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "OperationsClient.NewListPager": + res.resp, res.err = o.dispatchNewListPager(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (o *OperationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if o.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := o.newListPager.get(req) + if newListPager == nil { + resp := o.srv.NewListPager(nil) + newListPager = &resp + o.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armedgemarketplace.OperationsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + o.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + o.newListPager.remove(req) + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to OperationsServerTransport +var operationsServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/fake/publishers_server.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/fake/publishers_server.go new file mode 100644 index 000000000000..72a226c7fd89 --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/fake/publishers_server.go @@ -0,0 +1,338 @@ +// 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/edgemarketplace/armedgemarketplace" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// PublishersServer is a fake server for instances of the armedgemarketplace.PublishersClient type. +type PublishersServer struct { + // Get is the fake for method PublishersClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, resourceURI string, publisherName string, options *armedgemarketplace.PublishersClientGetOptions) (resp azfake.Responder[armedgemarketplace.PublishersClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method PublishersClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(resourceURI string, options *armedgemarketplace.PublishersClientListOptions) (resp azfake.PagerResponder[armedgemarketplace.PublishersClientListResponse]) + + // NewListBySubscriptionPager is the fake for method PublishersClient.NewListBySubscriptionPager + // HTTP status codes to indicate success: http.StatusOK + NewListBySubscriptionPager func(options *armedgemarketplace.PublishersClientListBySubscriptionOptions) (resp azfake.PagerResponder[armedgemarketplace.PublishersClientListBySubscriptionResponse]) +} + +// NewPublishersServerTransport creates a new instance of PublishersServerTransport with the provided implementation. +// The returned PublishersServerTransport instance is connected to an instance of armedgemarketplace.PublishersClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewPublishersServerTransport(srv *PublishersServer) *PublishersServerTransport { + return &PublishersServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[armedgemarketplace.PublishersClientListResponse]](), + newListBySubscriptionPager: newTracker[azfake.PagerResponder[armedgemarketplace.PublishersClientListBySubscriptionResponse]](), + } +} + +// PublishersServerTransport connects instances of armedgemarketplace.PublishersClient to instances of PublishersServer. +// Don't use this type directly, use NewPublishersServerTransport instead. +type PublishersServerTransport struct { + srv *PublishersServer + newListPager *tracker[azfake.PagerResponder[armedgemarketplace.PublishersClientListResponse]] + newListBySubscriptionPager *tracker[azfake.PagerResponder[armedgemarketplace.PublishersClientListBySubscriptionResponse]] +} + +// Do implements the policy.Transporter interface for PublishersServerTransport. +func (p *PublishersServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return p.dispatchToMethodFake(req, method) +} + +func (p *PublishersServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if publishersServerTransportInterceptor != nil { + res.resp, res.err, intercepted = publishersServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "PublishersClient.Get": + res.resp, res.err = p.dispatchGet(req) + case "PublishersClient.NewListPager": + res.resp, res.err = p.dispatchNewListPager(req) + case "PublishersClient.NewListBySubscriptionPager": + res.resp, res.err = p.dispatchNewListBySubscriptionPager(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (p *PublishersServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if p.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.EdgeMarketplace/publishers/(?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) + } + resourceURIParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceUri")]) + if err != nil { + return nil, err + } + publisherNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("publisherName")]) + if err != nil { + return nil, err + } + respr, errRespr := p.srv.Get(req.Context(), resourceURIParam, publisherNameParam, 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).Publisher, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (p *PublishersServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := p.newListPager.get(req) + if newListPager == nil { + const regexStr = `/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.EdgeMarketplace/publishers` + 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() + resourceURIParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceUri")]) + 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) (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 + } + skipUnescaped, err := url.QueryUnescape(qp.Get("skip")) + if err != nil { + return nil, err + } + skipParam, err := parseOptional(skipUnescaped, 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 + } + maxpagesizeUnescaped, err := url.QueryUnescape(qp.Get("maxpagesize")) + if err != nil { + return nil, err + } + maxpagesizeParam, err := parseOptional(maxpagesizeUnescaped, 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 + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armedgemarketplace.PublishersClientListOptions + if topParam != nil || skipParam != nil || maxpagesizeParam != nil || filterParam != nil || skipTokenParam != nil { + options = &armedgemarketplace.PublishersClientListOptions{ + Top: topParam, + Skip: skipParam, + Maxpagesize: maxpagesizeParam, + Filter: filterParam, + SkipToken: skipTokenParam, + } + } + resp := p.srv.NewListPager(resourceURIParam, options) + newListPager = &resp + p.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *armedgemarketplace.PublishersClientListResponse, 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) { + p.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + p.newListPager.remove(req) + } + return resp, nil +} + +func (p *PublishersServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListBySubscriptionPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListBySubscriptionPager not implemented")} + } + newListBySubscriptionPager := p.newListBySubscriptionPager.get(req) + if newListBySubscriptionPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.EdgeMarketplace/publishers` + 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() + 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 + } + skipUnescaped, err := url.QueryUnescape(qp.Get("skip")) + if err != nil { + return nil, err + } + skipParam, err := parseOptional(skipUnescaped, 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 + } + maxpagesizeUnescaped, err := url.QueryUnescape(qp.Get("maxpagesize")) + if err != nil { + return nil, err + } + maxpagesizeParam, err := parseOptional(maxpagesizeUnescaped, 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 + } + filterUnescaped, err := url.QueryUnescape(qp.Get("$filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) + if err != nil { + return nil, err + } + skipTokenParam := getOptional(skipTokenUnescaped) + var options *armedgemarketplace.PublishersClientListBySubscriptionOptions + if topParam != nil || skipParam != nil || maxpagesizeParam != nil || filterParam != nil || skipTokenParam != nil { + options = &armedgemarketplace.PublishersClientListBySubscriptionOptions{ + Top: topParam, + Skip: skipParam, + Maxpagesize: maxpagesizeParam, + Filter: filterParam, + SkipToken: skipTokenParam, + } + } + resp := p.srv.NewListBySubscriptionPager(options) + newListBySubscriptionPager = &resp + p.newListBySubscriptionPager.add(req, newListBySubscriptionPager) + server.PagerResponderInjectNextLinks(newListBySubscriptionPager, req, func(page *armedgemarketplace.PublishersClientListBySubscriptionResponse, 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) { + p.newListBySubscriptionPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListBySubscriptionPager) { + p.newListBySubscriptionPager.remove(req) + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to PublishersServerTransport +var publishersServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/fake/server_factory.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/fake/server_factory.go new file mode 100644 index 000000000000..faf41aa47898 --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/fake/server_factory.go @@ -0,0 +1,87 @@ +// 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 armedgemarketplace.ClientFactory type. +type ServerFactory struct { + // OffersServer contains the fakes for client OffersClient + OffersServer OffersServer + + // OperationsServer contains the fakes for client OperationsClient + OperationsServer OperationsServer + + // PublishersServer contains the fakes for client PublishersClient + PublishersServer PublishersServer +} + +// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. +// The returned ServerFactoryTransport instance is connected to an instance of armedgemarketplace.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 armedgemarketplace.ClientFactory to instances of ServerFactory. +// Don't use this type directly, use NewServerFactoryTransport instead. +type ServerFactoryTransport struct { + srv *ServerFactory + trMu sync.Mutex + trOffersServer *OffersServerTransport + trOperationsServer *OperationsServerTransport + trPublishersServer *PublishersServerTransport +} + +// 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 "OffersClient": + initServer(s, &s.trOffersServer, func() *OffersServerTransport { return NewOffersServerTransport(&s.srv.OffersServer) }) + resp, err = s.trOffersServer.Do(req) + case "OperationsClient": + initServer(s, &s.trOperationsServer, func() *OperationsServerTransport { return NewOperationsServerTransport(&s.srv.OperationsServer) }) + resp, err = s.trOperationsServer.Do(req) + case "PublishersClient": + initServer(s, &s.trPublishersServer, func() *PublishersServerTransport { return NewPublishersServerTransport(&s.srv.PublishersServer) }) + resp, err = s.trPublishersServer.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/edgemarketplace/armedgemarketplace/go.mod b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/go.mod new file mode 100644 index 000000000000..0dc94a7f4e8e --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/go.mod @@ -0,0 +1,13 @@ +module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/edgemarketplace/armedgemarketplace + +go 1.23.0 + +toolchain go1.23.8 + +require github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1 + +require ( + github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect + golang.org/x/net v0.37.0 // indirect + golang.org/x/text v0.23.0 // indirect +) diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/go.sum b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/go.sum new file mode 100644 index 000000000000..cfff861c9769 --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/go.sum @@ -0,0 +1,16 @@ +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1 h1:DSDNVxqkoXJiko6x8a90zidoYqnYYa6c1MTzDKzKkTo= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1/go.mod h1:zGqV2R4Cr/k8Uye5w+dgQ06WJtEcbQG/8J7BB6hnCr4= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0/go.mod h1:iZDifYGJTIgIIkYRNWPENUnqx6bJ2xnSDFI2tjwZNuY= +github.com/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/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/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c= +golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= +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/edgemarketplace/armedgemarketplace/models.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/models.go new file mode 100644 index 000000000000..cafb68d68146 --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/models.go @@ -0,0 +1,348 @@ +// 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 armedgemarketplace + +import "time" + +// AccessTokenReadRequest - Access token request object +type AccessTokenReadRequest struct { + // REQUIRED; The name of the publisher. + RequestID *string +} + +// AccessTokenRequest - Access token request object +type AccessTokenRequest struct { + // REQUIRED; The region where the disk will be created. + EdgeMarketPlaceRegion *string + + // The device sku. + DeviceSKU *string + + // The device sku version. + DeviceVersion *string + + // The region where the disk will be created. + EgeMarketPlaceResourceID *string + + // The hyperv version. + HypervGeneration *string + + // The marketplace sku. + MarketPlaceSKU *string + + // The marketplace sku version. + MarketPlaceSKUVersion *string + + // The name of the publisher. + PublisherName *string +} + +// DiskAccessToken - The disk access token +type DiskAccessToken struct { + // REQUIRED; The access token. + AccessToken *string + + // The disk id. + DiskID *string + + // The access token creation status. + Status *string +} + +// IconFileUris - Icon files +type IconFileUris struct { + // uri of large icon + Large *string + + // uri of medium icon + Medium *string + + // uri of small icon + Small *string + + // uri of wide icon + Wide *string +} + +// MarketplaceSKU - The marketplace sku +type MarketplaceSKU struct { + // REQUIRED; The catalog plan id + CatalogPlanID *string + + // REQUIRED; The marketplace sku id + MarketplaceSKUID *string + + // The description + Description *string + + // The display name of marketplace sku + DisplayName *string + + // The display rank of the sku + DisplayRank *int32 + + // The generation + Generation *string + + // The long summary + LongSummary *string + + // The marketplace sku version + MarketplaceSKUVersions []*MarketplaceSKUVersion + + // The operating system supported + OperatingSystem *SKUOperatingSystem + + // The summary + Summary *string + + // The type of marketplace sku + Type *string +} + +// MarketplaceSKUVersion - The marketplace sku version +type MarketplaceSKUVersion struct { + // REQUIRED; The name of sku version + Name *string + + // The size of the download + MinimumDownloadSizeInMb *int32 + + // The size of the image + SizeOnDiskInMb *int32 + + // The stage name + StageName *string +} + +// Offer - An offer. +type Offer struct { + // The resource-specific properties for this resource. + Properties *OfferProperties + + // READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string + + // READ-ONLY; The name of the resource + Name *string + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string +} + +// OfferContent - The offer content +type OfferContent struct { + // REQUIRED; The display name of the offer + DisplayName *string + + // REQUIRED; The offer id + OfferID *string + + // The availability of the offer + Availability *OfferAvailability + + // The category ids + CategoryIDs []*string + + // The description + Description *string + + // The icon files + IconFileUris *IconFileUris + + // The long summary + LongSummary *string + + // The publisher of the offer + OfferPublisher *OfferPublisher + + // The offer type + OfferType *string + + // The operating systems + OperatingSystems []*string + + // The popularity of the offer + Popularity *int32 + + // The release type of the offer + ReleaseType *OfferReleaseType + + // The summary + Summary *string + + // The support uri + SupportURI *string + + // The terms and conditions + TermsAndConditions *TermsAndConditions +} + +// OfferListResult - The response of a Offer list operation. +type OfferListResult struct { + // REQUIRED; The Offer items on this page + Value []*Offer + + // The link to the next page of items + NextLink *string +} + +// OfferProperties - The offer properties +type OfferProperties struct { + // REQUIRED; The offer content + OfferContent *OfferContent + + // The content url + ContentURL *string + + // The content version + ContentVersion *string + + // The marketplace skus + MarketplaceSKUs []*MarketplaceSKU + + // The resource provisioning state + ProvisioningState *ResourceProvisioningState +} + +// OfferPublisher - The offer publisher +type OfferPublisher struct { + // REQUIRED; The publisher name + PublisherDisplayName *string + + // REQUIRED; The publisher Id + PublisherID *string +} + +// Operation - Details of a REST API operation, returned from the Resource Provider Operations API +type Operation struct { + // Localized display information for this particular operation. + Display *OperationDisplay + + // READ-ONLY; Enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + ActionType *ActionType + + // READ-ONLY; Whether the operation applies to data-plane. This is "true" for data-plane operations and "false" for ARM/control-plane + // operations. + IsDataAction *bool + + // READ-ONLY; The name of the operation, as per Resource-Based Access Control (RBAC). Examples: "Microsoft.Compute/virtualMachines/write", + // "Microsoft.Compute/virtualMachines/capture/action" + Name *string + + // READ-ONLY; The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default + // value is "user,system" + Origin *Origin +} + +// OperationDisplay - Localized display information for this particular operation. +type OperationDisplay struct { + // READ-ONLY; The short, localized friendly description of the operation; suitable for tool tips and detailed views. + Description *string + + // READ-ONLY; The concise, localized friendly name for the operation; suitable for dropdowns. E.g. "Create or Update Virtual + // Machine", "Restart Virtual Machine". + Operation *string + + // READ-ONLY; The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring Insights" or "Microsoft + // Compute". + Provider *string + + // READ-ONLY; The localized friendly name of the resource type related to this operation. E.g. "Virtual Machines" or "Job + // Schedule Collections". + Resource *string +} + +// OperationListResult - A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to +// get the next set of results. +type OperationListResult struct { + // READ-ONLY; URL to get the next set of operation list results (if there are any). + NextLink *string + + // READ-ONLY; List of operations supported by the resource provider + Value []*Operation +} + +// Publisher - A publisher who provides offers. +type Publisher struct { + // The resource-specific properties for this resource. + Properties *PublisherProperties + + // READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string + + // READ-ONLY; The name of the resource + Name *string + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string +} + +// PublisherListResult - The response of a Publisher list operation. +type PublisherListResult struct { + // REQUIRED; The Publisher items on this page + Value []*Publisher + + // The link to the next page of items + NextLink *string +} + +// PublisherProperties - Publisher properties +type PublisherProperties struct { + // REQUIRED; The resource provisioning state + ProvisioningState *ResourceProvisioningState +} + +// SKUOperatingSystem - The sku operating system +type SKUOperatingSystem struct { + // REQUIRED; The name of the operating system + Name *string + + // The family of the operating system + Family *string + + // The type of the operating system + 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 + + // The identity that created the resource. + CreatedBy *string + + // The type of identity that created the resource. + CreatedByType *CreatedByType + + // The timestamp of resource last modification (UTC) + LastModifiedAt *time.Time + + // The identity that last modified the resource. + LastModifiedBy *string + + // The type of identity that last modified the resource. + LastModifiedByType *CreatedByType +} + +// TermsAndConditions - Terms and conditions +type TermsAndConditions struct { + // The type of legal terms + LegalTermsType *string + + // The legal terms and conditions uri + LegalTermsURI *string + + // The privacy policy uri + PrivacyPolicyURI *string +} diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/models_serde.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/models_serde.go new file mode 100644 index 000000000000..31d91815c5c3 --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/models_serde.go @@ -0,0 +1,857 @@ +// 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 armedgemarketplace + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" +) + +// MarshalJSON implements the json.Marshaller interface for type AccessTokenReadRequest. +func (a AccessTokenReadRequest) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "requestId", a.RequestID) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type AccessTokenReadRequest. +func (a *AccessTokenReadRequest) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", a, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "requestId": + err = unpopulate(val, "RequestID", &a.RequestID) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", a, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type AccessTokenRequest. +func (a AccessTokenRequest) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "deviceSku", a.DeviceSKU) + populate(objectMap, "deviceVersion", a.DeviceVersion) + populate(objectMap, "edgeMarketPlaceRegion", a.EdgeMarketPlaceRegion) + populate(objectMap, "egeMarketPlaceResourceId", a.EgeMarketPlaceResourceID) + populate(objectMap, "hypervGeneration", a.HypervGeneration) + populate(objectMap, "marketPlaceSku", a.MarketPlaceSKU) + populate(objectMap, "marketPlaceSkuVersion", a.MarketPlaceSKUVersion) + populate(objectMap, "publisherName", a.PublisherName) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type AccessTokenRequest. +func (a *AccessTokenRequest) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", a, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "deviceSku": + err = unpopulate(val, "DeviceSKU", &a.DeviceSKU) + delete(rawMsg, key) + case "deviceVersion": + err = unpopulate(val, "DeviceVersion", &a.DeviceVersion) + delete(rawMsg, key) + case "edgeMarketPlaceRegion": + err = unpopulate(val, "EdgeMarketPlaceRegion", &a.EdgeMarketPlaceRegion) + delete(rawMsg, key) + case "egeMarketPlaceResourceId": + err = unpopulate(val, "EgeMarketPlaceResourceID", &a.EgeMarketPlaceResourceID) + delete(rawMsg, key) + case "hypervGeneration": + err = unpopulate(val, "HypervGeneration", &a.HypervGeneration) + delete(rawMsg, key) + case "marketPlaceSku": + err = unpopulate(val, "MarketPlaceSKU", &a.MarketPlaceSKU) + delete(rawMsg, key) + case "marketPlaceSkuVersion": + err = unpopulate(val, "MarketPlaceSKUVersion", &a.MarketPlaceSKUVersion) + delete(rawMsg, key) + case "publisherName": + err = unpopulate(val, "PublisherName", &a.PublisherName) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", a, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type DiskAccessToken. +func (d DiskAccessToken) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "accessToken", d.AccessToken) + populate(objectMap, "diskId", d.DiskID) + populate(objectMap, "status", d.Status) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type DiskAccessToken. +func (d *DiskAccessToken) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "accessToken": + err = unpopulate(val, "AccessToken", &d.AccessToken) + delete(rawMsg, key) + case "diskId": + err = unpopulate(val, "DiskID", &d.DiskID) + delete(rawMsg, key) + case "status": + err = unpopulate(val, "Status", &d.Status) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type IconFileUris. +func (i IconFileUris) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "large", i.Large) + populate(objectMap, "medium", i.Medium) + populate(objectMap, "small", i.Small) + populate(objectMap, "wide", i.Wide) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type IconFileUris. +func (i *IconFileUris) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", i, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "large": + err = unpopulate(val, "Large", &i.Large) + delete(rawMsg, key) + case "medium": + err = unpopulate(val, "Medium", &i.Medium) + delete(rawMsg, key) + case "small": + err = unpopulate(val, "Small", &i.Small) + delete(rawMsg, key) + case "wide": + err = unpopulate(val, "Wide", &i.Wide) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", i, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type MarketplaceSKU. +func (m MarketplaceSKU) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "catalogPlanId", m.CatalogPlanID) + populate(objectMap, "description", m.Description) + populate(objectMap, "displayName", m.DisplayName) + populate(objectMap, "displayRank", m.DisplayRank) + populate(objectMap, "generation", m.Generation) + populate(objectMap, "longSummary", m.LongSummary) + populate(objectMap, "marketplaceSkuId", m.MarketplaceSKUID) + populate(objectMap, "marketplaceSkuVersions", m.MarketplaceSKUVersions) + populate(objectMap, "operatingSystem", m.OperatingSystem) + populate(objectMap, "summary", m.Summary) + populate(objectMap, "type", m.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type MarketplaceSKU. +func (m *MarketplaceSKU) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", m, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "catalogPlanId": + err = unpopulate(val, "CatalogPlanID", &m.CatalogPlanID) + delete(rawMsg, key) + case "description": + err = unpopulate(val, "Description", &m.Description) + delete(rawMsg, key) + case "displayName": + err = unpopulate(val, "DisplayName", &m.DisplayName) + delete(rawMsg, key) + case "displayRank": + err = unpopulate(val, "DisplayRank", &m.DisplayRank) + delete(rawMsg, key) + case "generation": + err = unpopulate(val, "Generation", &m.Generation) + delete(rawMsg, key) + case "longSummary": + err = unpopulate(val, "LongSummary", &m.LongSummary) + delete(rawMsg, key) + case "marketplaceSkuId": + err = unpopulate(val, "MarketplaceSKUID", &m.MarketplaceSKUID) + delete(rawMsg, key) + case "marketplaceSkuVersions": + err = unpopulate(val, "MarketplaceSKUVersions", &m.MarketplaceSKUVersions) + delete(rawMsg, key) + case "operatingSystem": + err = unpopulate(val, "OperatingSystem", &m.OperatingSystem) + delete(rawMsg, key) + case "summary": + err = unpopulate(val, "Summary", &m.Summary) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &m.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", m, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type MarketplaceSKUVersion. +func (m MarketplaceSKUVersion) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "minimumDownloadSizeInMb", m.MinimumDownloadSizeInMb) + populate(objectMap, "name", m.Name) + populate(objectMap, "sizeOnDiskInMb", m.SizeOnDiskInMb) + populate(objectMap, "stageName", m.StageName) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type MarketplaceSKUVersion. +func (m *MarketplaceSKUVersion) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", m, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "minimumDownloadSizeInMb": + err = unpopulate(val, "MinimumDownloadSizeInMb", &m.MinimumDownloadSizeInMb) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &m.Name) + delete(rawMsg, key) + case "sizeOnDiskInMb": + err = unpopulate(val, "SizeOnDiskInMb", &m.SizeOnDiskInMb) + delete(rawMsg, key) + case "stageName": + err = unpopulate(val, "StageName", &m.StageName) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", m, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type Offer. +func (o Offer) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", o.ID) + populate(objectMap, "name", o.Name) + populate(objectMap, "properties", o.Properties) + populate(objectMap, "systemData", o.SystemData) + populate(objectMap, "type", o.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Offer. +func (o *Offer) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &o.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &o.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &o.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &o.SystemData) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &o.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type OfferContent. +func (o OfferContent) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "availability", o.Availability) + populate(objectMap, "categoryIds", o.CategoryIDs) + populate(objectMap, "description", o.Description) + populate(objectMap, "displayName", o.DisplayName) + populate(objectMap, "iconFileUris", o.IconFileUris) + populate(objectMap, "longSummary", o.LongSummary) + populate(objectMap, "offerId", o.OfferID) + populate(objectMap, "offerPublisher", o.OfferPublisher) + populate(objectMap, "offerType", o.OfferType) + populate(objectMap, "operatingSystems", o.OperatingSystems) + populate(objectMap, "popularity", o.Popularity) + populate(objectMap, "releaseType", o.ReleaseType) + populate(objectMap, "summary", o.Summary) + populate(objectMap, "supportUri", o.SupportURI) + populate(objectMap, "termsAndConditions", o.TermsAndConditions) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type OfferContent. +func (o *OfferContent) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "availability": + err = unpopulate(val, "Availability", &o.Availability) + delete(rawMsg, key) + case "categoryIds": + err = unpopulate(val, "CategoryIDs", &o.CategoryIDs) + delete(rawMsg, key) + case "description": + err = unpopulate(val, "Description", &o.Description) + delete(rawMsg, key) + case "displayName": + err = unpopulate(val, "DisplayName", &o.DisplayName) + delete(rawMsg, key) + case "iconFileUris": + err = unpopulate(val, "IconFileUris", &o.IconFileUris) + delete(rawMsg, key) + case "longSummary": + err = unpopulate(val, "LongSummary", &o.LongSummary) + delete(rawMsg, key) + case "offerId": + err = unpopulate(val, "OfferID", &o.OfferID) + delete(rawMsg, key) + case "offerPublisher": + err = unpopulate(val, "OfferPublisher", &o.OfferPublisher) + delete(rawMsg, key) + case "offerType": + err = unpopulate(val, "OfferType", &o.OfferType) + delete(rawMsg, key) + case "operatingSystems": + err = unpopulate(val, "OperatingSystems", &o.OperatingSystems) + delete(rawMsg, key) + case "popularity": + err = unpopulate(val, "Popularity", &o.Popularity) + delete(rawMsg, key) + case "releaseType": + err = unpopulate(val, "ReleaseType", &o.ReleaseType) + delete(rawMsg, key) + case "summary": + err = unpopulate(val, "Summary", &o.Summary) + delete(rawMsg, key) + case "supportUri": + err = unpopulate(val, "SupportURI", &o.SupportURI) + delete(rawMsg, key) + case "termsAndConditions": + err = unpopulate(val, "TermsAndConditions", &o.TermsAndConditions) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type OfferListResult. +func (o OfferListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", o.NextLink) + populate(objectMap, "value", o.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type OfferListResult. +func (o *OfferListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &o.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &o.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type OfferProperties. +func (o OfferProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "contentUrl", o.ContentURL) + populate(objectMap, "contentVersion", o.ContentVersion) + populate(objectMap, "marketplaceSkus", o.MarketplaceSKUs) + populate(objectMap, "offerContent", o.OfferContent) + populate(objectMap, "provisioningState", o.ProvisioningState) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type OfferProperties. +func (o *OfferProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "contentUrl": + err = unpopulate(val, "ContentURL", &o.ContentURL) + delete(rawMsg, key) + case "contentVersion": + err = unpopulate(val, "ContentVersion", &o.ContentVersion) + delete(rawMsg, key) + case "marketplaceSkus": + err = unpopulate(val, "MarketplaceSKUs", &o.MarketplaceSKUs) + delete(rawMsg, key) + case "offerContent": + err = unpopulate(val, "OfferContent", &o.OfferContent) + delete(rawMsg, key) + case "provisioningState": + err = unpopulate(val, "ProvisioningState", &o.ProvisioningState) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type OfferPublisher. +func (o OfferPublisher) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "publisherDisplayName", o.PublisherDisplayName) + populate(objectMap, "publisherId", o.PublisherID) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type OfferPublisher. +func (o *OfferPublisher) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "publisherDisplayName": + err = unpopulate(val, "PublisherDisplayName", &o.PublisherDisplayName) + delete(rawMsg, key) + case "publisherId": + err = unpopulate(val, "PublisherID", &o.PublisherID) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type Operation. +func (o Operation) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "actionType", o.ActionType) + populate(objectMap, "display", o.Display) + populate(objectMap, "isDataAction", o.IsDataAction) + populate(objectMap, "name", o.Name) + populate(objectMap, "origin", o.Origin) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Operation. +func (o *Operation) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "actionType": + err = unpopulate(val, "ActionType", &o.ActionType) + delete(rawMsg, key) + case "display": + err = unpopulate(val, "Display", &o.Display) + delete(rawMsg, key) + case "isDataAction": + err = unpopulate(val, "IsDataAction", &o.IsDataAction) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &o.Name) + delete(rawMsg, key) + case "origin": + err = unpopulate(val, "Origin", &o.Origin) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type OperationDisplay. +func (o OperationDisplay) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "description", o.Description) + populate(objectMap, "operation", o.Operation) + populate(objectMap, "provider", o.Provider) + populate(objectMap, "resource", o.Resource) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type OperationDisplay. +func (o *OperationDisplay) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "description": + err = unpopulate(val, "Description", &o.Description) + delete(rawMsg, key) + case "operation": + err = unpopulate(val, "Operation", &o.Operation) + delete(rawMsg, key) + case "provider": + err = unpopulate(val, "Provider", &o.Provider) + delete(rawMsg, key) + case "resource": + err = unpopulate(val, "Resource", &o.Resource) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type OperationListResult. +func (o OperationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", o.NextLink) + populate(objectMap, "value", o.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type OperationListResult. +func (o *OperationListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &o.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &o.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type Publisher. +func (p Publisher) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", p.ID) + populate(objectMap, "name", p.Name) + populate(objectMap, "properties", p.Properties) + populate(objectMap, "systemData", p.SystemData) + populate(objectMap, "type", p.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Publisher. +func (p *Publisher) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &p.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &p.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &p.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &p.SystemData) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &p.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type PublisherListResult. +func (p PublisherListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", p.NextLink) + populate(objectMap, "value", p.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type PublisherListResult. +func (p *PublisherListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &p.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &p.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type PublisherProperties. +func (p PublisherProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "provisioningState", p.ProvisioningState) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type PublisherProperties. +func (p *PublisherProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "provisioningState": + err = unpopulate(val, "ProvisioningState", &p.ProvisioningState) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type SKUOperatingSystem. +func (s SKUOperatingSystem) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "family", s.Family) + populate(objectMap, "name", s.Name) + populate(objectMap, "type", s.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SKUOperatingSystem. +func (s *SKUOperatingSystem) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "family": + err = unpopulate(val, "Family", &s.Family) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &s.Name) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &s.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type SystemData. +func (s SystemData) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populateDateTimeRFC3339(objectMap, "createdAt", s.CreatedAt) + populate(objectMap, "createdBy", s.CreatedBy) + populate(objectMap, "createdByType", s.CreatedByType) + populateDateTimeRFC3339(objectMap, "lastModifiedAt", s.LastModifiedAt) + populate(objectMap, "lastModifiedBy", s.LastModifiedBy) + populate(objectMap, "lastModifiedByType", s.LastModifiedByType) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SystemData. +func (s *SystemData) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "createdAt": + err = unpopulateDateTimeRFC3339(val, "CreatedAt", &s.CreatedAt) + delete(rawMsg, key) + case "createdBy": + err = unpopulate(val, "CreatedBy", &s.CreatedBy) + delete(rawMsg, key) + case "createdByType": + err = unpopulate(val, "CreatedByType", &s.CreatedByType) + delete(rawMsg, key) + case "lastModifiedAt": + err = unpopulateDateTimeRFC3339(val, "LastModifiedAt", &s.LastModifiedAt) + delete(rawMsg, key) + case "lastModifiedBy": + err = unpopulate(val, "LastModifiedBy", &s.LastModifiedBy) + delete(rawMsg, key) + case "lastModifiedByType": + err = unpopulate(val, "LastModifiedByType", &s.LastModifiedByType) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type TermsAndConditions. +func (t TermsAndConditions) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "legalTermsType", t.LegalTermsType) + populate(objectMap, "legalTermsUri", t.LegalTermsURI) + populate(objectMap, "privacyPolicyUri", t.PrivacyPolicyURI) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type TermsAndConditions. +func (t *TermsAndConditions) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "legalTermsType": + err = unpopulate(val, "LegalTermsType", &t.LegalTermsType) + delete(rawMsg, key) + case "legalTermsUri": + err = unpopulate(val, "LegalTermsURI", &t.LegalTermsURI) + delete(rawMsg, key) + case "privacyPolicyUri": + err = unpopulate(val, "PrivacyPolicyURI", &t.PrivacyPolicyURI) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + } + return nil +} + +func populate(m map[string]any, k string, v any) { + if v == nil { + return + } else if azcore.IsNullValue(v) { + m[k] = nil + } else if !reflect.ValueOf(v).IsNil() { + m[k] = v + } +} + +func unpopulate(data json.RawMessage, fn string, v any) error { + if data == nil || string(data) == "null" { + return nil + } + if err := json.Unmarshal(data, v); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + return nil +} diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/offers_client.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/offers_client.go new file mode 100644 index 000000000000..f43717eb1554 --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/offers_client.go @@ -0,0 +1,371 @@ +// 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 armedgemarketplace + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strconv" + "strings" +) + +// OffersClient contains the methods for the Offers group. +// Don't use this type directly, use NewOffersClient() instead. +type OffersClient struct { + internal *arm.Client + subscriptionID string +} + +// NewOffersClient creates a new instance of OffersClient with the specified values. +// - subscriptionID - The ID of the target subscription. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewOffersClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*OffersClient, error) { + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &OffersClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// BeginGenerateAccessToken - A long-running resource action. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2023-08-01 +// - resourceURI - The fully qualified Azure Resource manager identifier of the resource. +// - offerID - Id of the offer +// - body - The content of the action request +// - options - OffersClientBeginGenerateAccessTokenOptions contains the optional parameters for the OffersClient.BeginGenerateAccessToken +// method. +func (client *OffersClient) BeginGenerateAccessToken(ctx context.Context, resourceURI string, offerID string, body AccessTokenRequest, options *OffersClientBeginGenerateAccessTokenOptions) (*runtime.Poller[OffersClientGenerateAccessTokenResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.generateAccessToken(ctx, resourceURI, offerID, body, options) + if err != nil { + return nil, err + } + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[OffersClientGenerateAccessTokenResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + Tracer: client.internal.Tracer(), + }) + return poller, err + } else { + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[OffersClientGenerateAccessTokenResponse]{ + Tracer: client.internal.Tracer(), + }) + } +} + +// GenerateAccessToken - A long-running resource action. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2023-08-01 +func (client *OffersClient) generateAccessToken(ctx context.Context, resourceURI string, offerID string, body AccessTokenRequest, options *OffersClientBeginGenerateAccessTokenOptions) (*http.Response, error) { + var err error + const operationName = "OffersClient.BeginGenerateAccessToken" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.generateAccessTokenCreateRequest(ctx, resourceURI, offerID, body, options) + if err != nil { + return nil, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return nil, err + } + return httpResp, nil +} + +// generateAccessTokenCreateRequest creates the GenerateAccessToken request. +func (client *OffersClient) generateAccessTokenCreateRequest(ctx context.Context, resourceURI string, offerID string, body AccessTokenRequest, _ *OffersClientBeginGenerateAccessTokenOptions) (*policy.Request, error) { + urlPath := "/{resourceUri}/providers/Microsoft.EdgeMarketplace/offers/{offerId}/generateAccessToken" + urlPath = strings.ReplaceAll(urlPath, "{resourceUri}", resourceURI) + if offerID == "" { + return nil, errors.New("parameter offerID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{offerId}", url.PathEscape(offerID)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2023-08-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + if err := runtime.MarshalAsJSON(req, body); err != nil { + return nil, err + } + return req, nil +} + +// Get - Get a Offer +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2023-08-01 +// - resourceURI - The fully qualified Azure Resource manager identifier of the resource. +// - offerID - Id of the offer +// - options - OffersClientGetOptions contains the optional parameters for the OffersClient.Get method. +func (client *OffersClient) Get(ctx context.Context, resourceURI string, offerID string, options *OffersClientGetOptions) (OffersClientGetResponse, error) { + var err error + const operationName = "OffersClient.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, resourceURI, offerID, options) + if err != nil { + return OffersClientGetResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return OffersClientGetResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return OffersClientGetResponse{}, err + } + resp, err := client.getHandleResponse(httpResp) + return resp, err +} + +// getCreateRequest creates the Get request. +func (client *OffersClient) getCreateRequest(ctx context.Context, resourceURI string, offerID string, _ *OffersClientGetOptions) (*policy.Request, error) { + urlPath := "/{resourceUri}/providers/Microsoft.EdgeMarketplace/offers/{offerId}" + urlPath = strings.ReplaceAll(urlPath, "{resourceUri}", resourceURI) + if offerID == "" { + return nil, errors.New("parameter offerID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{offerId}", url.PathEscape(offerID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2023-08-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *OffersClient) getHandleResponse(resp *http.Response) (OffersClientGetResponse, error) { + result := OffersClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.Offer); err != nil { + return OffersClientGetResponse{}, err + } + return result, nil +} + +// GetAccessToken - get access token. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2023-08-01 +// - resourceURI - The fully qualified Azure Resource manager identifier of the resource. +// - offerID - Id of the offer +// - body - The content of the action request +// - options - OffersClientGetAccessTokenOptions contains the optional parameters for the OffersClient.GetAccessToken method. +func (client *OffersClient) GetAccessToken(ctx context.Context, resourceURI string, offerID string, body AccessTokenReadRequest, options *OffersClientGetAccessTokenOptions) (OffersClientGetAccessTokenResponse, error) { + var err error + const operationName = "OffersClient.GetAccessToken" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.getAccessTokenCreateRequest(ctx, resourceURI, offerID, body, options) + if err != nil { + return OffersClientGetAccessTokenResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return OffersClientGetAccessTokenResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return OffersClientGetAccessTokenResponse{}, err + } + resp, err := client.getAccessTokenHandleResponse(httpResp) + return resp, err +} + +// getAccessTokenCreateRequest creates the GetAccessToken request. +func (client *OffersClient) getAccessTokenCreateRequest(ctx context.Context, resourceURI string, offerID string, body AccessTokenReadRequest, _ *OffersClientGetAccessTokenOptions) (*policy.Request, error) { + urlPath := "/{resourceUri}/providers/Microsoft.EdgeMarketplace/offers/{offerId}/getAccessToken" + urlPath = strings.ReplaceAll(urlPath, "{resourceUri}", resourceURI) + if offerID == "" { + return nil, errors.New("parameter offerID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{offerId}", url.PathEscape(offerID)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2023-08-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + if err := runtime.MarshalAsJSON(req, body); err != nil { + return nil, err + } + return req, nil +} + +// getAccessTokenHandleResponse handles the GetAccessToken response. +func (client *OffersClient) getAccessTokenHandleResponse(resp *http.Response) (OffersClientGetAccessTokenResponse, error) { + result := OffersClientGetAccessTokenResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.DiskAccessToken); err != nil { + return OffersClientGetAccessTokenResponse{}, err + } + return result, nil +} + +// NewListPager - List Offer resources by parent +// +// Generated from API version 2023-08-01 +// - resourceURI - The fully qualified Azure Resource manager identifier of the resource. +// - options - OffersClientListOptions contains the optional parameters for the OffersClient.NewListPager method. +func (client *OffersClient) NewListPager(resourceURI string, options *OffersClientListOptions) *runtime.Pager[OffersClientListResponse] { + return runtime.NewPager(runtime.PagingHandler[OffersClientListResponse]{ + More: func(page OffersClientListResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *OffersClientListResponse) (OffersClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "OffersClient.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, resourceURI, options) + }, nil) + if err != nil { + return OffersClientListResponse{}, err + } + return client.listHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listCreateRequest creates the List request. +func (client *OffersClient) listCreateRequest(ctx context.Context, resourceURI string, options *OffersClientListOptions) (*policy.Request, error) { + urlPath := "/{resourceUri}/providers/Microsoft.EdgeMarketplace/offers" + urlPath = strings.ReplaceAll(urlPath, "{resourceUri}", resourceURI) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + if options != nil && options.Filter != nil { + reqQP.Set("$filter", *options.Filter) + } + if options != nil && options.SkipToken != nil { + reqQP.Set("$skipToken", *options.SkipToken) + } + if options != nil && options.Top != nil { + reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10)) + } + reqQP.Set("api-version", "2023-08-01") + if options != nil && options.Maxpagesize != nil { + reqQP.Set("maxpagesize", strconv.FormatInt(int64(*options.Maxpagesize), 10)) + } + if options != nil && options.Skip != nil { + reqQP.Set("skip", strconv.FormatInt(int64(*options.Skip), 10)) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listHandleResponse handles the List response. +func (client *OffersClient) listHandleResponse(resp *http.Response) (OffersClientListResponse, error) { + result := OffersClientListResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.OfferListResult); err != nil { + return OffersClientListResponse{}, err + } + return result, nil +} + +// NewListBySubscriptionPager - List Offer resources by subscription +// +// Generated from API version 2023-08-01 +// - options - OffersClientListBySubscriptionOptions contains the optional parameters for the OffersClient.NewListBySubscriptionPager +// method. +func (client *OffersClient) NewListBySubscriptionPager(options *OffersClientListBySubscriptionOptions) *runtime.Pager[OffersClientListBySubscriptionResponse] { + return runtime.NewPager(runtime.PagingHandler[OffersClientListBySubscriptionResponse]{ + More: func(page OffersClientListBySubscriptionResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *OffersClientListBySubscriptionResponse) (OffersClientListBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "OffersClient.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 OffersClientListBySubscriptionResponse{}, err + } + return client.listBySubscriptionHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listBySubscriptionCreateRequest creates the ListBySubscription request. +func (client *OffersClient) listBySubscriptionCreateRequest(ctx context.Context, options *OffersClientListBySubscriptionOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.EdgeMarketplace/offers" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + if options != nil && options.Filter != nil { + reqQP.Set("$filter", *options.Filter) + } + if options != nil && options.SkipToken != nil { + reqQP.Set("$skipToken", *options.SkipToken) + } + if options != nil && options.Top != nil { + reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10)) + } + reqQP.Set("api-version", "2023-08-01") + if options != nil && options.Maxpagesize != nil { + reqQP.Set("maxpagesize", strconv.FormatInt(int64(*options.Maxpagesize), 10)) + } + if options != nil && options.Skip != nil { + reqQP.Set("skip", strconv.FormatInt(int64(*options.Skip), 10)) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listBySubscriptionHandleResponse handles the ListBySubscription response. +func (client *OffersClient) listBySubscriptionHandleResponse(resp *http.Response) (OffersClientListBySubscriptionResponse, error) { + result := OffersClientListBySubscriptionResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.OfferListResult); err != nil { + return OffersClientListBySubscriptionResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/operations_client.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/operations_client.go new file mode 100644 index 000000000000..a29734994072 --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/operations_client.go @@ -0,0 +1,85 @@ +// 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 armedgemarketplace + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" +) + +// OperationsClient contains the methods for the Operations group. +// Don't use this type directly, use NewOperationsClient() instead. +type OperationsClient struct { + internal *arm.Client +} + +// NewOperationsClient creates a new instance of OperationsClient with the specified values. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewOperationsClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*OperationsClient, error) { + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &OperationsClient{ + internal: cl, + } + return client, nil +} + +// NewListPager - List the operations for the provider +// +// Generated from API version 2023-08-01 +// - options - OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. +func (client *OperationsClient) NewListPager(options *OperationsClientListOptions) *runtime.Pager[OperationsClientListResponse] { + return runtime.NewPager(runtime.PagingHandler[OperationsClientListResponse]{ + More: func(page OperationsClientListResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *OperationsClientListResponse) (OperationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "OperationsClient.NewListPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink + } + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listCreateRequest(ctx, options) + }, nil) + if err != nil { + return OperationsClientListResponse{}, err + } + return client.listHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listCreateRequest creates the List request. +func (client *OperationsClient) listCreateRequest(ctx context.Context, _ *OperationsClientListOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.EdgeMarketplace/operations" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2023-08-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listHandleResponse handles the List response. +func (client *OperationsClient) listHandleResponse(resp *http.Response) (OperationsClientListResponse, error) { + result := OperationsClientListResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.OperationListResult); err != nil { + return OperationsClientListResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/options.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/options.go new file mode 100644 index 000000000000..a5410574e30c --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/options.go @@ -0,0 +1,107 @@ +// 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 armedgemarketplace + +// OffersClientBeginGenerateAccessTokenOptions contains the optional parameters for the OffersClient.BeginGenerateAccessToken +// method. +type OffersClientBeginGenerateAccessTokenOptions struct { + // Resumes the long-running operation from the provided token. + ResumeToken string +} + +// OffersClientGetAccessTokenOptions contains the optional parameters for the OffersClient.GetAccessToken method. +type OffersClientGetAccessTokenOptions struct { + // placeholder for future optional parameters +} + +// OffersClientGetOptions contains the optional parameters for the OffersClient.Get method. +type OffersClientGetOptions struct { + // placeholder for future optional parameters +} + +// OffersClientListBySubscriptionOptions contains the optional parameters for the OffersClient.NewListBySubscriptionPager +// method. +type OffersClientListBySubscriptionOptions struct { + // Filter the result list using the given expression. + Filter *string + + // The maximum number of result items per page. + Maxpagesize *int32 + + // The number of result items to skip. + Skip *int32 + + // Skip over when retrieving results. + SkipToken *string + + // The number of result items to return. + Top *int32 +} + +// OffersClientListOptions contains the optional parameters for the OffersClient.NewListPager method. +type OffersClientListOptions struct { + // Filter the result list using the given expression. + Filter *string + + // The maximum number of result items per page. + Maxpagesize *int32 + + // The number of result items to skip. + Skip *int32 + + // Skip over when retrieving results. + SkipToken *string + + // The number of result items to return. + Top *int32 +} + +// OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. +type OperationsClientListOptions struct { + // placeholder for future optional parameters +} + +// PublishersClientGetOptions contains the optional parameters for the PublishersClient.Get method. +type PublishersClientGetOptions struct { + // placeholder for future optional parameters +} + +// PublishersClientListBySubscriptionOptions contains the optional parameters for the PublishersClient.NewListBySubscriptionPager +// method. +type PublishersClientListBySubscriptionOptions struct { + // Filter the result list using the given expression. + Filter *string + + // The maximum number of result items per page. + Maxpagesize *int32 + + // The number of result items to skip. + Skip *int32 + + // Skip over when retrieving results. + SkipToken *string + + // The number of result items to return. + Top *int32 +} + +// PublishersClientListOptions contains the optional parameters for the PublishersClient.NewListPager method. +type PublishersClientListOptions struct { + // Filter the result list using the given expression. + Filter *string + + // The maximum number of result items per page. + Maxpagesize *int32 + + // The number of result items to skip. + Skip *int32 + + // Skip over when retrieving results. + SkipToken *string + + // The number of result items to return. + Top *int32 +} diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/publishers_client.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/publishers_client.go new file mode 100644 index 000000000000..9a6214f56384 --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/publishers_client.go @@ -0,0 +1,236 @@ +// 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 armedgemarketplace + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strconv" + "strings" +) + +// PublishersClient contains the methods for the Publishers group. +// Don't use this type directly, use NewPublishersClient() instead. +type PublishersClient struct { + internal *arm.Client + subscriptionID string +} + +// NewPublishersClient creates a new instance of PublishersClient with the specified values. +// - subscriptionID - The ID of the target subscription. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewPublishersClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*PublishersClient, error) { + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &PublishersClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// Get - Get a Publisher +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2023-08-01 +// - resourceURI - The fully qualified Azure Resource manager identifier of the resource. +// - publisherName - Name of the publisher +// - options - PublishersClientGetOptions contains the optional parameters for the PublishersClient.Get method. +func (client *PublishersClient) Get(ctx context.Context, resourceURI string, publisherName string, options *PublishersClientGetOptions) (PublishersClientGetResponse, error) { + var err error + const operationName = "PublishersClient.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, resourceURI, publisherName, options) + if err != nil { + return PublishersClientGetResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return PublishersClientGetResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return PublishersClientGetResponse{}, err + } + resp, err := client.getHandleResponse(httpResp) + return resp, err +} + +// getCreateRequest creates the Get request. +func (client *PublishersClient) getCreateRequest(ctx context.Context, resourceURI string, publisherName string, _ *PublishersClientGetOptions) (*policy.Request, error) { + urlPath := "/{resourceUri}/providers/Microsoft.EdgeMarketplace/publishers/{publisherName}" + urlPath = strings.ReplaceAll(urlPath, "{resourceUri}", resourceURI) + if publisherName == "" { + return nil, errors.New("parameter publisherName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{publisherName}", url.PathEscape(publisherName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2023-08-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *PublishersClient) getHandleResponse(resp *http.Response) (PublishersClientGetResponse, error) { + result := PublishersClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.Publisher); err != nil { + return PublishersClientGetResponse{}, err + } + return result, nil +} + +// NewListPager - List Publisher resources by parent +// +// Generated from API version 2023-08-01 +// - resourceURI - The fully qualified Azure Resource manager identifier of the resource. +// - options - PublishersClientListOptions contains the optional parameters for the PublishersClient.NewListPager method. +func (client *PublishersClient) NewListPager(resourceURI string, options *PublishersClientListOptions) *runtime.Pager[PublishersClientListResponse] { + return runtime.NewPager(runtime.PagingHandler[PublishersClientListResponse]{ + More: func(page PublishersClientListResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *PublishersClientListResponse) (PublishersClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PublishersClient.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, resourceURI, options) + }, nil) + if err != nil { + return PublishersClientListResponse{}, err + } + return client.listHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listCreateRequest creates the List request. +func (client *PublishersClient) listCreateRequest(ctx context.Context, resourceURI string, options *PublishersClientListOptions) (*policy.Request, error) { + urlPath := "/{resourceUri}/providers/Microsoft.EdgeMarketplace/publishers" + urlPath = strings.ReplaceAll(urlPath, "{resourceUri}", resourceURI) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + if options != nil && options.Filter != nil { + reqQP.Set("$filter", *options.Filter) + } + if options != nil && options.SkipToken != nil { + reqQP.Set("$skipToken", *options.SkipToken) + } + if options != nil && options.Top != nil { + reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10)) + } + reqQP.Set("api-version", "2023-08-01") + if options != nil && options.Maxpagesize != nil { + reqQP.Set("maxpagesize", strconv.FormatInt(int64(*options.Maxpagesize), 10)) + } + if options != nil && options.Skip != nil { + reqQP.Set("skip", strconv.FormatInt(int64(*options.Skip), 10)) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listHandleResponse handles the List response. +func (client *PublishersClient) listHandleResponse(resp *http.Response) (PublishersClientListResponse, error) { + result := PublishersClientListResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.PublisherListResult); err != nil { + return PublishersClientListResponse{}, err + } + return result, nil +} + +// NewListBySubscriptionPager - List Publisher resources in subscription +// +// Generated from API version 2023-08-01 +// - options - PublishersClientListBySubscriptionOptions contains the optional parameters for the PublishersClient.NewListBySubscriptionPager +// method. +func (client *PublishersClient) NewListBySubscriptionPager(options *PublishersClientListBySubscriptionOptions) *runtime.Pager[PublishersClientListBySubscriptionResponse] { + return runtime.NewPager(runtime.PagingHandler[PublishersClientListBySubscriptionResponse]{ + More: func(page PublishersClientListBySubscriptionResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *PublishersClientListBySubscriptionResponse) (PublishersClientListBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PublishersClient.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 PublishersClientListBySubscriptionResponse{}, err + } + return client.listBySubscriptionHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listBySubscriptionCreateRequest creates the ListBySubscription request. +func (client *PublishersClient) listBySubscriptionCreateRequest(ctx context.Context, options *PublishersClientListBySubscriptionOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.EdgeMarketplace/publishers" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + if options != nil && options.Filter != nil { + reqQP.Set("$filter", *options.Filter) + } + if options != nil && options.SkipToken != nil { + reqQP.Set("$skipToken", *options.SkipToken) + } + if options != nil && options.Top != nil { + reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10)) + } + reqQP.Set("api-version", "2023-08-01") + if options != nil && options.Maxpagesize != nil { + reqQP.Set("maxpagesize", strconv.FormatInt(int64(*options.Maxpagesize), 10)) + } + if options != nil && options.Skip != nil { + reqQP.Set("skip", strconv.FormatInt(int64(*options.Skip), 10)) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listBySubscriptionHandleResponse handles the ListBySubscription response. +func (client *PublishersClient) listBySubscriptionHandleResponse(resp *http.Response) (PublishersClientListBySubscriptionResponse, error) { + result := PublishersClientListBySubscriptionResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.PublisherListResult); err != nil { + return PublishersClientListBySubscriptionResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/responses.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/responses.go new file mode 100644 index 000000000000..bb8a89424378 --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/responses.go @@ -0,0 +1,60 @@ +// 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 armedgemarketplace + +// OffersClientGenerateAccessTokenResponse contains the response from method OffersClient.BeginGenerateAccessToken. +type OffersClientGenerateAccessTokenResponse struct { + // The disk access token + DiskAccessToken +} + +// OffersClientGetAccessTokenResponse contains the response from method OffersClient.GetAccessToken. +type OffersClientGetAccessTokenResponse struct { + // The disk access token + DiskAccessToken +} + +// OffersClientGetResponse contains the response from method OffersClient.Get. +type OffersClientGetResponse struct { + // An offer. + Offer +} + +// OffersClientListBySubscriptionResponse contains the response from method OffersClient.NewListBySubscriptionPager. +type OffersClientListBySubscriptionResponse struct { + // The response of a Offer list operation. + OfferListResult +} + +// OffersClientListResponse contains the response from method OffersClient.NewListPager. +type OffersClientListResponse struct { + // The response of a Offer list operation. + OfferListResult +} + +// OperationsClientListResponse contains the response from method OperationsClient.NewListPager. +type OperationsClientListResponse struct { + // A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to get the next set of results. + OperationListResult +} + +// PublishersClientGetResponse contains the response from method PublishersClient.Get. +type PublishersClientGetResponse struct { + // A publisher who provides offers. + Publisher +} + +// PublishersClientListBySubscriptionResponse contains the response from method PublishersClient.NewListBySubscriptionPager. +type PublishersClientListBySubscriptionResponse struct { + // The response of a Publisher list operation. + PublisherListResult +} + +// PublishersClientListResponse contains the response from method PublishersClient.NewListPager. +type PublishersClientListResponse struct { + // The response of a Publisher list operation. + PublisherListResult +} diff --git a/sdk/resourcemanager/edgemarketplace/armedgemarketplace/time_rfc3339.go b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/time_rfc3339.go new file mode 100644 index 000000000000..3d5326a32ceb --- /dev/null +++ b/sdk/resourcemanager/edgemarketplace/armedgemarketplace/time_rfc3339.go @@ -0,0 +1,110 @@ +// 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 armedgemarketplace + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "regexp" + "strings" + "time" +) + +// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. +var tzOffsetRegex = regexp.MustCompile(`(?:Z|z|\+|-)(?:\d+:\d+)*"*$`) + +const ( + utcDateTime = "2006-01-02T15:04:05.999999999" + utcDateTimeJSON = `"` + utcDateTime + `"` + utcDateTimeNoT = "2006-01-02 15:04:05.999999999" + utcDateTimeJSONNoT = `"` + utcDateTimeNoT + `"` + dateTimeNoT = `2006-01-02 15:04:05.999999999Z07:00` + dateTimeJSON = `"` + time.RFC3339Nano + `"` + dateTimeJSONNoT = `"` + dateTimeNoT + `"` +) + +type dateTimeRFC3339 time.Time + +func (t dateTimeRFC3339) MarshalJSON() ([]byte, error) { + tt := time.Time(t) + return tt.MarshalJSON() +} + +func (t dateTimeRFC3339) MarshalText() ([]byte, error) { + tt := time.Time(t) + return tt.MarshalText() +} + +func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { + tzOffset := tzOffsetRegex.Match(data) + hasT := strings.Contains(string(data), "T") || strings.Contains(string(data), "t") + var layout string + if tzOffset && hasT { + layout = dateTimeJSON + } else if tzOffset { + layout = dateTimeJSONNoT + } else if hasT { + layout = utcDateTimeJSON + } else { + layout = utcDateTimeJSONNoT + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + if len(data) == 0 { + return nil + } + tzOffset := tzOffsetRegex.Match(data) + hasT := strings.Contains(string(data), "T") || strings.Contains(string(data), "t") + var layout string + if tzOffset && hasT { + layout = time.RFC3339Nano + } else if tzOffset { + layout = dateTimeNoT + } else if hasT { + layout = utcDateTime + } else { + layout = utcDateTimeNoT + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) Parse(layout, value string) error { + p, err := time.Parse(layout, strings.ToUpper(value)) + *t = dateTimeRFC3339(p) + return err +} + +func (t dateTimeRFC3339) String() string { + return time.Time(t).Format(time.RFC3339Nano) +} + +func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { + if t == nil { + return + } else if azcore.IsNullValue(t) { + m[k] = nil + return + } else if reflect.ValueOf(t).IsNil() { + return + } + m[k] = (*dateTimeRFC3339)(t) +} + +func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { + if data == nil || string(data) == "null" { + return nil + } + var aux dateTimeRFC3339 + if err := json.Unmarshal(data, &aux); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + *t = (*time.Time)(&aux) + return nil +}