serverops

package
v0.0.0-...-2ab6009 Latest Latest
Warning

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

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

Documentation

Overview

Package serverops provides core infrastructure for server operations including data persistence, state management, error handling, and security utilities and other primitives or wiring for libraries.

Subpackages are prohibited from cross-importing. Shared utilities in other words: subpackages of serverops are NEVER allowed to use other subpackages of serverops.

Index

Constants

View Source
const DefaultAdminUser = "admin@admin.com"
View Source
const DefaultDefaultServiceGroup = "admin_panel"
View Source
const DefaultServerGroup = "server"

Variables

View Source
var ErrDecodeInvalidJSON = errors.New("serverops: decoding failing, invalid json")
View Source
var ErrEncodeInvalidJSON = errors.New("serverops: encoding failing, invalid json")
View Source
var ErrFileEmpty = errors.New("serverops: file cannot be empty")

ErrFileEmpty indicates an attempt to upload an empty file.

View Source
var ErrFileSizeLimitExceeded = errors.New("serverops: file size limit exceeded")

ErrFileSizeLimitExceeded indicates the specific file exceeded its allowed size limit.

Functions

func CheckResourceAuthorization

func CheckResourceAuthorization(ctx context.Context, resource string, requiredPermission store.Permission) error

CheckResourceAuthorization checks if the user has the required permission for a given resource.

func CheckServiceAuthorization

func CheckServiceAuthorization[T ServiceMeta](ctx context.Context, s T, permission store.Permission) error

func CreateAuthToken

func CreateAuthToken(subject string, permissions store.AccessList) (string, time.Time, error)

func Decode

func Decode[T any](r *http.Request) (T, error)

func Encode

func Encode[T any](w http.ResponseWriter, _ *http.Request, status int, v T) error

func Error

func Error(w http.ResponseWriter, r *http.Request, err error, op Operation) error

Error sends a JSON-encoded error response with an appropriate status code

func GetIdentity

func GetIdentity(ctx context.Context) (string, error)

GetIdentity extracts the identity from the context using the JWT secret from the ServiceManager.

func LoadConfig

func LoadConfig[T any](cfg *T) error

func NewServiceManager

func NewServiceManager(config *Config) error

NewServiceManager creates a new instance of server.

func RefreshPlainToken

func RefreshPlainToken(ctx context.Context, token string, withGracePeriod *time.Duration) (string, bool, time.Time, error)

func RefreshToken

func RefreshToken(ctx context.Context) (string, bool, time.Time, error)

func ValidateConfig

func ValidateConfig(cfg *Config) error

Types

type Config

type Config struct {
	DatabaseURL         string `json:"database_url"`
	Port                string `json:"port"`
	Addr                string `json:"addr"`
	AllowedAPIOrigins   string `json:"allowed_api_origins"`
	AllowedMethods      string `json:"allowed_methods"`
	AllowedHeaders      string `json:"allowed_headers"`
	SigningKey          string `json:"signing_key"`
	EncryptionKey       string `json:"encryption_key"`
	JWTSecret           string `json:"jwt_secret"`
	JWTExpiry           string `json:"jwt_expiry"`
	TiKVPDEndpoint      string `json:"tikv_pd_endpoint"`
	NATSURL             string `json:"nats_url"`
	NATSUser            string `json:"nats_user"`
	NATSPassword        string `json:"nats_password"`
	SecurityEnabled     string `json:"security_enabled"`
	OpensearchURL       string `json:"opensearch_url"`
	ProxyOrigin         string `json:"proxy_origin"`
	UIBaseURL           string `json:"ui_base_url"`
	TokenizerServiceURL string `env:"TOKENIZER_SERVICE_URL" envDefault:"tokenizer:50051"`
}

type ConfigTokenizerService

type ConfigTokenizerService struct {
	Addr                 string `json:"addr"`
	FallbackModel        string `json:"fallback_model"`
	ModelSourceAuthToken string `json:"model_source_auth_token"`
	PreloadModels        string `json:"preload_models"`
	UseDefaultURLs       bool   `json:"use_default_urls"`
}

type ErrBadPathValue

type ErrBadPathValue string

func (ErrBadPathValue) Error

func (v ErrBadPathValue) Error() string

type LLMChatClient

type LLMChatClient interface {
	Chat(ctx context.Context, Messages []Message) (Message, error)
}

Client interfaces for different capabilities

type LLMEmbedClient

type LLMEmbedClient interface {
	Embed(ctx context.Context, prompt string) ([]float32, error)
}

type LLMStreamClient

type LLMStreamClient interface {
	Stream(ctx context.Context, prompt string) (<-chan string, error)
}

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type Operation

type Operation uint16
const (
	CreateOperation Operation = iota
	GetOperation
	UpdateOperation
	DeleteOperation
	ListOperation
	AuthorizeOperation
	ServerOperation
)

type ServiceManager

type ServiceManager interface {
	RegisterServices(s ...ServiceMeta) error
	GetServices() ([]ServiceMeta, error)
	IsSecurityEnabled(serviceName string) bool
	HasValidLicenseFor(serviceName string) bool
	GetSecret() string
	GetTokenExpiry() time.Duration
}

func GetManagerInstance

func GetManagerInstance() ServiceManager

type ServiceMeta

type ServiceMeta interface {
	GetServiceName() string
	GetServiceGroup() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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