MCPcopy
hub / github.com/crowdsecurity/crowdsec / prepareAPIURL

Function prepareAPIURL

cmd/crowdsec-cli/clilapi/status.go:84–104  ·  view source on GitHub ↗

prepareAPIURL checks/fixes a LAPI connection url (http, https or socket) and returns an URL struct

(clientCfg *csconfig.LocalApiClientCfg, apiURL string)

Source from the content-addressed store, hash-verified

82
83// prepareAPIURL checks/fixes a LAPI connection url (http, https or socket) and returns an URL struct
84func prepareAPIURL(clientCfg *csconfig.LocalApiClientCfg, apiURL string) (*url.URL, error) {
85 if apiURL == "" {
86 if clientCfg == nil || clientCfg.Credentials == nil || clientCfg.Credentials.URL == "" {
87 return nil, errors.New("no Local API URL. Please provide it in your configuration or with the -u parameter")
88 }
89
90 apiURL = clientCfg.Credentials.URL
91 }
92
93 // URL needs to end with /, but user doesn't care
94 if !strings.HasSuffix(apiURL, "/") {
95 apiURL += "/"
96 }
97
98 // URL needs to start with http://, but user doesn't care
99 if !strings.HasPrefix(apiURL, "http://") && !strings.HasPrefix(apiURL, "https://") && !strings.HasPrefix(apiURL, "/") {
100 apiURL = "http://" + apiURL
101 }
102
103 return url.Parse(apiURL)
104}
105
106func (cli *cliLapi) newStatusCmd() *cobra.Command {
107 cmdLapiStatus := &cobra.Command{

Callers 7

registerMethod · 0.85
TestPrepareAPIURL_HttpFunction · 0.85
TestPrepareAPIURL_HttpsFunction · 0.85
TestPrepareAPIURL_EmptyFunction · 0.85

Calls 1

ParseMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…