github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/uaa/resources.go (about) 1 package uaa 2 3 import ( 4 "fmt" 5 "net/http" 6 7 "code.cloudfoundry.org/cli/api/uaa/internal" 8 ) 9 10 // AuthInfo represents a GET response from a login server 11 type AuthInfo struct { 12 Links struct { 13 UAA string `json:"uaa"` 14 } `json:"links"` 15 } 16 17 // SetupResources configures the client to use the specified settings and diescopers the UAA and Authentication resources 18 func (client *Client) SetupResources(bootstrapURL string) error { 19 request, err := client.newRequest(requestOptions{ 20 Method: http.MethodGet, 21 URL: fmt.Sprintf("%s/login", bootstrapURL), 22 }) 23 24 if err != nil { 25 return err 26 } 27 28 info := AuthInfo{} // Explicitly initializing 29 response := Response{ 30 Result: &info, 31 } 32 33 err = client.connection.Make(request, &response) 34 if err != nil { 35 return err 36 } 37 38 UAALink := info.Links.UAA 39 if UAALink == "" { 40 UAALink = bootstrapURL 41 } 42 client.config.SetUAAEndpoint(UAALink) 43 44 resources := map[string]string{ 45 "uaa": UAALink, 46 "authorization_endpoint": bootstrapURL, 47 } 48 49 client.router = internal.NewRouter(internal.APIRoutes, resources) 50 51 return nil 52 }