LEFT | RIGHT |
1 // Copyright 2014 Canonical Ltd. | 1 // Copyright 2014 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package usermanager | 4 package usermanager |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | 7 "fmt" |
8 | 8 |
9 » "github.com/loggo/loggo" | 9 » "github.com/juju/loggo" |
10 | 10 |
11 "launchpad.net/juju-core/errors" | |
12 "launchpad.net/juju-core/state" | 11 "launchpad.net/juju-core/state" |
13 "launchpad.net/juju-core/state/api/params" | 12 "launchpad.net/juju-core/state/api/params" |
14 "launchpad.net/juju-core/state/apiserver/common" | 13 "launchpad.net/juju-core/state/apiserver/common" |
15 ) | 14 ) |
16 | 15 |
17 var logger = loggo.GetLogger("juju.state.apiserver.usermanager") | 16 var logger = loggo.GetLogger("juju.state.apiserver.usermanager") |
18 | 17 |
19 // UserManager defines the methods on the usermanager API end point. | 18 // UserManager defines the methods on the usermanager API end point. |
20 type UserManager interface { | 19 type UserManager interface { |
21 AddUser(arg params.EntityPasswords) (params.ErrorResults, error) | 20 AddUser(arg params.EntityPasswords) (params.ErrorResults, error) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 result.Results[0].Error = common.ServerError(err) | 60 result.Results[0].Error = common.ServerError(err) |
62 return result, err | 61 return result, err |
63 } | 62 } |
64 for i, arg := range args.Changes { | 63 for i, arg := range args.Changes { |
65 if !canWrite(arg.Tag) { | 64 if !canWrite(arg.Tag) { |
66 result.Results[0].Error = common.ServerError(common.ErrP
erm) | 65 result.Results[0].Error = common.ServerError(common.ErrP
erm) |
67 continue | 66 continue |
68 } | 67 } |
69 _, err := api.state.AddUser(arg.Tag, arg.Password) | 68 _, err := api.state.AddUser(arg.Tag, arg.Password) |
70 if err != nil { | 69 if err != nil { |
71 » » » err = errors.NewAlreadyExists(err, "Failed to create use
r") | 70 » » » err = fmt.Errorf("Failed to create user: %v", err) |
72 result.Results[i].Error = common.ServerError(err) | 71 result.Results[i].Error = common.ServerError(err) |
73 continue | 72 continue |
74 } | 73 } |
75 } | 74 } |
76 return result, nil | 75 return result, nil |
77 } | 76 } |
78 | 77 |
79 func (api *UserManagerAPI) RemoveUser(args params.Entities) (params.ErrorResults
, error) { | 78 func (api *UserManagerAPI) RemoveUser(args params.Entities) (params.ErrorResults
, error) { |
80 result := params.ErrorResults{ | 79 result := params.ErrorResults{ |
81 Results: make([]params.ErrorResult, len(args.Entities)), | 80 Results: make([]params.ErrorResult, len(args.Entities)), |
(...skipping 16 matching lines...) Expand all Loading... |
98 continue | 97 continue |
99 } | 98 } |
100 err = user.Deactivate() | 99 err = user.Deactivate() |
101 if err != nil { | 100 if err != nil { |
102 result.Results[i].Error = common.ServerError(fmt.Errorf(
"Failed to remove user: %s", err)) | 101 result.Results[i].Error = common.ServerError(fmt.Errorf(
"Failed to remove user: %s", err)) |
103 continue | 102 continue |
104 } | 103 } |
105 } | 104 } |
106 return result, nil | 105 return result, nil |
107 } | 106 } |
LEFT | RIGHT |