本文整理汇总了Golang中github.com/juju/juju/apiserver/common.Resources.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Resources.Get方法的具体用法?Golang Resources.Get怎么用?Golang Resources.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/apiserver/common.Resources
的用法示例。
在下文中一共展示了Resources.Get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewPinger
// NewPinger returns an object that can be pinged by calling its Ping method.
// If this method is not called frequently enough, the connection will be
// dropped.
func NewPinger(st *state.State, resources *common.Resources, authorizer common.Authorizer) (Pinger, error) {
pingTimeout, ok := resources.Get("pingTimeout").(*pingTimeout)
if !ok {
return nullPinger{}, nil
}
return pingTimeout, 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: TestWatchMeterStatus
// TestWatchMeterStatus tests the meter status watcher functionality.
func TestWatchMeterStatus(c *gc.C, status meterstatus.MeterStatus, unit *jujustate.Unit, state *jujustate.State, resources *common.Resources) {
c.Assert(resources.Count(), gc.Equals, 0)
args := params.Entities{Entities: []params.Entity{
{Tag: unit.UnitTag().String()},
{Tag: "unit-foo-42"},
}}
result, err := status.WatchMeterStatus(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.DeepEquals, params.NotifyWatchResults{
Results: []params.NotifyWatchResult{
{NotifyWatcherId: "1"},
{Error: apiservertesting.ErrUnauthorized},
},
})
// Verify the resource was registered and stop when done
c.Assert(resources.Count(), gc.Equals, 1)
resource := resources.Get("1")
defer statetesting.AssertStop(c, resource)
// Check that the Watch has consumed the initial event ("returned" in
// the Watch call)
wc := statetesting.NewNotifyWatcherC(c, state, resource.(jujustate.NotifyWatcher))
wc.AssertNoChange()
err = unit.SetMeterStatus("GREEN", "No additional information.")
c.Assert(err, jc.ErrorIsNil)
wc.AssertOneChange()
}
示例4: extractResourceValue
func extractResourceValue(resources *common.Resources, key string) (string, error) {
res := resources.Get(key)
strRes, ok := res.(common.StringResource)
if !ok {
if res == nil {
strRes = ""
} else {
return "", errors.Errorf("invalid %s resource: %v", key, res)
}
}
return strRes.String(), nil
}
示例5: newNotifyWatcher
func newNotifyWatcher(st *state.State, resources *common.Resources, auth common.Authorizer, id string) (interface{}, error) {
if !isAgent(auth) {
return nil, common.ErrPerm
}
watcher, ok := resources.Get(id).(state.NotifyWatcher)
if !ok {
return nil, common.ErrUnknownWatcher
}
return &srvNotifyWatcher{
watcher: watcher,
id: id,
resources: resources,
}, nil
}
示例6: 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
}
示例7: newMachineStorageIdsWatcher
func newMachineStorageIdsWatcher(
st *state.State,
resources *common.Resources,
auth common.Authorizer,
id string,
parser func([]string) ([]params.MachineStorageId, error),
) (interface{}, error) {
if !isAgent(auth) {
return nil, common.ErrPerm
}
watcher, ok := resources.Get(id).(state.StringsWatcher)
if !ok {
return nil, common.ErrUnknownWatcher
}
return &srvMachineStorageIdsWatcher{watcher, id, resources, parser}, nil
}
示例8: newMigrationStatusWatcher
func newMigrationStatusWatcher(
st *state.State,
resources *common.Resources,
auth common.Authorizer,
id string,
) (interface{}, error) {
if !(auth.AuthMachineAgent() || auth.AuthUnitAgent()) {
return nil, common.ErrPerm
}
w, ok := resources.Get(id).(state.NotifyWatcher)
if !ok {
return nil, common.ErrUnknownWatcher
}
return &srvMigrationStatusWatcher{
watcher: w,
id: id,
resources: resources,
st: getMigrationBackend(st),
}, nil
}
示例9: newMigrationMasterWatcher
func newMigrationMasterWatcher(
st *state.State,
resources *common.Resources,
auth common.Authorizer,
id string,
) (interface{}, error) {
if !auth.AuthModelManager() {
return nil, common.ErrPerm
}
w, ok := resources.Get(id).(state.NotifyWatcher)
if !ok {
return nil, common.ErrUnknownWatcher
}
return &srvMigrationMasterWatcher{
watcher: w,
id: id,
resources: resources,
st: migrationGetter(st),
}, nil
}
示例10: 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
}