From 22604ae14995010e007fd9625bd89a567e0299b7 Mon Sep 17 00:00:00 2001 From: Peng Jiahui <46921893+Alancere@users.noreply.github.com> Date: Mon, 25 Dec 2023 10:23:30 +0800 Subject: [PATCH] sdk/resourcemanager/msi/armmsi live test (#22094) --- sdk/resourcemanager/msi/armmsi/assets.json | 6 + sdk/resourcemanager/msi/armmsi/go.mod | 10 +- sdk/resourcemanager/msi/armmsi/go.sum | 16 ++ .../msi/armmsi/managedidentity_live_test.go | 183 ++++++++++++++++++ 4 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 sdk/resourcemanager/msi/armmsi/assets.json create mode 100644 sdk/resourcemanager/msi/armmsi/managedidentity_live_test.go diff --git a/sdk/resourcemanager/msi/armmsi/assets.json b/sdk/resourcemanager/msi/armmsi/assets.json new file mode 100644 index 000000000000..c2dd32527e4e --- /dev/null +++ b/sdk/resourcemanager/msi/armmsi/assets.json @@ -0,0 +1,6 @@ +{ + "AssetsRepo": "Azure/azure-sdk-assets", + "AssetsRepoPrefixPath": "go", + "TagPrefix": "go/resourcemanager/msi/armmsi", + "Tag": "go/resourcemanager/msi/armmsi_80e83a5723" +} diff --git a/sdk/resourcemanager/msi/armmsi/go.mod b/sdk/resourcemanager/msi/armmsi/go.mod index 8be5a0df1eb2..7460c7b1e42b 100644 --- a/sdk/resourcemanager/msi/armmsi/go.mod +++ b/sdk/resourcemanager/msi/armmsi/go.mod @@ -5,17 +5,25 @@ go 1.18 require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 + github.com/stretchr/testify v1.8.4 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dnaeon/go-vcr v1.2.0 // indirect github.com/golang-jwt/jwt/v5 v5.0.0 // indirect github.com/google/uuid v1.3.1 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/crypto v0.14.0 // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/sys v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/sdk/resourcemanager/msi/armmsi/go.sum b/sdk/resourcemanager/msi/armmsi/go.sum index 7985f1da436f..88bb72abf2ba 100644 --- a/sdk/resourcemanager/msi/armmsi/go.sum +++ b/sdk/resourcemanager/msi/armmsi/go.sum @@ -4,20 +4,31 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 h1:BMAjVKJM0U/CYF27gA0ZM github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0/go.mod h1:1fXstnBMas5kzG+S3q8UoJcmyU6nUeunJcMDHcRYHhs= github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs= github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 h1:PTFGRSlMKCQelWwxUyYVEUqseBJVemLyqWJjvMyt0do= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0/go.mod h1:LRr2FzBTQlONPPa5HREE5+RjSCTXl7BwOvYOaWTqCaI= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 h1:pPvTJ1dY0sA35JOeFq6TsY2xj6Z85Yo23Pj4wCCvu4o= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 h1:7CBQ+Ei8SP2c6ydQTGCCrS35bDxgTMfoP2miAwK++OU= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1/go.mod h1:c/wcGeGx5FUPbM/JltUYHZcKmigwyVLJlDq+4HdtXaw= github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 h1:WpB/QDNLpMw72xHJc34BNNykqSOeEJDAWkhf0u12/Jk= github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/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/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= @@ -27,5 +38,10 @@ golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/resourcemanager/msi/armmsi/managedidentity_live_test.go b/sdk/resourcemanager/msi/armmsi/managedidentity_live_test.go new file mode 100644 index 000000000000..db3035f691b5 --- /dev/null +++ b/sdk/resourcemanager/msi/armmsi/managedidentity_live_test.go @@ -0,0 +1,183 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +package armmsi_test + +import ( + "context" + "fmt" + "testing" + + "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/to" + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi" + "github.com/stretchr/testify/suite" +) + +type ManagedIdentityTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + armEndpoint string + federatedIdentityCredentialResourceName string + resourceName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *ManagedIdentityTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/msi/armmsi/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.armEndpoint = "https://management.azure.com" + testsuite.federatedIdentityCredentialResourceName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "federate", 14, false) + testsuite.resourceName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "resource", 14, false) + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") + testsuite.resourceGroupName = recording.GetEnvVariable("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name + testsuite.Prepare() +} + +func (testsuite *ManagedIdentityTestSuite) TearDownSuite() { + testsuite.Cleanup() + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestManagedIdentityTestSuite(t *testing.T) { + suite.Run(t, new(ManagedIdentityTestSuite)) +} + +func (testsuite *ManagedIdentityTestSuite) Prepare() { + var err error + // From step UserAssignedIdentities_CreateOrUpdate + fmt.Println("Call operation: UserAssignedIdentities_CreateOrUpdate") + userAssignedIdentitiesClient, err := armmsi.NewUserAssignedIdentitiesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = userAssignedIdentitiesClient.CreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.resourceName, armmsi.Identity{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{ + "key1": to.Ptr("value1"), + "key2": to.Ptr("value2"), + }, + }, nil) + testsuite.Require().NoError(err) +} + +// Microsoft.ManagedIdentity/userAssignedIdentities/{resourceName} +func (testsuite *ManagedIdentityTestSuite) TestUserAssignedIdentities() { + var err error + // From step UserAssignedIdentities_ListBySubscription + fmt.Println("Call operation: UserAssignedIdentities_ListBySubscription") + userAssignedIdentitiesClient, err := armmsi.NewUserAssignedIdentitiesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + userAssignedIdentitiesClientNewListBySubscriptionPager := userAssignedIdentitiesClient.NewListBySubscriptionPager(nil) + for userAssignedIdentitiesClientNewListBySubscriptionPager.More() { + _, err := userAssignedIdentitiesClientNewListBySubscriptionPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step UserAssignedIdentities_ListByResourceGroup + fmt.Println("Call operation: UserAssignedIdentities_ListByResourceGroup") + userAssignedIdentitiesClientNewListByResourceGroupPager := userAssignedIdentitiesClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) + for userAssignedIdentitiesClientNewListByResourceGroupPager.More() { + _, err := userAssignedIdentitiesClientNewListByResourceGroupPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step UserAssignedIdentities_Get + fmt.Println("Call operation: UserAssignedIdentities_Get") + _, err = userAssignedIdentitiesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.resourceName, nil) + testsuite.Require().NoError(err) + + // From step UserAssignedIdentities_Update + fmt.Println("Call operation: UserAssignedIdentities_Update") + _, err = userAssignedIdentitiesClient.Update(testsuite.ctx, testsuite.resourceGroupName, testsuite.resourceName, armmsi.IdentityUpdate{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{ + "key1": to.Ptr("value1"), + "key2": to.Ptr("value2"), + }, + }, nil) + testsuite.Require().NoError(err) +} + +// Microsoft.ManagedIdentity/userAssignedIdentities/{resourceName}/federatedIdentityCredentials/{federatedIdentityCredentialResourceName} +func (testsuite *ManagedIdentityTestSuite) TestFederatedIdentityCredentials() { + var err error + // From step FederatedIdentityCredentials_CreateOrUpdate + fmt.Println("Call operation: FederatedIdentityCredentials_CreateOrUpdate") + federatedIdentityCredentialsClient, err := armmsi.NewFederatedIdentityCredentialsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = federatedIdentityCredentialsClient.CreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.resourceName, testsuite.federatedIdentityCredentialResourceName, armmsi.FederatedIdentityCredential{ + Properties: &armmsi.FederatedIdentityCredentialProperties{ + Audiences: []*string{ + to.Ptr("api://AzureADTokenExchange")}, + Issuer: to.Ptr("https://oidc.prod-aks.azure.com/TenantGUID/IssuerGUID"), + Subject: to.Ptr("system:serviceaccount:ns:svcaccount"), + }, + }, nil) + testsuite.Require().NoError(err) + + // From step FederatedIdentityCredentials_List + fmt.Println("Call operation: FederatedIdentityCredentials_List") + federatedIdentityCredentialsClientNewListPager := federatedIdentityCredentialsClient.NewListPager(testsuite.resourceGroupName, testsuite.resourceName, &armmsi.FederatedIdentityCredentialsClientListOptions{Top: nil, + Skiptoken: nil, + }) + for federatedIdentityCredentialsClientNewListPager.More() { + _, err := federatedIdentityCredentialsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step FederatedIdentityCredentials_Get + fmt.Println("Call operation: FederatedIdentityCredentials_Get") + _, err = federatedIdentityCredentialsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.resourceName, testsuite.federatedIdentityCredentialResourceName, nil) + testsuite.Require().NoError(err) + + // From step FederatedIdentityCredentials_Delete + fmt.Println("Call operation: FederatedIdentityCredentials_Delete") + _, err = federatedIdentityCredentialsClient.Delete(testsuite.ctx, testsuite.resourceGroupName, testsuite.resourceName, testsuite.federatedIdentityCredentialResourceName, nil) + testsuite.Require().NoError(err) +} + +// Microsoft.ManagedIdentity/operations +func (testsuite *ManagedIdentityTestSuite) TestOperations() { + var err error + // From step Operations_List + fmt.Println("Call operation: Operations_List") + operationsClient, err := armmsi.NewOperationsClient(testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + operationsClientNewListPager := operationsClient.NewListPager(nil) + for operationsClientNewListPager.More() { + _, err := operationsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } +} + +func (testsuite *ManagedIdentityTestSuite) Cleanup() { + var err error + // From step UserAssignedIdentities_Delete + fmt.Println("Call operation: UserAssignedIdentities_Delete") + userAssignedIdentitiesClient, err := armmsi.NewUserAssignedIdentitiesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = userAssignedIdentitiesClient.Delete(testsuite.ctx, testsuite.resourceGroupName, testsuite.resourceName, nil) + testsuite.Require().NoError(err) +}