certmagic_storage_crdb

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: MIT Imports: 7 Imported by: 0

README

certmagic-storage-crdb

GoDoc

An implementation of certmagic's Storage interface for CockroachDB.

See tables.sql for the expected tables in the database.

Usage

package main

import (
	"context"
	"log"

	"github.com/caddyserver/certmagic"
	crdb "github.com/maragudk/certmagic-storage-crdb"
)

func main() {
	s := crdb.New(crdb.Options{
		User:     "certmagic",
		Host:     "localhost",
		Port:     26257,
		Database: "certmagic",
		Cert:     "path/to/cert",
		Key:      "path/to/key",
		RootCert: "path/to/root/cert",
	})
	certmagic.Default.Storage = s
	if err := s.Connect(context.Background()); err != nil {
		log.Fatalln("Error connecting to storage:", err)
	}

	err := certmagic.HTTPS([]string{"example.com"}, nil)
}

Limitations

List and Stat behave a bit differently than the default filesystem implementation, in that they only support terminal keys, i.e. keys that have data. The filesystem implementation, in contrast, has directories that can be traversed. This currently has no implications on certmagic, so you can safely use this implementation.

This may change in a later version, if needed.

Documentation

Overview

Package certmagic_storage_crdb provides a certmagic.Storer implementation for CockroachDB.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CRDBStorage

type CRDBStorage struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

CRDBStorage implements certmagic.Storage.

func New

func New(options Options) *CRDBStorage

New CRDBStorage.

func (*CRDBStorage) Connect

func (s *CRDBStorage) Connect(ctx context.Context) error

func (*CRDBStorage) Delete

func (s *CRDBStorage) Delete(key string) error

func (*CRDBStorage) Exists

func (s *CRDBStorage) Exists(key string) bool

func (*CRDBStorage) List

func (s *CRDBStorage) List(prefix string, recursive bool) ([]string, error)

List does not support the recursive flag, but it is provided in the signature to satisfy certmagic.Storage.

func (*CRDBStorage) Load

func (s *CRDBStorage) Load(key string) ([]byte, error)

func (*CRDBStorage) Lock

func (s *CRDBStorage) Lock(ctx context.Context, key string) error

func (*CRDBStorage) Stat

func (s *CRDBStorage) Stat(key string) (certmagic.KeyInfo, error)

Stat only supports keys that are terminal.

func (*CRDBStorage) Store

func (s *CRDBStorage) Store(key string, value []byte) error

func (*CRDBStorage) Unlock

func (s *CRDBStorage) Unlock(key string) error

type Options

type Options struct {
	User        string
	Host        string
	Port        int
	Database    string
	Cert        string
	Key         string
	RootCert    string
	LockTimeout time.Duration
}

Options for New.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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