storage

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

This section is empty.

Types

type BootstrapToken

type BootstrapToken struct {
	ID          string
	TokenHash   string
	Role        string
	OwnerID     string
	MaxUsages   int
	UsagesCount int
	Description string
	CreatedAt   time.Time
	ExpiresAt   time.Time
}

BootstrapToken represents a pre-shared token for node enrollment.

type EnrolledNode

type EnrolledNode struct {
	PeerID         string
	PublicKey      []byte
	Biscuit        []byte
	Role           string
	EnrollmentType string
	ClaimsJSON     string
	OwnerID        string
	EnrolledAt     time.Time
	ExpiresAt      time.Time
	Banned         bool
}

EnrolledNode represents a node enrolled in the mesh.

type EnrollmentRequest

type EnrollmentRequest struct {
	ID           string
	PeerID       string
	PublicKey    []byte
	TokenID      string
	Status       api.EnrollmentStatus
	BiscuitToken []byte
	CreatedAt    time.Time
	ResolvedAt   *time.Time
	ResolvedBy   string
}

EnrollmentRequest represents a pending or resolved node registration request (CSR).

type KeyPair

type KeyPair struct {
	Private    ed25519.PrivateKey
	Public     ed25519.PublicKey
	Expiration time.Time
}

KeyPair holds cryptographic key information.

type RouterLease

type RouterLease struct {
	PeerID         string
	Addresses      []string
	LastRenewal    time.Time
	ExpiresAt      time.Time
	ConnectedPeers []string
	DHTSize        int
}

RouterLease represents a router registered with the control plane.

type SQLStore

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

SQLStore implements Store interface using database/sql.

func NewSQLStore

func NewSQLStore(driverName, dataSourceName string) (*SQLStore, error)

NewSQLStore creates a new SQLStore, connects to the database, and initializes tables.

func (*SQLStore) Close

func (s *SQLStore) Close() error

Close implements Store.

func (*SQLStore) CreateEnrollmentRequest

func (s *SQLStore) CreateEnrollmentRequest(ctx context.Context, req *EnrollmentRequest) error

CreateEnrollmentRequest saves a new pending request.

func (*SQLStore) EnrollNode

func (s *SQLStore) EnrollNode(ctx context.Context, node *EnrolledNode) error

EnrollNode implements Store.

func (*SQLStore) GetActiveRouters

func (s *SQLStore) GetActiveRouters(ctx context.Context) ([]RouterLease, error)

GetActiveRouters implements Store.

func (*SQLStore) GetAllValidKeys

func (s *SQLStore) GetAllValidKeys(ctx context.Context) ([]KeyPair, error)

GetAllValidKeys implements Store.

func (*SQLStore) GetBootstrapToken

func (s *SQLStore) GetBootstrapToken(ctx context.Context, id string) (*BootstrapToken, error)

GetBootstrapToken retrieves a bootstrap token by its ID (sha256 hash).

func (*SQLStore) GetCurrentKey

func (s *SQLStore) GetCurrentKey(ctx context.Context) (ed25519.PrivateKey, ed25519.PublicKey, error)

GetCurrentKey implements Store.

func (*SQLStore) GetEnrollmentRequest

func (s *SQLStore) GetEnrollmentRequest(ctx context.Context, peerID string) (*EnrollmentRequest, error)

GetEnrollmentRequest retrieves request by PeerID.

func (*SQLStore) GetEnrollmentRequestByID

func (s *SQLStore) GetEnrollmentRequestByID(ctx context.Context, id string) (*EnrollmentRequest, error)

GetEnrollmentRequestByID retrieves request by UUID.

func (*SQLStore) GetMeshPolicy

func (s *SQLStore) GetMeshPolicy(ctx context.Context) ([]*api.PolicyRole, []*api.PolicyBinding, error)

GetMeshPolicy retrieves the entire mesh policy as structured data.

func (*SQLStore) GetNode

func (s *SQLStore) GetNode(ctx context.Context, peerID string) (*EnrolledNode, error)

GetNode implements Store.

func (*SQLStore) GetUser

func (s *SQLStore) GetUser(ctx context.Context, id string) (*User, error)

GetUser retrieves a user by ID.

func (*SQLStore) IncrementBootstrapTokenUsage

func (s *SQLStore) IncrementBootstrapTokenUsage(ctx context.Context, id string) error

IncrementBootstrapTokenUsage increments usage count.

func (*SQLStore) IsNodeBanned

func (s *SQLStore) IsNodeBanned(ctx context.Context, peerID string) (bool, error)

IsNodeBanned implements Store.

func (*SQLStore) ListBootstrapTokens

func (s *SQLStore) ListBootstrapTokens(ctx context.Context) ([]BootstrapToken, error)

ListBootstrapTokens retrieves all bootstrap tokens.

func (*SQLStore) ListEnrollmentRequests

func (s *SQLStore) ListEnrollmentRequests(ctx context.Context) ([]EnrollmentRequest, error)

ListEnrollmentRequests retrieves all requests.

func (*SQLStore) ListNodes

func (s *SQLStore) ListNodes(ctx context.Context) ([]EnrolledNode, error)

ListNodes retrieves all enrolled nodes.

func (*SQLStore) ListUsers

func (s *SQLStore) ListUsers(ctx context.Context) ([]User, error)

ListUsers retrieves all registered users.

func (*SQLStore) RotateKeys

func (s *SQLStore) RotateKeys(ctx context.Context, newPriv ed25519.PrivateKey, newPub ed25519.PublicKey, gracePeriod time.Duration) error

RotateKeys implements Store.

func (*SQLStore) SaveBootstrapToken

