MCPcopy
hub / github.com/smallstep/cli / trimURL

Function trimURL

command/certificate/remote.go:79–95  ·  view source on GitHub ↗

trimURL returns the host[:port] if the input is a URL, otherwise returns an empty string (and 'isURL:false'). If the URL is valid and no port is specified, the default port determined by the URL prefix is used. Examples: trimURL("https://smallstep.com/onboarding") -> "smallstep.com:443", true, nil

(ref string)

Source from the content-addressed store, hash-verified

77// trimURL("hTtPs://sMaLlStEp.cOm") -> "sMaLlStEp.cOm:443", true, nil
78// trimURL("hTtPs://sMaLlStEp.cOm hello") -> "", false, err{"invalid url"}
79func trimURL(ref string) (string, bool, error) {
80 tmp := strings.ToLower(ref)
81 for prefix := range urlPrefixes {
82 if strings.HasPrefix(tmp, prefix) {
83 u, err := url.Parse(ref)
84 if err != nil {
85 return "", false, errors.Wrapf(err, "error parsing URL '%s'", ref)
86 }
87 if _, _, err := net.SplitHostPort(u.Host); err != nil {
88 port := strconv.FormatUint(uint64(urlPrefixes[prefix]), 10)
89 u.Host = net.JoinHostPort(u.Host, port)
90 }
91 return u.Host, true, nil
92 }
93 }
94 return "", false, nil
95}

Callers 6

lintActionFunction · 0.85
TestTrimURLFunction · 0.85
inspectActionFunction · 0.85
needsRenewalActionFunction · 0.85
verifyActionFunction · 0.85
fingerprintActionFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestTrimURLFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…