26
30
if !authorizer.AuthMachineAgent() {
27
31
return nil, common.ErrPerm
33
getCanModify := func() (common.AuthFunc, error) {
34
return authorizer.AuthOwner, nil
29
36
getCanRead := func() (common.AuthFunc, error) {
30
37
return authorizer.AuthOwner, nil
32
39
return &MachinerAPI{
33
40
LifeGetter: common.NewLifeGetter(st, getCanRead),
34
StatusSetter: common.NewStatusSetter(st, getCanRead),
35
DeadEnsurer: common.NewDeadEnsurer(st, getCanRead),
41
StatusSetter: common.NewStatusSetter(st, getCanModify),
42
DeadEnsurer: common.NewDeadEnsurer(st, getCanModify),
36
43
AgentEntityWatcher: common.NewAgentEntityWatcher(st, resources, getCanRead),
46
getCanModify: getCanModify,
50
func (api *MachinerAPI) getMachine(tag string) (*state.Machine, error) {
51
entity, err := api.st.FindEntity(tag)
55
return entity.(*state.Machine), nil
58
func (api *MachinerAPI) SetMachineAddresses(args params.SetMachinesAddresses) (params.ErrorResults, error) {
59
results := params.ErrorResults{
60
Results: make([]params.ErrorResult, len(args.MachineAddresses)),
62
canModify, err := api.getCanModify()
64
return params.ErrorResults{}, err
66
for i, arg := range args.MachineAddresses {
68
if canModify(arg.Tag) {
70
m, err = api.getMachine(arg.Tag)
72
err = m.SetMachineAddresses(arg.Addresses)
73
} else if errors.IsNotFoundError(err) {
77
results.Results[i].Error = common.ServerError(err)