mirror of
https://github.com/ceph/go-ceph
synced 2024-12-18 20:35:33 +00:00
1de6083536
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>
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package admin
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
// QuotaSpec describes an object store quota for a user or a bucket
|
|
// Only user's quota are supported
|
|
type QuotaSpec struct {
|
|
UID string `json:"user_id" url:"uid"`
|
|
QuotaType string `url:"quota-type"`
|
|
Enabled *bool `json:"enabled" url:"enabled"`
|
|
CheckOnRaw bool `json:"check_on_raw"`
|
|
MaxSize *int64 `json:"max_size" url:"max-size"`
|
|
MaxSizeKb *int `json:"max_size_kb" url:"max-size-kb"`
|
|
MaxObjects *int64 `json:"max_objects" url:"max-objects"`
|
|
}
|
|
|
|
// GetUserQuota will return the quota for a user
|
|
func (api *API) GetUserQuota(ctx context.Context, quota QuotaSpec) (QuotaSpec, error) {
|
|
// Always for quota type to user
|
|
quota.QuotaType = "user"
|
|
|
|
if quota.UID == "" {
|
|
return QuotaSpec{}, errMissingUserID
|
|
}
|
|
|
|
body, err := api.call(ctx, http.MethodGet, "/user?quota", valueToURLParams(quota, []string{"uid", "quota-type"}))
|
|
if err != nil {
|
|
return QuotaSpec{}, err
|
|
}
|
|
|
|
ref := QuotaSpec{}
|
|
err = json.Unmarshal(body, &ref)
|
|
if err != nil {
|
|
return QuotaSpec{}, fmt.Errorf("%s. %s. %w", unmarshalError, string(body), err)
|
|
}
|
|
|
|
return ref, nil
|
|
}
|
|
|
|
// SetUserQuota sets quota to a user
|
|
// Global quotas (https://docs.ceph.com/en/latest/radosgw/admin/#reading-writing-global-quotas) are not surfaced in the Admin Ops API
|
|
// So this library cannot expose it yet
|
|
func (api *API) SetUserQuota(ctx context.Context, quota QuotaSpec) error {
|
|
// Always for quota type to user
|
|
quota.QuotaType = "user"
|
|
|
|
if quota.UID == "" {
|
|
return errMissingUserID
|
|
}
|
|
|
|
_, err := api.call(ctx, http.MethodPut, "/user?quota", valueToURLParams(quota, []string{"uid", "quota-type", "enabled", "max-size", "max-size-kb", "max-objects"}))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|