models

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: GPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorTypeConnection     = "connection"
	ErrorTypeAuthentication = "authentication"
	ErrorTypeBan            = "ban"
	ErrorTypeAPI            = "api"
)

Error types for categorization

View Source
const (
	LicenseStatusActive  = "active"
	LicenseStatusInvalid = "invalid"
)

LicenseStatus constants

Variables

View Source
var ErrAPIKeyNotFound = errors.New("api key not found")
View Source
var ErrClientAPIKeyNotFound = errors.New("client api key not found")
View Source
var ErrInstanceNotFound = errors.New("instance not found")
View Source
var ErrInvalidAPIKey = errors.New("invalid api key")
View Source
var (
	ErrLicenseNotFound = errors.New("license not found")
)
View Source
var ErrUserAlreadyExists = errors.New("user already exists")
View Source
var ErrUserNotFound = errors.New("user not found")

Functions

func GenerateAPIKey

func GenerateAPIKey() (string, error)

GenerateAPIKey generates a new API key

func HashAPIKey

func HashAPIKey(key string) string

HashAPIKey creates a SHA256 hash of the API key

Types

type APIKey

type APIKey struct {
	ID         int        `json:"id"`
	KeyHash    string     `json:"-"`
	Name       string     `json:"name"`
	CreatedAt  time.Time  `json:"createdAt"`
	LastUsedAt *time.Time `json:"lastUsedAt,omitempty"`
}

type APIKeyStore

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

func NewAPIKeyStore

func NewAPIKeyStore(db *sql.DB) *APIKeyStore

func (*APIKeyStore) Create

func (s *APIKeyStore) Create(ctx context.Context, name string) (string, *APIKey, error)

func (*APIKeyStore) Delete

func (s *APIKeyStore) Delete(ctx context.Context, id int) error

func (*APIKeyStore) GetByHash

func (s *APIKeyStore) GetByHash(ctx context.Context, keyHash string) (*APIKey, error)

func (*APIKeyStore) List

func (s *APIKeyStore) List(ctx context.Context) ([]*APIKey, error)

func (*APIKeyStore) UpdateLastUsed

func (s *APIKeyStore) UpdateLastUsed(ctx context.Context, id int) error

func (*APIKeyStore) ValidateAPIKey

func (s *APIKeyStore) ValidateAPIKey(ctx context.Context, rawKey string) (*APIKey, error)

ValidateAPIKey validates a raw API key and returns the associated APIKey if valid

type ClientAPIKey added in v1.0.0

type ClientAPIKey struct {
	ID         int        `json:"id"`
	KeyHash    string     `json:"-"`
	ClientName string     `json:"clientName"`
	InstanceID int        `json:"instanceId"`
	CreatedAt  time.Time  `json:"createdAt"`
	LastUsedAt *time.Time `json:"lastUsedAt,omitempty"`
}

type ClientAPIKeyStore added in v1.0.0

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

func NewClientAPIKeyStore added in v1.0.0

func NewClientAPIKeyStore(db *sql.DB) *ClientAPIKeyStore

func (*ClientAPIKeyStore) Create added in v1.0.0

func (s *ClientAPIKeyStore) Create(ctx context.Context, clientName string, instanceID int) (string, *ClientAPIKey, error)

func (*ClientAPIKeyStore) Delete added in v1.0.0

func (s *ClientAPIKeyStore) Delete(ctx context.Context, id int) error

func (*ClientAPIKeyStore) DeleteByInstanceID added in v1.0.0

func (s *ClientAPIKeyStore) DeleteByInstanceID(ctx context.Context, instanceID int) error

func (*ClientAPIKeyStore) GetAll added in v1.0.0

func (s *ClientAPIKeyStore) GetAll(ctx context.Context) ([]*ClientAPIKey, error)

func (*ClientAPIKeyStore) GetByKeyHash added in v1.0.0

func (s *ClientAPIKeyStore) GetByKeyHash(ctx context.Context, keyHash string) (*ClientAPIKey, error)

func (*ClientAPIKeyStore) UpdateLastUsed added in v1.0.0

func (s *ClientAPIKeyStore) UpdateLastUsed(ctx context.Context, keyHash string) error

func (*ClientAPIKeyStore) ValidateKey added in v1.0.0

func (s *ClientAPIKeyStore) ValidateKey(ctx context.Context, rawKey string) (*ClientAPIKey, error)

type Instance

type Instance struct {
	ID                     int     `json:"id"`
	Name                   string  `json:"name"`
	Host                   string  `json:"host"`
	Username               string  `json:"username"`
	PasswordEncrypted      string  `json:"-"`
	BasicUsername          *string `json:"basic_username,omitempty"`
	BasicPasswordEncrypted *string `json:"-"`
	TLSSkipVerify          bool    `json:"tlsSkipVerify"`
}

func (Instance) MarshalJSON added in v1.0.0

