|
@@ -175,17 +175,52 @@ func signalContainer() {
|
175
|
175
|
|
176
|
176
|
func getHostnamesForContainer(container *Container) []string {
|
177
|
177
|
if label, ok := container.Labels[config.Labels.Hostnames]; ok {
|
178
|
|
- return strings.Split(strings.Replace(label, ",", " ", -1), " ")
|
|
178
|
+ return applyWildcards(splitList(label), config.WildCardDomains)
|
179
|
179
|
} else {
|
180
|
180
|
return []string{}
|
181
|
181
|
}
|
182
|
182
|
}
|
183
|
183
|
|
|
184
|
+func applyWildcards(domains []string, wildcards []string) (result []string) {
|
|
185
|
+ result = []string{}
|
|
186
|
+ required := make(map[string]bool)
|
|
187
|
+ for _, domain := range domains {
|
|
188
|
+ found := false
|
|
189
|
+ for _, wildcard := range wildcards {
|
|
190
|
+ if wildcardMatches(wildcard, domain) {
|
|
191
|
+ if !required["*."+wildcard] {
|
|
192
|
+ result = append(result, "*."+wildcard)
|
|
193
|
+ required["*."+wildcard] = true
|
|
194
|
+ }
|
|
195
|
+ found = true
|
|
196
|
+ break
|
|
197
|
+ }
|
|
198
|
+ }
|
|
199
|
+
|
|
200
|
+ if !found && !required[domain] {
|
|
201
|
+ result = append(result, domain)
|
|
202
|
+ required[domain] = true
|
|
203
|
+ }
|
|
204
|
+ }
|
|
205
|
+ return
|
|
206
|
+}
|
|
207
|
+
|
|
208
|
+func wildcardMatches(wildcard, domain string) bool {
|
|
209
|
+ if len(domain) <= len(wildcard) {
|
|
210
|
+ return false
|
|
211
|
+ }
|
|
212
|
+
|
|
213
|
+ pivot := len(domain) - len(wildcard) - 1
|
|
214
|
+ start := domain[:pivot]
|
|
215
|
+ end := domain[pivot+1:]
|
|
216
|
+ return domain[pivot] == '.' && end == wildcard && !strings.ContainsRune(start, '.')
|
|
217
|
+}
|
|
218
|
+
|
184
|
219
|
func getHostnames(containers map[string]*Container) (hostnames map[string]*Hostname) {
|
185
|
220
|
hostnames = make(map[string]*Hostname)
|
186
|
221
|
for _, container := range containers {
|
187
|
222
|
if label, ok := container.Labels[config.Labels.Hostnames]; ok {
|
188
|
|
- names := strings.Split(strings.Replace(label, ",", " ", -1), " ")
|
|
223
|
+ names := splitList(label)
|
189
|
224
|
if hostname, ok := hostnames[names[0]]; ok {
|
190
|
225
|
hostname.Containers = append(hostname.Containers, container)
|
191
|
226
|
} else {
|
|
@@ -230,7 +265,8 @@ func deployCertForContainer(container *Container) bool {
|
230
|
265
|
}
|
231
|
266
|
|
232
|
267
|
func deployCert(certificate *SavedCertificate) bool {
|
233
|
|
- target := path.Join(config.DefaultCertDestination, fmt.Sprintf("%s.pem", certificate.Domains[0]))
|
|
268
|
+ name := fmt.Sprintf("%s.pem", strings.ReplaceAll("*", "_", certificate.Domains[0]))
|
|
269
|
+ target := path.Join(config.DefaultCertDestination, name)
|
234
|
270
|
content := append(certificate.Certificate, certificate.PrivateKey...)
|
235
|
271
|
|
236
|
272
|
buf, _ := ioutil.ReadFile(target)
|