github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/api/endpoints.go (about) 1 package api 2 3 import ( 4 "strings" 5 6 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 7 "code.cloudfoundry.org/cli/cf/net" 8 ) 9 10 type RemoteInfoRepository struct { 11 gateway net.Gateway 12 } 13 14 func NewEndpointRepository(gateway net.Gateway) RemoteInfoRepository { 15 r := RemoteInfoRepository{ 16 gateway: gateway, 17 } 18 return r 19 } 20 21 func (repo RemoteInfoRepository) GetCCInfo(endpoint string) (*coreconfig.CCInfo, string, error) { 22 if strings.HasPrefix(endpoint, "http") { 23 serverResponse, err := repo.getCCAPIInfo(endpoint) 24 if err != nil { 25 return nil, "", err 26 } 27 28 return serverResponse, endpoint, nil 29 } 30 31 finalEndpoint := "https://" + endpoint 32 serverResponse, err := repo.getCCAPIInfo(finalEndpoint) 33 if err != nil { 34 return nil, "", err 35 } 36 37 return serverResponse, finalEndpoint, nil 38 } 39 40 func (repo RemoteInfoRepository) getCCAPIInfo(endpoint string) (*coreconfig.CCInfo, error) { 41 serverResponse := new(coreconfig.CCInfo) 42 err := repo.gateway.GetResource(endpoint+"/v2/info", &serverResponse) 43 if err != nil { 44 return nil, err 45 } 46 47 return serverResponse, nil 48 }