func (s *SQLStore) SaveBootstrapToken(ctx context.Context, token *BootstrapToken) error

SaveBootstrapToken persists a new bootstrap token.

func (*SQLStore) SaveInitialKey

func (s *SQLStore) SaveInitialKey(ctx context.Context, priv ed25519.PrivateKey, pub ed25519.PublicKey) error

SaveInitialKey implements Store.

func (*SQLStore) SaveMeshPolicy

func (s *SQLStore) SaveMeshPolicy(ctx context.Context, roles []*api.PolicyRole, bindings []*api.PolicyBinding) error

SaveMeshPolicy replaces the entire mesh policy with the provided roles and bindings.

func (*SQLStore) SaveUser

func (s *SQLStore) SaveUser(ctx context.Context, user *User) error

SaveUser creates or updates a user.

func (*SQLStore) SetNodeBanned

func (s *SQLStore) SetNodeBanned(ctx context.Context, peerID string, banned bool) error

SetNodeBanned implements Store.

func (*SQLStore) UpdateEnrollmentRequest

func (s *SQLStore) UpdateEnrollmentRequest(ctx context.Context, id string, status api.EnrollmentStatus, biscuit []byte, resolvedBy string) error

UpdateEnrollmentRequest updates status, timestamp and biscuit token.

func (*SQLStore) UpsertRouterLease

func (s *SQLStore) UpsertRouterLease(ctx context.Context, lease *RouterLease) error

UpsertRouterLease implements Store.

type Store

type Store interface {
	// GetCurrentKey retrieves the active key pair for biscuit signing.
	GetCurrentKey(ctx context.Context) (ed25519.PrivateKey, ed25519.PublicKey, error)

	// GetAllValidKeys retrieves the active key pair and any non-expired historical key pairs.
	GetAllValidKeys(ctx context.Context) ([]KeyPair, error)

	// RotateKeys rotates the current key to a new key pair and sets the expiration of the old key.
	RotateKeys(ctx context.Context, newPriv ed25519.PrivateKey, newPub ed25519.PublicKey, gracePeriod time.Duration) error

	// SaveInitialKey sets the initial key pair if no keys exist yet.
	SaveInitialKey(ctx context.Context, priv ed25519.PrivateKey, pub ed25519.PublicKey) error

	// SaveUser creates or updates a User.
	SaveUser(ctx context.Context, user *User) error

	// GetUser retrieves a User by ID.
	GetUser(ctx context.Context, id string) (*User, error)

	// ListUsers retrieves all registered users.
	ListUsers(ctx context.Context) ([]User, error)

	// EnrollNode registers or updates a node enrollment.
	EnrollNode(ctx context.Context, node *EnrolledNode) error

	// GetNode retrieves node enrollment details.
	GetNode(ctx context.Context, peerID string) (*EnrolledNode, error)

	// SetNodeBanned updates the banned status of a node.
	SetNodeBanned(ctx context.Context, peerID string, banned bool) error

	// IsNodeBanned checks if a node is currently banned.
	IsNodeBanned(ctx context.Context, peerID string) (bool, error)

	// UpsertRouterLease updates or creates a lease for a sam-router.
	UpsertRouterLease(ctx context.Context, lease *RouterLease) error

	// GetActiveRouters retrieves all routers whose leases are still valid.
	GetActiveRouters(ctx context.Context) ([]RouterLease, error)

	// SaveMeshPolicy persists the mesh configurations.
	SaveMeshPolicy(ctx context.Context, roles []*api.PolicyRole, bindings []*api.PolicyBinding) error

	// GetMeshPolicy loads the mesh configurations.
	GetMeshPolicy(ctx context.Context) ([]*api.PolicyRole, []*api.PolicyBinding, error)

	// SaveBootstrapToken persists a new bootstrap token.
	SaveBootstrapToken(ctx context.Context, token *BootstrapToken) error

	// GetBootstrapToken retrieves a bootstrap token by its ID (sha256 hash).
	GetBootstrapToken(ctx context.Context, id string) (*BootstrapToken, error)

	// IncrementBootstrapTokenUsage increments the usage count of a token.
	IncrementBootstrapTokenUsage(ctx context.Context, id string) error

	// CreateEnrollmentRequest saves a new pending enrollment request.
	CreateEnrollmentRequest(ctx context.Context, req *EnrollmentRequest) error

	// GetEnrollmentRequest retrieves an enrollment request by PeerID.
	GetEnrollmentRequest(ctx context.Context, peerID string) (*EnrollmentRequest, error)

	// GetEnrollmentRequestByID retrieves an enrollment request by ID.
	GetEnrollmentRequestByID(ctx context.Context, id string) (*EnrollmentRequest, error)

	// ListEnrollmentRequests retrieves all enrollment requests.
	ListEnrollmentRequests(ctx context.Context) ([]EnrollmentRequest, error)

	// UpdateEnrollmentRequest updates status, resolved details, and stored Biscuit of a request.
	UpdateEnrollmentRequest(ctx context.Context, id string, status api.EnrollmentStatus, biscuit []byte, resolvedBy string) error

	// ListNodes retrieves all enrolled nodes.
	ListNodes(ctx context.Context) ([]EnrolledNode, error)

	// ListBootstrapTokens retrieves all bootstrap tokens.
	ListBootstrapTokens(ctx context.Context) ([]BootstrapToken, error)

	// Close closes the underlying database connection.
	Close() error
}

Store defines the persistent operations for the SAM control plane.

type User

type User struct {
	ID        string
	Email     string
	Role      string
	CreatedAt time.Time
}

User represents a human identity in the mesh.

Jump to

Keyboard shortcuts

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