MCPcopy Index your code
hub / github.com/coder/coder / loadCertificate

Method loadCertificate

coderd/notifications/dispatch/smtp.go:410–431  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

408}
409
410func (s *SMTPHandler) loadCertificate() (*tls.Certificate, error) {
411 if len(s.cfg.TLS.CertFile) == 0 && len(s.cfg.TLS.KeyFile) == 0 {
412 // nolint:nilnil // A nil certificate is a valid response.
413 return nil, nil
414 }
415
416 cert, err := os.ReadFile(s.cfg.TLS.CertFile.Value())
417 if err != nil {
418 return nil, xerrors.Errorf("load cert: %w", err)
419 }
420 key, err := os.ReadFile(s.cfg.TLS.KeyFile.String())
421 if err != nil {
422 return nil, xerrors.Errorf("load key: %w", err)
423 }
424
425 pair, err := tls.X509KeyPair(cert, key)
426 if err != nil {
427 return nil, xerrors.Errorf("invalid or unusable keypair: %w", err)
428 }
429
430 return &pair, nil
431}
432
433// auth returns a value which implements the smtp.Auth based on the available auth mechanisms.
434func (s *SMTPHandler) auth(ctx context.Context, mechs string) (sasl.Client, error) {

Callers 1

tlsConfigMethod · 0.95

Calls 4

ReadFileMethod · 0.65
ValueMethod · 0.45
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected