Add Tailscale certificate resolver
Co-authored-by: Mathieu Lonjaret <mathieu.lonjaret@gmail.com>
This commit is contained in:
parent
033fccccc7
commit
38d7011487
13 changed files with 957 additions and 48 deletions
|
@ -162,21 +162,32 @@ func (c *Certificate) AppendCertificate(certs map[string]map[string]*tls.Certifi
|
|||
return err
|
||||
}
|
||||
|
||||
// GetCertificate retrieves Certificate as tls.Certificate.
|
||||
// GetCertificate returns a tls.Certificate matching the configured CertFile and KeyFile.
|
||||
func (c *Certificate) GetCertificate() (tls.Certificate, error) {
|
||||
certContent, err := c.CertFile.Read()
|
||||
if err != nil {
|
||||
return tls.Certificate{}, fmt.Errorf("unable to read CertFile : %w", err)
|
||||
return tls.Certificate{}, fmt.Errorf("unable to read CertFile: %w", err)
|
||||
}
|
||||
|
||||
keyContent, err := c.KeyFile.Read()
|
||||
if err != nil {
|
||||
return tls.Certificate{}, fmt.Errorf("unable to read KeyFile : %w", err)
|
||||
return tls.Certificate{}, fmt.Errorf("unable to read KeyFile: %w", err)
|
||||
}
|
||||
|
||||
cert, err := tls.X509KeyPair(certContent, keyContent)
|
||||
if err != nil {
|
||||
return tls.Certificate{}, fmt.Errorf("unable to generate TLS certificate : %w", err)
|
||||
return tls.Certificate{}, fmt.Errorf("unable to parse TLS certificate: %w", err)
|
||||
}
|
||||
|
||||
return cert, nil
|
||||
}
|
||||
|
||||
// GetCertificateFromBytes returns a tls.Certificate matching the configured CertFile and KeyFile.
|
||||
// It assumes that the configured CertFile and KeyFile are of byte type.
|
||||
func (c *Certificate) GetCertificateFromBytes() (tls.Certificate, error) {
|
||||
cert, err := tls.X509KeyPair([]byte(c.CertFile), []byte(c.KeyFile))
|
||||
if err != nil {
|
||||
return tls.Certificate{}, fmt.Errorf("unable to parse TLS certificate: %w", err)
|
||||
}
|
||||
|
||||
return cert, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue