本文整理匯總了Golang中github.com/juju/juju/state.State.IsControllerAdministrator方法的典型用法代碼示例。如果您正苦於以下問題:Golang State.IsControllerAdministrator方法的具體用法?Golang State.IsControllerAdministrator怎麽用?Golang State.IsControllerAdministrator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/state.State
的用法示例。
在下文中一共展示了State.IsControllerAdministrator方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewControllerAPI
// NewControllerAPI creates a new api server endpoint for managing
// environments.
func NewControllerAPI(
st *state.State,
resources *common.Resources,
authorizer common.Authorizer,
) (*ControllerAPI, error) {
if !authorizer.AuthClient() {
return nil, errors.Trace(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)
isAdmin, err := st.IsControllerAdministrator(apiUser)
if err != nil {
return nil, errors.Trace(err)
}
// The entire end point is only accessible to controller administrators.
if !isAdmin {
return nil, errors.Trace(common.ErrPerm)
}
return &ControllerAPI{
state: st,
authorizer: authorizer,
apiUser: apiUser,
resources: resources,
}, nil
}
示例2: checkAuth
func checkAuth(authorizer common.Authorizer, st *state.State) error {
if !authorizer.AuthClient() {
return errors.Trace(common.ErrPerm)
}
// Type assertion is fine because AuthClient is true.
apiUser := authorizer.GetAuthTag().(names.UserTag)
if isAdmin, err := st.IsControllerAdministrator(apiUser); 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
}
示例3: NewUserManagerAPI
func NewUserManagerAPI(
st *state.State,
resources *common.Resources,
authorizer common.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 := st.IsControllerAdministrator(apiUser)
if err != nil {
return nil, errors.Trace(err)
}
resource, ok := resources.Get("createLocalLoginMacaroon").(common.ValueResource)
if !ok {
return nil, errors.NotFoundf("userAuth resource")
}
createLocalLoginMacaroon, ok := resource.Value.(func(names.UserTag) (*macaroon.Macaroon, error))
if !ok {
return nil, errors.NotValidf("userAuth resource")
}
return &UserManagerAPI{
state: st,
authorizer: authorizer,
createLocalLoginMacaroon: createLocalLoginMacaroon,
check: common.NewBlockChecker(st),
apiUser: apiUser,
isAdmin: isAdmin,
}, nil
}