1 Star 1 Fork 0

czy / go-ceph

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
caps.go 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
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))
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))
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
}
Go
1
https://gitee.com/czy233/go-ceph.git
git@gitee.com:czy233/go-ceph.git
czy233
go-ceph
go-ceph
v0.14.2

搜索帮助