本文整理汇总了Golang中github.com/wallyworld/core/state/apiserver/common.Authorizer.AuthClient方法的典型用法代码示例。如果您正苦于以下问题:Golang Authorizer.AuthClient方法的具体用法?Golang Authorizer.AuthClient怎么用?Golang Authorizer.AuthClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/wallyworld/core/state/apiserver/common.Authorizer
的用法示例。
在下文中一共展示了Authorizer.AuthClient方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewUserManagerAPI
func NewUserManagerAPI(
st *state.State,
authorizer common.Authorizer,
) (*UserManagerAPI, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
// TODO(mattyw) - replace stub with real canWrite function
getCanWrite := common.AuthAlways(true)
return &UserManagerAPI{
state: st,
authorizer: authorizer,
getCanWrite: getCanWrite},
nil
}
示例2: NewKeyManagerAPI
// NewKeyManagerAPI creates a new server-side keyupdater API end point.
func NewKeyManagerAPI(
st *state.State,
resources *common.Resources,
authorizer common.Authorizer,
) (*KeyManagerAPI, error) {
// Only clients and environment managers can access the key manager service.
if !authorizer.AuthClient() && !authorizer.AuthEnvironManager() {
return nil, common.ErrPerm
}
// TODO(wallyworld) - replace stub with real canRead function
// For now, only admins can read authorised ssh keys.
getCanRead := func() (common.AuthFunc, error) {
return func(tag string) bool {
return authorizer.GetAuthTag() == "user-admin"
}, nil
}
// TODO(wallyworld) - replace stub with real canWrite function
// For now, only admins can write authorised ssh keys for users.
// Machine agents can write the juju-system-key.
getCanWrite := func() (common.AuthFunc, error) {
return func(tag string) bool {
// Are we a machine agent writing the Juju system key.
if tag == config.JujuSystemKey {
_, _, err := names.ParseTag(authorizer.GetAuthTag(), names.MachineTagKind)
return err == nil
}
// Are we writing the auth key for a user.
if _, err := st.User(tag); err != nil {
return false
}
return authorizer.GetAuthTag() == "user-admin"
}, nil
}
return &KeyManagerAPI{
state: st, resources: resources, authorizer: authorizer, getCanRead: getCanRead, getCanWrite: getCanWrite}, nil
}