From dd55311d0c0372bd45e63b8168bbf864acae022d Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Wed, 14 Aug 2024 23:51:10 +0000 Subject: [PATCH] CodeGen from PR 29912 in Azure/azure-rest-api-specs Merge d64572e92b815d47de3ffcdbcc37c75fab0375da into 9778042723206fbc582306dcb407bddbd73df005 --- .../subscription/armsubscription/CHANGELOG.md | 13 ++ .../alias_client_example_test.go | 198 ------------------ .../subscription/armsubscription/autorest.md | 6 +- .../billingaccount_client_example_test.go | 51 ----- .../armsubscription/client_example_test.go | 150 ------------- .../armsubscription/client_factory.go | 50 +++-- .../subscription/armsubscription/constants.go | 20 +- .../armsubscription/fake/operation_server.go | 103 +++++++++ .../armsubscription/fake/server_factory.go | 5 + .../armsubscription/fake/time_rfc3339.go | 42 +++- .../subscription/armsubscription/go.mod | 12 +- .../subscription/armsubscription/go.sum | 17 -- .../subscription/armsubscription/models.go | 36 ++++ .../armsubscription/models_serde.go | 69 +++++- .../armsubscription/operation_client.go | 107 ++++++++++ .../operations_client_example_test.go | 55 ----- .../subscription/armsubscription/options.go | 5 + .../policy_client_example_test.go | 132 ------------ .../{response_types.go => responses.go} | 12 ++ .../subscriptions_client_example_test.go | 132 ------------ .../tenants_client_example_test.go | 54 ----- .../armsubscription/time_rfc3339.go | 42 +++- 22 files changed, 469 insertions(+), 842 deletions(-) delete mode 100644 sdk/resourcemanager/subscription/armsubscription/alias_client_example_test.go delete mode 100644 sdk/resourcemanager/subscription/armsubscription/billingaccount_client_example_test.go delete mode 100644 sdk/resourcemanager/subscription/armsubscription/client_example_test.go create mode 100644 sdk/resourcemanager/subscription/armsubscription/fake/operation_server.go create mode 100644 sdk/resourcemanager/subscription/armsubscription/operation_client.go delete mode 100644 sdk/resourcemanager/subscription/armsubscription/operations_client_example_test.go delete mode 100644 sdk/resourcemanager/subscription/armsubscription/policy_client_example_test.go rename sdk/resourcemanager/subscription/armsubscription/{response_types.go => responses.go} (91%) delete mode 100644 sdk/resourcemanager/subscription/armsubscription/subscriptions_client_example_test.go delete mode 100644 sdk/resourcemanager/subscription/armsubscription/tenants_client_example_test.go diff --git a/sdk/resourcemanager/subscription/armsubscription/CHANGELOG.md b/sdk/resourcemanager/subscription/armsubscription/CHANGELOG.md index 7d5fbb80c76d..61e5cbff1567 100644 --- a/sdk/resourcemanager/subscription/armsubscription/CHANGELOG.md +++ b/sdk/resourcemanager/subscription/armsubscription/CHANGELOG.md @@ -1,5 +1,18 @@ # Release History +## 1.3.0 (2024-08-14) +### Features Added + +- New enum type `Provisioning` with values `ProvisioningAccepted`, `ProvisioningPending`, `ProvisioningSucceeded` +- New function `*ClientFactory.NewOperationClient() *OperationClient` +- New function `NewOperationClient(azcore.TokenCredential, *arm.ClientOptions) (*OperationClient, error)` +- New function `*OperationClient.Get(context.Context, string, *OperationClientGetOptions) (OperationClientGetResponse, error)` +- New struct `CreationResult` +- New field `ProvisioningState` in struct `AcceptOwnershipStatusResponse` +- New field `Tags`, `TenantID` in struct `Subscription` +- New field `Country`, `CountryCode`, `DefaultDomain`, `DisplayName`, `Domains`, `TenantCategory`, `TenantType` in struct `TenantIDDescription` + + ## 1.2.0 (2023-11-24) ### Features Added diff --git a/sdk/resourcemanager/subscription/armsubscription/alias_client_example_test.go b/sdk/resourcemanager/subscription/armsubscription/alias_client_example_test.go deleted file mode 100644 index 8f92bacc68e7..000000000000 --- a/sdk/resourcemanager/subscription/armsubscription/alias_client_example_test.go +++ /dev/null @@ -1,198 +0,0 @@ -//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. -// DO NOT EDIT. - -package armsubscription_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/subscription/armsubscription" -) - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2021-10-01/examples/createAlias.json -func ExampleAliasClient_BeginCreate() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - poller, err := clientFactory.NewAliasClient().BeginCreate(ctx, "aliasForNewSub", armsubscription.PutAliasRequest{ - Properties: &armsubscription.PutAliasRequestProperties{ - AdditionalProperties: &armsubscription.PutAliasRequestAdditionalProperties{ - SubscriptionOwnerID: to.Ptr("f09b39eb-c496-482c-9ab9-afd799572f4c"), - SubscriptionTenantID: to.Ptr("66f6e4d6-07dc-4aea-94ea-e12d3026a3c8"), - Tags: map[string]*string{ - "tag1": to.Ptr("Messi"), - "tag2": to.Ptr("Ronaldo"), - "tag3": to.Ptr("Lebron"), - }, - }, - BillingScope: to.Ptr("/billingAccounts/af6231a7-7f8d-4fcc-a993-dd8466108d07:c663dac6-a9a5-405a-8938-cd903e12ab5b_2019_05_31/billingProfiles/QWDQ-QWHI-AUW-SJDO-DJH/invoiceSections/FEUF-EUHE-ISJ-SKDW-DJH"), - DisplayName: to.Ptr("Test Subscription"), - Workload: to.Ptr(armsubscription.WorkloadProduction), - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - res, err := poller.PollUntilDone(ctx, nil) - if err != nil { - log.Fatalf("failed to pull the result: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.AliasResponse = armsubscription.AliasResponse{ - // Name: to.Ptr("string"), - // Type: to.Ptr("string"), - // ID: to.Ptr("string"), - // Properties: &armsubscription.AliasResponseProperties{ - // AcceptOwnershipState: to.Ptr(armsubscription.AcceptOwnershipPending), - // AcceptOwnershipURL: to.Ptr("/providers/Microsoft.Subscription/e2283d0f-acad-4904-b803-627dd74cc072/acceptOwnership"), - // BillingScope: to.Ptr("/billingAccounts/af6231a7-7f8d-4fcc-a993-dd8466108d07:c663dac6-a9a5-405a-8938-cd903e12ab5b_2019_05_31/billingProfiles/QWDQ-QWHI-AUW-SJDO-DJH/invoiceSections/FEUF-EUHE-ISJ-SKDW-DJH"), - // DisplayName: to.Ptr("Test Subscription"), - // ProvisioningState: to.Ptr(armsubscription.ProvisioningStateSucceeded), - // SubscriptionID: to.Ptr("e2283d0f-acad-4904-b803-627dd74cc072"), - // SubscriptionOwnerID: to.Ptr("f09b39eb-c496-482c-9ab9-afd799572f4c"), - // Tags: map[string]*string{ - // "tag1": to.Ptr("Messi"), - // "tag2": to.Ptr("Ronaldo"), - // "tag3": to.Ptr("Lebron"), - // }, - // Workload: to.Ptr(armsubscription.WorkloadProduction), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2021-10-01/examples/getAlias.json -func ExampleAliasClient_Get() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewAliasClient().Get(ctx, "aliasForNewSub", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.AliasResponse = armsubscription.AliasResponse{ - // Name: to.Ptr("string"), - // Type: to.Ptr("string"), - // ID: to.Ptr("string"), - // Properties: &armsubscription.AliasResponseProperties{ - // AcceptOwnershipState: to.Ptr(armsubscription.AcceptOwnershipPending), - // AcceptOwnershipURL: to.Ptr("/providers/Microsoft.Subscription/e2283d0f-acad-4904-b803-627dd74cc072/acceptOwnership"), - // BillingScope: to.Ptr("/billingAccounts/af6231a7-7f8d-4fcc-a993-dd8466108d07:c663dac6-a9a5-405a-8938-cd903e12ab5b_2019_05_31/billingProfiles/QWDQ-QWHI-AUW-SJDO-DJH/invoiceSections/FEUF-EUHE-ISJ-SKDW-DJH"), - // DisplayName: to.Ptr("Test Subscription"), - // ProvisioningState: to.Ptr(armsubscription.ProvisioningStateSucceeded), - // SubscriptionID: to.Ptr("e2283d0f-acad-4904-b803-627dd74cc072"), - // SubscriptionOwnerID: to.Ptr("f09b39eb-c496-482c-9ab9-afd799572f4c"), - // Tags: map[string]*string{ - // "tag1": to.Ptr("Messi"), - // "tag2": to.Ptr("Ronaldo"), - // "tag3": to.Ptr("Lebron"), - // }, - // Workload: to.Ptr(armsubscription.WorkloadProduction), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2021-10-01/examples/deleteAlias.json -func ExampleAliasClient_Delete() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewAliasClient().Delete(ctx, "aliasForNewSub", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2021-10-01/examples/listAlias.json -func ExampleAliasClient_List() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewAliasClient().List(ctx, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.AliasListResult = armsubscription.AliasListResult{ - // Value: []*armsubscription.AliasResponse{ - // { - // Name: to.Ptr("string"), - // Type: to.Ptr("string"), - // ID: to.Ptr("string"), - // Properties: &armsubscription.AliasResponseProperties{ - // AcceptOwnershipState: to.Ptr(armsubscription.AcceptOwnershipPending), - // AcceptOwnershipURL: to.Ptr("/providers/Microsoft.Subscription/e2283d0f-acad-4904-b803-627dd74cc072/acceptOwnership"), - // BillingScope: to.Ptr("/billingAccounts/af6231a7-7f8d-4fcc-a993-dd8466108d07:c663dac6-a9a5-405a-8938-cd903e12ab5b_2019_05_31/billingProfiles/QWDQ-QWHI-AUW-SJDO-DJH/invoiceSections/FEUF-EUHE-ISJ-SKDW-DJH"), - // DisplayName: to.Ptr("Test Subscription"), - // ProvisioningState: to.Ptr(armsubscription.ProvisioningStateSucceeded), - // SubscriptionID: to.Ptr("e2283d0f-acad-4904-b803-627dd74cc072"), - // SubscriptionOwnerID: to.Ptr("f09b39eb-c496-482c-9ab9-afd799572f4c"), - // Tags: map[string]*string{ - // "tag1": to.Ptr("Messi"), - // "tag2": to.Ptr("Ronaldo"), - // "tag3": to.Ptr("Lebron"), - // }, - // Workload: to.Ptr(armsubscription.WorkloadProduction), - // }, - // }, - // { - // Name: to.Ptr("string"), - // Type: to.Ptr("string"), - // ID: to.Ptr("string"), - // Properties: &armsubscription.AliasResponseProperties{ - // AcceptOwnershipState: to.Ptr(armsubscription.AcceptOwnershipPending), - // AcceptOwnershipURL: to.Ptr("/providers/Microsoft.Subscription/091c6e56-a835-4422-a082-0427308ca9ee/acceptOwnership"), - // BillingScope: to.Ptr("/billingAccounts/af6231a7-7f8d-4fcc-a993-dd8466108d07:c663dac6-a9a5-405a-8938-cd903e12ab5b_2019_05_31/billingProfiles/QWDQ-QWHI-AUW-SJDO-DJH/invoiceSections/FEUF-EUHE-ISJ-SKDW-DJH"), - // DisplayName: to.Ptr("Test Subscription 2"), - // ProvisioningState: to.Ptr(armsubscription.ProvisioningStateSucceeded), - // SubscriptionID: to.Ptr("091c6e56-a835-4422-a082-0427308ca9ee"), - // SubscriptionOwnerID: to.Ptr("f09b39eb-c496-482c-9ab9-afd799572f4c"), - // Tags: map[string]*string{ - // "tag1": to.Ptr("Messi2"), - // "tag2": to.Ptr("Ronaldo2"), - // "tag3": to.Ptr("Lebron2"), - // }, - // Workload: to.Ptr(armsubscription.WorkloadProduction), - // }, - // }}, - // } -} diff --git a/sdk/resourcemanager/subscription/armsubscription/autorest.md b/sdk/resourcemanager/subscription/armsubscription/autorest.md index 927862913586..d190dc33f0c6 100644 --- a/sdk/resourcemanager/subscription/armsubscription/autorest.md +++ b/sdk/resourcemanager/subscription/armsubscription/autorest.md @@ -5,9 +5,9 @@ ``` yaml azure-arm: true require: -- https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/readme.md -- https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/readme.go.md +- /mnt/vss/_work/1/s/azure-rest-api-specs/specification/subscription/resource-manager/readme.md +- /mnt/vss/_work/1/s/azure-rest-api-specs/specification/subscription/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 1.2.0 +module-version: 1.3.0 ``` \ No newline at end of file diff --git a/sdk/resourcemanager/subscription/armsubscription/billingaccount_client_example_test.go b/sdk/resourcemanager/subscription/armsubscription/billingaccount_client_example_test.go deleted file mode 100644 index 57ae7cb207c9..000000000000 --- a/sdk/resourcemanager/subscription/armsubscription/billingaccount_client_example_test.go +++ /dev/null @@ -1,51 +0,0 @@ -//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. -// DO NOT EDIT. - -package armsubscription_test - -import ( - "context" - "log" - - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription" -) - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2021-10-01/examples/getBillingAccountPolicy.json -func ExampleBillingAccountClient_GetPolicy() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewBillingAccountClient().GetPolicy(ctx, "testBillingAccountId", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.BillingAccountPoliciesResponse = armsubscription.BillingAccountPoliciesResponse{ - // Name: to.Ptr("testBillingAccountId"), - // Type: to.Ptr("Microsoft.Subscription/policies"), - // ID: to.Ptr("/providers/Microsoft.Subscription/Policies/policyForBillingAccount"), - // Properties: &armsubscription.BillingAccountPoliciesResponseProperties{ - // AllowTransfers: to.Ptr(true), - // ServiceTenants: []*armsubscription.ServiceTenantResponse{ - // { - // TenantID: to.Ptr("b8ed2088-c458-4e77-bd61-9e048d96a1c0"), - // TenantName: to.Ptr("testServiceTenant"), - // }}, - // }, - // } -} diff --git a/sdk/resourcemanager/subscription/armsubscription/client_example_test.go b/sdk/resourcemanager/subscription/armsubscription/client_example_test.go deleted file mode 100644 index 080d84bbb0f6..000000000000 --- a/sdk/resourcemanager/subscription/armsubscription/client_example_test.go +++ /dev/null @@ -1,150 +0,0 @@ -//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. -// DO NOT EDIT. - -package armsubscription_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/subscription/armsubscription" -) - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2021-10-01/examples/cancelSubscription.json -func ExampleClient_Cancel() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewClient().Cancel(ctx, "83aa47df-e3e9-49ff-877b-94304bf3d3ad", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.CanceledSubscriptionID = armsubscription.CanceledSubscriptionID{ - // SubscriptionID: to.Ptr("83aa47df-e3e9-49ff-877b-94304bf3d3ad"), - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2021-10-01/examples/renameSubscription.json -func ExampleClient_Rename() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewClient().Rename(ctx, "83aa47df-e3e9-49ff-877b-94304bf3d3ad", armsubscription.Name{ - SubscriptionName: to.Ptr("Test Sub"), - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.RenamedSubscriptionID = armsubscription.RenamedSubscriptionID{ - // SubscriptionID: to.Ptr("83aa47df-e3e9-49ff-877b-94304bf3d3ad"), - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2021-10-01/examples/enableSubscription.json -func ExampleClient_Enable() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewClient().Enable(ctx, "7948bcee-488c-47ce-941c-38e20ede803d", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.EnabledSubscriptionID = armsubscription.EnabledSubscriptionID{ - // SubscriptionID: to.Ptr("7948bcee-488c-47ce-941c-38e20ede803d"), - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2021-10-01/examples/acceptSubscriptionOwnership.json -func ExampleClient_BeginAcceptOwnership() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - poller, err := clientFactory.NewClient().BeginAcceptOwnership(ctx, "291bba3f-e0a5-47bc-a099-3bdcb2a50a05", armsubscription.AcceptOwnershipRequest{ - Properties: &armsubscription.AcceptOwnershipRequestProperties{ - DisplayName: to.Ptr("Test Subscription"), - Tags: map[string]*string{ - "tag1": to.Ptr("Messi"), - "tag2": to.Ptr("Ronaldo"), - "tag3": to.Ptr("Lebron"), - }, - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - _, err = poller.PollUntilDone(ctx, nil) - if err != nil { - log.Fatalf("failed to pull the result: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2021-10-01/examples/acceptOwnershipStatus.json -func ExampleClient_AcceptOwnershipStatus() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewClient().AcceptOwnershipStatus(ctx, "291bba3f-e0a5-47bc-a099-3bdcb2a50a05", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.AcceptOwnershipStatusResponse = armsubscription.AcceptOwnershipStatusResponse{ - // AcceptOwnershipState: to.Ptr(armsubscription.AcceptOwnershipPending), - // BillingOwner: to.Ptr("abc@test.com"), - // DisplayName: to.Ptr("Test Subscription"), - // SubscriptionID: to.Ptr("291bba3f-e0a5-47bc-a099-3bdcb2a50a05"), - // SubscriptionTenantID: to.Ptr("6c541ca7-1cab-4ea0-adde-6305e1d534e2"), - // Tags: map[string]*string{ - // "tag1": to.Ptr("TagValue1"), - // }, - // } -} diff --git a/sdk/resourcemanager/subscription/armsubscription/client_factory.go b/sdk/resourcemanager/subscription/armsubscription/client_factory.go index 0a86ece29d66..64247dcc53d7 100644 --- a/sdk/resourcemanager/subscription/armsubscription/client_factory.go +++ b/sdk/resourcemanager/subscription/armsubscription/client_factory.go @@ -16,8 +16,7 @@ import ( // 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 { - credential azcore.TokenCredential - options *arm.ClientOptions + internal *arm.Client } // NewClientFactory creates a new instance of ClientFactory with the specified values. @@ -25,54 +24,67 @@ type ClientFactory struct { // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. func NewClientFactory(credential azcore.TokenCredential, options *arm.ClientOptions) (*ClientFactory, error) { - _, err := arm.NewClient(moduleName, moduleVersion, credential, options) + internal, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } return &ClientFactory{ - credential: credential, - options: options.Clone(), + internal: internal, }, nil } // NewAliasClient creates a new instance of AliasClient. func (c *ClientFactory) NewAliasClient() *AliasClient { - subClient, _ := NewAliasClient(c.credential, c.options) - return subClient + return &AliasClient{ + internal: c.internal, + } } // NewBillingAccountClient creates a new instance of BillingAccountClient. func (c *ClientFactory) NewBillingAccountClient() *BillingAccountClient { - subClient, _ := NewBillingAccountClient(c.credential, c.options) - return subClient + return &BillingAccountClient{ + internal: c.internal, + } } // NewClient creates a new instance of Client. func (c *ClientFactory) NewClient() *Client { - subClient, _ := NewClient(c.credential, c.options) - return subClient + return &Client{ + internal: c.internal, + } +} + +// NewOperationClient creates a new instance of OperationClient. +func (c *ClientFactory) NewOperationClient() *OperationClient { + return &OperationClient{ + internal: c.internal, + } } // NewOperationsClient creates a new instance of OperationsClient. func (c *ClientFactory) NewOperationsClient() *OperationsClient { - subClient, _ := NewOperationsClient(c.credential, c.options) - return subClient + return &OperationsClient{ + internal: c.internal, + } } // NewPolicyClient creates a new instance of PolicyClient. func (c *ClientFactory) NewPolicyClient() *PolicyClient { - subClient, _ := NewPolicyClient(c.credential, c.options) - return subClient + return &PolicyClient{ + internal: c.internal, + } } // NewSubscriptionsClient creates a new instance of SubscriptionsClient. func (c *ClientFactory) NewSubscriptionsClient() *SubscriptionsClient { - subClient, _ := NewSubscriptionsClient(c.credential, c.options) - return subClient + return &SubscriptionsClient{ + internal: c.internal, + } } // NewTenantsClient creates a new instance of TenantsClient. func (c *ClientFactory) NewTenantsClient() *TenantsClient { - subClient, _ := NewTenantsClient(c.credential, c.options) - return subClient + return &TenantsClient{ + internal: c.internal, + } } diff --git a/sdk/resourcemanager/subscription/armsubscription/constants.go b/sdk/resourcemanager/subscription/armsubscription/constants.go index ec6e624886cf..b889e0d4d068 100644 --- a/sdk/resourcemanager/subscription/armsubscription/constants.go +++ b/sdk/resourcemanager/subscription/armsubscription/constants.go @@ -10,7 +10,7 @@ package armsubscription const ( moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription" - moduleVersion = "v1.2.0" + moduleVersion = "v1.3.0" ) // AcceptOwnership - The accept ownership state of the resource. @@ -51,6 +51,24 @@ func PossibleCreatedByTypeValues() []CreatedByType { } } +// Provisioning - The provisioning state of the resource. +type Provisioning string + +const ( + ProvisioningAccepted Provisioning = "Accepted" + ProvisioningPending Provisioning = "Pending" + ProvisioningSucceeded Provisioning = "Succeeded" +) + +// PossibleProvisioningValues returns the possible values for the Provisioning const type. +func PossibleProvisioningValues() []Provisioning { + return []Provisioning{ + ProvisioningAccepted, + ProvisioningPending, + ProvisioningSucceeded, + } +} + // ProvisioningState - The provisioning state of the resource. type ProvisioningState string diff --git a/sdk/resourcemanager/subscription/armsubscription/fake/operation_server.go b/sdk/resourcemanager/subscription/armsubscription/fake/operation_server.go new file mode 100644 index 000000000000..af04f9937f3f --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/fake/operation_server.go @@ -0,0 +1,103 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// OperationServer is a fake server for instances of the armsubscription.OperationClient type. +type OperationServer struct { + // Get is the fake for method OperationClient.Get + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + Get func(ctx context.Context, operationID string, options *armsubscription.OperationClientGetOptions) (resp azfake.Responder[armsubscription.OperationClientGetResponse], errResp azfake.ErrorResponder) +} + +// NewOperationServerTransport creates a new instance of OperationServerTransport with the provided implementation. +// The returned OperationServerTransport instance is connected to an instance of armsubscription.OperationClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewOperationServerTransport(srv *OperationServer) *OperationServerTransport { + return &OperationServerTransport{srv: srv} +} + +// OperationServerTransport connects instances of armsubscription.OperationClient to instances of OperationServer. +// Don't use this type directly, use NewOperationServerTransport instead. +type OperationServerTransport struct { + srv *OperationServer +} + +// Do implements the policy.Transporter interface for OperationServerTransport. +func (o *OperationServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + var resp *http.Response + var err error + + switch method { + case "OperationClient.Get": + resp, err = o.dispatchGet(req) + default: + err = fmt.Errorf("unhandled API %s", method) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func (o *OperationServerTransport) 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 = `/providers/Microsoft\.Subscription/subscriptionOperations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + operationIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")]) + if err != nil { + return nil, err + } + respr, errRespr := o.srv.Get(req.Context(), operationIDParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusAccepted}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).CreationResult, req) + if err != nil { + return nil, err + } + if val := server.GetResponse(respr).Location; val != nil { + resp.Header.Set("Location", *val) + } + if val := server.GetResponse(respr).RetryAfter; val != nil { + resp.Header.Set("Retry-After", strconv.FormatInt(*val, 10)) + } + return resp, nil +} diff --git a/sdk/resourcemanager/subscription/armsubscription/fake/server_factory.go b/sdk/resourcemanager/subscription/armsubscription/fake/server_factory.go index 50513480f10e..c39805379a0a 100644 --- a/sdk/resourcemanager/subscription/armsubscription/fake/server_factory.go +++ b/sdk/resourcemanager/subscription/armsubscription/fake/server_factory.go @@ -22,6 +22,7 @@ type ServerFactory struct { AliasServer AliasServer BillingAccountServer BillingAccountServer Server Server + OperationServer OperationServer OperationsServer OperationsServer PolicyServer PolicyServer SubscriptionsServer SubscriptionsServer @@ -45,6 +46,7 @@ type ServerFactoryTransport struct { trAliasServer *AliasServerTransport trBillingAccountServer *BillingAccountServerTransport trServer *ServerTransport + trOperationServer *OperationServerTransport trOperationsServer *OperationsServerTransport trPolicyServer *PolicyServerTransport trSubscriptionsServer *SubscriptionsServerTransport @@ -75,6 +77,9 @@ func (s *ServerFactoryTransport) Do(req *http.Request) (*http.Response, error) { case "Client": initServer(s, &s.trServer, func() *ServerTransport { return NewServerTransport(&s.srv.Server) }) resp, err = s.trServer.Do(req) + case "OperationClient": + initServer(s, &s.trOperationServer, func() *OperationServerTransport { return NewOperationServerTransport(&s.srv.OperationServer) }) + resp, err = s.trOperationServer.Do(req) case "OperationsClient": initServer(s, &s.trOperationsServer, func() *OperationsServerTransport { return NewOperationsServerTransport(&s.srv.OperationsServer) }) resp, err = s.trOperationsServer.Do(req) diff --git a/sdk/resourcemanager/subscription/armsubscription/fake/time_rfc3339.go b/sdk/resourcemanager/subscription/armsubscription/fake/time_rfc3339.go index b0535a7b63e6..81f308b0d343 100644 --- a/sdk/resourcemanager/subscription/armsubscription/fake/time_rfc3339.go +++ b/sdk/resourcemanager/subscription/armsubscription/fake/time_rfc3339.go @@ -19,12 +19,16 @@ import ( ) // 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+)*"*$`) +var tzOffsetRegex = regexp.MustCompile(`(?:Z|z|\+|-)(?:\d+:\d+)*"*$`) const ( - utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` - utcDateTime = "2006-01-02T15:04:05.999999999" - dateTimeJSON = `"` + time.RFC3339Nano + `"` + 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 @@ -40,17 +44,33 @@ func (t dateTimeRFC3339) MarshalText() ([]byte, error) { } func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { - layout := utcDateTimeJSON - if tzOffsetRegex.Match(data) { + 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 { - layout := utcDateTime - if tzOffsetRegex.Match(data) { + 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)) } @@ -61,6 +81,10 @@ func (t *dateTimeRFC3339) Parse(layout, value string) error { 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 @@ -74,7 +98,7 @@ func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { } func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { - if data == nil || strings.EqualFold(string(data), "null") { + if data == nil || string(data) == "null" { return nil } var aux dateTimeRFC3339 diff --git a/sdk/resourcemanager/subscription/armsubscription/go.mod b/sdk/resourcemanager/subscription/armsubscription/go.mod index 1b164163bb7e..3b7b94c782f3 100644 --- a/sdk/resourcemanager/subscription/armsubscription/go.mod +++ b/sdk/resourcemanager/subscription/armsubscription/go.mod @@ -2,20 +2,10 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsub go 1.18 -require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.13.0 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0 -) +require github.com/Azure/azure-sdk-for-go/sdk/azcore v1.13.0 require ( github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect - github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect - github.com/golang-jwt/jwt/v5 v5.2.1 // indirect - github.com/google/uuid v1.6.0 // indirect - github.com/kylelemons/godebug v1.1.0 // indirect - github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect - golang.org/x/crypto v0.25.0 // indirect golang.org/x/net v0.27.0 // indirect - golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect ) diff --git a/sdk/resourcemanager/subscription/armsubscription/go.sum b/sdk/resourcemanager/subscription/armsubscription/go.sum index 09d275cb9a37..917448a001b7 100644 --- a/sdk/resourcemanager/subscription/armsubscription/go.sum +++ b/sdk/resourcemanager/subscription/armsubscription/go.sum @@ -1,29 +1,12 @@ github.com/Azure/azure-sdk-for-go/sdk/azcore v1.13.0 h1:GJHeeA2N7xrG3q30L2UXDyuWRzDM900/65j70wcM4Ww= github.com/Azure/azure-sdk-for-go/sdk/azcore v1.13.0/go.mod h1:l38EPgmsp71HHLq9j7De57JcKOWPyhrsW1Awm1JS6K0= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0 h1:tfLQ34V6F7tVSwoTf/4lH5sE0o6eCJuNDTmH09nDpbc= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0/go.mod h1:9kIvujWAA58nmPmWB1m23fyWic1kYZMxD9CxaWn4Qpg= 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/AzureAD/microsoft-authentication-library-for-go v1.2.2 h1:XHOnouVk1mxXfQidrMEnLlPk9UMeRtyBTnEFtxkV0kU= -github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= -github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= -github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= -github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= -golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= -golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/sdk/resourcemanager/subscription/armsubscription/models.go b/sdk/resourcemanager/subscription/armsubscription/models.go index d8957c8635d0..a3a9750bc6be 100644 --- a/sdk/resourcemanager/subscription/armsubscription/models.go +++ b/sdk/resourcemanager/subscription/armsubscription/models.go @@ -45,6 +45,9 @@ type AcceptOwnershipStatusResponse struct { // READ-ONLY; UPN of the billing owner BillingOwner *string + // READ-ONLY; The provisioning state of the resource. + ProvisioningState *Provisioning + // READ-ONLY; Newly created subscription Id. SubscriptionID *string } @@ -150,6 +153,12 @@ type CanceledSubscriptionID struct { SubscriptionID *string } +// CreationResult - The created subscription object. +type CreationResult struct { + // The link to the new subscription. Use this link to check the status of subscription creation operation. + SubscriptionLink *string +} + // EnabledSubscriptionID - The ID of the subscriptions that is being enabled type EnabledSubscriptionID struct { // READ-ONLY; The ID of the subscriptions that is being enabled @@ -378,6 +387,9 @@ type Subscription struct { // The subscription policies. SubscriptionPolicies *Policies + // Tags for the subscription + Tags map[string]*string + // READ-ONLY; The subscription display name. DisplayName *string @@ -389,6 +401,9 @@ type Subscription struct { // READ-ONLY; The subscription ID. SubscriptionID *string + + // READ-ONLY; The tenant ID. For example, 00000000-0000-0000-0000-000000000000. + TenantID *string } // SystemData - Metadata pertaining to creation and last modification of the resource. @@ -414,11 +429,32 @@ type SystemData struct { // TenantIDDescription - Tenant Id information. type TenantIDDescription struct { + // READ-ONLY; The country/region name of the address for the tenant. + Country *string + + // READ-ONLY; The Country/region abbreviation for the tenant. + CountryCode *string + + // READ-ONLY; The default domain for the tenant. + DefaultDomain *string + + // READ-ONLY; The display name of the tenant. + DisplayName *string + + // READ-ONLY; The list of domains for the tenant. + Domains *string + // READ-ONLY; The fully qualified ID of the tenant. For example, /tenants/00000000-0000-0000-0000-000000000000. ID *string + // READ-ONLY; The category of the tenant. Possible values are TenantCategoryHome,TenantCategoryProjectedBy,TenantCategoryManagedBy + TenantCategory *string + // READ-ONLY; The tenant ID. For example, 00000000-0000-0000-0000-000000000000. TenantID *string + + // READ-ONLY; The tenant type. Only available for Home tenant category. + TenantType *string } // TenantListResult - Tenant Ids information. diff --git a/sdk/resourcemanager/subscription/armsubscription/models_serde.go b/sdk/resourcemanager/subscription/armsubscription/models_serde.go index 0c88a1f596c1..bebc9a32ec49 100644 --- a/sdk/resourcemanager/subscription/armsubscription/models_serde.go +++ b/sdk/resourcemanager/subscription/armsubscription/models_serde.go @@ -83,6 +83,7 @@ func (a AcceptOwnershipStatusResponse) MarshalJSON() ([]byte, error) { populate(objectMap, "acceptOwnershipState", a.AcceptOwnershipState) populate(objectMap, "billingOwner", a.BillingOwner) populate(objectMap, "displayName", a.DisplayName) + populate(objectMap, "provisioningState", a.ProvisioningState) populate(objectMap, "subscriptionId", a.SubscriptionID) populate(objectMap, "subscriptionTenantId", a.SubscriptionTenantID) populate(objectMap, "tags", a.Tags) @@ -107,6 +108,9 @@ func (a *AcceptOwnershipStatusResponse) UnmarshalJSON(data []byte) error { case "displayName": err = unpopulate(val, "DisplayName", &a.DisplayName) delete(rawMsg, key) + case "provisioningState": + err = unpopulate(val, "ProvisioningState", &a.ProvisioningState) + delete(rawMsg, key) case "subscriptionId": err = unpopulate(val, "SubscriptionID", &a.SubscriptionID) delete(rawMsg, key) @@ -370,6 +374,33 @@ func (c *CanceledSubscriptionID) UnmarshalJSON(data []byte) error { return nil } +// MarshalJSON implements the json.Marshaller interface for type CreationResult. +func (c CreationResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "subscriptionLink", c.SubscriptionLink) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type CreationResult. +func (c *CreationResult) 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", c, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "subscriptionLink": + err = unpopulate(val, "SubscriptionLink", &c.SubscriptionLink) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + } + return nil +} + // MarshalJSON implements the json.Marshaller interface for type EnabledSubscriptionID. func (e EnabledSubscriptionID) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) @@ -1024,6 +1055,8 @@ func (s Subscription) MarshalJSON() ([]byte, error) { 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) } @@ -1054,6 +1087,12 @@ func (s *Subscription) UnmarshalJSON(data []byte) error { case "subscriptionPolicies": err = unpopulate(val, "SubscriptionPolicies", &s.SubscriptionPolicies) delete(rawMsg, key) + case "tags": + err = unpopulate(val, "Tags", &s.Tags) + delete(rawMsg, key) + case "tenantId": + err = unpopulate(val, "TenantID", &s.TenantID) + delete(rawMsg, key) } if err != nil { return fmt.Errorf("unmarshalling type %T: %v", s, err) @@ -1112,8 +1151,15 @@ func (s *SystemData) UnmarshalJSON(data []byte) error { // MarshalJSON implements the json.Marshaller interface for type TenantIDDescription. func (t TenantIDDescription) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) + 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, "tenantCategory", t.TenantCategory) populate(objectMap, "tenantId", t.TenantID) + populate(objectMap, "tenantType", t.TenantType) return json.Marshal(objectMap) } @@ -1126,12 +1172,33 @@ func (t *TenantIDDescription) UnmarshalJSON(data []byte) error { for key, val := range rawMsg { var err error switch key { + case "country": + err = unpopulate(val, "Country", &t.Country) + delete(rawMsg, key) + case "countryCode": + err = unpopulate(val, "CountryCode", &t.CountryCode) + delete(rawMsg, key) + case "defaultDomain": + err = unpopulate(val, "DefaultDomain", &t.DefaultDomain) + delete(rawMsg, key) + case "displayName": + err = unpopulate(val, "DisplayName", &t.DisplayName) + delete(rawMsg, key) + case "domains": + err = unpopulate(val, "Domains", &t.Domains) + delete(rawMsg, key) case "id": err = unpopulate(val, "ID", &t.ID) delete(rawMsg, key) + case "tenantCategory": + err = unpopulate(val, "TenantCategory", &t.TenantCategory) + delete(rawMsg, key) case "tenantId": err = unpopulate(val, "TenantID", &t.TenantID) delete(rawMsg, key) + case "tenantType": + err = unpopulate(val, "TenantType", &t.TenantType) + delete(rawMsg, key) } if err != nil { return fmt.Errorf("unmarshalling type %T: %v", t, err) @@ -1221,7 +1288,7 @@ func populate(m map[string]any, k string, v any) { } func unpopulate(data json.RawMessage, fn string, v any) error { - if data == nil { + if data == nil || string(data) == "null" { return nil } if err := json.Unmarshal(data, v); err != nil { diff --git a/sdk/resourcemanager/subscription/armsubscription/operation_client.go b/sdk/resourcemanager/subscription/armsubscription/operation_client.go new file mode 100644 index 000000000000..35f43e22ce82 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/operation_client.go @@ -0,0 +1,107 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armsubscription + +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" +) + +// OperationClient contains the methods for the SubscriptionOperation group. +// Don't use this type directly, use NewOperationClient() instead. +type OperationClient struct { + internal *arm.Client +} + +// NewOperationClient creates a new instance of OperationClient with the specified values. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewOperationClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*OperationClient, error) { + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &OperationClient{ + internal: cl, + } + return client, nil +} + +// Get - Get the status of the pending Microsoft.Subscription API operations. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2021-10-01 +// - operationID - The operation ID, which can be found from the Location field in the generate recommendation response header. +// - options - OperationClientGetOptions contains the optional parameters for the OperationClient.Get method. +func (client *OperationClient) Get(ctx context.Context, operationID string, options *OperationClientGetOptions) (OperationClientGetResponse, error) { + var err error + const operationName = "OperationClient.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, operationID, options) + if err != nil { + return OperationClientGetResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return OperationClientGetResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { + err = runtime.NewResponseError(httpResp) + return OperationClientGetResponse{}, err + } + resp, err := client.getHandleResponse(httpResp) + return resp, err +} + +// getCreateRequest creates the Get request. +func (client *OperationClient) getCreateRequest(ctx context.Context, operationID string, options *OperationClientGetOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Subscription/subscriptionOperations/{operationId}" + if operationID == "" { + return nil, errors.New("parameter operationID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{operationId}", url.PathEscape(operationID)) + 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", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *OperationClient) getHandleResponse(resp *http.Response) (OperationClientGetResponse, error) { + result := OperationClientGetResponse{} + if val := resp.Header.Get("Location"); val != "" { + result.Location = &val + } + if val := resp.Header.Get("Retry-After"); val != "" { + retryAfter, err := strconv.ParseInt(val, 10, 64) + if err != nil { + return OperationClientGetResponse{}, err + } + result.RetryAfter = &retryAfter + } + if err := runtime.UnmarshalAsJSON(resp, &result.CreationResult); err != nil { + return OperationClientGetResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/subscription/armsubscription/operations_client_example_test.go b/sdk/resourcemanager/subscription/armsubscription/operations_client_example_test.go deleted file mode 100644 index 87afc63fb566..000000000000 --- a/sdk/resourcemanager/subscription/armsubscription/operations_client_example_test.go +++ /dev/null @@ -1,55 +0,0 @@ -//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. -// DO NOT EDIT. - -package armsubscription_test - -import ( - "context" - "log" - - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription" -) - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2021-10-01/examples/getOperations.json -func ExampleOperationsClient_NewListPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewOperationsClient().NewListPager(nil) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.OperationListResult = armsubscription.OperationListResult{ - // Value: []*armsubscription.Operation{ - // { - // Name: to.Ptr("Microsoft.Subscription/createOperation/action"), - // Display: &armsubscription.OperationDisplay{ - // Operation: to.Ptr("Create a subscription"), - // Provider: to.Ptr("Microsoft Subscription"), - // Resource: to.Ptr("Resources"), - // }, - // IsDataAction: to.Ptr(false), - // }}, - // } - } -} diff --git a/sdk/resourcemanager/subscription/armsubscription/options.go b/sdk/resourcemanager/subscription/armsubscription/options.go index d02e831b6d8c..f95bb1dfc44c 100644 --- a/sdk/resourcemanager/subscription/armsubscription/options.go +++ b/sdk/resourcemanager/subscription/armsubscription/options.go @@ -60,6 +60,11 @@ type ClientRenameOptions struct { // placeholder for future optional parameters } +// OperationClientGetOptions contains the optional parameters for the OperationClient.Get method. +type OperationClientGetOptions struct { + // placeholder for future optional parameters +} + // OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. type OperationsClientListOptions struct { // placeholder for future optional parameters diff --git a/sdk/resourcemanager/subscription/armsubscription/policy_client_example_test.go b/sdk/resourcemanager/subscription/armsubscription/policy_client_example_test.go deleted file mode 100644 index 5e52c8760895..000000000000 --- a/sdk/resourcemanager/subscription/armsubscription/policy_client_example_test.go +++ /dev/null @@ -1,132 +0,0 @@ -//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. -// DO NOT EDIT. - -package armsubscription_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/subscription/armsubscription" -) - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2021-10-01/examples/changeTenantPolicy.json -func ExamplePolicyClient_AddUpdatePolicyForTenant() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewPolicyClient().AddUpdatePolicyForTenant(ctx, armsubscription.PutTenantPolicyRequestProperties{ - BlockSubscriptionsIntoTenant: to.Ptr(true), - BlockSubscriptionsLeavingTenant: to.Ptr(true), - ExemptedPrincipals: []*string{ - to.Ptr("e879cf0f-2b4d-5431-109a-f72fc9868693"), - to.Ptr("9792da87-c97b-410d-a97d-27021ba09ce6")}, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.GetTenantPolicyResponse = armsubscription.GetTenantPolicyResponse{ - // Name: to.Ptr("default"), - // Type: to.Ptr("providers/Microsoft.Subscription/policies"), - // ID: to.Ptr("providers/Microsoft.Subscription/policies/default"), - // Properties: &armsubscription.TenantPolicy{ - // BlockSubscriptionsIntoTenant: to.Ptr(true), - // BlockSubscriptionsLeavingTenant: to.Ptr(true), - // ExemptedPrincipals: []*string{ - // to.Ptr("e879cf0f-2b4d-5431-109a-f72fc9868693"), - // to.Ptr("9792da87-c97b-410d-a97d-27021ba09ce6")}, - // PolicyID: to.Ptr("291bba3f-e0a5-47bc-a099-3bdcb2a50a05"), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2021-10-01/examples/getTenantPolicy.json -func ExamplePolicyClient_GetPolicyForTenant() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewPolicyClient().GetPolicyForTenant(ctx, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.GetTenantPolicyResponse = armsubscription.GetTenantPolicyResponse{ - // Name: to.Ptr("default"), - // Type: to.Ptr("providers/Microsoft.Subscription/policies"), - // ID: to.Ptr("providers/Microsoft.Subscription/policies/default"), - // Properties: &armsubscription.TenantPolicy{ - // BlockSubscriptionsIntoTenant: to.Ptr(true), - // BlockSubscriptionsLeavingTenant: to.Ptr(true), - // ExemptedPrincipals: []*string{ - // to.Ptr("e879cf0f-2b4d-5431-109a-f72fc9868693"), - // to.Ptr("9792da87-c97b-410d-a97d-27021ba09ce6")}, - // PolicyID: to.Ptr("291bba3f-e0a5-47bc-a099-3bdcb2a50a05"), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2021-10-01/examples/getTenantPolicyList.json -func ExamplePolicyClient_NewListPolicyForTenantPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewPolicyClient().NewListPolicyForTenantPager(nil) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.GetTenantPolicyListResponse = armsubscription.GetTenantPolicyListResponse{ - // Value: []*armsubscription.GetTenantPolicyResponse{ - // { - // Name: to.Ptr("default"), - // Type: to.Ptr("providers/Microsoft.Subscription/policies"), - // ID: to.Ptr("providers/Microsoft.Subscription/policies/default"), - // Properties: &armsubscription.TenantPolicy{ - // BlockSubscriptionsIntoTenant: to.Ptr(true), - // BlockSubscriptionsLeavingTenant: to.Ptr(true), - // ExemptedPrincipals: []*string{ - // to.Ptr("e879cf0f-2b4d-5431-109a-f72fc9868693"), - // to.Ptr("9792da87-c97b-410d-a97d-27021ba09ce6")}, - // PolicyID: to.Ptr("291bba3f-e0a5-47bc-a099-3bdcb2a50a05"), - // }, - // }}, - // } - } -} diff --git a/sdk/resourcemanager/subscription/armsubscription/response_types.go b/sdk/resourcemanager/subscription/armsubscription/responses.go similarity index 91% rename from sdk/resourcemanager/subscription/armsubscription/response_types.go rename to sdk/resourcemanager/subscription/armsubscription/responses.go index 3dd5773bb0b4..aeddf5032ddb 100644 --- a/sdk/resourcemanager/subscription/armsubscription/response_types.go +++ b/sdk/resourcemanager/subscription/armsubscription/responses.go @@ -66,6 +66,18 @@ type ClientRenameResponse struct { RenamedSubscriptionID } +// OperationClientGetResponse contains the response from method OperationClient.Get. +type OperationClientGetResponse struct { + // The created subscription object. + CreationResult + + // Location contains the information returned from the Location header response. + Location *string + + // RetryAfter contains the information returned from the Retry-After header response. + RetryAfter *int64 +} + // OperationsClientListResponse contains the response from method OperationsClient.NewListPager. type OperationsClientListResponse struct { // Result of the request to list operations. It contains a list of operations and a URL link to get the next set of results. diff --git a/sdk/resourcemanager/subscription/armsubscription/subscriptions_client_example_test.go b/sdk/resourcemanager/subscription/armsubscription/subscriptions_client_example_test.go deleted file mode 100644 index 206fce557552..000000000000 --- a/sdk/resourcemanager/subscription/armsubscription/subscriptions_client_example_test.go +++ /dev/null @@ -1,132 +0,0 @@ -//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. -// DO NOT EDIT. - -package armsubscription_test - -import ( - "context" - "log" - - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription" -) - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2016-06-01/examples/listLocations.json -func ExampleSubscriptionsClient_NewListLocationsPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewSubscriptionsClient().NewListLocationsPager("83aa47df-e3e9-49ff-877b-94304bf3d3ad", nil) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.LocationListResult = armsubscription.LocationListResult{ - // Value: []*armsubscription.Location{ - // { - // Name: to.Ptr("eastasia"), - // DisplayName: to.Ptr("East Asia"), - // ID: to.Ptr("/subscriptions/83aa47df-e3e9-49ff-877b-94304bf3d3ad/locations/eastasia"), - // Latitude: to.Ptr("22.267"), - // Longitude: to.Ptr("114.188"), - // }, - // { - // Name: to.Ptr("southeastasia"), - // DisplayName: to.Ptr("Southeast Asia"), - // ID: to.Ptr("/subscriptions/83aa47df-e3e9-49ff-877b-94304bf3d3ad/locations/southeastasia"), - // Latitude: to.Ptr("1.283"), - // Longitude: to.Ptr("103.833"), - // }}, - // } - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2016-06-01/examples/getSubscription.json -func ExampleSubscriptionsClient_Get() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewSubscriptionsClient().Get(ctx, "83aa47df-e3e9-49ff-877b-94304bf3d3ad", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Subscription = armsubscription.Subscription{ - // AuthorizationSource: to.Ptr("Legacy"), - // DisplayName: to.Ptr("Subscription2"), - // ID: to.Ptr("/subscriptions/83aa47df-e3e9-49ff-877b-94304bf3d3ad"), - // State: to.Ptr(armsubscription.SubscriptionStateEnabled), - // SubscriptionID: to.Ptr("83aa47df-e3e9-49ff-877b-94304bf3d3ad"), - // SubscriptionPolicies: &armsubscription.Policies{ - // LocationPlacementID: to.Ptr("Internal_2014-09-01"), - // QuotaID: to.Ptr("Internal_2014-09-01"), - // SpendingLimit: to.Ptr(armsubscription.SpendingLimitOff), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2016-06-01/examples/listSubscriptions.json -func ExampleSubscriptionsClient_NewListPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewSubscriptionsClient().NewListPager(nil) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.ListResult = armsubscription.ListResult{ - // Value: []*armsubscription.Subscription{ - // { - // AuthorizationSource: to.Ptr("Legacy"), - // DisplayName: to.Ptr("SubscriptionName"), - // ID: to.Ptr("/subscriptions/83aa47df-e3e9-49ff-877b-94304bf3d3ad"), - // State: to.Ptr(armsubscription.SubscriptionStateEnabled), - // SubscriptionID: to.Ptr("83aa47df-e3e9-49ff-877b-94304bf3d3ad"), - // SubscriptionPolicies: &armsubscription.Policies{ - // LocationPlacementID: to.Ptr("Internal_2014-09-01"), - // QuotaID: to.Ptr("Internal_2014-09-01"), - // SpendingLimit: to.Ptr(armsubscription.SpendingLimitOff), - // }, - // }}, - // } - } -} diff --git a/sdk/resourcemanager/subscription/armsubscription/tenants_client_example_test.go b/sdk/resourcemanager/subscription/armsubscription/tenants_client_example_test.go deleted file mode 100644 index 589b8b902b25..000000000000 --- a/sdk/resourcemanager/subscription/armsubscription/tenants_client_example_test.go +++ /dev/null @@ -1,54 +0,0 @@ -//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. -// DO NOT EDIT. - -package armsubscription_test - -import ( - "context" - "log" - - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription" -) - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2016-06-01/examples/listTenants.json -func ExampleTenantsClient_NewListPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armsubscription.NewClientFactory(cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewTenantsClient().NewListPager(nil) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.TenantListResult = armsubscription.TenantListResult{ - // Value: []*armsubscription.TenantIDDescription{ - // { - // ID: to.Ptr("/tenants/72f988bf-86f1-41af-91ab-2d7cd011db47"), - // TenantID: to.Ptr("72f988bf-86f1-41af-91ab-2d7cd011db47"), - // }, - // { - // ID: to.Ptr("/tenants/33e01921-4d64-4f8c-a055-5bdaffd5e33d"), - // TenantID: to.Ptr("33e01921-4d64-4f8c-a055-5bdaffd5e33d"), - // }}, - // } - } -} diff --git a/sdk/resourcemanager/subscription/armsubscription/time_rfc3339.go b/sdk/resourcemanager/subscription/armsubscription/time_rfc3339.go index b818b6708481..b59b51fa9817 100644 --- a/sdk/resourcemanager/subscription/armsubscription/time_rfc3339.go +++ b/sdk/resourcemanager/subscription/armsubscription/time_rfc3339.go @@ -19,12 +19,16 @@ import ( ) // 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+)*"*$`) +var tzOffsetRegex = regexp.MustCompile(`(?:Z|z|\+|-)(?:\d+:\d+)*"*$`) const ( - utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` - utcDateTime = "2006-01-02T15:04:05.999999999" - dateTimeJSON = `"` + time.RFC3339Nano + `"` + 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 @@ -40,17 +44,33 @@ func (t dateTimeRFC3339) MarshalText() ([]byte, error) { } func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { - layout := utcDateTimeJSON - if tzOffsetRegex.Match(data) { + 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 { - layout := utcDateTime - if tzOffsetRegex.Match(data) { + 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)) } @@ -61,6 +81,10 @@ func (t *dateTimeRFC3339) Parse(layout, value string) error { 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 @@ -74,7 +98,7 @@ func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { } func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { - if data == nil || strings.EqualFold(string(data), "null") { + if data == nil || string(data) == "null" { return nil } var aux dateTimeRFC3339