Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit c529bce

Browse files
authored
Merge pull request #12 from philips-software/feature/delete-organization
Add delete organization support
2 parents 68f8785 + 9381e5a commit c529bce

File tree

3 files changed

+113
-4
lines changed

3 files changed

+113
-4
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
88

9+
## v0.15.0
10+
11+
- [NEW] Cartel API support
12+
- Switch to SCIM based organization management
13+
- Add Organizations.DeleteOrganization()
14+
- Add Organizations.DeleteStatus()
15+
16+
917
## v0.14.0
1018
- [IAM] Move user find API to v2
1119
- [IAM] Update go-hsdp-signer

iam/organizations_service.go

+36-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package iam
22

33
import (
4+
"bytes"
45
"fmt"
56
"net/http"
7+
"time"
68
)
79

810
const (
@@ -21,6 +23,20 @@ type GetOrganizationOptions struct {
2123
ExcludedAttributes *string `url:"excludedAttributes,omitempty"`
2224
}
2325

26+
type OrganizationStatus struct {
27+
Schemas []string `json:"schemas"`
28+
ID string `json:"id"`
29+
Status string `json:"status"`
30+
TotalResources int `json:"totalResources"`
31+
Meta struct {
32+
ResourceType string `json:"resourceType"`
33+
Created time.Time `json:"created"`
34+
LastModified time.Time `json:"lastModified"`
35+
Location string `json:"location"`
36+
Version string `json:"version"`
37+
} `json:"meta"`
38+
}
39+
2440
func FilterOrgEq(orgID string) *GetOrganizationOptions {
2541
query := "id eq \"" + orgID + "\""
2642
attributes := "id"
@@ -74,20 +90,22 @@ func (o *OrganizationsService) CreateOrganization(organization Organization) (*O
7490
}
7591

7692
// DeleteOrganization deletes the organization
77-
// WARNING: Not implemented in current IAM releases (As of May 11th 2020)
7893
func (o *OrganizationsService) DeleteOrganization(org Organization) (bool, *Response, error) {
7994
req, err := o.client.NewRequest(IDM, "DELETE", "authorize/scim/v2/Organizations/"+org.ID, nil, nil)
8095
if err != nil {
8196
return false, nil, err
8297
}
8398
req.Header.Set("api-version", organizationAPIVersion)
8499
req.Header.Set("Content-Type", "application/json")
100+
req.Header.Set("If-Method", "DELETE")
101+
102+
var deleteResponse bytes.Buffer
85103

86-
resp, err := o.client.Do(req, nil)
104+
resp, err := o.client.Do(req, &deleteResponse)
87105
if err != nil {
88106
return false, resp, err
89107
}
90-
return resp.StatusCode == http.StatusNoContent, resp, nil
108+
return resp.StatusCode == http.StatusAccepted, resp, nil
91109
}
92110

93111
// UpdateOrganization updates the description of the organization.
@@ -151,3 +169,18 @@ func (o *OrganizationsService) GetOrganization(opt *GetOrganizationOptions, opti
151169

152170
return o.GetOrganizationByID(bundleResponse.Resources[0].ID)
153171
}
172+
173+
// DeleteStatus returns the status of a delete operation on an organization
174+
func (o *OrganizationsService) DeleteStatus(id string) (*OrganizationStatus, *Response, error) {
175+
req, err := o.client.NewRequest(IDM, "GET", "authorize/scim/v2/Organizations/"+id+"/deleteStatus", nil, nil)
176+
if err != nil {
177+
return nil, nil, err
178+
}
179+
req.Header.Set("api-version", organizationAPIVersion)
180+
req.Header.Set("Content-Type", "application/json")
181+
182+
var deleteResponse OrganizationStatus
183+
184+
resp, err := o.client.Do(req, &deleteResponse)
185+
return &deleteResponse, resp, err
186+
}

iam/organizations_service_test.go

+69-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ func TestUpdateAndDeleteOrganization(t *testing.T) {
185185
w.WriteHeader(http.StatusOK)
186186
_, _ = io.WriteString(w, string(responseBody))
187187
case "DELETE":
188-
w.WriteHeader(http.StatusNoContent)
188+
if r.Header.Get("If-Method") != "DELETE" {
189+
w.WriteHeader(http.StatusForbidden)
190+
return
191+
}
192+
w.WriteHeader(http.StatusAccepted)
189193
return
190194
default:
191195
w.WriteHeader(http.StatusMethodNotAllowed)
@@ -202,6 +206,9 @@ func TestUpdateAndDeleteOrganization(t *testing.T) {
202206
}
203207

204208
updatedOrg, resp, err := client.Organizations.UpdateOrganization(*foundOrg)
209+
if !assert.Nil(t, err) {
210+
return
211+
}
205212
if !assert.NotNil(t, resp) {
206213
return
207214
}
@@ -275,3 +282,64 @@ func TestGetOrganization(t *testing.T) {
275282
assert.Equal(t, orgName, foundOrg.Name)
276283
assert.Equal(t, orgUUID, foundOrg.ID)
277284
}
285+
286+
func TestDeleteStatus(t *testing.T) {
287+
teardown := setup(t)
288+
defer teardown()
289+
290+
orgUUID := "c57b2625-eda3-4b27-a8e6-86f0a0e76afc"
291+
292+
muxIDM.HandleFunc("/authorize/scim/v2/Organizations/"+orgUUID+"/deleteStatus", func(w http.ResponseWriter, r *http.Request) {
293+
if r.Method != "GET" {
294+
w.WriteHeader(http.StatusMethodNotAllowed)
295+
return
296+
}
297+
w.Header().Set("Content-Type", "application/json")
298+
w.WriteHeader(http.StatusOK)
299+
_, _ = io.WriteString(w, `{
300+
"schemas": [
301+
"urn:ietf:params:scim:api:messages:philips:hsdp:2.0:DeleteStatus"
302+
],
303+
"id": "`+orgUUID+`",
304+
"status": "IN_PROGRESS",
305+
"totalResources": 100,
306+
"meta": {
307+
"resourceType": "Organization",
308+
"created": "2020-05-24T20:33:59.192Z",
309+
"lastModified": "2020-05-24T20:33:59.192Z",
310+
"location": "https://idm-xx.us-east.philips-healthsuite.com/authorize/scim/v2/Organizations/`+orgUUID+`",
311+
"version": "W/\"f250dd84f0671c3\""
312+
}
313+
}`)
314+
})
315+
316+
status, resp, err := client.Organizations.DeleteStatus(orgUUID)
317+
assert.Nil(t, err)
318+
if !assert.NotNil(t, resp) {
319+
return
320+
}
321+
if !assert.NotNil(t, status) {
322+
return
323+
}
324+
assert.Equal(t, http.StatusOK, resp.StatusCode)
325+
assert.Equal(t, "IN_PROGRESS", status.Status)
326+
assert.Equal(t, orgUUID, status.ID)
327+
}
328+
329+
func TestFilters(t *testing.T) {
330+
opts := FilterParentEq("xxx")
331+
if !assert.NotNil(t, opts) {
332+
return
333+
}
334+
assert.Equal(t, `parent.value eq "xxx"`, *opts.Filter)
335+
opts = FilterOrgEq("yyy")
336+
if !assert.NotNil(t, opts) {
337+
return
338+
}
339+
assert.Equal(t, `id eq "yyy"`, *opts.Filter)
340+
opts = FilterNameEq("zzz")
341+
if !assert.NotNil(t, opts) {
342+
return
343+
}
344+
assert.Equal(t, `name eq "zzz"`, *opts.Filter)
345+
}

0 commit comments

Comments
 (0)