MCPcopy
hub / github.com/caddyserver/caddy / Provision

Method Provision

modules/caddytls/tls.go:162–366  ·  view source on GitHub ↗

Provision sets up the configuration for the TLS app.

(ctx caddy.Context)

Source from the content-addressed store, hash-verified

160
161// Provision sets up the configuration for the TLS app.
162func (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 }

Callers 1

Calls 13

getConfigForNameMethod · 0.95
ReplaceAllMethod · 0.95
ReplaceOrErrMethod · 0.95
ProvisionMethod · 0.95
AppMethod · 0.80
LoadModuleMethod · 0.80
DurationMethod · 0.80
StorageMethod · 0.80
LoadCertificatesMethod · 0.65
ProvisionMethod · 0.65
LoggerMethod · 0.45

Tested by 1