Provision sets up the configuration for the TLS app.
(ctx caddy.Context)
| 160 | |
| 161 | // Provision sets up the configuration for the TLS app. |
| 162 | func (t *TLS) Provision(ctx caddy.Context) error { |
| 163 | eventsAppIface, err := ctx.App("events") |
| 164 | if err != nil { |
| 165 | return fmt.Errorf("getting events app: %v", err) |
| 166 | } |
| 167 | t.events = eventsAppIface.(*caddyevents.App) |
| 168 | t.ctx = ctx |
| 169 | t.logger = ctx.Logger() |
| 170 | repl := caddy.NewReplacer() |
| 171 | t.managing, t.loaded = make(map[string]string), make(map[string]string) |
| 172 | t.serverNames = make(map[string]serverNameRegistration) |
| 173 | t.serverNamesMu = new(sync.Mutex) |
| 174 | |
| 175 | // set up default DNS module, if any, and make sure it implements all the |
| 176 | // common libdns interfaces, since it could be used for a variety of things |
| 177 | // (do this before provisioning other modules, since they may rely on this) |
| 178 | if len(t.DNSRaw) > 0 { |
| 179 | dnsMod, err := ctx.LoadModule(t, "DNSRaw") |
| 180 | if err != nil { |
| 181 | return fmt.Errorf("loading overall DNS provider module: %v", err) |
| 182 | } |
| 183 | switch dnsMod.(type) { |
| 184 | case interface { |
| 185 | libdns.RecordAppender |
| 186 | libdns.RecordDeleter |
| 187 | libdns.RecordGetter |
| 188 | libdns.RecordSetter |
| 189 | }: |
| 190 | default: |
| 191 | return fmt.Errorf("DNS module does not implement the most common libdns interfaces: %T", dnsMod) |
| 192 | } |
| 193 | t.dns = dnsMod |
| 194 | } |
| 195 | |
| 196 | // set up a new certificate cache; this (re)loads all certificates |
| 197 | cacheOpts := certmagic.CacheOptions{ |
| 198 | GetConfigForCert: func(cert certmagic.Certificate) (*certmagic.Config, error) { |
| 199 | return t.getConfigForName(cert.Names[0]), nil |
| 200 | }, |
| 201 | Logger: t.logger.Named("cache"), |
| 202 | } |
| 203 | if t.Automation != nil { |
| 204 | cacheOpts.OCSPCheckInterval = time.Duration(t.Automation.OCSPCheckInterval) |
| 205 | cacheOpts.RenewCheckInterval = time.Duration(t.Automation.RenewCheckInterval) |
| 206 | } |
| 207 | if t.Cache != nil { |
| 208 | cacheOpts.Capacity = t.Cache.Capacity |
| 209 | } |
| 210 | if cacheOpts.Capacity <= 0 { |
| 211 | cacheOpts.Capacity = 10000 |
| 212 | } |
| 213 | |
| 214 | certCacheMu.Lock() |
| 215 | if certCache == nil { |
| 216 | certCache = certmagic.NewCache(cacheOpts) |
| 217 | } else { |
| 218 | certCache.SetOptions(cacheOpts) |
| 219 | } |