database

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 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 ActiveBuilder

type ActiveBuilder struct {
	BuilderID   int         `db:"builder_id"`
	Name        string      `db:"name"`
	IPAddress   pgtype.Inet `db:"ip_address"`
	TLSPubKey   []byte      `db:"tls_pubkey"`
	ECDSAPubKey []byte      `db:"ecdsa_pubkey"`
}

type Builder

type Builder struct {
	Name         string      `db:"name"`
	IPAddress    pgtype.Inet `db:"ip_address"`
	IsActive     bool        `db:"is_active"`
	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
	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) Close

func (s *Service) Close() error

func (*Service) GetActiveBuildersWithServiceCredentials

func (s *Service) GetActiveBuildersWithServiceCredentials(ctx context.Context) ([]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, attestationType 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