database

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package database provides a database adapter for postgres

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	Name         string         `db:"name"`
	IPAddress    pgtype.Inet    `db:"ip_address"`
	IsActive     bool           `db:"is_active"`
	Network      string         `db:"network"`
	DNSName      sql.NullString `db:"dns_name"`
	CreatedAt    time.Time      `db:"created_at"`
	UpdatedAt    time.Time      `db:"updated_at"`
	DeprecatedAt *time.Time     `db:"deprecated_at"`
}

type BuilderConfig

type BuilderConfig struct {
	ID          int             `db:"id"`
	BuilderName string          `db:"builder_name"`
	Config      json.RawMessage `db:"config"`
	IsActive    bool            `db:"is_active"`
	CreatedAt   time.Time       `db:"created_at"`
	UpdatedAt   time.Time       `db:"updated_at"`
}

type BuilderWithCredentials

type BuilderWithCredentials struct {
	Name        string
	IPAddress   pgtype.Inet
	DNSName     sql.NullString
	Credentials []ServiceCredential
}

type Measurement

type Measurement struct {
	ID              int             `db:"id"`
	Name            string          `db:"name"`
	AttestationType string          `db:"attestation_type"`
	Measurement     json.RawMessage `db:"measurement"`
	IsActive        bool            `db:"is_active"`
	CreatedAt       time.Time       `db:"created_at"`
	UpdatedAt       time.Time       `db:"updated_at"`
	DeprecatedAt    *time.Time      `db:"deprecated_at"`
}

type Service

type Service struct {
	DB *sqlx.DB
}

func NewDatabaseService

func NewDatabaseService(dsn string) (*Service, error)

func (*Service) AddBuilder added in v0.2.0

func (s *Service) AddBuilder(ctx context.Context, builder domain.Builder) error

func (*Service) AddBuilderConfig added in v0.2.0

func (s *Service) AddBuilderConfig(ctx context.Context, builderName string, config json.RawMessage) error

func (*Service) AddMeasurement added in v0.2.0

func (s *Service) AddMeasurement(ctx context.Context, measurement domain.Measurement, enabled bool) error

func (*Service) ChangeActiveStatusForBuilder added in v0.2.0

func (s *Service) ChangeActiveStatusForBuilder(ctx context.Context, builderName string, isActive bool) error

func (*Service) ChangeActiveStatusForMeasurement added in v0.2.0

func (s *Service) ChangeActiveStatusForMeasurement(ctx context.Context, measurementName string, isActive bool) error

func (*Service) Close

func (s *Service) Close() error

func (*Service) GetActiveBuildersWithServiceCredentials

func (s *Service) GetActiveBuildersWithServiceCredentials(ctx context.Context, network string) ([]domain.BuilderWithServices, error)

func (*Service) GetActiveConfigForBuilder

func (s *Service) GetActiveConfigForBuilder(ctx context.Context, builderName string) (json.RawMessage, error)

GetActiveConfigForBuilder retrieves the active config for a builder by name

func (*Service) GetActiveMeasurements

func (s *Service) GetActiveMeasurements(ctx context.Context) ([]domain.Measurement, error)

GetActiveMeasurements retrieves all measurements

func (*Service) GetActiveMeasurementsByType

func (s *Service) GetActiveMeasurementsByType(ctx context.Context, attestationType string) ([]domain.Measurement, error)

func (*Service) GetBuilderByIP

func (s *Service) GetBuilderByIP(ip net.IP) (*domain.Builder, error)

GetBuilderByIP retrieves a builder by IP address

func (*Service) LogEvent

func (s *Service) LogEvent(ctx context.Context, eventName, builderName, name string) error

LogEvent creates a new log entry in the event_log table. It uses hash and attestation_type to fetch the corresponding measurement_id via a subquery.

func (*Service) RegisterCredentialsForBuilder

func (s *Service) RegisterCredentialsForBuilder(ctx context.Context, builderName, service, tlsCert string, ecdsaPubKey []byte, measurementName, attestationType string) error

RegisterCredentialsForBuilder registers new credentials for a builder, deprecating all previous credentials It uses hash and attestation_type to fetch the corresponding measurement_id via a subquery.

type ServiceCredential

type ServiceCredential struct {
	Service     string
	TLSCert     sql.NullString
	ECDSAPubKey []byte
}

type ServiceCredentialRegistration

type ServiceCredentialRegistration struct {
	ID          int       `db:"id"`
	BuilderName string    `db:"builder_name"`
	Service     string    `db:"service"`
	TLSCert     string    `db:"tls_cert"`
	ECDSAPubKey []byte    `db:"ecdsa_pubkey"`
	CreatedAt   time.Time `db:"created_at"`
}

Jump to

Keyboard shortcuts

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