MCPcopy
hub / github.com/cloudfoundry/cli / setAPIEndpoint

Method setAPIEndpoint

cf/commands/api.go:88–122  ·  view source on GitHub ↗
(endpoint string, skipSSL bool, cmdName string)

Source from the content-addressed store, hash-verified

86}
87
88func (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}

Callers 2

ExecuteMethod · 0.95
ExecuteMethod · 0.95

Calls 8

RefreshMethod · 0.95
CommandColorFunction · 0.92
NewFunction · 0.92
WarningColorFunction · 0.92
SetSSLDisabledMethod · 0.65
SetAPIEndpointMethod · 0.65
SayMethod · 0.65
WarnMethod · 0.65

Tested by

no test coverage detected