~rogpeppe/goose/state-of-the-world

« back to all changes in this revision

Viewing changes to identity/legacy.go

  • Committer: Ian Booth
  • Date: 2012-11-21 07:56:19 UTC
  • Revision ID: ian.booth@canonical.com-20121121075619-4fh6i9yq6fj6cwct
Extract identity functionality from client, and also extract common HTTP methods

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
)
8
8
 
9
9
type Legacy struct {
 
10
        client *http.Client
10
11
}
11
12
 
12
 
func (l *Legacy) Auth(creds Credentials) (*AuthDetails, error) {
13
 
        client := &http.Client{}
 
13
func (l *Legacy) Auth(creds *Credentials) (*AuthDetails, error) {
 
14
        if l.client == nil {
 
15
                l.client = &http.Client{CheckRedirect: nil}
 
16
        }
14
17
        request, err := http.NewRequest("GET", creds.URL, nil)
15
18
        if err != nil {
16
19
                return nil, err
17
20
        }
18
21
        request.Header.Set("X-Auth-User", creds.User)
19
22
        request.Header.Set("X-Auth-Key", creds.Secrets)
20
 
        response, err := client.Do(request)
 
23
        response, err := l.client.Do(request)
21
24
        defer response.Body.Close()
22
25
        if err != nil {
23
26
                return nil, err
28
31
                        response.StatusCode, response.Status, content)
29
32
        }
30
33
        details := &AuthDetails{}
31
 
        details.Token = response.Header.Get("X-Auth-Token")
32
 
        if details.Token == "" {
 
34
        details.TokenId = response.Header.Get("X-Auth-Token")
 
35
        if details.TokenId == "" {
33
36
                return nil, fmt.Errorf("Did not get valid Token from auth request")
34
37
        }
35
38
        nova_url := response.Header.Get("X-Server-Management-Url")