sqlcertcache

package module
v0.0.0-...-99f858c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2018 License: MIT Imports: 6 Imported by: 1

README

GoDoc Go Report Card

sqlcertcache

SQL cache for acme/autocert written in Go.

Example

conn, err := sql.Open("postgres", "postgres://YOUR_CONNECTION_STRING")
if err != nil {
  // Handle error
}

cache, err := sqlcertcache.New(conn, "autocert_cache")
if err != nil {
  // Handle error
}

m := autocert.Manager{
  Prompt:     autocert.AcceptTOS,
  HostPolicy: autocert.HostWhitelist("example.org"),
  Cache:      cache,
}

s := &http.Server{
  Addr:      ":https",
  TLSConfig: &tls.Config{GetCertificate: m.GetCertificate},
}

s.ListenAndServeTLS("", "")

Performance

This is just a reminder that autocert has an internal in-memory cache that is used before quering this long-term cache. So you don't need to worry about your SQL database being hit many times just to get a certificate. It should only do once per process+key.

Thanks

Inspired by https://github.com/danilobuerger/autocert-s3-cache

License

MIT

Documentation

Overview

Package sqlcertcache implements an autocert.Cache to store certificate data within a SQL Database

See https://godoc.org/golang.org/x/crypto/acme/autocert

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyTableName = errors.New("tableName must not be empty")

ErrEmptyTableName is returned when given table name is empty

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache provides a SQL backend to the autocert cache.

func New

func New(conn *sql.DB, tableName string) (*Cache, error)

New creates an cache instance that can be used with autocert.Cache. It returns any errors that could happen while connecting to SQL.

func (*Cache) Delete

func (c *Cache) Delete(ctx context.Context, key string) error

Delete removes a certificate data from the cache under the specified key. If there's no such key in the cache, Delete returns nil.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key string) ([]byte, error)

Get returns a certificate data for the specified key. If there's no such key, Get returns ErrCacheMiss.

func (*Cache) Put

func (c *Cache) Put(ctx context.Context, key string, data []byte) error

Put stores the data in the cache under the specified key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL