forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
resources.go
52 lines (41 loc) · 1.03 KB
/
resources.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
package uaa
import (
"fmt"
"net/http"
"code.cloudfoundry.org/cli/api/uaa/internal"
)
// AuthInfo represents a GET response from a login server
type AuthInfo struct {
Links struct {
UAA string `json:"uaa"`
} `json:"links"`
}
// SetupResources configures the client to use the specified settings and diescopers the UAA and Authentication resources
func (client *Client) SetupResources(bootstrapURL string) error {
request, err := client.newRequest(requestOptions{
Method: http.MethodGet,
URL: fmt.Sprintf("%s/login", bootstrapURL),
})
if err != nil {
return err
}
info := AuthInfo{} // Explicitly initializing
response := Response{
Result: &info,
}
err = client.connection.Make(request, &response)
if err != nil {
return err
}
UAALink := info.Links.UAA
if UAALink == "" {
UAALink = bootstrapURL
}
client.config.SetUAAEndpoint(UAALink)
resources := map[string]string{
"uaa": UAALink,
"authorization_endpoint": bootstrapURL,
}
client.router = internal.NewRouter(internal.APIRoutes, resources)
return nil
}