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)
| 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. |
| 319 | func 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 | } |