mirror of
https://github.com/ceph/go-ceph
synced 2024-12-18 12:25:22 +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>
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package admin
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
// AddUserCap adds the capabilities for a user.
|
|
//
|
|
// On Success, it returns the updated list of UserCaps for the user.
|
|
func (api *API) AddUserCap(ctx context.Context, uid, userCap string) ([]UserCapSpec, error) {
|
|
if uid == "" {
|
|
return nil, errMissingUserID
|
|
}
|
|
if userCap == "" {
|
|
return nil, errMissingUserCap
|
|
}
|
|
|
|
user := User{ID: uid, UserCaps: userCap}
|
|
body, err := api.call(ctx, http.MethodPut, "/user?caps", valueToURLParams(user, []string{"uid", "user-caps"}))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var ref []UserCapSpec
|
|
err = json.Unmarshal(body, &ref)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("%s. %s. %w", unmarshalError, string(body), err)
|
|
}
|
|
|
|
return ref, nil
|
|
}
|
|
|
|
// RemoveUserCap removes the capabilities from a user.
|
|
//
|
|
// On Success, it returns the updated list of UserCaps for the user.
|
|
func (api *API) RemoveUserCap(ctx context.Context, uid, userCap string) ([]UserCapSpec, error) {
|
|
if uid == "" {
|
|
return nil, errMissingUserID
|
|
}
|
|
if userCap == "" {
|
|
return nil, errMissingUserCap
|
|
}
|
|
|
|
user := User{ID: uid, UserCaps: userCap}
|
|
body, err := api.call(ctx, http.MethodDelete, "/user?caps", valueToURLParams(user, []string{"uid", "user-caps"}))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var ref []UserCapSpec
|
|
err = json.Unmarshal(body, &ref)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("%s. %s. %w", unmarshalError, string(body), err)
|
|
}
|
|
|
|
return ref, nil
|
|
}
|