From 1041c438517cd533d9c8d614377dae25af06fe03 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Sat, 9 Apr 2022 04:07:58 +0000 Subject: [PATCH] CodeGen from PR 18629 in Azure/azure-rest-api-specs Merge df5458da75343dd1f040cfaba4616c6385731ad3 into 2c888f4fcc12ed71287c76a6e599cc66f34c1088 --- .../resources/armsubscriptions/CHANGELOG.md | 55 +++++++ .../resources/armsubscriptions/autorest.md | 6 +- .../resources/armsubscriptions/go.mod | 27 +++- .../resources/armsubscriptions/go.sum | 7 +- ..._example_subscriptionclient_client_test.go | 33 ---- ...rated_example_subscriptions_client_test.go | 97 ------------ ...e_generated_example_tenants_client_test.go | 40 ----- .../armsubscriptions/zz_generated_client.go | 100 +++++++----- .../zz_generated_constants.go | 41 +---- .../armsubscriptions/zz_generated_models.go | 145 +---------------- .../zz_generated_models_serde.go | 148 ++++++++++++++++++ .../armsubscriptions/zz_generated_pagers.go | 125 --------------- .../zz_generated_response_types.go | 48 +----- .../zz_generated_subscription_client.go | 29 ++-- .../zz_generated_tenants_client.go | 61 +++++--- 15 files changed, 363 insertions(+), 599 deletions(-) delete mode 100644 sdk/resourcemanager/resources/armsubscriptions/ze_generated_example_subscriptionclient_client_test.go delete mode 100644 sdk/resourcemanager/resources/armsubscriptions/ze_generated_example_subscriptions_client_test.go delete mode 100644 sdk/resourcemanager/resources/armsubscriptions/ze_generated_example_tenants_client_test.go create mode 100644 sdk/resourcemanager/resources/armsubscriptions/zz_generated_models_serde.go delete mode 100644 sdk/resourcemanager/resources/armsubscriptions/zz_generated_pagers.go diff --git a/sdk/resourcemanager/resources/armsubscriptions/CHANGELOG.md b/sdk/resourcemanager/resources/armsubscriptions/CHANGELOG.md index ee7c6a573ec8..aab7faf4e7bf 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/CHANGELOG.md +++ b/sdk/resourcemanager/resources/armsubscriptions/CHANGELOG.md @@ -1,5 +1,60 @@ # Release History +## 0.3.0 (2022-04-09) +### Breaking Changes + +- Function `*TenantsClient.List` return value(s) have been changed from `(*TenantsClientListPager)` to `(*runtime.Pager[TenantsClientListResponse])` +- Function `NewSubscriptionClient` return value(s) have been changed from `(*SubscriptionClient)` to `(*SubscriptionClient, error)` +- Function `NewClient` return value(s) have been changed from `(*Client)` to `(*Client, error)` +- Function `*Client.ListLocations` parameter(s) have been changed from `(context.Context, string, *ClientListLocationsOptions)` to `(string, *ClientListLocationsOptions)` +- Function `*Client.ListLocations` return value(s) have been changed from `(ClientListLocationsResponse, error)` to `(*runtime.Pager[ClientListLocationsResponse])` +- Function `*Client.List` return value(s) have been changed from `(*ClientListPager)` to `(*runtime.Pager[ClientListResponse])` +- Function `NewTenantsClient` return value(s) have been changed from `(*TenantsClient)` to `(*TenantsClient, error)` +- Type of `ErrorAdditionalInfo.Info` has been changed from `map[string]interface{}` to `interface{}` +- Function `RegionCategory.ToPtr` has been removed +- Function `SpendingLimit.ToPtr` has been removed +- Function `TenantCategory.ToPtr` has been removed +- Function `RegionType.ToPtr` has been removed +- Function `*ClientListPager.PageResponse` has been removed +- Function `*TenantsClientListPager.Err` has been removed +- Function `*TenantsClientListPager.NextPage` has been removed +- Function `*ClientListPager.NextPage` has been removed +- Function `*TenantsClientListPager.PageResponse` has been removed +- Function `SubscriptionState.ToPtr` has been removed +- Function `*ClientListPager.Err` has been removed +- Function `ResourceNameStatus.ToPtr` has been removed +- Function `LocationType.ToPtr` has been removed +- Struct `ClientCheckZonePeersResult` has been removed +- Struct `ClientGetResult` has been removed +- Struct `ClientListLocationsResult` has been removed +- Struct `ClientListPager` has been removed +- Struct `ClientListResult` has been removed +- Struct `SubscriptionClientCheckResourceNameResult` has been removed +- Struct `TenantsClientListPager` has been removed +- Struct `TenantsClientListResult` has been removed +- Field `SubscriptionClientCheckResourceNameResult` of struct `SubscriptionClientCheckResourceNameResponse` has been removed +- Field `RawResponse` of struct `SubscriptionClientCheckResourceNameResponse` has been removed +- Field `ClientCheckZonePeersResult` of struct `ClientCheckZonePeersResponse` has been removed +- Field `RawResponse` of struct `ClientCheckZonePeersResponse` has been removed +- Field `ClientGetResult` of struct `ClientGetResponse` has been removed +- Field `RawResponse` of struct `ClientGetResponse` has been removed +- Field `ClientListLocationsResult` of struct `ClientListLocationsResponse` has been removed +- Field `RawResponse` of struct `ClientListLocationsResponse` has been removed +- Field `ClientListResult` of struct `ClientListResponse` has been removed +- Field `RawResponse` of struct `ClientListResponse` has been removed +- Field `TenantsClientListResult` of struct `TenantsClientListResponse` has been removed +- Field `RawResponse` of struct `TenantsClientListResponse` has been removed + +### Features Added + +- New anonymous field `Subscription` in struct `ClientGetResponse` +- New anonymous field `TenantListResult` in struct `TenantsClientListResponse` +- New anonymous field `CheckZonePeersResult` in struct `ClientCheckZonePeersResponse` +- New anonymous field `SubscriptionListResult` in struct `ClientListResponse` +- New anonymous field `LocationListResult` in struct `ClientListLocationsResponse` +- New anonymous field `CheckResourceNameResult` in struct `SubscriptionClientCheckResourceNameResponse` + + ## 0.2.1 (2022-02-22) ### Other Changes diff --git a/sdk/resourcemanager/resources/armsubscriptions/autorest.md b/sdk/resourcemanager/resources/armsubscriptions/autorest.md index 2d708d95d78e..2227b7d6976b 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/autorest.md +++ b/sdk/resourcemanager/resources/armsubscriptions/autorest.md @@ -5,9 +5,9 @@ ``` yaml azure-arm: true require: -- https://github.com/Azure/azure-rest-api-specs/blob/35453a0a130097acc53af066f340c53c86c76e96/specification/resources/resource-manager/readme.md -- https://github.com/Azure/azure-rest-api-specs/blob/35453a0a130097acc53af066f340c53c86c76e96/specification/resources/resource-manager/readme.go.md +- /mnt/vss/_work/1/s/azure-rest-api-specs/specification/resources/resource-manager/readme.md +- /mnt/vss/_work/1/s/azure-rest-api-specs/specification/resources/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 0.2.1 +module-version: 0.3.0 package-subscriptions: true ``` \ No newline at end of file diff --git a/sdk/resourcemanager/resources/armsubscriptions/go.mod b/sdk/resourcemanager/resources/armsubscriptions/go.mod index 21e86e0962e3..bec2e86b2a40 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/go.mod +++ b/sdk/resourcemanager/resources/armsubscriptions/go.mod @@ -1,10 +1,29 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions -go 1.16 +go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v0.22.0 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.13.1 - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v0.1.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.23.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v0.2.0 github.com/stretchr/testify v1.7.0 ) + +require ( + github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.13.1 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v0.9.1 // indirect + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v0.3.1 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v0.4.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dnaeon/go-vcr v1.1.0 // indirect + github.com/golang-jwt/jwt v3.2.1+incompatible // indirect + github.com/google/uuid v1.1.1 // indirect + github.com/kylelemons/godebug v1.1.0 // indirect + github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 // indirect + golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect + golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect + golang.org/x/text v0.3.7 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect +) diff --git a/sdk/resourcemanager/resources/armsubscriptions/go.sum b/sdk/resourcemanager/resources/armsubscriptions/go.sum index 861905ed56b2..d78f0446a869 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/go.sum +++ b/sdk/resourcemanager/resources/armsubscriptions/go.sum @@ -1,14 +1,15 @@ github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.0/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM= -github.com/Azure/azure-sdk-for-go/sdk/azcore v0.22.0 h1:zBJcBJwte0x6PcPK7XaWDMvK2o2ZM2f1sMaqNNavQ5g= github.com/Azure/azure-sdk-for-go/sdk/azcore v0.22.0/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.23.0 h1:D7l5jspkc4kwBYRWoZE4DQnu6LVpLwDsMZjBKS4wZLQ= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.23.0/go.mod h1:w5pDIZuawUmY3Bj4tVx3Xb8KS96ToB0j315w9rqpAg0= github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.13.0/go.mod h1:TmXReXZ9yPp5D5TBRMTAtyz+UyOl15Py4hL5E5p6igQ= github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.13.1 h1:RxemzI2cHD0A8WyMqHu/UnDjfpGES/cmjtPbQoktWqs= github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.13.1/go.mod h1:+nVKciyKD2J9TyVcEQ82Bo9b+3F92PiQfHrIE/zqLqM= github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I= github.com/Azure/azure-sdk-for-go/sdk/internal v0.9.1 h1:sLZ/Y+P/5RRtsXWylBjB5lkgixYfm0MQPiwrSX//JSo= github.com/Azure/azure-sdk-for-go/sdk/internal v0.9.1/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v0.1.0 h1:/hWqo5bAXoNK7svf5GvgpXFPzOCpM29/Eu+WqcE34Uk= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v0.1.0/go.mod h1:wXFq4k1znCwV7Bw70gw4UDNYKv/nrCUr70hjUmOj1Jo= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v0.2.0 h1:XXN3bts0fUoLmcjptj5wymRVOfsQySQa7hsbAGrZ2n8= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v0.2.0/go.mod h1:wXFq4k1znCwV7Bw70gw4UDNYKv/nrCUr70hjUmOj1Jo= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v0.3.1 h1:EXTDtCSTfPauGawsG+Ae/W46B1PkrgzuKNrcFqy4ljM= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v0.3.1/go.mod h1:PoA99xQAlN13MyUjzgIPWMZEr0etHpYSuT25LmhR3zQ= github.com/AzureAD/microsoft-authentication-library-for-go v0.4.0 h1:WVsrXCnHlDDX8ls+tootqRE87/hL9S/g4ewig9RsD/c= diff --git a/sdk/resourcemanager/resources/armsubscriptions/ze_generated_example_subscriptionclient_client_test.go b/sdk/resourcemanager/resources/armsubscriptions/ze_generated_example_subscriptionclient_client_test.go deleted file mode 100644 index 74bae0ead831..000000000000 --- a/sdk/resourcemanager/resources/armsubscriptions/ze_generated_example_subscriptionclient_client_test.go +++ /dev/null @@ -1,33 +0,0 @@ -//go:build go1.16 -// +build go1.16 - -// 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. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -package armsubscriptions_test - -import ( - "context" - "log" - - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions" -) - -// x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/CheckResourceName.json -func ExampleSubscriptionClient_CheckResourceName() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - client := armsubscriptions.NewSubscriptionClient(cred, nil) - res, err := client.CheckResourceName(ctx, - &armsubscriptions.SubscriptionClientCheckResourceNameOptions{ResourceNameDefinition: nil}) - if err != nil { - log.Fatal(err) - } - log.Printf("Response result: %#v\n", res.SubscriptionClientCheckResourceNameResult) -} diff --git a/sdk/resourcemanager/resources/armsubscriptions/ze_generated_example_subscriptions_client_test.go b/sdk/resourcemanager/resources/armsubscriptions/ze_generated_example_subscriptions_client_test.go deleted file mode 100644 index 3403f1fc7c64..000000000000 --- a/sdk/resourcemanager/resources/armsubscriptions/ze_generated_example_subscriptions_client_test.go +++ /dev/null @@ -1,97 +0,0 @@ -//go:build go1.16 -// +build go1.16 - -// 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. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -package armsubscriptions_test - -import ( - "context" - "log" - - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions" -) - -// x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetLocations.json -func ExampleClient_ListLocations() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - client := armsubscriptions.NewClient(cred, nil) - res, err := client.ListLocations(ctx, - "", - &armsubscriptions.ClientListLocationsOptions{IncludeExtendedLocations: nil}) - if err != nil { - log.Fatal(err) - } - log.Printf("Response result: %#v\n", res.ClientListLocationsResult) -} - -// x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetSubscription.json -func ExampleClient_Get() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - client := armsubscriptions.NewClient(cred, nil) - res, err := client.Get(ctx, - "", - nil) - if err != nil { - log.Fatal(err) - } - log.Printf("Response result: %#v\n", res.ClientGetResult) -} - -// x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetSubscriptions.json -func ExampleClient_List() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - client := armsubscriptions.NewClient(cred, nil) - pager := client.List(nil) - for { - nextResult := pager.NextPage(ctx) - if err := pager.Err(); err != nil { - log.Fatalf("failed to advance page: %v", err) - } - if !nextResult { - break - } - for _, v := range pager.PageResponse().Value { - log.Printf("Pager result: %#v\n", v) - } - } -} - -// x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/PostCheckZonePeers.json -func ExampleClient_CheckZonePeers() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - client := armsubscriptions.NewClient(cred, nil) - res, err := client.CheckZonePeers(ctx, - "", - armsubscriptions.CheckZonePeersRequest{ - Location: to.StringPtr(""), - SubscriptionIDs: []*string{ - to.StringPtr("subscriptions/11111111-1111-1111-1111-111111111111")}, - }, - nil) - if err != nil { - log.Fatal(err) - } - log.Printf("Response result: %#v\n", res.ClientCheckZonePeersResult) -} diff --git a/sdk/resourcemanager/resources/armsubscriptions/ze_generated_example_tenants_client_test.go b/sdk/resourcemanager/resources/armsubscriptions/ze_generated_example_tenants_client_test.go deleted file mode 100644 index 1c59bb6c77bf..000000000000 --- a/sdk/resourcemanager/resources/armsubscriptions/ze_generated_example_tenants_client_test.go +++ /dev/null @@ -1,40 +0,0 @@ -//go:build go1.16 -// +build go1.16 - -// 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. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -package armsubscriptions_test - -import ( - "context" - "log" - - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions" -) - -// x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetTenants.json -func ExampleTenantsClient_List() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - client := armsubscriptions.NewTenantsClient(cred, nil) - pager := client.List(nil) - for { - nextResult := pager.NextPage(ctx) - if err := pager.Err(); err != nil { - log.Fatalf("failed to advance page: %v", err) - } - if !nextResult { - break - } - for _, v := range pager.PageResponse().Value { - log.Printf("Pager result: %#v\n", v) - } - } -} diff --git a/sdk/resourcemanager/resources/armsubscriptions/zz_generated_client.go b/sdk/resourcemanager/resources/armsubscriptions/zz_generated_client.go index 4d85b1b43657..52a1faeb8e48 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/zz_generated_client.go +++ b/sdk/resourcemanager/resources/armsubscriptions/zz_generated_client.go @@ -1,5 +1,5 @@ -//go:build go1.16 -// +build go1.16 +//go:build go1.18 +// +build go1.18 // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. @@ -14,6 +14,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "net/http" @@ -32,19 +33,23 @@ type Client struct { // NewClient creates a new instance of Client with the specified values. // credential - used to authorize requests. Usually a credential from azidentity. // options - pass nil to accept the default values. -func NewClient(credential azcore.TokenCredential, options *arm.ClientOptions) *Client { - cp := arm.ClientOptions{} - if options != nil { - cp = *options +func NewClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*Client, error) { + if options == nil { + options = &arm.ClientOptions{} } - if len(cp.Endpoint) == 0 { - cp.Endpoint = arm.AzurePublicCloud + ep := cloud.AzurePublicCloud.Services[cloud.ResourceManager].Endpoint + if c, ok := options.Cloud.Services[cloud.ResourceManager]; ok { + ep = c.Endpoint + } + pl, err := armruntime.NewPipeline(moduleName, moduleVersion, credential, runtime.PipelineOptions{}, options) + if err != nil { + return nil, err } client := &Client{ - host: string(cp.Endpoint), - pl: armruntime.NewPipeline(moduleName, moduleVersion, credential, runtime.PipelineOptions{}, &cp), + host: ep, + pl: pl, } - return client + return client, nil } // CheckZonePeers - Compares a subscriptions logical zone mapping @@ -87,7 +92,7 @@ func (client *Client) checkZonePeersCreateRequest(ctx context.Context, subscript // checkZonePeersHandleResponse handles the CheckZonePeers response. func (client *Client) checkZonePeersHandleResponse(resp *http.Response) (ClientCheckZonePeersResponse, error) { - result := ClientCheckZonePeersResponse{RawResponse: resp} + result := ClientCheckZonePeersResponse{} if err := runtime.UnmarshalAsJSON(resp, &result.CheckZonePeersResult); err != nil { return ClientCheckZonePeersResponse{}, err } @@ -133,7 +138,7 @@ func (client *Client) getCreateRequest(ctx context.Context, subscriptionID strin // getHandleResponse handles the Get response. func (client *Client) getHandleResponse(resp *http.Response) (ClientGetResponse, error) { - result := ClientGetResponse{RawResponse: resp} + result := ClientGetResponse{} if err := runtime.UnmarshalAsJSON(resp, &result.Subscription); err != nil { return ClientGetResponse{}, err } @@ -143,16 +148,32 @@ func (client *Client) getHandleResponse(resp *http.Response) (ClientGetResponse, // List - Gets all subscriptions for a tenant. // If the operation fails it returns an *azcore.ResponseError type. // options - ClientListOptions contains the optional parameters for the Client.List method. -func (client *Client) List(options *ClientListOptions) *ClientListPager { - return &ClientListPager{ - client: client, - requester: func(ctx context.Context) (*policy.Request, error) { - return client.listCreateRequest(ctx, options) +func (client *Client) List(options *ClientListOptions) *runtime.Pager[ClientListResponse] { + return runtime.NewPager(runtime.PageProcessor[ClientListResponse]{ + More: func(page ClientListResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 }, - advancer: func(ctx context.Context, resp ClientListResponse) (*policy.Request, error) { - return runtime.NewRequest(ctx, http.MethodGet, *resp.SubscriptionListResult.NextLink) + Fetcher: func(ctx context.Context, page *ClientListResponse) (ClientListResponse, error) { + var req *policy.Request + var err error + if page == nil { + req, err = client.listCreateRequest(ctx, options) + } else { + req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + } + if err != nil { + return ClientListResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ClientListResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ClientListResponse{}, runtime.NewResponseError(resp) + } + return client.listHandleResponse(resp) }, - } + }) } // listCreateRequest creates the List request. @@ -171,7 +192,7 @@ func (client *Client) listCreateRequest(ctx context.Context, options *ClientList // listHandleResponse handles the List response. func (client *Client) listHandleResponse(resp *http.Response) (ClientListResponse, error) { - result := ClientListResponse{RawResponse: resp} + result := ClientListResponse{} if err := runtime.UnmarshalAsJSON(resp, &result.SubscriptionListResult); err != nil { return ClientListResponse{}, err } @@ -183,19 +204,26 @@ func (client *Client) listHandleResponse(resp *http.Response) (ClientListRespons // If the operation fails it returns an *azcore.ResponseError type. // subscriptionID - The ID of the target subscription. // options - ClientListLocationsOptions contains the optional parameters for the Client.ListLocations method. -func (client *Client) ListLocations(ctx context.Context, subscriptionID string, options *ClientListLocationsOptions) (ClientListLocationsResponse, error) { - req, err := client.listLocationsCreateRequest(ctx, subscriptionID, options) - if err != nil { - return ClientListLocationsResponse{}, err - } - resp, err := client.pl.Do(req) - if err != nil { - return ClientListLocationsResponse{}, err - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - return ClientListLocationsResponse{}, runtime.NewResponseError(resp) - } - return client.listLocationsHandleResponse(resp) +func (client *Client) ListLocations(subscriptionID string, options *ClientListLocationsOptions) *runtime.Pager[ClientListLocationsResponse] { + return runtime.NewPager(runtime.PageProcessor[ClientListLocationsResponse]{ + More: func(page ClientListLocationsResponse) bool { + return false + }, + Fetcher: func(ctx context.Context, page *ClientListLocationsResponse) (ClientListLocationsResponse, error) { + req, err := client.listLocationsCreateRequest(ctx, subscriptionID, options) + if err != nil { + return ClientListLocationsResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ClientListLocationsResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ClientListLocationsResponse{}, runtime.NewResponseError(resp) + } + return client.listLocationsHandleResponse(resp) + }, + }) } // listLocationsCreateRequest creates the ListLocations request. @@ -221,7 +249,7 @@ func (client *Client) listLocationsCreateRequest(ctx context.Context, subscripti // listLocationsHandleResponse handles the ListLocations response. func (client *Client) listLocationsHandleResponse(resp *http.Response) (ClientListLocationsResponse, error) { - result := ClientListLocationsResponse{RawResponse: resp} + result := ClientListLocationsResponse{} if err := runtime.UnmarshalAsJSON(resp, &result.LocationListResult); err != nil { return ClientListLocationsResponse{}, err } diff --git a/sdk/resourcemanager/resources/armsubscriptions/zz_generated_constants.go b/sdk/resourcemanager/resources/armsubscriptions/zz_generated_constants.go index 18aa55d426ee..1c749b363eb4 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/zz_generated_constants.go +++ b/sdk/resourcemanager/resources/armsubscriptions/zz_generated_constants.go @@ -1,5 +1,5 @@ -//go:build go1.16 -// +build go1.16 +//go:build go1.18 +// +build go1.18 // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. @@ -10,7 +10,7 @@ package armsubscriptions const ( moduleName = "armsubscriptions" - moduleVersion = "v0.2.1" + moduleVersion = "v0.3.0" ) // LocationType - The location type. @@ -29,11 +29,6 @@ func PossibleLocationTypeValues() []LocationType { } } -// ToPtr returns a *LocationType pointing to the current value. -func (c LocationType) ToPtr() *LocationType { - return &c -} - // RegionCategory - The category of the region. type RegionCategory string @@ -52,11 +47,6 @@ func PossibleRegionCategoryValues() []RegionCategory { } } -// ToPtr returns a *RegionCategory pointing to the current value. -func (c RegionCategory) ToPtr() *RegionCategory { - return &c -} - // RegionType - The type of the region. type RegionType string @@ -73,11 +63,6 @@ func PossibleRegionTypeValues() []RegionType { } } -// ToPtr returns a *RegionType pointing to the current value. -func (c RegionType) ToPtr() *RegionType { - return &c -} - // ResourceNameStatus - Is the resource name Allowed or Reserved type ResourceNameStatus string @@ -94,11 +79,6 @@ func PossibleResourceNameStatusValues() []ResourceNameStatus { } } -// ToPtr returns a *ResourceNameStatus pointing to the current value. -func (c ResourceNameStatus) ToPtr() *ResourceNameStatus { - return &c -} - // SpendingLimit - The subscription spending limit. type SpendingLimit string @@ -117,11 +97,6 @@ func PossibleSpendingLimitValues() []SpendingLimit { } } -// ToPtr returns a *SpendingLimit pointing to the current value. -func (c SpendingLimit) ToPtr() *SpendingLimit { - return &c -} - // SubscriptionState - The subscription state. Possible values are Enabled, Warned, PastDue, Disabled, and Deleted. type SubscriptionState string @@ -144,11 +119,6 @@ func PossibleSubscriptionStateValues() []SubscriptionState { } } -// ToPtr returns a *SubscriptionState pointing to the current value. -func (c SubscriptionState) ToPtr() *SubscriptionState { - return &c -} - // TenantCategory - Category of the tenant. type TenantCategory string @@ -166,8 +136,3 @@ func PossibleTenantCategoryValues() []TenantCategory { TenantCategoryManagedBy, } } - -// ToPtr returns a *TenantCategory pointing to the current value. -func (c TenantCategory) ToPtr() *TenantCategory { - return &c -} diff --git a/sdk/resourcemanager/resources/armsubscriptions/zz_generated_models.go b/sdk/resourcemanager/resources/armsubscriptions/zz_generated_models.go index 5ec8290155cb..9c23dca01c26 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/zz_generated_models.go +++ b/sdk/resourcemanager/resources/armsubscriptions/zz_generated_models.go @@ -1,5 +1,5 @@ -//go:build go1.16 -// +build go1.16 +//go:build go1.18 +// +build go1.18 // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. @@ -8,12 +8,6 @@ package armsubscriptions -import ( - "encoding/json" - "github.com/Azure/azure-sdk-for-go/sdk/azcore" - "reflect" -) - // AvailabilityZonePeers - List of availability zones shared by the subscriptions. type AvailabilityZonePeers struct { // Details of shared availability zone. @@ -23,14 +17,6 @@ type AvailabilityZonePeers struct { AvailabilityZone *string `json:"availabilityZone,omitempty" azure:"ro"` } -// MarshalJSON implements the json.Marshaller interface for type AvailabilityZonePeers. -func (a AvailabilityZonePeers) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]interface{}) - populate(objectMap, "availabilityZone", a.AvailabilityZone) - populate(objectMap, "peers", a.Peers) - return json.Marshal(objectMap) -} - // CheckResourceNameResult - Resource Name valid if not a reserved word, does not contain a reserved word and does not start // with a reserved word type CheckResourceNameResult struct { @@ -53,14 +39,6 @@ type CheckZonePeersRequest struct { SubscriptionIDs []*string `json:"subscriptionIds,omitempty"` } -// MarshalJSON implements the json.Marshaller interface for type CheckZonePeersRequest. -func (c CheckZonePeersRequest) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]interface{}) - populate(objectMap, "location", c.Location) - populate(objectMap, "subscriptionIds", c.SubscriptionIDs) - return json.Marshal(objectMap) -} - // CheckZonePeersResult - Result of the Check zone peers operation. type CheckZonePeersResult struct { // The Availability Zones shared by the subscriptions. @@ -73,15 +51,6 @@ type CheckZonePeersResult struct { SubscriptionID *string `json:"subscriptionId,omitempty" azure:"ro"` } -// MarshalJSON implements the json.Marshaller interface for type CheckZonePeersResult. -func (c CheckZonePeersResult) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]interface{}) - populate(objectMap, "availabilityZonePeers", c.AvailabilityZonePeers) - populate(objectMap, "location", c.Location) - populate(objectMap, "subscriptionId", c.SubscriptionID) - return json.Marshal(objectMap) -} - // ClientCheckZonePeersOptions contains the optional parameters for the Client.CheckZonePeers method. type ClientCheckZonePeersOptions struct { // placeholder for future optional parameters @@ -113,7 +82,7 @@ type CloudError struct { // ErrorAdditionalInfo - The resource management error additional info. type ErrorAdditionalInfo struct { // READ-ONLY; The additional info. - Info map[string]interface{} `json:"info,omitempty" azure:"ro"` + Info interface{} `json:"info,omitempty" azure:"ro"` // READ-ONLY; The additional info type. Type *string `json:"type,omitempty" azure:"ro"` @@ -137,17 +106,6 @@ type ErrorDetail struct { Target *string `json:"target,omitempty" azure:"ro"` } -// MarshalJSON implements the json.Marshaller interface for type ErrorDetail. -func (e ErrorDetail) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]interface{}) - populate(objectMap, "additionalInfo", e.AdditionalInfo) - populate(objectMap, "code", e.Code) - populate(objectMap, "details", e.Details) - populate(objectMap, "message", e.Message) - populate(objectMap, "target", e.Target) - return json.Marshal(objectMap) -} - // ErrorResponse - Common error response for all Azure Resource Manager APIs to return error details for failed operations. // (This also follows the OData error response format.) type ErrorResponse struct { @@ -167,17 +125,6 @@ type ErrorResponse struct { Target *string `json:"target,omitempty" azure:"ro"` } -// MarshalJSON implements the json.Marshaller interface for type ErrorResponse. -func (e ErrorResponse) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]interface{}) - populate(objectMap, "additionalInfo", e.AdditionalInfo) - populate(objectMap, "code", e.Code) - populate(objectMap, "details", e.Details) - populate(objectMap, "message", e.Message) - populate(objectMap, "target", e.Target) - return json.Marshal(objectMap) -} - // ErrorResponseAutoGenerated - Common error response for all Azure Resource Manager APIs to return error details for failed // operations. (This also follows the OData error response format.). type ErrorResponseAutoGenerated struct { @@ -215,13 +162,6 @@ type LocationListResult struct { Value []*Location `json:"value,omitempty"` } -// MarshalJSON implements the json.Marshaller interface for type LocationListResult. -func (l LocationListResult) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]interface{}) - populate(objectMap, "value", l.Value) - return json.Marshal(objectMap) -} - // LocationMetadata - Location metadata information type LocationMetadata struct { // The regions paired to this region. @@ -249,20 +189,6 @@ type LocationMetadata struct { RegionType *RegionType `json:"regionType,omitempty" azure:"ro"` } -// MarshalJSON implements the json.Marshaller interface for type LocationMetadata. -func (l LocationMetadata) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]interface{}) - populate(objectMap, "geographyGroup", l.GeographyGroup) - populate(objectMap, "homeLocation", l.HomeLocation) - populate(objectMap, "latitude", l.Latitude) - populate(objectMap, "longitude", l.Longitude) - populate(objectMap, "pairedRegion", l.PairedRegion) - populate(objectMap, "physicalLocation", l.PhysicalLocation) - populate(objectMap, "regionCategory", l.RegionCategory) - populate(objectMap, "regionType", l.RegionType) - return json.Marshal(objectMap) -} - // ManagedByTenant - Information about a tenant managing the subscription. type ManagedByTenant struct { // READ-ONLY; The tenant ID of the managing tenant. This is a GUID. @@ -303,14 +229,6 @@ type OperationListResult struct { Value []*Operation `json:"value,omitempty"` } -// MarshalJSON implements the json.Marshaller interface for type OperationListResult. -func (o OperationListResult) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]interface{}) - populate(objectMap, "nextLink", o.NextLink) - populate(objectMap, "value", o.Value) - return json.Marshal(objectMap) -} - // PairedRegion - Information regarding paired region. type PairedRegion struct { // READ-ONLY; The fully qualified ID of the location. For example, /subscriptions/00000000-0000-0000-0000-000000000000/locations/westus. @@ -372,21 +290,6 @@ type Subscription struct { TenantID *string `json:"tenantId,omitempty" azure:"ro"` } -// MarshalJSON implements the json.Marshaller interface for type Subscription. -func (s Subscription) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]interface{}) - populate(objectMap, "authorizationSource", s.AuthorizationSource) - populate(objectMap, "displayName", s.DisplayName) - populate(objectMap, "id", s.ID) - populate(objectMap, "managedByTenants", s.ManagedByTenants) - populate(objectMap, "state", s.State) - populate(objectMap, "subscriptionId", s.SubscriptionID) - populate(objectMap, "subscriptionPolicies", s.SubscriptionPolicies) - populate(objectMap, "tags", s.Tags) - populate(objectMap, "tenantId", s.TenantID) - return json.Marshal(objectMap) -} - // SubscriptionClientCheckResourceNameOptions contains the optional parameters for the SubscriptionClient.CheckResourceName // method. type SubscriptionClientCheckResourceNameOptions struct { @@ -403,14 +306,6 @@ type SubscriptionListResult struct { Value []*Subscription `json:"value,omitempty"` } -// MarshalJSON implements the json.Marshaller interface for type SubscriptionListResult. -func (s SubscriptionListResult) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]interface{}) - populate(objectMap, "nextLink", s.NextLink) - populate(objectMap, "value", s.Value) - return json.Marshal(objectMap) -} - // SubscriptionPolicies - Subscription policies. type SubscriptionPolicies struct { // READ-ONLY; The subscription location placement ID. The ID indicates which regions are visible for a subscription. For example, @@ -458,22 +353,6 @@ type TenantIDDescription struct { TenantType *string `json:"tenantType,omitempty" azure:"ro"` } -// MarshalJSON implements the json.Marshaller interface for type TenantIDDescription. -func (t TenantIDDescription) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]interface{}) - populate(objectMap, "country", t.Country) - populate(objectMap, "countryCode", t.CountryCode) - populate(objectMap, "defaultDomain", t.DefaultDomain) - populate(objectMap, "displayName", t.DisplayName) - populate(objectMap, "domains", t.Domains) - populate(objectMap, "id", t.ID) - populate(objectMap, "tenantBrandingLogoUrl", t.TenantBrandingLogoURL) - populate(objectMap, "tenantCategory", t.TenantCategory) - populate(objectMap, "tenantId", t.TenantID) - populate(objectMap, "tenantType", t.TenantType) - return json.Marshal(objectMap) -} - // TenantListResult - Tenant Ids information. type TenantListResult struct { // REQUIRED; The URL to use for getting the next set of results. @@ -483,25 +362,7 @@ type TenantListResult struct { Value []*TenantIDDescription `json:"value,omitempty"` } -// MarshalJSON implements the json.Marshaller interface for type TenantListResult. -func (t TenantListResult) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]interface{}) - populate(objectMap, "nextLink", t.NextLink) - populate(objectMap, "value", t.Value) - return json.Marshal(objectMap) -} - // TenantsClientListOptions contains the optional parameters for the TenantsClient.List method. type TenantsClientListOptions struct { // placeholder for future optional parameters } - -func populate(m map[string]interface{}, k string, v interface{}) { - if v == nil { - return - } else if azcore.IsNullValue(v) { - m[k] = nil - } else if !reflect.ValueOf(v).IsNil() { - m[k] = v - } -} diff --git a/sdk/resourcemanager/resources/armsubscriptions/zz_generated_models_serde.go b/sdk/resourcemanager/resources/armsubscriptions/zz_generated_models_serde.go new file mode 100644 index 000000000000..8f58824ef126 --- /dev/null +++ b/sdk/resourcemanager/resources/armsubscriptions/zz_generated_models_serde.go @@ -0,0 +1,148 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armsubscriptions + +import ( + "encoding/json" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" +) + +// MarshalJSON implements the json.Marshaller interface for type AvailabilityZonePeers. +func (a AvailabilityZonePeers) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "availabilityZone", a.AvailabilityZone) + populate(objectMap, "peers", a.Peers) + return json.Marshal(objectMap) +} + +// MarshalJSON implements the json.Marshaller interface for type CheckZonePeersRequest. +func (c CheckZonePeersRequest) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "location", c.Location) + populate(objectMap, "subscriptionIds", c.SubscriptionIDs) + return json.Marshal(objectMap) +} + +// MarshalJSON implements the json.Marshaller interface for type CheckZonePeersResult. +func (c CheckZonePeersResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "availabilityZonePeers", c.AvailabilityZonePeers) + populate(objectMap, "location", c.Location) + populate(objectMap, "subscriptionId", c.SubscriptionID) + return json.Marshal(objectMap) +} + +// MarshalJSON implements the json.Marshaller interface for type ErrorDetail. +func (e ErrorDetail) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "additionalInfo", e.AdditionalInfo) + populate(objectMap, "code", e.Code) + populate(objectMap, "details", e.Details) + populate(objectMap, "message", e.Message) + populate(objectMap, "target", e.Target) + return json.Marshal(objectMap) +} + +// MarshalJSON implements the json.Marshaller interface for type ErrorResponse. +func (e ErrorResponse) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "additionalInfo", e.AdditionalInfo) + populate(objectMap, "code", e.Code) + populate(objectMap, "details", e.Details) + populate(objectMap, "message", e.Message) + populate(objectMap, "target", e.Target) + return json.Marshal(objectMap) +} + +// MarshalJSON implements the json.Marshaller interface for type LocationListResult. +func (l LocationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "value", l.Value) + return json.Marshal(objectMap) +} + +// MarshalJSON implements the json.Marshaller interface for type LocationMetadata. +func (l LocationMetadata) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "geographyGroup", l.GeographyGroup) + populate(objectMap, "homeLocation", l.HomeLocation) + populate(objectMap, "latitude", l.Latitude) + populate(objectMap, "longitude", l.Longitude) + populate(objectMap, "pairedRegion", l.PairedRegion) + populate(objectMap, "physicalLocation", l.PhysicalLocation) + populate(objectMap, "regionCategory", l.RegionCategory) + populate(objectMap, "regionType", l.RegionType) + return json.Marshal(objectMap) +} + +// MarshalJSON implements the json.Marshaller interface for type OperationListResult. +func (o OperationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", o.NextLink) + populate(objectMap, "value", o.Value) + return json.Marshal(objectMap) +} + +// MarshalJSON implements the json.Marshaller interface for type Subscription. +func (s Subscription) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "authorizationSource", s.AuthorizationSource) + populate(objectMap, "displayName", s.DisplayName) + populate(objectMap, "id", s.ID) + populate(objectMap, "managedByTenants", s.ManagedByTenants) + populate(objectMap, "state", s.State) + populate(objectMap, "subscriptionId", s.SubscriptionID) + populate(objectMap, "subscriptionPolicies", s.SubscriptionPolicies) + populate(objectMap, "tags", s.Tags) + populate(objectMap, "tenantId", s.TenantID) + return json.Marshal(objectMap) +} + +// MarshalJSON implements the json.Marshaller interface for type SubscriptionListResult. +func (s SubscriptionListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", s.NextLink) + populate(objectMap, "value", s.Value) + return json.Marshal(objectMap) +} + +// MarshalJSON implements the json.Marshaller interface for type TenantIDDescription. +func (t TenantIDDescription) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "country", t.Country) + populate(objectMap, "countryCode", t.CountryCode) + populate(objectMap, "defaultDomain", t.DefaultDomain) + populate(objectMap, "displayName", t.DisplayName) + populate(objectMap, "domains", t.Domains) + populate(objectMap, "id", t.ID) + populate(objectMap, "tenantBrandingLogoUrl", t.TenantBrandingLogoURL) + populate(objectMap, "tenantCategory", t.TenantCategory) + populate(objectMap, "tenantId", t.TenantID) + populate(objectMap, "tenantType", t.TenantType) + return json.Marshal(objectMap) +} + +// MarshalJSON implements the json.Marshaller interface for type TenantListResult. +func (t TenantListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", t.NextLink) + populate(objectMap, "value", t.Value) + return json.Marshal(objectMap) +} + +func populate(m map[string]interface{}, k string, v interface{}) { + if v == nil { + return + } else if azcore.IsNullValue(v) { + m[k] = nil + } else if !reflect.ValueOf(v).IsNil() { + m[k] = v + } +} diff --git a/sdk/resourcemanager/resources/armsubscriptions/zz_generated_pagers.go b/sdk/resourcemanager/resources/armsubscriptions/zz_generated_pagers.go deleted file mode 100644 index 0ab8d66b623f..000000000000 --- a/sdk/resourcemanager/resources/armsubscriptions/zz_generated_pagers.go +++ /dev/null @@ -1,125 +0,0 @@ -//go:build go1.16 -// +build go1.16 - -// 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. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -package armsubscriptions - -import ( - "context" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" - "net/http" - "reflect" -) - -// ClientListPager provides operations for iterating over paged responses. -type ClientListPager struct { - client *Client - current ClientListResponse - err error - requester func(context.Context) (*policy.Request, error) - advancer func(context.Context, ClientListResponse) (*policy.Request, error) -} - -// Err returns the last error encountered while paging. -func (p *ClientListPager) Err() error { - return p.err -} - -// NextPage returns true if the pager advanced to the next page. -// Returns false if there are no more pages or an error occurred. -func (p *ClientListPager) NextPage(ctx context.Context) bool { - var req *policy.Request - var err error - if !reflect.ValueOf(p.current).IsZero() { - if p.current.SubscriptionListResult.NextLink == nil || len(*p.current.SubscriptionListResult.NextLink) == 0 { - return false - } - req, err = p.advancer(ctx, p.current) - } else { - req, err = p.requester(ctx) - } - if err != nil { - p.err = err - return false - } - resp, err := p.client.pl.Do(req) - if err != nil { - p.err = err - return false - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - p.err = runtime.NewResponseError(resp) - return false - } - result, err := p.client.listHandleResponse(resp) - if err != nil { - p.err = err - return false - } - p.current = result - return true -} - -// PageResponse returns the current ClientListResponse page. -func (p *ClientListPager) PageResponse() ClientListResponse { - return p.current -} - -// TenantsClientListPager provides operations for iterating over paged responses. -type TenantsClientListPager struct { - client *TenantsClient - current TenantsClientListResponse - err error - requester func(context.Context) (*policy.Request, error) - advancer func(context.Context, TenantsClientListResponse) (*policy.Request, error) -} - -// Err returns the last error encountered while paging. -func (p *TenantsClientListPager) Err() error { - return p.err -} - -// NextPage returns true if the pager advanced to the next page. -// Returns false if there are no more pages or an error occurred. -func (p *TenantsClientListPager) NextPage(ctx context.Context) bool { - var req *policy.Request - var err error - if !reflect.ValueOf(p.current).IsZero() { - if p.current.TenantListResult.NextLink == nil || len(*p.current.TenantListResult.NextLink) == 0 { - return false - } - req, err = p.advancer(ctx, p.current) - } else { - req, err = p.requester(ctx) - } - if err != nil { - p.err = err - return false - } - resp, err := p.client.pl.Do(req) - if err != nil { - p.err = err - return false - } - if !runtime.HasStatusCode(resp, http.StatusOK) { - p.err = runtime.NewResponseError(resp) - return false - } - result, err := p.client.listHandleResponse(resp) - if err != nil { - p.err = err - return false - } - p.current = result - return true -} - -// PageResponse returns the current TenantsClientListResponse page. -func (p *TenantsClientListPager) PageResponse() TenantsClientListResponse { - return p.current -} diff --git a/sdk/resourcemanager/resources/armsubscriptions/zz_generated_response_types.go b/sdk/resourcemanager/resources/armsubscriptions/zz_generated_response_types.go index 97ab892d3696..8735464b1506 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/zz_generated_response_types.go +++ b/sdk/resourcemanager/resources/armsubscriptions/zz_generated_response_types.go @@ -1,5 +1,5 @@ -//go:build go1.16 -// +build go1.16 +//go:build go1.18 +// +build go1.18 // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. @@ -8,76 +8,32 @@ package armsubscriptions -import "net/http" - // ClientCheckZonePeersResponse contains the response from method Client.CheckZonePeers. type ClientCheckZonePeersResponse struct { - ClientCheckZonePeersResult - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - -// ClientCheckZonePeersResult contains the result from method Client.CheckZonePeers. -type ClientCheckZonePeersResult struct { CheckZonePeersResult } // ClientGetResponse contains the response from method Client.Get. type ClientGetResponse struct { - ClientGetResult - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - -// ClientGetResult contains the result from method Client.Get. -type ClientGetResult struct { Subscription } // ClientListLocationsResponse contains the response from method Client.ListLocations. type ClientListLocationsResponse struct { - ClientListLocationsResult - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - -// ClientListLocationsResult contains the result from method Client.ListLocations. -type ClientListLocationsResult struct { LocationListResult } // ClientListResponse contains the response from method Client.List. type ClientListResponse struct { - ClientListResult - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - -// ClientListResult contains the result from method Client.List. -type ClientListResult struct { SubscriptionListResult } // SubscriptionClientCheckResourceNameResponse contains the response from method SubscriptionClient.CheckResourceName. type SubscriptionClientCheckResourceNameResponse struct { - SubscriptionClientCheckResourceNameResult - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - -// SubscriptionClientCheckResourceNameResult contains the result from method SubscriptionClient.CheckResourceName. -type SubscriptionClientCheckResourceNameResult struct { CheckResourceNameResult } // TenantsClientListResponse contains the response from method TenantsClient.List. type TenantsClientListResponse struct { - TenantsClientListResult - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - -// TenantsClientListResult contains the result from method TenantsClient.List. -type TenantsClientListResult struct { TenantListResult } diff --git a/sdk/resourcemanager/resources/armsubscriptions/zz_generated_subscription_client.go b/sdk/resourcemanager/resources/armsubscriptions/zz_generated_subscription_client.go index e7b8d3c09328..3dc03b9b322b 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/zz_generated_subscription_client.go +++ b/sdk/resourcemanager/resources/armsubscriptions/zz_generated_subscription_client.go @@ -1,5 +1,5 @@ -//go:build go1.16 -// +build go1.16 +//go:build go1.18 +// +build go1.18 // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. @@ -13,6 +13,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "net/http" @@ -28,19 +29,23 @@ type SubscriptionClient struct { // NewSubscriptionClient creates a new instance of SubscriptionClient with the specified values. // credential - used to authorize requests. Usually a credential from azidentity. // options - pass nil to accept the default values. -func NewSubscriptionClient(credential azcore.TokenCredential, options *arm.ClientOptions) *SubscriptionClient { - cp := arm.ClientOptions{} - if options != nil { - cp = *options +func NewSubscriptionClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*SubscriptionClient, error) { + if options == nil { + options = &arm.ClientOptions{} } - if len(cp.Endpoint) == 0 { - cp.Endpoint = arm.AzurePublicCloud + ep := cloud.AzurePublicCloud.Services[cloud.ResourceManager].Endpoint + if c, ok := options.Cloud.Services[cloud.ResourceManager]; ok { + ep = c.Endpoint + } + pl, err := armruntime.NewPipeline(moduleName, moduleVersion, credential, runtime.PipelineOptions{}, options) + if err != nil { + return nil, err } client := &SubscriptionClient{ - host: string(cp.Endpoint), - pl: armruntime.NewPipeline(moduleName, moduleVersion, credential, runtime.PipelineOptions{}, &cp), + host: ep, + pl: pl, } - return client + return client, nil } // CheckResourceName - A resource name is valid if it is not a reserved word, does not contains a reserved word and does not @@ -82,7 +87,7 @@ func (client *SubscriptionClient) checkResourceNameCreateRequest(ctx context.Con // checkResourceNameHandleResponse handles the CheckResourceName response. func (client *SubscriptionClient) checkResourceNameHandleResponse(resp *http.Response) (SubscriptionClientCheckResourceNameResponse, error) { - result := SubscriptionClientCheckResourceNameResponse{RawResponse: resp} + result := SubscriptionClientCheckResourceNameResponse{} if err := runtime.UnmarshalAsJSON(resp, &result.CheckResourceNameResult); err != nil { return SubscriptionClientCheckResourceNameResponse{}, err } diff --git a/sdk/resourcemanager/resources/armsubscriptions/zz_generated_tenants_client.go b/sdk/resourcemanager/resources/armsubscriptions/zz_generated_tenants_client.go index fd6c34830188..aa2ee57c287f 100644 --- a/sdk/resourcemanager/resources/armsubscriptions/zz_generated_tenants_client.go +++ b/sdk/resourcemanager/resources/armsubscriptions/zz_generated_tenants_client.go @@ -1,5 +1,5 @@ -//go:build go1.16 -// +build go1.16 +//go:build go1.18 +// +build go1.18 // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. @@ -13,6 +13,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "net/http" @@ -28,34 +29,54 @@ type TenantsClient struct { // NewTenantsClient creates a new instance of TenantsClient with the specified values. // credential - used to authorize requests. Usually a credential from azidentity. // options - pass nil to accept the default values. -func NewTenantsClient(credential azcore.TokenCredential, options *arm.ClientOptions) *TenantsClient { - cp := arm.ClientOptions{} - if options != nil { - cp = *options +func NewTenantsClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*TenantsClient, error) { + if options == nil { + options = &arm.ClientOptions{} } - if len(cp.Endpoint) == 0 { - cp.Endpoint = arm.AzurePublicCloud + ep := cloud.AzurePublicCloud.Services[cloud.ResourceManager].Endpoint + if c, ok := options.Cloud.Services[cloud.ResourceManager]; ok { + ep = c.Endpoint + } + pl, err := armruntime.NewPipeline(moduleName, moduleVersion, credential, runtime.PipelineOptions{}, options) + if err != nil { + return nil, err } client := &TenantsClient{ - host: string(cp.Endpoint), - pl: armruntime.NewPipeline(moduleName, moduleVersion, credential, runtime.PipelineOptions{}, &cp), + host: ep, + pl: pl, } - return client + return client, nil } // List - Gets the tenants for your account. // If the operation fails it returns an *azcore.ResponseError type. // options - TenantsClientListOptions contains the optional parameters for the TenantsClient.List method. -func (client *TenantsClient) List(options *TenantsClientListOptions) *TenantsClientListPager { - return &TenantsClientListPager{ - client: client, - requester: func(ctx context.Context) (*policy.Request, error) { - return client.listCreateRequest(ctx, options) +func (client *TenantsClient) List(options *TenantsClientListOptions) *runtime.Pager[TenantsClientListResponse] { + return runtime.NewPager(runtime.PageProcessor[TenantsClientListResponse]{ + More: func(page TenantsClientListResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 }, - advancer: func(ctx context.Context, resp TenantsClientListResponse) (*policy.Request, error) { - return runtime.NewRequest(ctx, http.MethodGet, *resp.TenantListResult.NextLink) + Fetcher: func(ctx context.Context, page *TenantsClientListResponse) (TenantsClientListResponse, error) { + var req *policy.Request + var err error + if page == nil { + req, err = client.listCreateRequest(ctx, options) + } else { + req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + } + if err != nil { + return TenantsClientListResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return TenantsClientListResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return TenantsClientListResponse{}, runtime.NewResponseError(resp) + } + return client.listHandleResponse(resp) }, - } + }) } // listCreateRequest creates the List request. @@ -74,7 +95,7 @@ func (client *TenantsClient) listCreateRequest(ctx context.Context, options *Ten // listHandleResponse handles the List response. func (client *TenantsClient) listHandleResponse(resp *http.Response) (TenantsClientListResponse, error) { - result := TenantsClientListResponse{RawResponse: resp} + result := TenantsClientListResponse{} if err := runtime.UnmarshalAsJSON(resp, &result.TenantListResult); err != nil { return TenantsClientListResponse{}, err }