本文整理汇总了Golang中github.com/juju/juju/apiserver/common.Authorizer.AuthClient方法的典型用法代码示例。如果您正苦于以下问题:Golang Authorizer.AuthClient方法的具体用法?Golang Authorizer.AuthClient怎么用?Golang Authorizer.AuthClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/apiserver/common.Authorizer
的用法示例。
在下文中一共展示了Authorizer.AuthClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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.
canRead := func(_ string) bool {
return authorizer.GetAuthTag() == adminUser
}
// 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.
canWrite := func(user string) bool {
// Are we a machine agent writing the Juju system key.
if user == config.JujuSystemKey {
_, ismachinetag := authorizer.GetAuthTag().(names.MachineTag)
return ismachinetag
}
// Are we writing the auth key for a user.
if _, err := st.User(user); err != nil {
return false
}
return authorizer.GetAuthTag() == adminUser
}
return &KeyManagerAPI{
state: st,
resources: resources,
authorizer: authorizer,
canRead: canRead,
canWrite: canWrite}, nil
}
示例2: NewUserManagerAPI
func NewUserManagerAPI(
st *state.State,
resources *common.Resources,
authorizer common.Authorizer,
) (*UserManagerAPI, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
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),
}, nil
}
示例3: 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
}
示例4: NewAPI
// NewAPI creates a new instance of the Backups API facade.
func NewAPI(st *state.State, resources *common.Resources, authorizer common.Authorizer) (*API, error) {
if !authorizer.AuthClient() {
return nil, errors.Trace(common.ErrPerm)
}
// 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{
st: st,
paths: &paths,
machineID: machineID,
}
return &b, nil
}
示例5: NewActionAPI
// NewActionAPI returns an initialized ActionAPI
func NewActionAPI(st *state.State, resources *common.Resources, authorizer common.Authorizer) (*ActionAPI, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
return &ActionAPI{
state: st,
resources: resources,
authorizer: authorizer,
}, nil
}
示例6: NewMetricsManagerAPI
// NewMetricsManagerAPI creates a new API endpoint for calling metrics manager functions.
func NewMetricsManagerAPI(
st *state.State,
resources *common.Resources,
authorizer common.Authorizer,
) (*MetricsManagerAPI, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
return &MetricsManagerAPI{state: st}, nil
}
示例7: NewHighAvailabilityAPI
// NewHighAvailabilityAPI creates a new server-side highavailability API end point.
func NewHighAvailabilityAPI(st *state.State, resources *common.Resources, authorizer common.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
}
示例8: NewClient
// NewClient creates a new instance of the Client Facade.
func NewClient(st *state.State, resources *common.Resources, authorizer common.Authorizer) (*Client, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
return &Client{api: &API{
state: st,
auth: authorizer,
resources: resources,
statusSetter: common.NewStatusSetter(st, common.AuthAlways()),
}}, nil
}
示例9: newAPIWithBacking
// newAPIWithBacking creates a new server-side Spaces API facade with
// the given Backing.
func newAPIWithBacking(backing networkingcommon.NetworkBacking, resources *common.Resources, authorizer common.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
}
示例10: NewImageManagerAPI
// NewImageManagerAPI creates a new server-side imagemanager API end point.
func NewImageManagerAPI(st *state.State, resources *common.Resources, authorizer common.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
}
示例11: newPublicFacade
// newPublicFacade is passed into common.RegisterStandardFacade
// in registerPublicFacade.
func (resources) newPublicFacade(st *corestate.State, _ *common.Resources, authorizer common.Authorizer) (*server.Facade, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
rst, err := st.Resources()
//rst, err := state.NewState(&resourceState{raw: st})
if err != nil {
return nil, errors.Trace(err)
}
return server.NewFacade(rst), nil
}
示例12: newClientAllWatcher
func newClientAllWatcher(st *state.State, resources *common.Resources, auth common.Authorizer, id string) (interface{}, error) {
if !auth.AuthClient() {
return nil, common.ErrPerm
}
watcher, ok := resources.Get(id).(*state.Multiwatcher)
if !ok {
return nil, common.ErrUnknownWatcher
}
return &srvClientAllWatcher{
watcher: watcher,
id: id,
resources: resources,
}, nil
}
示例13: createAPI
// createAPI returns a new image metadata API facade.
func createAPI(
st metadataAcess,
resources *common.Resources,
authorizer common.Authorizer,
) (*API, error) {
if !authorizer.AuthClient() && !authorizer.AuthModelManager() {
return nil, common.ErrPerm
}
return &API{
metadata: st,
authorizer: authorizer,
}, nil
}
示例14: NewAPI
// NewAPI returns a new charm annotator API facade.
func NewAPI(
st *state.State,
resources *common.Resources,
authorizer common.Authorizer,
) (*API, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
return &API{
access: getState(st),
authorizer: authorizer,
}, nil
}
示例15: NewUserManagerAPI
func NewUserManagerAPI(
st *state.State,
resources *common.Resources,
authorizer common.Authorizer,
) (*UserManagerAPI, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
return &UserManagerAPI{
state: st,
authorizer: authorizer,
}, nil
}