go-ceph/rgw/admin/link.go
Sebastian Riese 1de6083536 rgw/admin: Clean up the parameter serialization
The following changes have been done:

* Up until now everything in the argument objects was serialized to
  the API calls. This was updated to restrict the serialization to
  the API call parameters that are parsed in the Ceph RGW source code.

  Parameters not yet supported by us are documented as comments.
  Note, that a superset of the documented parameters is supported.

  Documentation for the API:
  <https://docs.ceph.com/en/pacific/radosgw/adminops/>

  Link to the used source tree:
  <193895ffba/src/rgw>

  The argument parsing happens in the rgw_rest_*.cc files.

* The serialization code (valueToURLParams) has been updated to
  be more in line with other serialization methods:

  - A tag "-" causes the field to be ignored
  - Only the first item in a list of tag items is interpreted as
    name.
  - The handling of pointer and direct data types has been
    harmonized (the same rules for the names and value apply now).

* There is still room for improvement to make things more consistent:
  A pointer to a non-elementary data type will emit unexpected
  request parameters.

* Presence of required parameters is not validated by the library,
  this is left to the API.

Signed-off-by: Sebastian Riese <sebastian.riese@cloudandheat.com>
2022-03-17 17:47:25 +00:00

46 lines
1.2 KiB
Go

//go:build ceph_preview
// +build ceph_preview
package admin
import (
"context"
"net/http"
)
// BucketLinkInput the bucket link/unlink input parameters
type BucketLinkInput struct {
Bucket string `url:"bucket" json:"bucket"`
BucketID string `url:"bucket-id" json:"bucket_id"`
UID string `url:"uid" json:"uid"`
}
// UnlinkBucket unlink a bucket from a specified user
// Primarily useful for changing bucket ownership.
// PREVIEW
func (api *API) UnlinkBucket(ctx context.Context, link BucketLinkInput) error {
if link.UID == "" {
return errMissingUserID
}
if link.Bucket == "" {
return errMissingBucket
}
_, err := api.call(ctx, http.MethodPost, "/bucket", valueToURLParams(link, []string{"uid", "bucket"}))
return err
}
// LinkBucket will link a bucket to a specified user
// unlinking the bucket from any previous user
// PREVIEW
func (api *API) LinkBucket(ctx context.Context, link BucketLinkInput) error {
if link.UID == "" {
return errMissingUserID
}
if link.Bucket == "" {
return errMissingBucket
}
// valid parameters not supported by go-ceph: new-bucket-name
_, err := api.call(ctx, http.MethodPut, "/bucket", valueToURLParams(link, []string{"uid", "bucket-id", "bucket"}))
return err
}