From 8d04b1786d731b47e3af2a890ba96e1fc908fcc7 Mon Sep 17 00:00:00 2001 From: Amber Brown Date: Fri, 25 Aug 2023 12:22:08 +1000 Subject: [PATCH] update code to use our generated msgraph sdk --- hack/cluster/cluster.go | 4 ++-- pkg/cluster/cluster.go | 4 ++-- pkg/env/armhelper.go | 3 +-- pkg/util/azureclient/environments.go | 7 ++++--- pkg/util/cluster/aad.go | 9 +++++---- pkg/util/cluster/cluster.go | 3 +-- pkg/util/graph/graph.go | 5 ++--- pkg/util/steps/runner.go | 5 +++-- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/hack/cluster/cluster.go b/hack/cluster/cluster.go index 214c5886587..ace7cb1cfca 100644 --- a/hack/cluster/cluster.go +++ b/hack/cluster/cluster.go @@ -12,11 +12,11 @@ import ( "time" "github.com/davecgh/go-spew/spew" - msgraph_errors "github.com/microsoftgraph/msgraph-sdk-go/models/odataerrors" "github.com/sirupsen/logrus" "github.com/Azure/ARO-RP/pkg/env" "github.com/Azure/ARO-RP/pkg/util/cluster" + msgraph_errors "github.com/Azure/ARO-RP/pkg/util/graph/graphsdk/models/odataerrors" utillog "github.com/Azure/ARO-RP/pkg/util/log" "github.com/Azure/ARO-RP/pkg/util/version" ) @@ -75,7 +75,7 @@ func main() { if err := run(context.Background(), log); err != nil { if oDataError, ok := err.(msgraph_errors.ODataErrorable); ok { - spew.Dump(oDataError.GetError()) + spew.Dump(oDataError.GetErrorEscaped()) } log.Fatal(err) } diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index c667c5a4ae2..066b198224d 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -9,7 +9,6 @@ import ( "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure" - msgraph "github.com/microsoftgraph/msgraph-sdk-go" configclient "github.com/openshift/client-go/config/clientset/versioned" imageregistryclient "github.com/openshift/client-go/imageregistry/clientset/versioned" machineclient "github.com/openshift/client-go/machine/clientset/versioned" @@ -37,6 +36,7 @@ import ( "github.com/Azure/ARO-RP/pkg/util/billing" "github.com/Azure/ARO-RP/pkg/util/dns" "github.com/Azure/ARO-RP/pkg/util/encryption" + utilgraph "github.com/Azure/ARO-RP/pkg/util/graph" "github.com/Azure/ARO-RP/pkg/util/refreshable" "github.com/Azure/ARO-RP/pkg/util/storage" "github.com/Azure/ARO-RP/pkg/util/subnet" @@ -64,7 +64,7 @@ type manager struct { localFpAuthorizer autorest.Authorizer metricsEmitter metrics.Emitter - spGraphClient *msgraph.GraphServiceClient + spGraphClient *utilgraph.GraphServiceClient disks compute.DisksClient virtualMachines compute.VirtualMachinesClient interfaces network.InterfacesClient diff --git a/pkg/env/armhelper.go b/pkg/env/armhelper.go index 208b8c3982c..baf3b548a66 100644 --- a/pkg/env/armhelper.go +++ b/pkg/env/armhelper.go @@ -14,7 +14,6 @@ import ( "github.com/Azure/go-autorest/autorest/azure" "github.com/Azure/go-autorest/autorest/to" "github.com/jongio/azidext/go/azidext" - msgraph "github.com/microsoftgraph/msgraph-sdk-go" "github.com/sirupsen/logrus" "github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/authorization" @@ -64,7 +63,7 @@ type armHelper struct { log *logrus.Entry env Interface - fpGraphClient *msgraph.GraphServiceClient + fpGraphClient *utilgraph.GraphServiceClient roleassignments authorization.RoleAssignmentsClient } diff --git a/pkg/util/azureclient/environments.go b/pkg/util/azureclient/environments.go index eef92f6716c..acae0668a6b 100644 --- a/pkg/util/azureclient/environments.go +++ b/pkg/util/azureclient/environments.go @@ -11,7 +11,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/go-autorest/autorest/azure" - msgraph "github.com/microsoftgraph/msgraph-sdk-go" + + utilgraph "github.com/Azure/ARO-RP/pkg/util/graph" ) // AROEnvironment contains additional, cloud-specific information needed by ARO. @@ -131,9 +132,9 @@ func (e *AROEnvironment) ManagedIdentityCredentialOptions() *azidentity.ManagedI } } -func (e *AROEnvironment) NewGraphServiceClient(tokenCredential azcore.TokenCredential) (*msgraph.GraphServiceClient, error) { +func (e *AROEnvironment) NewGraphServiceClient(tokenCredential azcore.TokenCredential) (*utilgraph.GraphServiceClient, error) { scopes := []string{e.MicrosoftGraphScope} - client, err := msgraph.NewGraphServiceClientWithCredentials(tokenCredential, scopes) + client, err := utilgraph.NewGraphServiceClientWithCredentials(tokenCredential, scopes) if err != nil { return nil, err } diff --git a/pkg/util/cluster/aad.go b/pkg/util/cluster/aad.go index 12e7460f195..dcccbf81e15 100644 --- a/pkg/util/cluster/aad.go +++ b/pkg/util/cluster/aad.go @@ -8,10 +8,11 @@ import ( "fmt" "time" - msgraph_apps "github.com/microsoftgraph/msgraph-sdk-go/applications" - msgraph_models "github.com/microsoftgraph/msgraph-sdk-go/models" - msgraph_errors "github.com/microsoftgraph/msgraph-sdk-go/models/odataerrors" "k8s.io/apimachinery/pkg/util/wait" + + msgraph_apps "github.com/Azure/ARO-RP/pkg/util/graph/graphsdk/applications" + msgraph_models "github.com/Azure/ARO-RP/pkg/util/graph/graphsdk/models" + msgraph_errors "github.com/Azure/ARO-RP/pkg/util/graph/graphsdk/models/odataerrors" ) func (c *Cluster) createApplication(ctx context.Context, displayName string) (string, string, error) { @@ -58,7 +59,7 @@ func (c *Cluster) createServicePrincipal(ctx context.Context, appID string) (str result, err = c.spGraphClient.ServicePrincipals().Post(ctx, requestBody, nil) if oDataError, ok := err.(msgraph_errors.ODataErrorable); ok && - *oDataError.GetError().GetCode() == "accessDenied" { + *oDataError.GetErrorEscaped().GetCode() == "accessDenied" { // goal is to retry the following error: // graphrbac.ServicePrincipalsClient#Create: Failure responding to // request: StatusCode=403 -- Original Error: autorest/azure: diff --git a/pkg/util/cluster/cluster.go b/pkg/util/cluster/cluster.go index 37b03ac13e8..888cf9496b1 100644 --- a/pkg/util/cluster/cluster.go +++ b/pkg/util/cluster/cluster.go @@ -24,7 +24,6 @@ import ( "github.com/Azure/go-autorest/autorest/azure" "github.com/Azure/go-autorest/autorest/to" "github.com/jongio/azidext/go/azidext" - msgraph "github.com/microsoftgraph/msgraph-sdk-go" "github.com/sirupsen/logrus" "k8s.io/apimachinery/pkg/util/wait" @@ -55,7 +54,7 @@ type Cluster struct { ci bool ciParentVnet string - spGraphClient *msgraph.GraphServiceClient + spGraphClient *utilgraph.GraphServiceClient deployments features.DeploymentsClient groups features.ResourceGroupsClient openshiftclustersv20200430 redhatopenshift20200430.OpenShiftClustersClient diff --git a/pkg/util/graph/graph.go b/pkg/util/graph/graph.go index d01fede70e4..fb887b0063b 100644 --- a/pkg/util/graph/graph.go +++ b/pkg/util/graph/graph.go @@ -7,13 +7,12 @@ import ( "context" "fmt" - msgraph "github.com/microsoftgraph/msgraph-sdk-go" - msgraph_sps "github.com/microsoftgraph/msgraph-sdk-go/serviceprincipals" + msgraph_sps "github.com/Azure/ARO-RP/pkg/util/graph/graphsdk/serviceprincipals" ) // GetServicePrincipalIDByAppID returns a service principal's object ID from // an application (client) ID. -func GetServicePrincipalIDByAppID(ctx context.Context, graph *msgraph.GraphServiceClient, appId string) (*string, error) { +func GetServicePrincipalIDByAppID(ctx context.Context, graph *GraphServiceClient, appId string) (*string, error) { filter := fmt.Sprintf("appId eq '%s'", appId) requestConfiguration := &msgraph_sps.ServicePrincipalsRequestBuilderGetRequestConfiguration{ QueryParameters: &msgraph_sps.ServicePrincipalsRequestBuilderGetQueryParameters{ diff --git a/pkg/util/steps/runner.go b/pkg/util/steps/runner.go index dd41c220ca2..c2666dda07c 100644 --- a/pkg/util/steps/runner.go +++ b/pkg/util/steps/runner.go @@ -11,8 +11,9 @@ import ( "time" "github.com/davecgh/go-spew/spew" - msgraph_errors "github.com/microsoftgraph/msgraph-sdk-go/models/odataerrors" "github.com/sirupsen/logrus" + + msgraph_errors "github.com/Azure/ARO-RP/pkg/util/graph/graphsdk/models/odataerrors" ) // FriendlyName returns a "friendly" stringified name of the given func. @@ -54,7 +55,7 @@ func Run(ctx context.Context, log *logrus.Entry, pollInterval time.Duration, ste if err != nil { log.Errorf("step %s encountered error: %s", step, err.Error()) if oDataError, ok := err.(msgraph_errors.ODataErrorable); ok { - spew.Fdump(log.Writer(), oDataError.GetError()) + spew.Fdump(log.Writer(), oDataError.GetErrorEscaped()) } return nil, err }