Skip to content

Commit

Permalink
update code to use our generated msgraph sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkowl committed Aug 31, 2023
1 parent 62eca6d commit 8d04b17
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions hack/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pkg/env/armhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -64,7 +63,7 @@ type armHelper struct {
log *logrus.Entry
env Interface

fpGraphClient *msgraph.GraphServiceClient
fpGraphClient *utilgraph.GraphServiceClient
roleassignments authorization.RoleAssignmentsClient
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/util/azureclient/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/util/cluster/aad.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions pkg/util/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions pkg/util/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
5 changes: 3 additions & 2 deletions pkg/util/steps/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 8d04b17

Please sign in to comment.