Skip to content

Commit

Permalink
remove settings from provider struct
Browse files Browse the repository at this point in the history
  • Loading branch information
vinay-gopalan committed Nov 14, 2023
1 parent 8f3888d commit e6348ad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
15 changes: 9 additions & 6 deletions api/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/google/uuid"
"github.com/hashicorp/go-multierror"
msgraphsdkgo "github.com/microsoftgraph/msgraph-sdk-go"
auth "github.com/microsoftgraph/msgraph-sdk-go-core/authentication"
"github.com/microsoftgraph/msgraph-sdk-go/applications"
Expand Down Expand Up @@ -46,11 +45,11 @@ type PasswordCredential struct {
SecretText string
}

// NewMSGraphApplicationClient returns a new MSGraphClient configured to interact with
// NewMSGraphClient returns a new MSGraphClient configured to interact with
// the Microsoft Graph API. It can be configured to target alternative national cloud
// deployments via graphURI. For details on the client configuration see
// https://learn.microsoft.com/en-us/graph/sdks/national-clouds
func NewMSGraphApplicationClient(graphURI string, creds azcore.TokenCredential) (*MSGraphClient, error) {
func NewMSGraphClient(graphURI string, creds azcore.TokenCredential) (*MSGraphClient, error) {
scopes := []string{
fmt.Sprintf("%s/.default", graphURI),
}
Expand Down Expand Up @@ -138,11 +137,15 @@ func (c *MSGraphClient) CreateApplication(ctx context.Context, displayName strin
// This will in turn remove the service principal (but not the role assignments).
func (c *MSGraphClient) DeleteApplication(ctx context.Context, applicationObjectID string, permanentlyDelete bool) error {
err := c.client.Applications().ByApplicationId(applicationObjectID).Delete(ctx, nil)
if err != nil {
return err
}

if permanentlyDelete {
e := c.client.Directory().DeletedItems().ByDirectoryObjectId(applicationObjectID).Delete(ctx, nil)
merr := multierror.Append(err, e)
return merr.ErrorOrNil()
err = c.client.Directory().DeletedItems().ByDirectoryObjectId(applicationObjectID).Delete(ctx, nil)
if err != nil {
return err
}
}

return err
Expand Down
5 changes: 4 additions & 1 deletion path_service_principal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,10 @@ func TestCredentialInteg_msgraph(t *testing.T) {
Storage: s,
}

b.spRevoke(context.Background(), req, nil)
_, err = b.spRevoke(context.Background(), req, nil)
if err != nil {
t.Fatalf("error revoking service principal: %s", err.Error())
}

// Verify that SP get is an error after delete. Expected there
// to be a delay and that this step would take some time/retries,
Expand Down
4 changes: 1 addition & 3 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func newAzureProvider(settings *clientSettings, passwords api.Passwords) (AzureP
return nil, err
}

msGraphAppClient, err := api.NewMSGraphApplicationClient(settings.GraphURI, cred)
msGraphAppClient, err := api.NewMSGraphClient(settings.GraphURI, cred)
if err != nil {
return nil, fmt.Errorf("failed to create MS graph client: %w", err)
}
Expand All @@ -83,8 +83,6 @@ func newAzureProvider(settings *clientSettings, passwords api.Passwords) (AzureP
}

p := &provider{
settings: settings,

appClient: msGraphAppClient,
spClient: msGraphAppClient,
groupsClient: msGraphAppClient,
Expand Down

0 comments on commit e6348ad

Please sign in to comment.