本文整理匯總了Golang中github.com/juju/juju/apiserver/facade.Authorizer.HasPermission方法的典型用法代碼示例。如果您正苦於以下問題:Golang Authorizer.HasPermission方法的具體用法?Golang Authorizer.HasPermission怎麽用?Golang Authorizer.HasPermission使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/apiserver/facade.Authorizer
的用法示例。
在下文中一共展示了Authorizer.HasPermission方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewModelManagerAPI
// NewModelManagerAPI creates a new api server endpoint for managing
// models.
func NewModelManagerAPI(
st common.ModelManagerBackend,
configGetter environs.EnvironConfigGetter,
authorizer facade.Authorizer,
) (*ModelManagerAPI, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
// Since we know this is a user tag (because AuthClient is true),
// we just do the type assertion to the UserTag.
apiUser, _ := authorizer.GetAuthTag().(names.UserTag)
// Pretty much all of the user manager methods have special casing for admin
// users, so look once when we start and remember if the user is an admin.
isAdmin, err := authorizer.HasPermission(permission.SuperuserAccess, st.ControllerTag())
if err != nil {
return nil, errors.Trace(err)
}
urlGetter := common.NewToolsURLGetter(st.ModelUUID(), st)
return &ModelManagerAPI{
ModelStatusAPI: common.NewModelStatusAPI(st, authorizer, apiUser),
state: st,
check: common.NewBlockChecker(st),
authorizer: authorizer,
toolsFinder: common.NewToolsFinder(configGetter, st, urlGetter),
apiUser: apiUser,
isAdmin: isAdmin,
}, nil
}
示例2: NewCloudAPI
// NewCloudAPI creates a new API server endpoint for managing the controller's
// cloud definition and cloud credentials.
func NewCloudAPI(backend Backend, authorizer facade.Authorizer) (*CloudAPI, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
getUserAuthFunc := func() (common.AuthFunc, error) {
authUser, _ := authorizer.GetAuthTag().(names.UserTag)
isAdmin, err := authorizer.HasPermission(permission.SuperuserAccess, backend.ControllerTag())
if err != nil && !errors.IsNotFound(err) {
return nil, err
}
return func(tag names.Tag) bool {
userTag, ok := tag.(names.UserTag)
if !ok {
return false
}
return isAdmin || userTag == authUser
}, nil
}
return &CloudAPI{
backend: backend,
authorizer: authorizer,
getCredentialsAuthFunc: getUserAuthFunc,
}, nil
}
示例3: NewUserManagerAPI
func NewUserManagerAPI(
st *state.State,
resources facade.Resources,
authorizer facade.Authorizer,
) (*UserManagerAPI, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
// Since we know this is a user tag (because AuthClient is true),
// we just do the type assertion to the UserTag.
apiUser, _ := authorizer.GetAuthTag().(names.UserTag)
// Pretty much all of the user manager methods have special casing for admin
// users, so look once when we start and remember if the user is an admin.
isAdmin, err := authorizer.HasPermission(permission.SuperuserAccess, st.ControllerTag())
if err != nil {
return nil, errors.Trace(err)
}
return &UserManagerAPI{
state: st,
authorizer: authorizer,
check: common.NewBlockChecker(st),
apiUser: apiUser,
isAdmin: isAdmin,
}, nil
}
示例4: checkAuth
func checkAuth(authorizer facade.Authorizer, st *state.State) error {
if !authorizer.AuthClient() {
return errors.Trace(common.ErrPerm)
}
if isAdmin, err := authorizer.HasPermission(permission.SuperuserAccess, st.ControllerTag()); err != nil {
return errors.Trace(err)
} else if !isAdmin {
// The entire facade is only accessible to controller administrators.
return errors.Trace(common.ErrPerm)
}
return nil
}
示例5: NewAPI
// NewAPI creates a new instance of the Backups API facade.
func NewAPI(backend Backend, resources facade.Resources, authorizer facade.Authorizer) (*API, error) {
isControllerAdmin, err := authorizer.HasPermission(permission.SuperuserAccess, backend.ControllerTag())
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
if !authorizer.AuthClient() || !isControllerAdmin {
return nil, common.ErrPerm
}
// For now, backup operations are only permitted on the controller environment.
if !backend.IsController() {
return nil, errors.New("backups are not supported for hosted models")
}
// Get the backup paths.
dataDir, err := extractResourceValue(resources, "dataDir")
if err != nil {
return nil, errors.Trace(err)
}
logsDir, err := extractResourceValue(resources, "logDir")
if err != nil {
return nil, errors.Trace(err)
}
paths := backups.Paths{
DataDir: dataDir,
LogsDir: logsDir,
}
// Build the API.
machineID, err := extractResourceValue(resources, "machineID")
if err != nil {
return nil, errors.Trace(err)
}
b := API{
backend: backend,
paths: &paths,
machineID: machineID,
}
return &b, nil
}