models

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: GPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

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

LicenseStatus constants

Variables

View Source
var ErrAPIKeyNotFound = errors.New("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 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(name string) (string, *APIKey, error)

func (*APIKeyStore) Delete

func (s *APIKeyStore) Delete(id int) error

func (*APIKeyStore) GetByHash

func (s *APIKeyStore) GetByHash(keyHash string) (*APIKey, error)

func (*APIKeyStore) List

func (s *APIKeyStore) List() ([]*APIKey, error)

func (*APIKeyStore) UpdateLastUsed

func (s *APIKeyStore) UpdateLastUsed(id int) error

func (*APIKeyStore) ValidateAPIKey

func (s *APIKeyStore) ValidateAPIKey(rawKey string) (*APIKey, error)

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

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:"-"`
	IsActive               bool       `json:"is_active"`
	LastConnectedAt        *time.Time `json:"last_connected_at,omitempty"`
	CreatedAt              time.Time  `json:"created_at"`
	UpdatedAt              time.Time  `json:"updated_at"`
}

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(name, rawHost, username, password string, basicUsername, basicPassword *string) (*Instance, error)

func (*InstanceStore) Delete

func (s *InstanceStore) Delete(id int) error

func (*InstanceStore) Get

func (s *InstanceStore) Get(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(activeOnly bool) ([]*Instance, error)

func (*InstanceStore) Update

func (s *InstanceStore) Update(id int, name, rawHost, username, password string, basicUsername, basicPassword *string) (*Instance, error)

func (*InstanceStore) UpdateActive

func (s *InstanceStore) UpdateActive(id int, isActive bool) error

func (*InstanceStore) UpdateLastConnected

func (s *InstanceStore) UpdateLastConnected(id int) error

type ThemeLicense

type ThemeLicense struct {
	ID              int        `json:"id" db:"id"`
	LicenseKey      string     `json:"licenseKey" db:"license_key"`
	ThemeName       string     `json:"themeName" db:"theme_name"`
	Status          string     `json:"status" db:"status"`
	ActivatedAt     time.Time  `json:"activatedAt" db:"activated_at"`
	ExpiresAt       *time.Time `json:"expiresAt,omitempty" db:"expires_at"`
	LastValidated   time.Time  `json:"lastValidated" db:"last_validated"`
	PolarCustomerID *string    `json:"polarCustomerId,omitempty" db:"polar_customer_id"`
	PolarProductID  *string    `json:"polarProductId,omitempty" db:"polar_product_id"`
	CreatedAt       time.Time  `json:"createdAt" db:"created_at"`
	UpdatedAt       time.Time  `json:"updatedAt" db:"updated_at"`
}

ThemeLicense represents a theme license key in the database

func (*ThemeLicense) IsValid

func (tl *ThemeLicense) IsValid() bool

IsValid returns true if the license is currently valid

func (*ThemeLicense) IsValidOffline

func (tl *ThemeLicense) IsValidOffline() bool

IsValidOffline returns true if the license is valid for offline use Allows 7 days grace period since last validation

func (*ThemeLicense) Value

func (tl *ThemeLicense) Value() (driver.Value, error)

Value implements driver.Valuer for database storage

type User

type User struct {
	ID           int       `json:"id"`
	Username     string    `json:"username"`
	PasswordHash string    `json:"-"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

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(username, passwordHash string) (*User, error)

func (*UserStore) Exists

func (s *UserStore) Exists() (bool, error)

func (*UserStore) Get

func (s *UserStore) Get() (*User, error)

func (*UserStore) GetByUsername

func (s *UserStore) GetByUsername(username string) (*User, error)

func (*UserStore) UpdatePassword

func (s *UserStore) UpdatePassword(passwordHash string) error

Jump to

Keyboard shortcuts

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