github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/configuration/coreconfig/api_config_refresher.go (about) 1 package coreconfig 2 3 import ( 4 "strings" 5 6 . "code.cloudfoundry.org/cli/cf/i18n" 7 ) 8 9 //go:generate counterfeiter . EndpointRepository 10 11 type EndpointRepository interface { 12 GetCCInfo(string) (*CCInfo, string, error) 13 } 14 15 type APIConfigRefresher struct { 16 EndpointRepo EndpointRepository 17 Config ReadWriter 18 Endpoint string 19 } 20 21 func (a APIConfigRefresher) Refresh() (Warning, error) { 22 ccInfo, endpoint, err := a.EndpointRepo.GetCCInfo(a.Endpoint) 23 if err != nil { 24 return nil, err 25 } 26 27 if endpoint != a.Config.APIEndpoint() { 28 a.Config.ClearSession() 29 } 30 31 a.Config.SetAPIEndpoint(endpoint) 32 a.Config.SetAPIVersion(ccInfo.APIVersion) 33 a.Config.SetAuthenticationEndpoint(ccInfo.AuthorizationEndpoint) 34 a.Config.SetSSHOAuthClient(ccInfo.SSHOAuthClient) 35 a.Config.SetMinCLIVersion(ccInfo.MinCLIVersion) 36 a.Config.SetMinRecommendedCLIVersion(ccInfo.MinRecommendedCLIVersion) 37 38 a.Config.SetDopplerEndpoint(ccInfo.DopplerEndpoint) 39 a.Config.SetRoutingAPIEndpoint(ccInfo.RoutingAPIEndpoint) 40 41 if !strings.HasPrefix(endpoint, "https://") { 42 return new(insecureWarning), nil 43 } 44 return nil, nil 45 } 46 47 type Warning interface { 48 Warn() string 49 } 50 51 type insecureWarning struct{} 52 53 func (w insecureWarning) Warn() string { 54 return T("Warning: Insecure http API endpoint detected: secure https API endpoints are recommended\n") 55 }