-
Notifications
You must be signed in to change notification settings - Fork 0
/
adminv0.go
66 lines (57 loc) · 1.58 KB
/
adminv0.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2013, 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package apiserver
import (
"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/apiserver/params"
)
// adminApiV0 implements the API that a client first sees when connecting to
// the API. We start serving a different API once the user has logged in.
type adminApiV0 struct {
admin *adminV0
}
type adminV0 struct {
*admin
}
func newAdminApiV0(srv *Server, root *apiHandler, reqNotifier *requestNotifier) interface{} {
return &adminApiV0{
admin: &adminV0{
&admin{
srv: srv,
root: root,
reqNotifier: reqNotifier,
},
},
}
}
// Admin returns an object that provides API access to methods that can be
// called even when not authenticated.
func (r *adminApiV0) Admin(id string) (*adminV0, error) {
if id != "" {
// Safeguard id for possible future use.
return nil, common.ErrBadId
}
return r.admin, nil
}
// Login logs in with the provided credentials. All subsequent requests on the
// connection will act as the authenticated user.
func (a *adminV0) Login(c params.Creds) (params.LoginResult, error) {
var fail params.LoginResult
resultV1, err := a.doLogin(params.LoginRequest{
AuthTag: c.AuthTag,
Credentials: c.Password,
Nonce: c.Nonce,
}, 0)
if err != nil {
return fail, err
}
resultV0 := params.LoginResult{
Servers: resultV1.Servers,
EnvironTag: resultV1.EnvironTag,
Facades: resultV1.Facades,
}
if resultV1.UserInfo != nil {
resultV0.LastConnection = resultV1.UserInfo.LastConnection
}
return resultV0, nil
}