forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_config_refresher.go
55 lines (42 loc) · 1.29 KB
/
api_config_refresher.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
53
54
55
package coreconfig
import (
"strings"
. "code.cloudfoundry.org/cli/cf/i18n"
)
//go:generate counterfeiter . EndpointRepository
type EndpointRepository interface {
GetCCInfo(string) (*CCInfo, string, error)
}
type APIConfigRefresher struct {
EndpointRepo EndpointRepository
Config ReadWriter
Endpoint string
}
func (a APIConfigRefresher) Refresh() (Warning, error) {
ccInfo, endpoint, err := a.EndpointRepo.GetCCInfo(a.Endpoint)
if err != nil {
return nil, err
}
if endpoint != a.Config.APIEndpoint() {
a.Config.ClearSession()
}
a.Config.SetAPIEndpoint(endpoint)
a.Config.SetAPIVersion(ccInfo.APIVersion)
a.Config.SetAuthenticationEndpoint(ccInfo.AuthorizationEndpoint)
a.Config.SetSSHOAuthClient(ccInfo.SSHOAuthClient)
a.Config.SetMinCLIVersion(ccInfo.MinCLIVersion)
a.Config.SetMinRecommendedCLIVersion(ccInfo.MinRecommendedCLIVersion)
a.Config.SetDopplerEndpoint(ccInfo.DopplerEndpoint)
a.Config.SetRoutingAPIEndpoint(ccInfo.RoutingAPIEndpoint)
if !strings.HasPrefix(endpoint, "https://") {
return new(insecureWarning), nil
}
return nil, nil
}
type Warning interface {
Warn() string
}
type insecureWarning struct{}
func (w insecureWarning) Warn() string {
return T("Warning: Insecure http API endpoint detected: secure https API endpoints are recommended\n")
}