func (i Instance) MarshalJSON() ([]byte, error)

func (*Instance) UnmarshalJSON added in v1.0.0

func (i *Instance) UnmarshalJSON(data []byte) error

type InstanceError added in v1.0.0

type InstanceError struct {
	ID           int       `json:"id"`
	InstanceID   int       `json:"instanceId"`
	ErrorType    string    `json:"errorType"`
	ErrorMessage string    `json:"errorMessage"`
	OccurredAt   time.Time `json:"occurredAt"`
}

type InstanceErrorStore added in v1.0.0

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

func NewInstanceErrorStore added in v1.0.0

func NewInstanceErrorStore(db *sql.DB) *InstanceErrorStore

func (*InstanceErrorStore) ClearErrors added in v1.0.0

func (s *InstanceErrorStore) ClearErrors(ctx context.Context, instanceID int) error

ClearErrors removes all errors for an instance (called on successful connection)

func (*InstanceErrorStore) GetRecentErrors added in v1.0.0

func (s *InstanceErrorStore) GetRecentErrors(ctx context.Context, instanceID int, limit int) ([]InstanceError, error)

GetRecentErrors retrieves the last N errors for an instance

func (*InstanceErrorStore) RecordError added in v1.0.0

func (s *InstanceErrorStore) RecordError(ctx context.Context, instanceID int, err error) error

RecordError stores an error for an instance with simple deduplication

type InstanceStore

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

func NewInstanceStore

func NewInstanceStore(db *sql.DB, encryptionKey []byte) (*InstanceStore, error)

func (*InstanceStore) Create

func (s *InstanceStore) Create(ctx context.Context, name, rawHost, username, password string, basicUsername, basicPassword *string, tlsSkipVerify bool) (*Instance, error)

func (*InstanceStore) Delete

func (s *InstanceStore) Delete(ctx context.Context, id int) error

func (*InstanceStore) Get

func (s *InstanceStore) Get(ctx context.Context, id int) (*Instance, error)

func (*InstanceStore) GetDecryptedBasicPassword

func (s *InstanceStore) GetDecryptedBasicPassword(instance *Instance) (*string, error)

GetDecryptedBasicPassword returns the decrypted basic auth password for an instance

func (*InstanceStore) GetDecryptedPassword

func (s *InstanceStore) GetDecryptedPassword(instance *Instance) (string, error)

GetDecryptedPassword returns the decrypted password for an instance

func (*InstanceStore) List

func (s *InstanceStore) List(ctx context.Context) ([]*Instance, error)

func (*InstanceStore) Update

func (s *InstanceStore) Update(ctx context.Context, id int, name, rawHost, username, password string, basicUsername, basicPassword *string, tlsSkipVerify *bool) (*Instance, error)

type LicenseInfo added in v1.0.0

type LicenseInfo struct {
	Key          string     `json:"key"`
	ProductName  string     `json:"productName"`
	CustomerID   string     `json:"customerId"`
	ProductID    string     `json:"productId"`
	ExpiresAt    *time.Time `json:"expiresAt,omitempty"`
	Valid        bool       `json:"valid"`
	ErrorMessage string     `json:"errorMessage,omitempty"`
}

LicenseInfo contains license validation information

type ProductLicense added in v1.0.0

type ProductLicense struct {
	ID                int        `json:"id"`
	LicenseKey        string     `json:"licenseKey"`
	ProductName       string     `json:"productName"`
	Status            string     `json:"status"`
	ActivatedAt       time.Time  `json:"activatedAt"`
	ExpiresAt         *time.Time `json:"expiresAt,omitempty"`
	LastValidated     time.Time  `json:"lastValidated"`
	PolarCustomerID   *string    `json:"polarCustomerId,omitempty"`
	PolarProductID    *string    `json:"polarProductId,omitempty"`
	PolarActivationID string     `json:"polarActivationId,omitempty"`
	Username          string     `json:"username"`
	CreatedAt         time.Time  `json:"createdAt"`
	UpdatedAt         time.Time  `json:"updatedAt"`
}

ProductLicense represents a product license in the database

type User

type User struct {
	ID           int    `json:"id"`
	Username     string `json:"username"`
	PasswordHash string `json:"-"`
}

type UserStore

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

func NewUserStore

func NewUserStore(db *sql.DB) *UserStore

func (*UserStore) Create

func (s *UserStore) Create(ctx context.Context, username, passwordHash string) (*User, error)

func (*UserStore) Exists

func (s *UserStore) Exists(ctx context.Context) (bool, error)

func (*UserStore) Get

func (s *UserStore) Get(ctx context.Context) (*User, error)

func (*UserStore) GetByUsername

func (s *UserStore) GetByUsername(ctx context.Context, username string) (*User, error)

func (*UserStore) UpdatePassword

func (s *UserStore) UpdatePassword(ctx context.Context, passwordHash string) error

Jump to

Keyboard shortcuts

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