MCPcopy Create free account
hub / github.com/coder/coder / ConvertAppHostForCSP

Function ConvertAppHostForCSP

coderd/workspaceapps/appurl/appurl.go:319–334  ·  view source on GitHub ↗

ConvertAppHostForCSP converts the wildcard host to a format accepted by CSP. For example *--apps.coder.com must become *.coder.com. If there is no wildcard host, or it cannot be converted, return the base host.

(host, wildcard string)

Source from the content-addressed store, hash-verified

317// For example *--apps.coder.com must become *.coder.com. If there is no
318// wildcard host, or it cannot be converted, return the base host.
319func ConvertAppHostForCSP(host, wildcard string) string {
320 if wildcard == "" {
321 return host
322 }
323 parts := strings.Split(wildcard, ".")
324 for i, part := range parts {
325 if strings.Contains(part, "*") {
326 // The wildcard can only be in the first section.
327 if i != 0 {
328 return host
329 }
330 parts[i] = "*"
331 }
332 }
333 return strings.Join(parts, ".")
334}

Callers 3

NewFunction · 0.92
TestConvertAppURLForCSPFunction · 0.92
runOnceMethod · 0.92

Calls 1

ContainsMethod · 0.45

Tested by 1

TestConvertAppURLForCSPFunction · 0.74