( pairings []sbAddrAssociation, options map[string]any, warnings []caddyconfig.Warning, )
| 34 | ) |
| 35 | |
| 36 | func (st ServerType) buildTLSApp( |
| 37 | pairings []sbAddrAssociation, |
| 38 | options map[string]any, |
| 39 | warnings []caddyconfig.Warning, |
| 40 | ) (*caddytls.TLS, []caddyconfig.Warning, error) { |
| 41 | tlsApp := &caddytls.TLS{CertificatesRaw: make(caddy.ModuleMap)} |
| 42 | var certLoaders []caddytls.CertificateLoader |
| 43 | |
| 44 | httpPort := strconv.Itoa(caddyhttp.DefaultHTTPPort) |
| 45 | if hp, ok := options["http_port"].(int); ok { |
| 46 | httpPort = strconv.Itoa(hp) |
| 47 | } |
| 48 | autoHTTPS := []string{} |
| 49 | if ah, ok := options["auto_https"].([]string); ok { |
| 50 | autoHTTPS = ah |
| 51 | } |
| 52 | |
| 53 | // find all hosts that share a server block with a hostless |
| 54 | // key, so that they don't get forgotten/omitted by auto-HTTPS |
| 55 | // (since they won't appear in route matchers) |
| 56 | httpsHostsSharedWithHostlessKey := make(map[string]struct{}) |
| 57 | if !slices.Contains(autoHTTPS, "off") { |
| 58 | for _, pair := range pairings { |
| 59 | for _, sb := range pair.serverBlocks { |
| 60 | for _, addr := range sb.parsedKeys { |
| 61 | if addr.Host != "" { |
| 62 | continue |
| 63 | } |
| 64 | |
| 65 | // this server block has a hostless key, now |
| 66 | // go through and add all the hosts to the set |
| 67 | for _, otherAddr := range sb.parsedKeys { |
| 68 | if otherAddr.Original == addr.Original { |
| 69 | continue |
| 70 | } |
| 71 | if otherAddr.Host != "" && otherAddr.Scheme != "http" && otherAddr.Port != httpPort { |
| 72 | httpsHostsSharedWithHostlessKey[otherAddr.Host] = struct{}{} |
| 73 | } |
| 74 | } |
| 75 | break |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // a catch-all automation policy is used as a "default" for all subjects that |
| 82 | // don't have custom configuration explicitly associated with them; this |
| 83 | // is only to add if the global settings or defaults are non-empty |
| 84 | catchAllAP, err := newBaseAutomationPolicy(options, warnings, false) |
| 85 | if err != nil { |
| 86 | return nil, warnings, err |
| 87 | } |
| 88 | if catchAllAP != nil { |
| 89 | if tlsApp.Automation == nil { |
| 90 | tlsApp.Automation = new(caddytls.AutomationConfig) |
| 91 | } |
| 92 | tlsApp.Automation.Policies = append(tlsApp.Automation.Policies, catchAllAP) |
| 93 | } |
no test coverage detected