本文整理汇总了Golang中github.com/juju/juju/apiserver/facade.Authorizer.AuthClient方法的典型用法代码示例。如果您正苦于以下问题:Golang Authorizer.AuthClient方法的具体用法?Golang Authorizer.AuthClient怎么用?Golang Authorizer.AuthClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/apiserver/facade.Authorizer
的用法示例。
在下文中一共展示了Authorizer.AuthClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: NewClient
// NewClient creates a new instance of the Client Facade.
func NewClient(
st Backend,
modelConfigAPI *modelconfig.ModelConfigAPI,
resources facade.Resources,
authorizer facade.Authorizer,
statusSetter *common.StatusSetter,
toolsFinder *common.ToolsFinder,
newEnviron func() (environs.Environ, error),
blockChecker *common.BlockChecker,
) (*Client, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
client := &Client{
modelConfigAPI,
&API{
stateAccessor: st,
auth: authorizer,
resources: resources,
statusSetter: statusSetter,
toolsFinder: toolsFinder,
},
newEnviron,
blockChecker,
}
return client, nil
}
示例3: 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
}
示例4: 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
}
示例5: newAPIWithBacking
// newAPIWithBacking creates a new server-side Spaces API facade with
// the given Backing.
func newAPIWithBacking(backing networkingcommon.NetworkBacking, resources facade.Resources, authorizer facade.Authorizer) (API, error) {
// Only clients can access the Spaces facade.
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
return &spacesAPI{
backing: backing,
resources: resources,
authorizer: authorizer,
}, nil
}
示例6: NewHighAvailabilityAPI
// NewHighAvailabilityAPI creates a new server-side highavailability API end point.
func NewHighAvailabilityAPI(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*HighAvailabilityAPI, error) {
// Only clients and environment managers can access the high availability service.
if !authorizer.AuthClient() && !authorizer.AuthModelManager() {
return nil, common.ErrPerm
}
return &HighAvailabilityAPI{
state: st,
resources: resources,
authorizer: authorizer,
}, nil
}
示例7: NewModelConfigAPI
// NewModelConfigAPI creates a new instance of the ModelConfig Facade.
func NewModelConfigAPI(backend Backend, authorizer facade.Authorizer) (*ModelConfigAPI, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
client := &ModelConfigAPI{
backend: backend,
auth: authorizer,
check: common.NewBlockChecker(backend),
}
return client, nil
}
示例8: NewImageManagerAPI
// NewImageManagerAPI creates a new server-side imagemanager API end point.
func NewImageManagerAPI(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*ImageManagerAPI, error) {
// Only clients can access the image manager service.
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
return &ImageManagerAPI{
state: getState(st),
resources: resources,
authorizer: authorizer,
check: common.NewBlockChecker(st),
}, nil
}
示例9: NewMetricsDebugAPI
// NewMetricsDebugAPI creates a new API endpoint for calling metrics debug functions.
func NewMetricsDebugAPI(
st *state.State,
resources facade.Resources,
authorizer facade.Authorizer,
) (*MetricsDebugAPI, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
return &MetricsDebugAPI{
state: st,
}, nil
}
示例10: 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
}
示例11: NewAPI
// NewAPI returns a new block API facade.
func NewAPI(
st *state.State,
resources facade.Resources,
authorizer facade.Authorizer,
) (*API, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
return &API{
access: getState(st),
authorizer: authorizer,
}, nil
}
示例12: createAPI
// createAPI returns a new image metadata API facade.
func createAPI(
st metadataAcess,
newEnviron func() (environs.Environ, error),
resources facade.Resources,
authorizer facade.Authorizer,
) (*API, error) {
if !authorizer.AuthClient() && !authorizer.AuthModelManager() {
return nil, common.ErrPerm
}
return &API{
metadata: st,
newEnviron: newEnviron,
authorizer: authorizer,
}, nil
}
示例13: NewAPI
// NewAPI returns a new application API facade.
func NewAPI(
backend Backend,
authorizer facade.Authorizer,
blockChecker BlockChecker,
stateCharm func(Charm) *state.Charm,
) (*API, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
return &API{
backend: backend,
authorizer: authorizer,
check: blockChecker,
stateCharm: stateCharm,
}, nil
}
示例14: NewMachineManagerAPI
// NewMachineManagerAPI creates a new server-side MachineManager API facade.
func NewMachineManagerAPI(
st *state.State,
resources facade.Resources,
authorizer facade.Authorizer,
) (*MachineManagerAPI, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
s := getState(st)
return &MachineManagerAPI{
st: s,
authorizer: authorizer,
check: common.NewBlockChecker(s),
}, nil
}
示例15: NewAPI
// NewAPI returns a new storage API facade.
func NewAPI(
st storageAccess,
registry storage.ProviderRegistry,
pm poolmanager.PoolManager,
resources facade.Resources,
authorizer facade.Authorizer,
) (*API, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
return &API{
storage: st,
registry: registry,
poolManager: pm,
authorizer: authorizer,
}, nil
}