Skip to content

Commit 4d39f08

Browse files
Add force delete KMIP object (#128)
Signed-off-by: Giakhanh Hoang <[email protected]>
1 parent fb6c853 commit 4d39f08

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

key_rings.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ func (c *Client) GetKeyRings(ctx context.Context) (*KeyRings, error) {
5959
return &rings, nil
6060
}
6161

62-
type DeleteKeyRingQueryOption func(*http.Request)
62+
type RequestOpt func(*http.Request)
6363

64-
func WithForce(force bool) DeleteKeyRingQueryOption {
64+
func WithForce(force bool) RequestOpt {
6565
return func(req *http.Request) {
6666
query := req.URL.Query()
6767
query.Add("force", strconv.FormatBool(force))
@@ -72,7 +72,7 @@ func WithForce(force bool) DeleteKeyRingQueryOption {
7272
// DeleteRing method deletes the key ring with the provided name in the instance
7373
// For information please refer to the link below:
7474
// https://cloud.ibm.com/docs/key-protect?topic=key-protect-managing-key-rings#delete-key-ring-api
75-
func (c *Client) DeleteKeyRing(ctx context.Context, id string, opts ...DeleteKeyRingQueryOption) error {
75+
func (c *Client) DeleteKeyRing(ctx context.Context, id string, opts ...RequestOpt) error {
7676
req, err := c.newRequest("DELETE", fmt.Sprintf(keyRingPath+"/%s", id), nil)
7777
for _, opt := range opts {
7878
opt(req)

kmip_mgmt_objects.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,17 @@ func (c *Client) GetKMIPObject(ctx context.Context, adapter_id, object_id string
9292
return unwrapKMIPObject(objects), nil
9393
}
9494

95-
func (c *Client) DeleteKMIPObject(ctx context.Context, adapter_id, object_id string) error {
95+
func (c *Client) DeleteKMIPObject(ctx context.Context, adapter_id, object_id string, opts ...RequestOpt) error {
9696
req, err := c.newRequest("DELETE", fmt.Sprintf("%s/%s/%s/%s",
9797
kmipAdapterPath, adapter_id, kmipObjectSubPath, object_id), nil)
9898
if err != nil {
9999
return err
100100
}
101101

102+
for _, opt := range opts {
103+
opt(req)
104+
}
105+
102106
_, err = c.do(ctx, req, nil)
103107
if err != nil {
104108
return err

kp_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5623,7 +5623,7 @@ func TestKMIPMgmtAPI(t *testing.T) {
56235623
gock.New(baseURL).
56245624
Delete(objectPath + "/" + UUID).
56255625
Reply(http.StatusNoContent)
5626-
err := api.DeleteKMIPObject(ctx, UUID, UUID)
5626+
err := api.DeleteKMIPObject(ctx, UUID, UUID, WithForce(false))
56275627
assert.NoError(t, err)
56285628
return nil
56295629
},

0 commit comments

Comments
 (0)