Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove named returns #72

Merged
merged 3 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions api/application_aad.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type ActiveDirectoryApplicationClient struct {
Passwords Passwords
}

func (a *ActiveDirectoryApplicationClient) GetApplication(ctx context.Context, applicationObjectID string) (result ApplicationResult, err error) {
func (a *ActiveDirectoryApplicationClient) GetApplication(ctx context.Context, applicationObjectID string) (ApplicationResult, error) {
app, err := a.Client.Get(ctx, applicationObjectID)
if err != nil {
return ApplicationResult{}, err
Expand All @@ -31,7 +31,7 @@ func (a *ActiveDirectoryApplicationClient) GetApplication(ctx context.Context, a
}, nil
}

func (a *ActiveDirectoryApplicationClient) CreateApplication(ctx context.Context, displayName string) (result ApplicationResult, err error) {
func (a *ActiveDirectoryApplicationClient) CreateApplication(ctx context.Context, displayName string) (ApplicationResult, error) {
appURL := fmt.Sprintf("https://%s", displayName)

app, err := a.Client.Create(ctx, graphrbac.ApplicationCreateParameters{
Expand Down Expand Up @@ -62,7 +62,7 @@ func (a *ActiveDirectoryApplicationClient) DeleteApplication(ctx context.Context
return nil
}

func (a *ActiveDirectoryApplicationClient) AddApplicationPassword(ctx context.Context, applicationObjectID string, displayName string, endDateTime date.Time) (result PasswordCredentialResult, err error) {
func (a *ActiveDirectoryApplicationClient) AddApplicationPassword(ctx context.Context, applicationObjectID string, displayName string, endDateTime date.Time) (PasswordCredentialResult, error) {
keyID, err := uuid.GenerateUUID()
if err != nil {
return PasswordCredentialResult{}, err
Expand Down Expand Up @@ -106,7 +106,7 @@ func (a *ActiveDirectoryApplicationClient) AddApplicationPassword(ctx context.Co
return PasswordCredentialResult{}, fmt.Errorf("error updating credentials: %w", err)
}

result = PasswordCredentialResult{
result := PasswordCredentialResult{
PasswordCredential: PasswordCredential{
DisplayName: to.StringPtr(displayName),
StartDate: &now,
Expand All @@ -118,7 +118,7 @@ func (a *ActiveDirectoryApplicationClient) AddApplicationPassword(ctx context.Co
return result, nil
}

func (a *ActiveDirectoryApplicationClient) RemoveApplicationPassword(ctx context.Context, applicationObjectID string, keyID string) (err error) {
func (a *ActiveDirectoryApplicationClient) RemoveApplicationPassword(ctx context.Context, applicationObjectID string, keyID string) error {
// Load current credentials
resp, err := a.Client.ListPasswordCredentials(ctx, applicationObjectID)
if err != nil {
Expand Down
65 changes: 39 additions & 26 deletions api/application_msgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func (c *AppClient) AddToUserAgent(extension string) error {
return c.client.AddToUserAgent(extension)
}

func (c *AppClient) GetApplication(ctx context.Context, applicationObjectID string) (result ApplicationResult, err error) {
func (c *AppClient) GetApplication(ctx context.Context, applicationObjectID string) (ApplicationResult, error) {
var result ApplicationResult
req, err := c.getApplicationPreparer(ctx, applicationObjectID)
if err != nil {
return result, autorest.NewErrorWithError(err, "provider", "GetApplication", nil, "Failure preparing request")
Expand All @@ -72,7 +73,9 @@ func (c *AppClient) GetApplication(ctx context.Context, applicationObjectID stri
}

// CreateApplication create a new Azure application object.
func (c *AppClient) CreateApplication(ctx context.Context, displayName string) (result ApplicationResult, err error) {
func (c *AppClient) CreateApplication(ctx context.Context, displayName string) (ApplicationResult, error) {
var result ApplicationResult

req, err := c.createApplicationPreparer(ctx, displayName)
if err != nil {
return result, autorest.NewErrorWithError(err, "provider", "CreateApplication", nil, "Failure preparing request")
Expand All @@ -87,15 +90,14 @@ func (c *AppClient) CreateApplication(ctx context.Context, displayName string) (
result, err = c.createApplicationResponder(resp)
jasonodonnell marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return result, autorest.NewErrorWithError(err, "provider", "CreateApplication", resp, "Failure responding to request")

}

return result, nil
}

// DeleteApplication deletes an Azure application object.
// This will in turn remove the service principal (but not the role assignments).
func (c *AppClient) DeleteApplication(ctx context.Context, applicationObjectID string) (err error) {
func (c *AppClient) DeleteApplication(ctx context.Context, applicationObjectID string) error {
req, err := c.deleteApplicationPreparer(ctx, applicationObjectID)
if err != nil {
return autorest.NewErrorWithError(err, "provider", "DeleteApplication", nil, "Failure preparing request")
Expand All @@ -111,10 +113,17 @@ func (c *AppClient) DeleteApplication(ctx context.Context, applicationObjectID s
c.client.ByInspecting(),
azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusNotFound),
autorest.ByClosing())
return autorest.NewErrorWithError(err, "provider", "DeleteApplication", resp, "Failure responding to request")

if err != nil {
return autorest.NewErrorWithError(err, "provider", "DeleteApplication", resp, "Failure responding to request")
}

return nil
}

func (c *AppClient) AddApplicationPassword(ctx context.Context, applicationObjectID string, displayName string, endDateTime date.Time) (result PasswordCredentialResult, err error) {
func (c *AppClient) AddApplicationPassword(ctx context.Context, applicationObjectID string, displayName string, endDateTime date.Time) (PasswordCredentialResult, error) {
var result PasswordCredentialResult

req, err := c.addPasswordPreparer(ctx, applicationObjectID, displayName, endDateTime)
if err != nil {
return PasswordCredentialResult{}, autorest.NewErrorWithError(err, "provider", "AddApplicationPassword", nil, "Failure preparing request")
Expand All @@ -136,7 +145,7 @@ func (c *AppClient) AddApplicationPassword(ctx context.Context, applicationObjec
return result, nil
}

func (c *AppClient) RemoveApplicationPassword(ctx context.Context, applicationObjectID string, keyID string) (err error) {
func (c *AppClient) RemoveApplicationPassword(ctx context.Context, applicationObjectID string, keyID string) error {
req, err := c.removePasswordPreparer(ctx, applicationObjectID, keyID)
if err != nil {
return autorest.NewErrorWithError(err, "provider", "RemoveApplicationPassword", nil, "Failure preparing request")
Expand Down Expand Up @@ -174,8 +183,9 @@ func (c AppClient) getApplicationSender(req *http.Request) (*http.Response, erro
return autorest.SendWithSender(c.client, req, sd...)
}

func (c AppClient) getApplicationResponder(resp *http.Response) (result ApplicationResult, err error) {
err = autorest.Respond(
func (c AppClient) getApplicationResponder(resp *http.Response) (ApplicationResult, error) {
var result ApplicationResult
err := autorest.Respond(
resp,
c.client.ByInspecting(),
azure.WithErrorUnlessStatusCode(http.StatusOK),
Expand Down Expand Up @@ -214,8 +224,9 @@ func (c AppClient) addPasswordSender(req *http.Request) (*http.Response, error)
return autorest.SendWithSender(c.client, req, sd...)
}

func (c AppClient) addPasswordResponder(resp *http.Response) (result PasswordCredentialResult, err error) {
err = autorest.Respond(
func (c AppClient) addPasswordResponder(resp *http.Response) (PasswordCredentialResult, error) {
var result PasswordCredentialResult
err := autorest.Respond(
resp,
c.client.ByInspecting(),
azure.WithErrorUnlessStatusCode(http.StatusOK),
Expand Down Expand Up @@ -251,8 +262,9 @@ func (c AppClient) removePasswordSender(req *http.Request) (*http.Response, erro
return autorest.SendWithSender(c.client, req, sd...)
}

func (c AppClient) removePasswordResponder(resp *http.Response) (result autorest.Response, err error) {
err = autorest.Respond(
func (c AppClient) removePasswordResponder(resp *http.Response) (autorest.Response, error) {
var result autorest.Response
err := autorest.Respond(
resp,
c.client.ByInspecting(),
azure.WithErrorUnlessStatusCode(http.StatusNoContent),
Expand Down Expand Up @@ -284,8 +296,9 @@ func (c AppClient) createApplicationSender(req *http.Request) (*http.Response, e
return autorest.SendWithSender(c.client, req, sd...)
}

func (c AppClient) createApplicationResponder(resp *http.Response) (result ApplicationResult, err error) {
err = autorest.Respond(
func (c AppClient) createApplicationResponder(resp *http.Response) (ApplicationResult, error) {
var result ApplicationResult
err := autorest.Respond(
resp,
c.client.ByInspecting(),
azure.WithErrorUnlessStatusCode(http.StatusCreated),
Expand Down Expand Up @@ -360,7 +373,7 @@ type groupResponse struct {
DisplayName string `json:"displayName"`
}

func (c AppClient) GetGroup(ctx context.Context, groupID string) (result Group, err error) {
func (c AppClient) GetGroup(ctx context.Context, groupID string) (Group, error) {
if groupID == "" {
return Group{}, fmt.Errorf("missing groupID")
}
Expand All @@ -374,7 +387,7 @@ func (c AppClient) GetGroup(ctx context.Context, groupID string) (result Group,
)

groupResp := groupResponse{}
err = c.SendRequest(ctx, preparer,
err := c.SendRequest(ctx, preparer,
azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
autorest.ByUnmarshallingJSON(&groupResp),
)
Expand All @@ -396,7 +409,7 @@ type listGroupsResponse struct {
Groups []groupResponse `json:"value"`
}

func (c AppClient) ListGroups(ctx context.Context, filter string) (result []Group, err error) {
func (c AppClient) ListGroups(ctx context.Context, filter string) ([]Group, error) {
filterArgs := url.Values{}
if filter != "" {
filterArgs.Set("$filter", filter)
Expand All @@ -408,7 +421,7 @@ func (c AppClient) ListGroups(ctx context.Context, filter string) (result []Grou
)

respBody := listGroupsResponse{}
err = c.SendRequest(ctx, preparer,
err := c.SendRequest(ctx, preparer,
azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
autorest.ByUnmarshallingJSON(&respBody),
)
Expand All @@ -431,12 +444,12 @@ func (c AppClient) ListGroups(ctx context.Context, filter string) (result []Grou
return groups, nil
}

func (c *AppClient) CreateServicePrincipal(ctx context.Context, appID string, startDate time.Time, endDate time.Time) (spID string, password string, err error) {
spID, err = c.createServicePrincipal(ctx, appID)
func (c *AppClient) CreateServicePrincipal(ctx context.Context, appID string, startDate time.Time, endDate time.Time) (string, string, error) {
spID, err := c.createServicePrincipal(ctx, appID)
if err != nil {
return "", "", err
}
password, err = c.setPasswordForServicePrincipal(ctx, spID, startDate, endDate)
password, err := c.setPasswordForServicePrincipal(ctx, spID, startDate, endDate)
if err != nil {
dErr := c.deleteServicePrincipal(ctx, spID)
merr := multierror.Append(err, dErr)
Expand All @@ -445,7 +458,7 @@ func (c *AppClient) CreateServicePrincipal(ctx context.Context, appID string, st
return spID, password, nil
}

func (c *AppClient) createServicePrincipal(ctx context.Context, appID string) (id string, err error) {
func (c *AppClient) createServicePrincipal(ctx context.Context, appID string) (string, error) {
body := map[string]interface{}{
"appId": appID,
"accountEnabled": true,
Expand All @@ -457,7 +470,7 @@ func (c *AppClient) createServicePrincipal(ctx context.Context, appID string) (i
)

respBody := createServicePrincipalResponse{}
err = c.SendRequest(ctx, preparer,
err := c.SendRequest(ctx, preparer,
autorest.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
autorest.ByUnmarshallingJSON(&respBody),
)
Expand All @@ -468,7 +481,7 @@ func (c *AppClient) createServicePrincipal(ctx context.Context, appID string) (i
return respBody.ID, nil
}

func (c *AppClient) setPasswordForServicePrincipal(ctx context.Context, spID string, startDate time.Time, endDate time.Time) (password string, err error) {
func (c *AppClient) setPasswordForServicePrincipal(ctx context.Context, spID string, startDate time.Time, endDate time.Time) (string, error) {
pathParams := map[string]interface{}{
"id": spID,
}
Expand All @@ -484,7 +497,7 @@ func (c *AppClient) setPasswordForServicePrincipal(ctx context.Context, spID str
)

respBody := PasswordCredential{}
err = c.SendRequest(ctx, preparer,
err := c.SendRequest(ctx, preparer,
autorest.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
autorest.ByUnmarshallingJSON(&respBody),
)
Expand Down