Left: | ||
Right: |
OLD | NEW |
---|---|
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/loggo/loggo" |
10 | 10 |
11 "launchpad.net/juju-core/errors" | |
11 "launchpad.net/juju-core/state" | 12 "launchpad.net/juju-core/state" |
12 "launchpad.net/juju-core/state/api/params" | 13 "launchpad.net/juju-core/state/api/params" |
13 "launchpad.net/juju-core/state/apiserver/common" | 14 "launchpad.net/juju-core/state/apiserver/common" |
14 ) | 15 ) |
15 | 16 |
16 var logger = loggo.GetLogger("juju.state.apiserver.usermanager") | 17 var logger = loggo.GetLogger("juju.state.apiserver.usermanager") |
17 | 18 |
18 // UserManager defines the methods on the usermanager API end point. | 19 // UserManager defines the methods on the usermanager API end point. |
19 type UserManager interface { | 20 type UserManager interface { |
20 AddUser(arg params.EntityPasswords) (params.ErrorResults, error) | 21 AddUser(arg params.EntityPasswords) (params.ErrorResults, error) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 result.Results[0].Error = common.ServerError(err) | 61 result.Results[0].Error = common.ServerError(err) |
61 return result, err | 62 return result, err |
62 } | 63 } |
63 for i, arg := range args.Changes { | 64 for i, arg := range args.Changes { |
64 if !canWrite(arg.Tag) { | 65 if !canWrite(arg.Tag) { |
65 result.Results[0].Error = common.ServerError(common.ErrP erm) | 66 result.Results[0].Error = common.ServerError(common.ErrP erm) |
66 continue | 67 continue |
67 } | 68 } |
68 _, err := api.state.AddUser(arg.Tag, arg.Password) | 69 _, err := api.state.AddUser(arg.Tag, arg.Password) |
69 if err != nil { | 70 if err != nil { |
70 » » » result.Results[i].Error = common.ServerError(fmt.Errorf( "Failed to create user: %s", err)) | 71 » » » err = errors.NewAlreadyExists(err, "Failed to create use r") |
rog
2014/04/14 18:19:28
This doesn't seem right. How do we know that the e
dimitern
2014/04/17 13:12:59
Reverted the logic back, just reformatted.
| |
72 » » » result.Results[i].Error = common.ServerError(err) | |
71 continue | 73 continue |
72 } | 74 } |
73 } | 75 } |
74 return result, nil | 76 return result, nil |
75 } | 77 } |
76 | 78 |
77 func (api *UserManagerAPI) RemoveUser(args params.Entities) (params.ErrorResults , error) { | 79 func (api *UserManagerAPI) RemoveUser(args params.Entities) (params.ErrorResults , error) { |
78 result := params.ErrorResults{ | 80 result := params.ErrorResults{ |
79 Results: make([]params.ErrorResult, len(args.Entities)), | 81 Results: make([]params.ErrorResult, len(args.Entities)), |
80 } | 82 } |
(...skipping 15 matching lines...) Expand all Loading... | |
96 continue | 98 continue |
97 } | 99 } |
98 err = user.Deactivate() | 100 err = user.Deactivate() |
99 if err != nil { | 101 if err != nil { |
100 result.Results[i].Error = common.ServerError(fmt.Errorf( "Failed to remove user: %s", err)) | 102 result.Results[i].Error = common.ServerError(fmt.Errorf( "Failed to remove user: %s", err)) |
101 continue | 103 continue |
102 } | 104 } |
103 } | 105 } |
104 return result, nil | 106 return result, nil |
105 } | 107 } |
OLD | NEW |