Skip to content

Commit

Permalink
Merge pull request #260 from manicminer/application/fallbackpublicclient
Browse files Browse the repository at this point in the history
ApplicationsClient: add the `SetFallbackPublicClient()` method
  • Loading branch information
manicminer authored Oct 18, 2023
2 parents e40d39c + 74d9058 commit 38fa0e8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
44 changes: 44 additions & 0 deletions msgraph/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,50 @@ func (c *ApplicationsClient) RestoreDeleted(ctx context.Context, id string) (*Ap
return &restoredApplication, status, nil
}

// SetFallbackPublicClient amends the manifest of an existing Application.
func (c *ApplicationsClient) SetFallbackPublicClient(ctx context.Context, id string, fallbackPublicClient *bool) (int, error) {
var status int

application := struct {
DirectoryObject
IsFallbackPublicClient *bool `json:"isFallbackPublicClient"`
}{
DirectoryObject: DirectoryObject{
Id: &id,
},
IsFallbackPublicClient: fallbackPublicClient,
}

body, err := json.Marshal(application)
if err != nil {
return status, fmt.Errorf("json.Marshal(): %v", err)
}

checkApplicationConsistency := func(resp *http.Response, o *odata.OData) bool {
if resp == nil {
return false
}
if resp.StatusCode == http.StatusNotFound {
return true
}
return false
}

_, status, _, err = c.BaseClient.Patch(ctx, PatchHttpRequestInput{
Body: body,
ConsistencyFailureFunc: checkApplicationConsistency,
ValidStatusCodes: []int{http.StatusNoContent},
Uri: Uri{
Entity: fmt.Sprintf("/applications/%s", *application.ID()),
},
})
if err != nil {
return status, fmt.Errorf("ApplicationsClient.BaseClient.Patch(): %v", err)
}

return status, nil
}

// AddPassword appends a new password credential to an Application.
func (c *ApplicationsClient) AddPassword(ctx context.Context, applicationId string, passwordCredential PasswordCredential) (*PasswordCredential, int, error) {
var status int
Expand Down
16 changes: 16 additions & 0 deletions msgraph/applications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ func TestApplicationsClient(t *testing.T) {
testApplicationsClient_ListExtension(t, c, *app.ID())
testApplicationsClient_DeleteExtension(t, c, extensionId, *app.ID())

testApplicationsClient_SetFallbackPublicClient(t, c, *app.ID(), utils.BoolPtr(true))
testApplicationsClient_SetFallbackPublicClient(t, c, *app.ID(), utils.BoolPtr(false))
testApplicationsClient_SetFallbackPublicClient(t, c, *app.ID(), nil)
testApplicationsClient_Get(t, c, *app.ID())

testApplicationsClient_Update(t, c, *app)
testApplicationsClient_Update(t, c, *app)

owners := testApplicationsClient_ListOwners(t, c, *app.ID())
Expand Down Expand Up @@ -128,6 +134,16 @@ func testApplicationsClient_Update(t *testing.T, c *test.Test, a msgraph.Applica
}
}

func testApplicationsClient_SetFallbackPublicClient(t *testing.T, c *test.Test, appId string, fallbackPublicClient *bool) {
status, err := c.ApplicationsClient.SetFallbackPublicClient(c.Context, appId, fallbackPublicClient)
if err != nil {
t.Fatalf("ApplicationsClient.SetFallbackPublicClient(): %v", err)
}
if status < 200 || status >= 300 {
t.Fatalf("ApplicationsClient.SetFallbackPublicClient(): invalid status: %d", status)
}
}

func testApplicationsClient_List(t *testing.T, c *test.Test) (applications *[]msgraph.Application) {
applications, _, err := c.ApplicationsClient.List(c.Context, odata.Query{})
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions msgraph/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -1140,11 +1140,11 @@ type ImplicitGrantSettings struct {
}

type InformationalUrl struct {
LogoUrl *string `json:"logoUrl,omitempty"`
MarketingUrl *string `json:"marketingUrl"`
PrivacyStatementUrl *string `json:"privacyStatementUrl"`
SupportUrl *string `json:"supportUrl"`
TermsOfServiceUrl *string `json:"termsOfServiceUrl"`
LogoUrl *StringNullWhenEmpty `json:"logoUrl,omitempty"`
MarketingUrl *StringNullWhenEmpty `json:"marketingUrl"`
PrivacyStatementUrl *StringNullWhenEmpty `json:"privacyStatementUrl"`
SupportUrl *StringNullWhenEmpty `json:"supportUrl"`
TermsOfServiceUrl *StringNullWhenEmpty `json:"termsOfServiceUrl"`
}

// Invitation describes a Invitation object.
Expand Down

0 comments on commit 38fa0e8

Please sign in to comment.