Skip to content

Add force delete option for KMIP object #128

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

Merged
merged 1 commit into from
Jun 27, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions key_rings.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func (c *Client) GetKeyRings(ctx context.Context) (*KeyRings, error) {
return &rings, nil
}

type DeleteKeyRingQueryOption func(*http.Request)
type RequestOpt func(*http.Request)

func WithForce(force bool) DeleteKeyRingQueryOption {
func WithForce(force bool) RequestOpt {
return func(req *http.Request) {
query := req.URL.Query()
query.Add("force", strconv.FormatBool(force))
Expand All @@ -72,7 +72,7 @@ func WithForce(force bool) DeleteKeyRingQueryOption {
// DeleteRing method deletes the key ring with the provided name in the instance
// For information please refer to the link below:
// https://cloud.ibm.com/docs/key-protect?topic=key-protect-managing-key-rings#delete-key-ring-api
func (c *Client) DeleteKeyRing(ctx context.Context, id string, opts ...DeleteKeyRingQueryOption) error {
func (c *Client) DeleteKeyRing(ctx context.Context, id string, opts ...RequestOpt) error {
req, err := c.newRequest("DELETE", fmt.Sprintf(keyRingPath+"/%s", id), nil)
for _, opt := range opts {
opt(req)
Expand Down
6 changes: 5 additions & 1 deletion kmip_mgmt_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,17 @@ func (c *Client) GetKMIPObject(ctx context.Context, adapter_id, object_id string
return unwrapKMIPObject(objects), nil
}

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

for _, opt := range opts {
opt(req)
}

_, err = c.do(ctx, req, nil)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion kp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5623,7 +5623,7 @@ func TestKMIPMgmtAPI(t *testing.T) {
gock.New(baseURL).
Delete(objectPath + "/" + UUID).
Reply(http.StatusNoContent)
err := api.DeleteKMIPObject(ctx, UUID, UUID)
err := api.DeleteKMIPObject(ctx, UUID, UUID, WithForce(false))
assert.NoError(t, err)
return nil
},
Expand Down