本文整理汇总了Golang中github.com/juju/juju/apiserver/common.NewPasswordChanger函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPasswordChanger函数的具体用法?Golang NewPasswordChanger怎么用?Golang NewPasswordChanger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewPasswordChanger函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestSetPasswordsNoArgsNoError
func (*passwordSuite) TestSetPasswordsNoArgsNoError(c *gc.C) {
getCanChange := func() (common.AuthFunc, error) {
return nil, fmt.Errorf("splat")
}
pc := common.NewPasswordChanger(&fakeState{}, getCanChange)
result, err := pc.SetPasswords(params.EntityPasswords{})
c.Assert(err, gc.IsNil)
c.Assert(result.Results, gc.HasLen, 0)
}
开发者ID:kapilt,项目名称:juju,代码行数:9,代码来源:password_test.go
示例2: NewProvisionerAPI
// NewProvisionerAPI creates a new server-side ProvisionerAPI facade.
func NewProvisionerAPI(st *state.State, resources *common.Resources, authorizer common.Authorizer) (*ProvisionerAPI, error) {
if !authorizer.AuthMachineAgent() && !authorizer.AuthEnvironManager() {
return nil, common.ErrPerm
}
getAuthFunc := func() (common.AuthFunc, error) {
isEnvironManager := authorizer.AuthEnvironManager()
isMachineAgent := authorizer.AuthMachineAgent()
authEntityTag := authorizer.GetAuthTag()
return func(tag names.Tag) bool {
if isMachineAgent && tag == authEntityTag {
// A machine agent can always access its own machine.
return true
}
switch tag := tag.(type) {
case names.MachineTag:
parentId := state.ParentId(tag.Id())
if parentId == "" {
// All top-level machines are accessible by the
// environment manager.
return isEnvironManager
}
// All containers with the authenticated machine as a
// parent are accessible by it.
// TODO(dfc) sometimes authEntity tag is nil, which is fine because nil is
// only equal to nil, but it suggests someone is passing an authorizer
// with a nil tag.
return isMachineAgent && names.NewMachineTag(parentId) == authEntityTag
default:
return false
}
}, nil
}
env, err := st.Environment()
if err != nil {
return nil, err
}
urlGetter := common.NewToolsURLGetter(env.UUID(), st)
return &ProvisionerAPI{
Remover: common.NewRemover(st, false, getAuthFunc),
StatusSetter: common.NewStatusSetter(st, getAuthFunc),
StatusGetter: common.NewStatusGetter(st, getAuthFunc),
DeadEnsurer: common.NewDeadEnsurer(st, getAuthFunc),
PasswordChanger: common.NewPasswordChanger(st, getAuthFunc),
LifeGetter: common.NewLifeGetter(st, getAuthFunc),
StateAddresser: common.NewStateAddresser(st),
APIAddresser: common.NewAPIAddresser(st, resources),
EnvironWatcher: common.NewEnvironWatcher(st, resources, authorizer),
EnvironMachinesWatcher: common.NewEnvironMachinesWatcher(st, resources, authorizer),
InstanceIdGetter: common.NewInstanceIdGetter(st, getAuthFunc),
ToolsFinder: common.NewToolsFinder(st, st, urlGetter),
st: st,
resources: resources,
authorizer: authorizer,
getAuthFunc: getAuthFunc,
}, nil
}
开发者ID:Pankov404,项目名称:juju,代码行数:58,代码来源:provisioner.go
示例3: TestSetPasswords
func (*passwordSuite) TestSetPasswords(c *gc.C) {
st := &fakeState{
entities: map[names.Tag]entityWithError{
u("x/0"): &fakeAuthenticator{},
u("x/1"): &fakeAuthenticator{},
u("x/2"): &fakeAuthenticator{
err: fmt.Errorf("x2 error"),
},
u("x/3"): &fakeAuthenticator{
fetchError: "x3 error",
},
u("x/4"): &fakeUnitAuthenticator{},
u("x/5"): &fakeMachineAuthenticator{jobs: []state.MachineJob{state.JobHostUnits}},
u("x/6"): &fakeMachineAuthenticator{jobs: []state.MachineJob{state.JobManageEnviron}},
},
}
getCanChange := func() (common.AuthFunc, error) {
return func(tag names.Tag) bool {
return tag != names.NewUnitTag("x/0")
}, nil
}
pc := common.NewPasswordChanger(st, getCanChange)
var changes []params.EntityPassword
for i := 0; i < len(st.entities); i++ {
tag := fmt.Sprintf("unit-x-%d", i)
changes = append(changes, params.EntityPassword{
Tag: tag,
Password: fmt.Sprintf("%spass", tag),
})
}
results, err := pc.SetPasswords(params.EntityPasswords{
Changes: changes,
})
c.Assert(err, gc.IsNil)
c.Assert(results, jc.DeepEquals, params.ErrorResults{
Results: []params.ErrorResult{
{apiservertesting.ErrUnauthorized},
{nil},
{¶ms.Error{Message: "x2 error"}},
{¶ms.Error{Message: "x3 error"}},
{nil},
{nil},
{nil},
},
})
c.Check(st.entities[u("x/0")].(*fakeAuthenticator).pass, gc.Equals, "")
c.Check(st.entities[u("x/1")].(*fakeAuthenticator).pass, gc.Equals, "unit-x-1pass")
c.Check(st.entities[u("x/2")].(*fakeAuthenticator).pass, gc.Equals, "")
c.Check(st.entities[u("x/4")].(*fakeUnitAuthenticator).pass, gc.Equals, "unit-x-4pass")
c.Check(st.entities[u("x/4")].(*fakeUnitAuthenticator).mongoPass, gc.Equals, "")
c.Check(st.entities[u("x/5")].(*fakeMachineAuthenticator).pass, gc.Equals, "unit-x-5pass")
c.Check(st.entities[u("x/5")].(*fakeMachineAuthenticator).mongoPass, gc.Equals, "")
c.Check(st.entities[u("x/6")].(*fakeMachineAuthenticator).pass, gc.Equals, "unit-x-6pass")
c.Check(st.entities[u("x/6")].(*fakeMachineAuthenticator).mongoPass, gc.Equals, "unit-x-6pass")
}
开发者ID:kapilt,项目名称:juju,代码行数:55,代码来源:password_test.go
示例4: NewAPI
// NewAPI returns an object implementing an agent API
// with the given authorizer representing the currently logged in client.
func NewAPI(st *state.State, resources *common.Resources, auth common.Authorizer) (*API, error) {
// Agents are defined to be any user that's not a client user.
if !auth.AuthMachineAgent() && !auth.AuthUnitAgent() {
return nil, common.ErrPerm
}
getCanChange := func() (common.AuthFunc, error) {
return auth.AuthOwner, nil
}
return &API{
PasswordChanger: common.NewPasswordChanger(st, getCanChange),
st: st,
auth: auth,
}, nil
}
开发者ID:zhouqt,项目名称:juju,代码行数:16,代码来源:agent.go
示例5: TestSetPasswordsError
func (*passwordSuite) TestSetPasswordsError(c *gc.C) {
getCanChange := func() (common.AuthFunc, error) {
return nil, fmt.Errorf("splat")
}
pc := common.NewPasswordChanger(&fakeState{}, getCanChange)
var changes []params.EntityPassword
for i := 0; i < 4; i++ {
tag := fmt.Sprintf("x%d", i)
changes = append(changes, params.EntityPassword{
Tag: tag,
Password: fmt.Sprintf("%spass", tag),
})
}
_, err := pc.SetPasswords(params.EntityPasswords{Changes: changes})
c.Assert(err, gc.ErrorMatches, "splat")
}
开发者ID:kapilt,项目名称:juju,代码行数:16,代码来源:password_test.go
示例6: NewDeployerAPI
// NewDeployerAPI creates a new server-side DeployerAPI facade.
func NewDeployerAPI(
st *state.State,
resources facade.Resources,
authorizer facade.Authorizer,
) (*DeployerAPI, error) {
if !authorizer.AuthMachineAgent() {
return nil, common.ErrPerm
}
getAuthFunc := func() (common.AuthFunc, error) {
// Get all units of the machine and cache them.
thisMachineTag := authorizer.GetAuthTag()
units, err := getAllUnits(st, thisMachineTag)
if err != nil {
return nil, err
}
// Then we just check if the unit is already known.
return func(tag names.Tag) bool {
for _, unit := range units {
// TODO (thumper): remove the names.Tag conversion when gccgo
// implements concrete-type-to-interface comparison correctly.
if names.Tag(names.NewUnitTag(unit)) == tag {
return true
}
}
return false
}, nil
}
getCanWatch := func() (common.AuthFunc, error) {
return authorizer.AuthOwner, nil
}
return &DeployerAPI{
Remover: common.NewRemover(st, true, getAuthFunc),
PasswordChanger: common.NewPasswordChanger(st, getAuthFunc),
LifeGetter: common.NewLifeGetter(st, getAuthFunc),
StateAddresser: common.NewStateAddresser(st),
APIAddresser: common.NewAPIAddresser(st, resources),
UnitsWatcher: common.NewUnitsWatcher(st, resources, getCanWatch),
StatusSetter: common.NewStatusSetter(st, getAuthFunc),
st: st,
resources: resources,
authorizer: authorizer,
}, nil
}
开发者ID:bac,项目名称:juju,代码行数:44,代码来源:deployer.go
注:本文中的github.com/juju/juju/apiserver/common.NewPasswordChanger函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论