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

Method Provision

modules/caddytls/capools.go:406–454  ·  view source on GitHub ↗

Provision implements caddy.Provisioner.

(ctx caddy.Context)

Source from the content-addressed store, hash-verified

404
405// Provision implements caddy.Provisioner.
406func (ca *StoragePool) Provision(ctx caddy.Context) error {
407 if ca.StorageRaw != nil {
408 val, err := ctx.LoadModule(ca, "StorageRaw")
409 if err != nil {
410 return fmt.Errorf("loading storage module: %v", err)
411 }
412 cmStorage, err := val.(caddy.StorageConverter).CertMagicStorage()
413 if err != nil {
414 return fmt.Errorf("creating storage configuration: %v", err)
415 }
416 ca.storage = cmStorage
417 }
418 if ca.storage == nil {
419 ca.storage = ctx.Storage()
420 }
421 if len(ca.PEMKeys) == 0 {
422 return fmt.Errorf("no PEM keys specified")
423 }
424 caPool := x509.NewCertPool()
425 var certs []*x509.Certificate
426 for _, caID := range ca.PEMKeys {
427 bs, err := ca.storage.Load(ctx, caID)
428 if err != nil {
429 return fmt.Errorf("error loading cert '%s' from storage: %s", caID, err)
430 }
431 // Parse PEM to extract certificates
432 pemData := bs
433 for len(pemData) > 0 {
434 var block *pem.Block
435 block, pemData = pem.Decode(pemData)
436 if block == nil {
437 break
438 }
439 if block.Type != "CERTIFICATE" {
440 continue
441 }
442 cert, err := x509.ParseCertificate(block.Bytes)
443 if err != nil {
444 return fmt.Errorf("parsing certificate '%s': %v", caID, err)
445 }
446 caPool.AddCert(cert)
447 certs = append(certs, cert)
448 }
449 }
450 ca.pool = caPool
451 ca.certs = certs
452
453 return nil
454}
455
456// Syntax:
457//

Callers

nothing calls this directly

Calls 4

LoadModuleMethod · 0.80
StorageMethod · 0.80
LoadMethod · 0.80
CertMagicStorageMethod · 0.65

Tested by

no test coverage detected