(endpoint string, skipSSL bool, cmdName string)
| 86 | } |
| 87 | |
| 88 | func (cmd API) setAPIEndpoint(endpoint string, skipSSL bool, cmdName string) error { |
| 89 | if strings.HasSuffix(endpoint, "/") { |
| 90 | endpoint = strings.TrimSuffix(endpoint, "/") |
| 91 | } |
| 92 | |
| 93 | cmd.config.SetSSLDisabled(skipSSL) |
| 94 | |
| 95 | refresher := coreconfig.APIConfigRefresher{ |
| 96 | Endpoint: endpoint, |
| 97 | EndpointRepo: cmd.endpointRepo, |
| 98 | Config: cmd.config, |
| 99 | } |
| 100 | |
| 101 | warning, err := refresher.Refresh() |
| 102 | if err != nil { |
| 103 | cmd.config.SetAPIEndpoint("") |
| 104 | cmd.config.SetSSLDisabled(false) |
| 105 | |
| 106 | switch typedErr := err.(type) { |
| 107 | case *errors.InvalidSSLCert: |
| 108 | cfAPICommand := terminal.CommandColor(fmt.Sprintf("%s %s --skip-ssl-validation", cf.Name, cmdName)) |
| 109 | tipMessage := T("TIP: Use '{{.APICommand}}' to continue with an insecure API endpoint", |
| 110 | map[string]interface{}{"APICommand": cfAPICommand}) |
| 111 | return errors.New(T("Invalid SSL Cert for {{.URL}}\n{{.TipMessage}}", |
| 112 | map[string]interface{}{"URL": typedErr.URL, "TipMessage": tipMessage})) |
| 113 | default: |
| 114 | return typedErr |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | if warning != nil { |
| 119 | cmd.ui.Say(terminal.WarningColor(warning.Warn())) |
| 120 | } |
| 121 | return nil |
| 122 | } |
no test coverage detected