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
- Variables
- func CheckPassword(password, encodedHash, salt, signingKey string) (bool, error)
- func CheckResourceAuthorization(ctx context.Context, storeInstance store.Store, args ResourceArgs) error
- func CheckServiceAuthorization[T ServiceMeta](ctx context.Context, storeInstance store.Store, s T, ...) error
- func CreateAuthToken(subject string, permissions store.AccessList) (string, time.Time, error)
- func Decode[T any](r *http.Request) (T, error)
- func Encode[T any](w http.ResponseWriter, _ *http.Request, status int, v T) error
- func Error(w http.ResponseWriter, r *http.Request, err error, op Operation) error
- func GetIdentity(ctx context.Context) (string, error)
- func InitCredentials(ctx context.Context, config *Config, tx dbexec.Exec) error
- func LoadConfig[T any](cfg *T) error
- func NewPasswordHash(password, signingKey string) (encodedHash, encodedSalt string, err error)
- func NewServiceManager(config *Config) error
- func RefreshPlainToken(ctx context.Context, token string, withGracePeriod *time.Duration) (string, bool, time.Time, error)
- func RefreshToken(ctx context.Context) (string, bool, time.Time, error)
- func ValidateConfig(cfg *Config) error
- type Config
- type ConfigTokenizerService
- type Event
- type Operation
- type RateLimiter
- type ResourceArgs
- type ServiceManager
- type ServiceMeta
Constants ¶
const ( DefaultServerGroup = "server" DefaultDefaultServiceGroup = "admin_panel" )
const ( TasksPoolID = "internal_tasks_pool" TasksPoolName = "Tasks" TenantID = "6ba7b810-9dad-11d1-80b4-00c04fd430c8" )
Variables ¶
var ( ErrEncodeInvalidJSON = errors.New("serverops: encoding failing, invalid json") ErrDecodeInvalidJSON = errors.New("serverops: decoding failing, invalid json") ErrDecodeInvalidYAML = errors.New("serverops: decoding failing, invalid yaml") ErrDecodeBase64 = errors.New("serverops: decoding failing, invalid base64 data") ErrUnsupportedContentType = errors.New("serverops: unsupported content type for decoding") ErrReadingRequestBody = errors.New("serverops: failed to read request body") ErrMalformedContentType = errors.New("serverops: malformed Content-Type header") )
var ( ErrInvalidParameterValue = errors.New("serverops: invalid parameter value type") ErrBadPathValue = errors.New("serverops: bad path value") ErrImmutableModel = errors.New("serverops: immutable model") ErrImmutablePool = errors.New("serverops: immutable pool") ErrMissingParameter = errors.New("serverops: missing parameter") )
var CoreVersion = "CORE-UNSET-dev"
var DefaultAdminUser string = "admin@admin.com"
var ErrFileEmpty = errors.New("serverops: file cannot be empty")
ErrFileEmpty indicates an attempt to upload an empty file.
var ErrFileSizeLimitExceeded = errors.New("serverops: file size limit exceeded")
ErrFileSizeLimitExceeded indicates the specific file exceeded its allowed size limit.
var ErrInvalidChain = errors.New("invalid chain definition")
Functions ¶
func CheckPassword ¶
func CheckResourceAuthorization ¶
func CheckResourceAuthorization(ctx context.Context, storeInstance store.Store, args ResourceArgs) error
CheckResourceAuthorization checks if the user has the required permission for a given resource.
func CheckServiceAuthorization ¶
func CheckServiceAuthorization[T ServiceMeta](ctx context.Context, storeInstance store.Store, s T, permission store.Permission) error
func CreateAuthToken ¶
func GetIdentity ¶
GetIdentity extracts the identity from the context using the JWT secret from the ServiceManager.
func InitCredentials ¶
func LoadConfig ¶
func NewPasswordHash ¶
func NewServiceManager ¶
NewServiceManager creates a new instance of server.
func RefreshPlainToken ¶
func ValidateConfig ¶
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 `json:"tokenizer_service_url"`
VectorStoreURL string `json:"vector_store_url"`
WorkerUserAccountID string `json:"worker_user_account_id"`
WorkerUserPassword string `json:"worker_user_password"`
WorkerUserEmail string `json:"worker_user_email"`
KVBackend string `json:"kv_backend"`
KVHost string `json:"kv_host"`
KVPassword string `json:"kv_password"`
RuntimeBaseUrl string `json:"runtime_base_url"`
// RateLimit string `json:"rate_limit"`
// RateWindow string `json:"rate_window"`
DownstreamToken string `json:"downstream_token"`
GatewayURL string `json:"gateway_url"`
}
type ConfigTokenizerService ¶
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
func NewRateLimiter ¶
func NewRateLimiter(kv libkv.KVManager) *RateLimiter
func (*RateLimiter) Allow ¶
func (r *RateLimiter) Allow(ctx context.Context, key string, limit int, window time.Duration) (bool, error)
Allow checks whether a request should be allowed based on approximate rate limiting. This implementation tracks recent events and approximates a sliding window. Under high concurrency, with multiple nodes it may allow more than `limit` requests. This implementation is lock-free.
type ResourceArgs ¶
type ResourceArgs struct {
ResourceType string
Resource string
RequiredPermission store.Permission
}
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