-
Notifications
You must be signed in to change notification settings - Fork 929
/
endpoints.go
48 lines (38 loc) · 1.04 KB
/
endpoints.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
package api
import (
"strings"
"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
"code.cloudfoundry.org/cli/cf/net"
)
type RemoteInfoRepository struct {
gateway net.Gateway
}
func NewEndpointRepository(gateway net.Gateway) RemoteInfoRepository {
r := RemoteInfoRepository{
gateway: gateway,
}
return r
}
func (repo RemoteInfoRepository) GetCCInfo(endpoint string) (*coreconfig.CCInfo, string, error) {
if strings.HasPrefix(endpoint, "http") {
serverResponse, err := repo.getCCAPIInfo(endpoint)
if err != nil {
return nil, "", err
}
return serverResponse, endpoint, nil
}
finalEndpoint := "https://" + endpoint
serverResponse, err := repo.getCCAPIInfo(finalEndpoint)
if err != nil {
return nil, "", err
}
return serverResponse, finalEndpoint, nil
}
func (repo RemoteInfoRepository) getCCAPIInfo(endpoint string) (*coreconfig.CCInfo, error) {
serverResponse := new(coreconfig.CCInfo)
err := repo.gateway.GetResource(endpoint+"/v2/info", &serverResponse)
if err != nil {
return nil, err
}
return serverResponse, nil
}