This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 558
Adding DeleteApp func to AzureClient and returning appObjectID in CreateApp #3869
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
931da57
adding delete app fn and adding appObjectID to createApp
a244076
changed appName to applicationName
8dd4afb
returning autorest.Response from CreateApp
a68ac31
returning graphrbac.Application type for CreateApp
9df2d47
correcting param name
33f10f8
updating test files
f1a4484
updating test files
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
|
||
"github.com/Azure/azure-sdk-for-go/services/authorization/mgmt/2015-07-01/authorization" | ||
"github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac" | ||
"github.com/Azure/go-autorest/autorest" | ||
"github.com/Azure/go-autorest/autorest/date" | ||
"github.com/Azure/go-autorest/autorest/to" | ||
"github.com/satori/go.uuid" | ||
|
@@ -28,6 +29,11 @@ func (az *AzureClient) CreateGraphApplication(ctx context.Context, applicationCr | |
return az.applicationsClient.Create(ctx, applicationCreateParameters) | ||
} | ||
|
||
// DeleteGraphApplication creates an application via the graphrbac client | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should say "deletes an application". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup ! I ll change it now |
||
func (az *AzureClient) DeleteGraphApplication(ctx context.Context, applicationObjectID string) (result autorest.Response, err error) { | ||
return az.applicationsClient.Delete(ctx, applicationObjectID) | ||
} | ||
|
||
// CreateGraphPrincipal creates a service principal via the graphrbac client | ||
func (az *AzureClient) CreateGraphPrincipal(ctx context.Context, servicePrincipalCreateParameters graphrbac.ServicePrincipalCreateParameters) (graphrbac.ServicePrincipal, error) { | ||
return az.servicePrincipalsClient.Create(ctx, servicePrincipalCreateParameters) | ||
|
@@ -50,7 +56,7 @@ func (az *AzureClient) ListRoleAssignmentsForPrincipal(ctx context.Context, scop | |
} | ||
|
||
// CreateApp is a simpler method for creating an application | ||
func (az *AzureClient) CreateApp(ctx context.Context, appName, appURL string, replyURLs *[]string, requiredResourceAccess *[]graphrbac.RequiredResourceAccess) (applicationID, servicePrincipalObjectID, servicePrincipalClientSecret string, err error) { | ||
func (az *AzureClient) CreateApp(ctx context.Context, appName, appURL string, replyURLs *[]string, requiredResourceAccess *[]graphrbac.RequiredResourceAccess) (applicationObjectID, applicationID, servicePrincipalObjectID, servicePrincipalClientSecret string, err error) { | ||
notBefore := time.Now() | ||
notAfter := time.Now().Add(10000 * 24 * time.Hour) | ||
|
||
|
@@ -78,9 +84,10 @@ func (az *AzureClient) CreateApp(ctx context.Context, appName, appURL string, re | |
} | ||
applicationResp, err := az.CreateGraphApplication(ctx, applicationReq) | ||
if err != nil { | ||
return "", "", "", err | ||
return "", "", "", "", err | ||
} | ||
applicationID = to.String(applicationResp.AppID) | ||
applicationObjectID = to.String(applicationResp.ObjectID) | ||
|
||
log.Debugf("ad: creating servicePrincipal for applicationID: %q", applicationID) | ||
|
||
|
@@ -90,12 +97,22 @@ func (az *AzureClient) CreateApp(ctx context.Context, appName, appURL string, re | |
} | ||
servicePrincipalResp, err := az.servicePrincipalsClient.Create(ctx, servicePrincipalReq) | ||
if err != nil { | ||
return "", "", "", err | ||
return "", "", "", "", err | ||
} | ||
|
||
servicePrincipalObjectID = to.String(servicePrincipalResp.ObjectID) | ||
|
||
return applicationID, servicePrincipalObjectID, servicePrincipalClientSecret, nil | ||
return applicationObjectID, applicationID, servicePrincipalObjectID, servicePrincipalClientSecret, nil | ||
} | ||
|
||
// DeleteApp is a simpler method for deleting an application and the associated spn | ||
func (az *AzureClient) DeleteApp(ctx context.Context, appName, applicationObjectID string) (autorest.Response, error) { | ||
shrutir25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
log.Debugf("ad: deleting application with name=%q", appName) | ||
applicationResp, err := az.DeleteGraphApplication(ctx, applicationObjectID) | ||
if err != nil { | ||
return applicationResp, err | ||
} | ||
return applicationResp, nil | ||
} | ||
|
||
// CreateRoleAssignmentSimple is a wrapper around RoleAssignmentsClient.Create | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"github.com/Azure/azure-sdk-for-go/services/preview/msi/mgmt/2015-08-31-preview/msi" | ||
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources" | ||
azStorage "github.com/Azure/azure-sdk-for-go/storage" | ||
"github.com/Azure/go-autorest/autorest" | ||
log "github.com/sirupsen/logrus" | ||
"k8s.io/api/core/v1" | ||
) | ||
|
@@ -102,7 +103,8 @@ type ACSEngineClient interface { | |
|
||
// CreateGraphPrincipal creates a service principal via the graphrbac client | ||
CreateGraphPrincipal(ctx context.Context, servicePrincipalCreateParameters graphrbac.ServicePrincipalCreateParameters) (graphrbac.ServicePrincipal, error) | ||
CreateApp(ctx context.Context, applicationName, applicationURL string, replyURLs *[]string, requiredResourceAccess *[]graphrbac.RequiredResourceAccess) (applicationID, servicePrincipalObjectID, secret string, err error) | ||
CreateApp(ctx context.Context, applicationName, applicationURL string, replyURLs *[]string, requiredResourceAccess *[]graphrbac.RequiredResourceAccess) (applicationObjectID, applicationID, servicePrincipalObjectID, secret string, err error) | ||
DeleteApp(ctx context.Context, appName, applicationObjectID string) (autorest.Response, error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this parameter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure makes sense ! |
||
|
||
// User Assigned MSI | ||
//CreateUserAssignedID - Creates a user assigned msi. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shrutir25 I think it would be good to avoid underscore placeholders since it goes against the tenets of idiomatic Go. We could change the return type of CreateApp to autorest.Response instead.
I see two benefits
We address the concern above.
It also becomes consistent with DeleteApplication.