From b21be89aafbeaf6d9b6acf0415887ec616e9faea Mon Sep 17 00:00:00 2001 From: Alex Wilcox Date: Thu, 15 Jun 2023 21:20:34 +0000 Subject: [PATCH 1/2] Add delete func AccessPackageResourceRoleScope --- msgraph/accesspackageresourcerolescope.go | 16 ++++++++++++++++ msgraph/accesspackageresourcerolescope_test.go | 12 +++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/msgraph/accesspackageresourcerolescope.go b/msgraph/accesspackageresourcerolescope.go index dc8025d2..ca4435fd 100644 --- a/msgraph/accesspackageresourcerolescope.go +++ b/msgraph/accesspackageresourcerolescope.go @@ -153,3 +153,19 @@ func (c *AccessPackageResourceRoleScopeClient) Get(ctx context.Context, accessPa return &accessPackageResourceRoleScope, status, nil } + +// Delete removes a AccessPackageResourceRoleScope. +func (c *AccessPackageResourceRoleScopeClient) Delete(ctx context.Context, accessPackageId string, id string) (int, error) { + _, status, _, err := c.BaseClient.Delete(ctx, DeleteHttpRequestInput{ + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + ValidStatusCodes: []int{http.StatusOK}, + Uri: Uri{ + Entity: fmt.Sprintf("/identityGovernance/entitlementManagement/accessPackages/%s/accessPackageResourceRoleScopes/%s", accessPackageId, id), + }, + }) + if err != nil { + return status, fmt.Errorf("AccessPackageResourceRoleScopeClient.BaseClient.Delete(): %v", err) + } + + return status, nil +} diff --git a/msgraph/accesspackageresourcerolescope_test.go b/msgraph/accesspackageresourcerolescope_test.go index a102929a..f2ca7811 100644 --- a/msgraph/accesspackageresourcerolescope_test.go +++ b/msgraph/accesspackageresourcerolescope_test.go @@ -67,6 +67,7 @@ func TestAccessPackageResourceRoleScopeClient(t *testing.T) { testAccessPackageResourceRoleScopeClient_Get(t, c, *accessPackageResourceRoleScope.AccessPackageId, *accessPackageResourceRoleScope.ID) testAccessPackageResourceRoleScopeResource_Get(t, c, *accessPackageResourceRequest.CatalogId, *accessPackageResourceRequest.AccessPackageResource.OriginId) testAccessPackageResourceRoleScopeClient_List(t, c, *accessPackageResourceRoleScope.AccessPackageId) + testAccessPackageResourceRoleScopeClient_Delete(t, c, *accessPackageResourceRoleScope.AccessPackageId, *accessPackageResourceRoleScope.ID) // Force-replacement scenario testAccessPackageResourceRoleScopeAP_Delete(t, c, *accessPackage.ID) @@ -93,7 +94,6 @@ func TestAccessPackageResourceRoleScopeClient(t *testing.T) { }, }) - //testAccessPackageResourceRoleScopeClient_Delete(t, c, *accessPackageResourceRoleScope) //testAccessPackageResourceRequestClient_Delete(t, c, accessPackageResourceRequest) // Cleanup @@ -147,6 +147,16 @@ func testAccessPackageResourceRoleScopeClient_List(t *testing.T, c *test.Test, a return } +func testAccessPackageResourceRoleScopeClient_Delete(t *testing.T, c *test.Test, accessPackageId string, id string) { + status, err := c.AccessPackageResourceRoleScopeClient.Delete(c.Context, accessPackageId, id) + if err != nil { + t.Fatalf("AccessPackageResourceRequestClient.Delete(): %v", err) + } + if status < 200 || status >= 300 { + t.Fatalf("AccessPackageResourceRequestClient.Delete(): invalid status: %d", status) + } +} + // AccessPackageResourceRequest func testAccessPackageResourceRoleScopeResourceRequest_Create(t *testing.T, c *test.Test, a msgraph.AccessPackageResourceRequest, pollForId bool) (accessPackageResourceRequest *msgraph.AccessPackageResourceRequest) { From 23bfa7f90aa4898dd0822c4dd53293bb43d073d2 Mon Sep 17 00:00:00 2001 From: Alex Wilcox Date: Sat, 17 Jun 2023 15:06:15 +0000 Subject: [PATCH 2/2] Return 404 when item cannot be found --- msgraph/accesspackageresource.go | 2 +- msgraph/accesspackageresourcerolescope.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/msgraph/accesspackageresource.go b/msgraph/accesspackageresource.go index 151f0818..92f6c01a 100644 --- a/msgraph/accesspackageresource.go +++ b/msgraph/accesspackageresource.go @@ -83,7 +83,7 @@ func (c *AccessPackageResourceClient) Get(ctx context.Context, catalogId string, accessPackageResources := data.AccessPackageResources if len(accessPackageResources) == 0 { - return nil, status, fmt.Errorf("No accessPackageResource found with catalogId %v and originId %v", catalogId, originId) + return nil, http.StatusNotFound, fmt.Errorf("No accessPackageResource found with catalogId %v and originId %v", catalogId, originId) } return &accessPackageResources[0], status, nil diff --git a/msgraph/accesspackageresourcerolescope.go b/msgraph/accesspackageresourcerolescope.go index ca4435fd..068c0197 100644 --- a/msgraph/accesspackageresourcerolescope.go +++ b/msgraph/accesspackageresourcerolescope.go @@ -148,7 +148,7 @@ func (c *AccessPackageResourceRoleScopeClient) Get(ctx context.Context, accessPa } if accessPackageResourceRoleScope.ID == nil { - return nil, status, fmt.Errorf("AccessPackageResourceRoleScopeClient.BaseClient.Get(): Could not find accessPackageResourceRoleScope ID") + return nil, http.StatusNotFound, fmt.Errorf("AccessPackageResourceRoleScopeClient.BaseClient.Get(): Could not find accessPackageResourceRoleScope ID %s", id) } return &accessPackageResourceRoleScope, status, nil