certdb

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlavorUnknown = Dbflavor(iota)
	FlavorPostgreSQL
	FlavorSQLite
	FlavorMySQL
)

Variables

View Source
var IdColumnConstraint = map[Dbflavor]string{
	FlavorUnknown:    "PRIMARY KEY",
	FlavorPostgreSQL: "PRIMARY KEY GENERATED ALWAYS AS IDENTITY",
	FlavorSQLite:     "PRIMARY KEY",
	FlavorMySQL:      "PRIMARY KEY AUTO_INCREMENT",
}
View Source
var TableCert = &TableInfo{
	Name:       "cert",
	ForeignKey: "stream",
	Create: `CREATE TABLE IF NOT EXISTS {TableName} (
id BIGINT {IdColumnConstraint},
stream BIGINT NOT NULL, -- stream.id
index BIGINT NOT NULL, -- CT log entry index
seen TIMESTAMP NOT NULL,
notbefore TIMESTAMP NOT NULL,
notafter TIMESTAMP NOT NULL,
json TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS {TableName}_notbefore_idx ON {TableName} (notbefore);
CREATE INDEX IF NOT EXISTS {TableName}_notafter_idx ON {TableName} (notafter);
{AlterTableForeignKey}
`,
	Upsert: ``,
}
View Source
var TableDNSName = &TableInfo{
	Name:       "dnsname",
	ForeignKey: "cert",
	Create: `CREATE TABLE IF NOT EXISTS {TableName} (
cert BIGINT NOT NULL, -- cert.id
name VARCHAR(256) NOT NULL, -- e.g. 'foo.example.com'
rname VARCHAR(256) NOT NULL, -- e.g. 'com.example.foo'
PRIMARY KEY (cert, name)
);
CREATE INDEX IF NOT EXISTS {TableName}_name_idx ON {TableName} (name);
CREATE INDEX IF NOT EXISTS {TableName}_rname_idx ON {TableName} (rname);
{AlterTableForeignKey}
`,
	Upsert: ``,
}
View Source
var TableEmail = &TableInfo{
	Name:       "email",
	ForeignKey: "cert",
	Create: `CREATE TABLE IF NOT EXISTS {TableName} (
cert BIGINT NOT NULL, -- cert.id
email VARCHAR(128) NOT NULL, -- e.g. 'user@example.com'
PRIMARY KEY (cert, email)
);
CREATE INDEX IF NOT EXISTS {TableName}_email_idx ON {TableName} (email);
{AlterTableForeignKey}
`,
	Upsert: ``,
}
View Source
var TableIPAddress = &TableInfo{
	Name:       "ipaddress",
	ForeignKey: "cert",
	Create: `CREATE TABLE IF NOT EXISTS {TableName} (
cert BIGINT NOT NULL, -- cert.id
addr VARCHAR(45) NOT NULL, -- e.g. '192.168.1.1'
PRIMARY KEY (cert, addr)
);
CREATE INDEX IF NOT EXISTS {TableName}_addr_idx ON {TableName} (addr);
{AlterTableForeignKey}
`,
	Upsert: ``,
}
View Source
var TableOperator = &TableInfo{
	Name: "operator",
	Create: `CREATE TABLE IF NOT EXISTS {TableName} (
id BIGINT {IdColumnConstraint},
domain VARCHAR(128) NOT NULL,
name VARCHAR(128) NOT NULL,
email VARCHAR(128) NOT NULL
);
`,
	Upsert: ``,
}
View Source
var TablePrefix = "certdb_"
View Source
var TableStream = &TableInfo{
	Name:       "stream",
	ForeignKey: "operator",
	Create: `CREATE TABLE IF NOT EXISTS {TableName} (
id BIGINT {IdColumnConstraint},
operator BIGINT NOT NULL, -- operator.id
url VARCHAR(256) NOT NULL, -- CT log stream URL
lastindex BIGINT NOT NULL, -- last CT log entry index written
json TEXT NOT NULL
);
{AlterTableForeignKey}
`,
	Upsert: ``,
}
View Source
var URITable = &TableInfo{
	Name:       "uri",
	ForeignKey: "cert",
	Create: `CREATE TABLE IF NOT EXISTS {TableName} (
cert BIGINT NOT NULL, -- cert.id
uri VARCHAR(1024) NOT NULL, -- e.g. 'https://www.example.com/path'
PRIMARY KEY (cert, uri)
);
CREATE INDEX IF NOT EXISTS {TableName}_uri_idx ON {TableName} (uri);
{AlterTableForeignKey}
`,
	Upsert: ``,
}

Functions

func AlterTableForeignKeySQL

func AlterTableForeignKeySQL(flavor Dbflavor, table, fk string) string

func CreateSchema

func CreateSchema(ctx context.Context, db *sql.DB) (err error)

Types

type Certdb

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

Certdb integrates with sql.DB to manage certificate stream data

func New

func New(ctx context.Context, db *sql.DB) (cdb *Certdb, err error)

New creates a Certdb and creates the needed tables and indices if they don't exist.

func (*Certdb) Close

func (cdb *Certdb) Close() error

Close frees resources used.

func (*Certdb) Insert

func (cdb *Certdb) Insert(le *certstream.LogEntry)

type Dbflavor

type Dbflavor int

func GetDbflavor

func GetDbflavor(ctx context.Context, db *sql.DB) Dbflavor

type TableInfo

type TableInfo struct {
	Name       string
	ForeignKey string // column which references ForeignKey(id)
	Create     string
	Upsert     string
}

func (*TableInfo) CreateStmt

func (ti *TableInfo) CreateStmt(flavor Dbflavor) string

Jump to

Keyboard shortcuts

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