Documentation
¶
Overview ¶
File: core/meta.go
Index ¶
- Constants
- Variables
- func APIExists(id string) bool
- func ClearAuthCookie(w http.ResponseWriter, ctx Context)
- func CronTaskDefinitionDaily() gocron.JobDefinition
- func CronTaskDefinitionOneTimeJob() gocron.JobDefinition
- func CronTaskNoArgsFactory() any
- func EchoAuthCookie(w http.ResponseWriter, r *http.Request, ctx Context)
- func GenerateSecurityToken() string
- func GetAPIs() map[string]API
- func GetPluginForService(id string) string
- func GetProtocols() map[string]Protocol
- func GetService[T Service](ctx Context, id string) T
- func IsAccountError(err error) bool
- func IsCoreService(id string) bool
- func JWTGenerateToken(domain string, privateKey ed25519.PrivateKey, userID uint, purpose JWTPurpose, ...) (string, error)
- func JWTGenerateTokenWithDuration(domain string, privateKey ed25519.PrivateKey, userID uint, ...) (string, error)
- func JWTVerifyToken(token string, domain string, privateKey ed25519.PrivateKey, ...) (*jwt.RegisteredClaims, error)
- func PluginHasAPI(plugin PluginInfo) bool
- func PluginHasCron(pi PluginInfo) bool
- func PluginHasProtocol(plugin PluginInfo) bool
- func PluginHasServices(plugin PluginInfo) bool
- func ProtocolExists(id string) bool
- func ProtocolHasDataRequestHandler(name string) bool
- func ProtocolHasPinHandler(name string) bool
- func RegisterAPI(id string, api API)
- func RegisterEvent(id string, event Eventer)
- func RegisterPlugin(info PluginInfo)
- func RegisterProtocol(id string, protocol Protocol)
- func RegisterService(service ServiceInfo, plugin ...string)
- func RegisterServicesFromPlugins()
- func RegisterUploadDataHandler(id string, handler UploadDataHandler)
- func SendJWT(w http.ResponseWriter, jwt string)
- func ServiceExists(ctx Context, id string) bool
- func SetAuthCookie(w http.ResponseWriter, ctx Context, jwt string)
- func TOTPGenerate(domain string, email string) (string, error)
- func TOTPValidate(secret string, code string) bool
- type API
- type APIInit
- type AccessModel
- type AccessModelDef
- type AccessPolicy
- type AccessService
- type AccountError
- type AccountErrorType
- type AuthService
- type ConfigPropertyUpdateHandler
- type ConfigService
- type Configurable
- type Context
- type ContextBuilderOption
- func ContextOptions(options ...ContextBuilderOption) []ContextBuilderOption
- func ContextWithCron(factory CronFactory) ContextBuilderOption
- func ContextWithDB(db *gorm.DB) ContextBuilderOption
- func ContextWithEvents(events ...Eventer) ContextBuilderOption
- func ContextWithExitFunc(f LifecycleFunc) ContextBuilderOption
- func ContextWithService(id string, svc Service) ContextBuilderOption
- func ContextWithStartupFunc(f LifecycleFunc) ContextBuilderOption
- type CronFactory
- type CronService
- type CronTaskArgs
- type CronTaskArgsFactoryFunction
- type CronTaskDefArgsFactoryFunction
- type CronTaskFunction
- type CronTaskNoArgs
- type Cronable
- type DBMigration
- type Event
- func (e *Event) Abort(abort bool)
- func (e *Event) Add(key string, val any)
- func (e *Event) AttachTo(em event.ManagerFace)
- func (e *Event) Data() map[string]any
- func (e *Event) Fill(target any, data event.M) *Event
- func (e *Event) Get(key string) any
- func (e *Event) IsAborted() bool
- func (e *Event) Name() string
- func (e *Event) Set(key string, val any)
- func (e *Event) SetData(data event.M) event.Event
- func (e *Event) SetName(name string) Eventer
- func (e *Event) SetTarget(target any) *Event
- func (e *Event) Target() any
- type Eventer
- type FileNameEncoderFunc
- type HTTPService
- type JWTPurpose
- type LifecycleFunc
- type Logger
- type MailerService
- type MailerTemplate
- type MailerTemplateData
- type MailerTemplates
- type MultipartUploadParams
- type OTPService
- type PasswordResetService
- type PinFilter
- type PinService
- type PluginFactory
- type PluginInfo
- type PortalMeta
- type PortalMetaBuilder
- type PortalMetaPlugin
- type PortalMetaPlugins
- type Protocol
- type ProtocolInit
- type ProtocolPinHandler
- type ProtocolRequestDataHandler
- type ProtocolStart
- type ProtocolStop
- type ReaderFactory
- type RenterHostFilterMode
- type RenterHostUsabilityMode
- type RenterService
- type RequestFilter
- type RequestService
- type RoutableAPI
- type Service
- type ServiceFactory
- type ServiceInfo
- type StorageHash
- type StorageProtocol
- type StorageService
- type StorageUploadOption
- func StorageUploadWithData(data io.ReadSeeker) StorageUploadOption
- func StorageUploadWithMultipartUploadParams(params *MultipartUploadParams) StorageUploadOption
- func StorageUploadWithProof(proof StorageHash) StorageUploadOption
- func StorageUploadWithProtocol(protocol StorageProtocol) StorageUploadOption
- func StorageUploadWithSize(size uint64) StorageUploadOption
- type StorageUploadRequest
- type StorageUploadStatus
- type TUSService
- type UploadDataHandler
- type UploadIDHandler
- type UploadService
- type UserService
- type VerifyTokenFunc
Constants ¶
View Source
const ( ACCESS_SERVICE = "access" ACCESS_ADMIN_ROLE = "admin" ACCESS_USER_ROLE = "user" )
View Source
const ( PROOF_EXTENSION = ".obao" S3_MULTIPART_MAX_PARTS = 9500 S3_MULTIPART_MIN_PART_SIZE = uint64(5 * units.MiB) )
View Source
const ( ExitCodeSuccess = iota ExitCodeFailedStartup ExitCodeForceQuit ExitCodeFailedQuit )
View Source
const ( STORAGE_SERVICE = "storage" TEMPORARY_UPLOADS_PATH = "uploads" )
View Source
const AUTH_COOKIE_NAME = "auth_token"
View Source
const AUTH_SERVICE = "auth"
View Source
const AUTH_TOKEN_NAME = "auth_token"
View Source
const CONFIG_SERVICE = "config"
View Source
const CRON_SERVICE = "cron"
View Source
const HTTP_SERVICE = "http"
View Source
const MAILER_SERVICE = "mailer"
View Source
const MAILER_TPL_PASSWORD_RESET = "password_reset"
View Source
const MAILER_TPL_VERIFY_EMAIL = "verify_email"
View Source
const OTP_SERVICE = "otp"
View Source
const PASSWORD_RESET_SERVICE = "password_reset"
View Source
const PIN_SERVICE = "pin"
View Source
const RENTER_SERVICE = "renter"
View Source
const REQUEST_SERVICE = "request"
View Source
const TUS_SERVICE = "tus"
View Source
const UPLOAD_SERVICE = "upload"
View Source
const USER_SERVICE = "user"
Variables ¶
View Source
var ( ErrJWTUnexpectedClaimsType = errors.New("unexpected claims type") ErrJWTUnexpectedIssuer = errors.New("unexpected issuer") ErrJWTInvalid = errors.New("invalid JWT") )
View Source
var (
ErrDuplicateRequest = errors.New("duplicate request")
)
View Source
var (
ErrInvalidModel = errors.New("model is invalid")
)
View Source
var (
ErrInvalidOTPCode = errors.New("Invalid OTP code")
)
View Source
var (
ErrProofNotSupported = errors.New("protocol does not support proofs")
)
View Source
var (
ErrUploadNotFound = errors.New("upload not found")
)
View Source
var ( ErrorCodeToHttpStatus = map[AccountErrorType]int{ ErrKeyAccountCreationFailed: http.StatusInternalServerError, ErrKeyEmailAlreadyExists: http.StatusConflict, ErrKeyPasswordHashingFailed: http.StatusInternalServerError, ErrKeyAssigningAdminRoleFailed: http.StatusInternalServerError, ErrorAssigningUserRoleFailed: http.StatusInternalServerError, ErrKeyUserNotFound: http.StatusNotFound, ErrKeyPublicKeyNotFound: http.StatusNotFound, ErrKeyAccountDeletionRequestAlreadyExists: http.StatusConflict, ErrKeyInvalidLogin: http.StatusUnauthorized, ErrKeyInvalidPassword: http.StatusUnauthorized, ErrKeyInvalidOTPCode: http.StatusBadRequest, ErrKeyOTPVerificationFailed: http.StatusBadRequest, ErrKeyLoginFailed: http.StatusInternalServerError, ErrKeyAccountPendingDeletion: http.StatusForbidden, ErrKeyAccountNotVerified: http.StatusForbidden, ErrKeyAccountUpdateFailed: http.StatusInternalServerError, ErrKeyAccountAlreadyVerified: http.StatusConflict, ErrKeyJWTGenerationFailed: http.StatusInternalServerError, ErrKeyOTPGenerationFailed: http.StatusInternalServerError, ErrKeyOTPEnableFailed: http.StatusInternalServerError, ErrKeyOTPDisableFailed: http.StatusInternalServerError, ErrKeyAddPublicKeyFailed: http.StatusInternalServerError, ErrKeyPublicKeyExists: http.StatusConflict, ErrKeyPinAddFailed: http.StatusInternalServerError, ErrKeyPinDeleteFailed: http.StatusInternalServerError, ErrKeyPinsRetrievalFailed: http.StatusInternalServerError, ErrKeyDatabaseOperationFailed: http.StatusInternalServerError, ErrKeyHashingFailed: http.StatusInternalServerError, ErrKeySecurityTokenExpired: http.StatusUnauthorized, ErrKeySecurityInvalidToken: http.StatusUnauthorized, ErrKeyAccountSubdomainNotSet: http.StatusInternalServerError, } )
Functions ¶
func ClearAuthCookie ¶
func ClearAuthCookie(w http.ResponseWriter, ctx Context)
func CronTaskDefinitionDaily ¶ added in v0.2.0
func CronTaskDefinitionDaily() gocron.JobDefinition
func CronTaskDefinitionOneTimeJob ¶
func CronTaskDefinitionOneTimeJob() gocron.JobDefinition
func CronTaskNoArgsFactory ¶
func CronTaskNoArgsFactory() any
func EchoAuthCookie ¶
func EchoAuthCookie(w http.ResponseWriter, r *http.Request, ctx Context)
func GenerateSecurityToken ¶
func GenerateSecurityToken() string
func GetPluginForService ¶
func GetProtocols ¶
func GetService ¶ added in v0.2.0
func IsAccountError ¶ added in v0.2.0
func IsCoreService ¶
func JWTGenerateToken ¶
func JWTGenerateToken(domain string, privateKey ed25519.PrivateKey, userID uint, purpose JWTPurpose, rememberMe bool) (string, error)
func JWTGenerateTokenWithDuration ¶
func JWTGenerateTokenWithDuration(domain string, privateKey ed25519.PrivateKey, userID uint, duration time.Duration, purpose JWTPurpose) (string, error)
func JWTVerifyToken ¶
func JWTVerifyToken(token string, domain string, privateKey ed25519.PrivateKey, verifyFunc VerifyTokenFunc) (*jwt.RegisteredClaims, error)
func PluginHasAPI ¶
func PluginHasAPI(plugin PluginInfo) bool
func PluginHasCron ¶ added in v0.2.0
func PluginHasCron(pi PluginInfo) bool
func PluginHasProtocol ¶
func PluginHasProtocol(plugin PluginInfo) bool
func PluginHasServices ¶
func PluginHasServices(plugin PluginInfo) bool
func ProtocolExists ¶ added in v0.2.0
func ProtocolHasDataRequestHandler ¶ added in v0.2.0
func ProtocolHasPinHandler ¶ added in v0.2.0
func RegisterAPI ¶
func RegisterEvent ¶ added in v0.1.1
func RegisterPlugin ¶
func RegisterPlugin(info PluginInfo)
func RegisterProtocol ¶
func RegisterService ¶
func RegisterService(service ServiceInfo, plugin ...string)
func RegisterServicesFromPlugins ¶
func RegisterServicesFromPlugins()
func RegisterUploadDataHandler ¶ added in v0.2.0
func RegisterUploadDataHandler(id string, handler UploadDataHandler)
func SendJWT ¶
func SendJWT(w http.ResponseWriter, jwt string)
func ServiceExists ¶ added in v0.2.0
func SetAuthCookie ¶
func SetAuthCookie(w http.ResponseWriter, ctx Context, jwt string)
func TOTPValidate ¶
Types ¶
type API ¶
type API interface { Name() string Subdomain() string Configure(router *gorilla.Router, accessSvc AccessService) error AuthTokenName() string Config() config.APIConfig }
func GetAPIList ¶
func GetAPIList() []API
type APIInit ¶
type APIInit interface {
Init() ([]ContextBuilderOption, error)
}
type AccessModel ¶ added in v0.2.0
type AccessModel struct { RequestDefinition AccessModelDef `json:"request_definition"` PolicyDefinition AccessModelDef `json:"policy_definition"` RoleDefinition AccessModelDef `json:"role_definition"` PolicyEffect AccessModelDef `json:"policy_effect"` Matchers AccessModelDef `json:"matchers"` }
type AccessModelDef ¶ added in v0.2.0
type AccessPolicy ¶ added in v0.2.0
type AccessService ¶ added in v0.2.0
type AccessService interface { // RegisterRoute adds a new route with its associated role and permissions RegisterRoute(subdomain, path, method, role string) error // RegisterRole adds a new role with its associated permissions AssignRoleToUser(userId uint, role string) error // CheckAccess checks if a given role has access to a specific route CheckAccess(userId uint, fqdn, path, method string) (bool, error) // ExportUserPolicy returns the policy for a specific user ExportUserPolicy(userId uint) ([]*AccessPolicy, error) // ExportModel returns the model for the access service ExportModel() *AccessModel Service }
AccessService interface defines the simplified methods for managing access control
type AccountError ¶
type AccountError struct { Key AccountErrorType // A unique identifier for the error type Message string // Human-readable error message Err error // Underlying error, if any }
func AsAccountError ¶ added in v0.2.0
func AsAccountError(err error) *AccountError
func NewAccountError ¶
func NewAccountError(key AccountErrorType, err error, customMessage ...string) *AccountError
func (*AccountError) Error ¶
func (e *AccountError) Error() string
func (*AccountError) HttpStatus ¶ added in v0.2.0
func (e *AccountError) HttpStatus() int
func (*AccountError) IsErrorType ¶ added in v0.2.0
func (e *AccountError) IsErrorType(key AccountErrorType) bool
type AccountErrorType ¶ added in v0.2.0
type AccountErrorType string
const ( // Account creation errors ErrKeyAccountCreationFailed AccountErrorType = "ErrAccountCreationFailed" ErrKeyEmailAlreadyExists AccountErrorType = "ErrEmailAlreadyExists" ErrKeyUpdatingSameEmail AccountErrorType = "ErrUpdatingSameEmail" ErrKeyPasswordHashingFailed AccountErrorType = "ErrPasswordHashingFailed" // Account role errors ErrKeyAssigningAdminRoleFailed AccountErrorType = "ErrAssigningAdminRoleFailed" ErrorAssigningUserRoleFailed AccountErrorType = "ErrorAssigningUserRoleFailed" // Account lookup and existence verification errors ErrKeyUserNotFound AccountErrorType = "ErrUserNotFound" ErrKeyPublicKeyNotFound AccountErrorType = "ErrPublicKeyNotFound" // Account deletion errors ErrKeyAccountDeletionRequestAlreadyExists AccountErrorType = "ErrAccountDeletionRequestAlreadyExists" // Authentication and login errors ErrKeyInvalidLogin AccountErrorType = "ErrInvalidLogin" ErrKeyInvalidPassword AccountErrorType = "ErrInvalidPassword" ErrKeyInvalidOTPCode AccountErrorType = "ErrInvalidOTPCode" ErrKeyOTPVerificationFailed AccountErrorType = "ErrOTPVerificationFailed" ErrKeyLoginFailed AccountErrorType = "ErrLoginFailed" ErrKeyHashingFailed AccountErrorType = "ErrHashingFailed" ErrKeyAccountPendingDeletion AccountErrorType = "ErrAccountPendingDeletion" ErrKeyAccountNotVerified AccountErrorType = "ErrAccountNotVerified" // Account update errors ErrKeyAccountUpdateFailed AccountErrorType = "ErrAccountUpdateFailed" ErrKeyAccountAlreadyVerified AccountErrorType = "ErrAccountAlreadyVerified" // JWT generation errors ErrKeyJWTGenerationFailed AccountErrorType = "ErrJWTGenerationFailed" // OTP management errors ErrKeyOTPGenerationFailed AccountErrorType = "ErrOTPGenerationFailed" ErrKeyOTPEnableFailed AccountErrorType = "ErrOTPEnableFailed" ErrKeyOTPDisableFailed AccountErrorType = "ErrOTPDisableFailed" // Public key management errors ErrKeyAddPublicKeyFailed AccountErrorType = "ErrAddPublicKeyFailed" ErrKeyPublicKeyExists AccountErrorType = "ErrPublicKeyExists" // Pin management errors ErrKeyPinAddFailed AccountErrorType = "ErrPinAddFailed" ErrKeyPinDeleteFailed AccountErrorType = "ErrPinDeleteFailed" ErrKeyPinsRetrievalFailed AccountErrorType = "ErrPinsRetrievalFailed" // General errors ErrKeyDatabaseOperationFailed = "ErrDatabaseOperationFailed" // Security token errors ErrKeySecurityTokenExpired AccountErrorType = "ErrSecurityTokenExpired" ErrKeySecurityInvalidToken AccountErrorType = "ErrSecurityInvalidToken" // Internal errors ErrKeyAccountSubdomainNotSet AccountErrorType = "ErrAccountSubdomainNotSet" )
type AuthService ¶
type AuthService interface { // LoginPassword authenticates a user with the provided email and password. // It returns the generated JWT token and the authenticated user if successful. LoginPassword(email string, password string, ip string, rememberMe bool) (string, *models.User, error) // LoginOTP authenticates a user with the provided user ID and OTP code. // It returns the generated JWT token if successful. LoginOTP(userId uint, code string) (string, error) // LoginPubkey authenticates a user with the provided public key. // It returns the generated JWT token if successful. LoginPubkey(pubkey string, ip string) (string, error) // LoginID authenticates a user with the provided user ID. // It returns the generated JWT token if successful. LoginID(id uint, ip string) (string, error) // ValidLoginByUserObj checks if the provided password is valid for the given user. ValidLoginByUserObj(user *models.User, password string) bool // ValidLoginByEmail checks if the provided email and password are valid. // It returns a boolean indicating success, the authenticated user, and an error if any. ValidLoginByEmail(email string, password string) (bool, *models.User, error) // ValidLoginByUserID checks if the provided user ID and password are valid. // It returns a boolean indicating success, the authenticated user, and an error if any. ValidLoginByUserID(id uint, password string) (bool, *models.User, error) Service }
type ConfigPropertyUpdateHandler ¶ added in v0.2.0
type ConfigService ¶ added in v0.2.0
type ConfigService interface {
RegisterPropertyHandler(scope config.Scope, handler ConfigPropertyUpdateHandler)
}
type Configurable ¶
type Context ¶
type Context interface { context.Context Service(id string) any OnExit(f LifecycleFunc) OnStartup(f LifecycleFunc) StartupFuncs() []func(Context) error ExitFuncs() []func(Context) error DB() *gorm.DB Logger() *Logger ProtocolLogger(protocol Protocol) *Logger APILogger(api API) *Logger ServiceLogger(service Service) *Logger NamedLogger(name string) *Logger Config() config.Manager Cancel() ExitCode() int Event() *event.Manager SetExitCode(code int) GetContext() context.Context }
Context interface
func NewContext ¶
func NewContext(config config.Manager, logger *Logger, options ...ContextBuilderOption) (Context, error)
NewContext creates a new Context
type ContextBuilderOption ¶
func ContextOptions ¶
func ContextOptions(options ...ContextBuilderOption) []ContextBuilderOption
func ContextWithCron ¶ added in v0.2.0
func ContextWithCron(factory CronFactory) ContextBuilderOption
func ContextWithDB ¶ added in v0.1.1
func ContextWithDB(db *gorm.DB) ContextBuilderOption
func ContextWithEvents ¶ added in v0.1.1
func ContextWithEvents(events ...Eventer) ContextBuilderOption
func ContextWithExitFunc ¶
func ContextWithExitFunc(f LifecycleFunc) ContextBuilderOption
func ContextWithService ¶
func ContextWithService(id string, svc Service) ContextBuilderOption
func ContextWithStartupFunc ¶
func ContextWithStartupFunc(f LifecycleFunc) ContextBuilderOption
type CronFactory ¶ added in v0.2.0
type CronService ¶
type CronService interface { RegisterEntity(entity Cronable) RegisterTask(name string, taskFunc CronTaskFunction[CronTaskArgs], taskDefFunc CronTaskDefArgsFactoryFunction, taskArgFunc CronTaskArgsFactoryFunction, recurring bool) CreateJob(function string, args any) error JobExists(function string, args any) (bool, *models.CronJob) CreateJobScheduled(function string, args any) error CreateExistingJobScheduled(uuid uuid.UUID) error CreateJobIfNotExists(function string, args any) error CreateRecurringOneOffJob(function string, args any) error Start() error Service }
type CronTaskArgs ¶ added in v0.2.0
type CronTaskArgs interface{}
type CronTaskArgsFactoryFunction ¶
type CronTaskArgsFactoryFunction func() any
type CronTaskDefArgsFactoryFunction ¶
type CronTaskDefArgsFactoryFunction func() gocron.JobDefinition
type CronTaskFunction ¶
type CronTaskFunction[T CronTaskArgs] func(T, Context) error
func CronTaskFuncHandler ¶ added in v0.2.0
func CronTaskFuncHandler[T CronTaskArgs](f func(args T, ctx Context) error) CronTaskFunction[CronTaskArgs]
type CronTaskNoArgs ¶
type CronTaskNoArgs struct{}
type Cronable ¶
type Cronable interface { RegisterTasks(cron CronService) error ScheduleJobs(cron CronService) error }
type DBMigration ¶ added in v0.2.0
type Event ¶ added in v0.1.1
type Event struct {
// contains filtered or unexported fields
}
func (*Event) AttachTo ¶ added in v0.2.0
func (e *Event) AttachTo(em event.ManagerFace)
AttachTo add current event to the event manager.
type FileNameEncoderFunc ¶
type HTTPService ¶
type JWTPurpose ¶
type JWTPurpose string
const ( JWTPurposeLogin JWTPurpose = "login" JWTPurpose2FA JWTPurpose = "2fa" JWTPurposeNone JWTPurpose = "" )
type LifecycleFunc ¶ added in v0.2.0
type Logger ¶
func (*Logger) Level ¶
func (l *Logger) Level() *zap.AtomicLevel
func (*Logger) SetLevelFromConfig ¶
func (l *Logger) SetLevelFromConfig()
type MailerService ¶
type MailerService interface { TemplateSend(template string, subjectVars MailerTemplateData, bodyVars MailerTemplateData, to string) error TemplateRegister(name string, template MailerTemplate) error Service }
type MailerTemplate ¶ added in v0.2.0
type MailerTemplateData ¶
type MailerTemplates ¶ added in v0.2.0
type MailerTemplates map[string]MailerTemplate
type MultipartUploadParams ¶ added in v0.2.0
type MultipartUploadParams struct { ReaderFactory ReaderFactory Bucket string FileName string Size uint64 }
type OTPService ¶
type OTPService interface { // OTPGenerate generates a new OTP secret for the given user ID. // It returns the OTP secret and an error if any. OTPGenerate(userId uint) (string, error) // OTPVerify verifies the provided OTP code for the given user ID. // It returns a boolean indicating whether the code is valid, and an error if any. OTPVerify(userId uint, code string) (bool, error) // OTPEnable enables OTP for the given user ID after verifying the provided code. // It returns an error if any. OTPEnable(userId uint, code string) error // OTPDisable disables OTP for the given user ID. // It returns an error if any. OTPDisable(userId uint) error Service }
type PasswordResetService ¶
type PasswordResetService interface { // SendPasswordReset sends a password reset email to the given user. SendPasswordReset(user *models.User) error // ResetPassword resets the password for the given email, using the provided token and new password. ResetPassword(email string, token string, password string) error Service }
type PinService ¶
type PinService interface { // AccountPins retrieves the list of pins (uploads) for the given user ID, // created after the specified timestamp. AccountPins(id uint, createdAfter uint64) ([]*models.Pin, error) // AllAccountPins retrieves all pins (uploads) for the given user ID. AllAccountPins(id uint) ([]*models.Pin, error) // DeletePinByHash deletes the pin associated with the given hash and user ID. DeletePinByHash(hash StorageHash, userId uint) error // PinByHash creates a new pin for the given hash and user ID if it doesn't exist. PinByHash(hash StorageHash, userId uint, protocolData any) error // PinByID creates a new pin for the given upload ID and user ID if it doesn't exist. PinByID(uploadId uint, userId uint, protocolData any) error // UploadPinnedGlobal checks if the upload with the given hash is pinned globally. UploadPinnedGlobal(hash StorageHash) (bool, error) // UploadPinnedByUser checks if the upload with the given hash is pinned by the specified user. UploadPinnedByUser(hash StorageHash, userId uint) (bool, error) // GetPinsByUploadID retrieves the list of pins for the given upload ID. GetPinsByUploadID(ctx context.Context, uploadID uint) ([]*models.Pin, error) // CreatePin creates a new pin or returns an existing one. CreatePin(ctx context.Context, pin *models.Pin, protocolData any) (*models.Pin, error) // UpdatePin updates a pin. UpdatePin(ctx context.Context, pin *models.Pin) error // GetPin retrieves a pin by ID. GetPin(ctx context.Context, id uint) (*models.Pin, error) // DeletePin deletes a pin by ID. DeletePin(ctx context.Context, id uint) error // QueryPin queries for a pin based on the provided query and filter. QueryPin(ctx context.Context, query interface{}, filter PinFilter) (*models.Pin, error) // UpdateProtocolPin updates the protocol-specific data for a pin. UpdateProtocolPin(ctx context.Context, id uint, protocolData any) error // GetProtocolPin retrieves the protocol-specific data for a pin. GetProtocolPin(ctx context.Context, id uint) (any, error) //QueryProtocolData queries for protocol-specific data based on the provided query and filter. QueryProtocolPin(ctx context.Context, protocol string, query any, filter PinFilter) (any, error) Service }
type PluginFactory ¶
type PluginFactory func() PluginInfo
type PluginInfo ¶
type PluginInfo struct { ID string Version build.BuildInfo Meta func(Context, PortalMetaBuilder) error API func() (API, []ContextBuilderOption, error) Protocol func() (Protocol, []ContextBuilderOption, error) Services func() ([]ServiceInfo, error) Models []any Migrations []DBMigration Events []Eventer Depends []string Cron func() CronFactory MailerTemplates MailerTemplates }
func GetPlugin ¶
func GetPlugin(name string) PluginInfo
func GetPlugins ¶
func GetPlugins() []PluginInfo
func (PluginInfo) String ¶
func (pi PluginInfo) String() string
type PortalMeta ¶ added in v0.2.0
type PortalMeta struct { Domain string `json:"domain"` Plugins PortalMetaPlugins `json:"plugins"` FeatureFlags map[string]bool `json:"feature_flags"` Build build.Info `json:"build"` // Core build info }
PortalMeta represents the portal metadata
type PortalMetaBuilder ¶ added in v0.2.0
type PortalMetaBuilder interface { // Core functionality AddFeatureFlag(key string, value bool) PortalMetaBuilder // Plugin management AddPlugin(key string) PortalMetaBuilder AddPluginWithBuild(key string, buildInfo build.Info) PortalMetaBuilder AddPluginMeta(pluginKey string, metaKey string, metaValue any) PortalMetaBuilder Build() *PortalMeta }
PortalMetaBuilder interface for building portal metadata
type PortalMetaPlugin ¶ added in v0.2.0
type PortalMetaPlugins ¶ added in v0.2.0
type PortalMetaPlugins = map[string]PortalMetaPlugin
type Protocol ¶
type Protocol interface { Name() string Config() config.ProtocolConfig }
func GetProtocol ¶
func GetProtocolList ¶
func GetProtocolList() []Protocol
type ProtocolInit ¶
type ProtocolPinHandler ¶ added in v0.2.0
type ProtocolPinHandler interface { CreateProtocolPin(ctx context.Context, id uint, data any) error GetProtocolPin(ctx context.Context, tx *gorm.DB, id uint) (any, error) UpdateProtocolPin(ctx context.Context, id uint, data any) error DeleteProtocolPin(ctx context.Context, id uint) error QueryProtocolPin(ctx context.Context, query any) *gorm.DB GetProtocolPinModel() any }
func GetProtocolPinHandler ¶ added in v0.2.0
func GetProtocolPinHandler(name string) ProtocolPinHandler
type ProtocolRequestDataHandler ¶ added in v0.2.0
type ProtocolRequestDataHandler interface { CreateProtocolData(ctx context.Context, id uint, data any) error GetProtocolData(ctx context.Context, tx *gorm.DB, id uint) (any, error) UpdateProtocolData(ctx context.Context, id uint, data any) error DeleteProtocolData(ctx context.Context, id uint) error QueryProtocolData(ctx context.Context, tx *gorm.DB, query any) *gorm.DB CompleteProtocolData(ctx context.Context, id uint) error GetProtocolDataModel() any }
func GetProtocolDataRequestHandler ¶ added in v0.2.0
func GetProtocolDataRequestHandler(name string) ProtocolRequestDataHandler
type ProtocolStart ¶
type ProtocolStop ¶
type ReaderFactory ¶
type ReaderFactory func(start uint, end uint) (io.ReadCloser, error)
type RenterHostFilterMode ¶ added in v0.3.0
type RenterHostFilterMode string
const ( RenterHostFilterModeAll RenterHostFilterMode = "all" RenterHostFilterModeAllowed RenterHostFilterMode = "allowed" RenterHostFilterModeBlocked RenterHostFilterMode = "blocked" )
type RenterHostUsabilityMode ¶ added in v0.3.0
type RenterHostUsabilityMode string
const ( RenterHostUsabilityModeAll RenterHostUsabilityMode = "all" RenterHostUsabilityModeUsable RenterHostUsabilityMode = "usable" RenterHostUsabilityModeUnusable RenterHostUsabilityMode = "unusable" )
type RenterService ¶
type RenterService interface { CreateBucketIfNotExists(bucket string) error UploadObject(ctx context.Context, file io.Reader, bucket string, fileName string) error ImportObjectMetadata(ctx context.Context, bucket string, fileName string, object_ object.Object) error GetObject(ctx context.Context, bucket string, fileName string, options api.DownloadObjectOptions) (*api.GetObjectResponse, error) GetObjectMetadata(ctx context.Context, bucket string, fileName string) (*api.Object, error) DeleteObjectMetadata(ctx context.Context, bucket string, fileName string) error GetSetting(ctx context.Context, setting string, out any) error UploadExists(ctx context.Context, bucket string, fileName string) (bool, *models.SiaUpload, error) UploadObjectMultipart(ctx context.Context, params *MultipartUploadParams) error DeleteObject(ctx context.Context, bucket string, fileName string) error UpdateGougingSettings(ctx context.Context, settings api.GougingSettings) error GougingSettings(ctx context.Context) (api.GougingSettings, error) RedundancySettings(ctx context.Context) (api.RedundancySettings, error) AutopilotConfig(_ context.Context) (api.AutopilotConfig, error) AutopilotState(_ context.Context) (api.AutopilotStateResponse, error) TestAutoPilotConfig(ctx context.Context, gs api.GougingSettings) (api.ConfigEvaluationResponse, error) TriggerAutoPilot(_ context.Context) (bool, error) AddHostsToAllowlist(ctx context.Context, hosts []types.PublicKey) error GetAllowlistedHosts(ctx context.Context) ([]types.PublicKey, error) SlabSize(ctx context.Context) (uint64, error) ScanHost(ctx context.Context, host types.PublicKey, hostIP string) (api.RHPScanResponse, error) Hosts(ctx context.Context, usabilityMode RenterHostUsabilityMode, filterMode RenterHostFilterMode) ([]api.Host, error) Host(ctx context.Context, host types.PublicKey) (api.Host, error) AutopilotHosts(ctx context.Context, usabilityMode RenterHostUsabilityMode, filterMode RenterHostFilterMode) ([]api.HostResponse, error) ConsensusState(ctx context.Context) (api.ConsensusState, error) RecommendedFee(ctx context.Context) (types.Currency, error) Service }
type RequestFilter ¶ added in v0.2.0
type RequestService ¶ added in v0.2.0
type RequestService interface { // Core CRUD operations CreateRequest(ctx context.Context, req *models.Request, protocolData any, uploadData any) (*models.Request, error) GetRequest(ctx context.Context, id uint) (*models.Request, error) UpdateRequest(ctx context.Context, req *models.Request) error DeleteRequest(ctx context.Context, id uint) error QueryRequest(ctx context.Context, query any, filter RequestFilter) (*models.Request, error) CompleteRequest(ctx context.Context, id uint) error // Query operations GetRequestByHash(ctx context.Context, hash StorageHash, filter RequestFilter) (*models.Request, error) GetRequestByUploadHash(ctx context.Context, hash StorageHash, filter RequestFilter) (*models.Request, error) ListRequestsByUser(ctx context.Context, userID uint, filter RequestFilter) ([]*models.Request, error) ListRequestsByStatus(ctx context.Context, status string, filter RequestFilter) ([]*models.Request, error) // Status operations UpdateRequestStatus(ctx context.Context, id uint, status models.RequestStatusType) error // Protocol data operations UpdateProtocolData(ctx context.Context, id uint, data any) error GetProtocolData(ctx context.Context, id uint) (any, error) QueryProtocolData(ctx context.Context, protocol string, query any, filter RequestFilter) (any, error) // Upload data operations UpdateUploadData(ctx context.Context, id uint, data any) error GetUploadData(ctx context.Context, id uint) (any, error) DeleteUploadData(ctx context.Context, id uint) error QueryUploadData(ctx context.Context, uploadMethod models.RequestOperationType, query any, filter RequestFilter) (any, error) CompleteUploadData(ctx context.Context, id uint) error // Utility operations RequestExists(ctx context.Context, id uint) (bool, error) Service }
type RoutableAPI ¶
type RoutableAPI interface { Can(w http.ResponseWriter, r *http.Request) bool Handle(w http.ResponseWriter, r *http.Request) }
type ServiceFactory ¶
type ServiceFactory func() (Service, []ContextBuilderOption, error)
type ServiceInfo ¶
type ServiceInfo struct { ID string Factory ServiceFactory Depends []string }
func GetServiceInfo ¶
func GetServiceInfo(id string) *ServiceInfo
func GetServices ¶
func GetServices() []ServiceInfo
type StorageHash ¶ added in v0.2.0
type StorageProtocol ¶
type StorageProtocol interface { Name() string EncodeFileName(StorageHash) string Hash(r io.Reader, size uint64) (StorageHash, error) }
type StorageService ¶
type StorageService interface { UploadObject(ctx context.Context, request StorageUploadRequest) (*models.Upload, error) UploadObjectProof(ctx context.Context, protocol StorageProtocol, data io.ReadSeeker, proof StorageHash, size uint64) error DownloadObject(ctx context.Context, protocol StorageProtocol, objectHash StorageHash, start int64) (io.ReadCloser, error) DownloadObjectProof(ctx context.Context, protocol StorageProtocol, objectHash StorageHash) (io.ReadCloser, error) DeleteObject(ctx context.Context, protocol StorageProtocol, objectHash StorageHash) error DeleteObjectProof(ctx context.Context, protocol StorageProtocol, objectHash StorageHash) error S3Client(ctx context.Context) (*s3.Client, error) S3MultipartUpload(ctx context.Context, data io.ReadCloser, bucket, key string, size uint64) error S3TemporaryUpload(ctx context.Context, data io.ReadCloser, size uint64, protocol StorageProtocol) (string, error) S3GetTemporaryUpload(ctx context.Context, protocol StorageProtocol, uploadId string) (io.ReadCloser, error) S3DeleteTemporaryUpload(ctx context.Context, protocol StorageProtocol, uploadId string) error UploadStatus(ctx context.Context, protocol StorageProtocol, objectName string) (StorageUploadStatus, *time.Time, error) Service }
type StorageUploadOption ¶ added in v0.2.0
type StorageUploadOption func(StorageUploadRequest)
StorageUploadOption defines a function to configure StorageUploadRequest
func StorageUploadWithData ¶ added in v0.2.0
func StorageUploadWithData(data io.ReadSeeker) StorageUploadOption
WithData sets the data for the upload request
func StorageUploadWithMultipartUploadParams ¶ added in v0.2.0
func StorageUploadWithMultipartUploadParams(params *MultipartUploadParams) StorageUploadOption
WithMultipartUploadParams sets the multipart upload parameters for the upload request
func StorageUploadWithProof ¶ added in v0.2.0
func StorageUploadWithProof(proof StorageHash) StorageUploadOption
WithProof sets the proof for the upload request
func StorageUploadWithProtocol ¶ added in v0.2.0
func StorageUploadWithProtocol(protocol StorageProtocol) StorageUploadOption
WithProtocol sets the protocol for the upload request
func StorageUploadWithSize ¶ added in v0.2.0
func StorageUploadWithSize(size uint64) StorageUploadOption
WithSize sets the size for the upload request
type StorageUploadRequest ¶ added in v0.2.0
type StorageUploadRequest interface { Protocol() StorageProtocol SetProtocol(StorageProtocol) Data() io.ReadSeeker SetData(io.ReadSeeker) Size() uint64 SetSize(uint64) MuParams() *MultipartUploadParams SetMuParams(*MultipartUploadParams) Hash() StorageHash SetHash(StorageHash) }
type StorageUploadStatus ¶
type StorageUploadStatus string
const ( StorageUploadStatusUnknown StorageUploadStatus = "unknown" StorageUploadStatusProcessing StorageUploadStatus = "processing" StorageUploadStatusActive StorageUploadStatus = "completed" )
type TUSService ¶ added in v0.2.0
type TUSService interface { UploadExists(ctx context.Context, id string) (bool, *models.TUSRequest) UploadHashExists(ctx context.Context, hash StorageHash) (bool, *models.TUSRequest) Uploads(ctx context.Context, uploaderID uint) ([]*models.TUSRequest, error) CreateUpload(ctx context.Context, hash StorageHash, uploadID string, uploaderID uint, uploaderIP string, protocol StorageProtocol, mimeType string) (*models.TUSRequest, error) UploadProgress(ctx context.Context, uploadID string) error UploadProcessing(ctx context.Context, uploadID string) error UploadCompleted(ctx context.Context, uploadID string) error DeleteUpload(ctx context.Context, uploadID string) error SetHash(ctx context.Context, uploadID string, hash StorageHash) error Service }
type UploadDataHandler ¶ added in v0.2.0
type UploadDataHandler interface { CreateUploadData(ctx context.Context, tx *gorm.DB, id uint, data any) error GetUploadData(ctx context.Context, tx *gorm.DB, id uint) (any, error) UpdateUploadData(ctx context.Context, tx *gorm.DB, id uint, data any) error DeleteUploadData(ctx context.Context, tx *gorm.DB, id uint) error QueryUploadData(ctx context.Context, tx *gorm.DB, query any) *gorm.DB CompleteUploadData(ctx context.Context, tx *gorm.DB, id uint) error GetUploadDataModel() any }
func GetUploadDataHandler ¶ added in v0.2.0
func GetUploadDataHandler(id string) (UploadDataHandler, bool)
type UploadIDHandler ¶
type UploadIDHandler func(uploadID string)
type UploadService ¶ added in v0.2.0
type UploadService interface { SaveUpload(ctx context.Context, upload *models.Upload) error GetUpload(ctx context.Context, objectHash StorageHash) (*models.Upload, error) DeleteUpload(ctx context.Context, objectHash StorageHash) error GetAllUploads(ctx context.Context) ([]*models.Upload, error) GetUploadByID(ctx context.Context, uploadID uint) (*models.Upload, error) Service }
type UserService ¶
type UserService interface { // Exists checks if a record with the given conditions exists. Exists(model any, conditions map[string]any) (bool, any, error) // EmailExists checks if an email already exists in the system. EmailExists(email string) (bool, *models.User, error) // PubkeyExists checks if a public key already exists in the system. PubkeyExists(pubkey string) (bool, *models.PublicKey, error) // AccountExists checks if an account with the given ID exists. AccountExists(id uint) (bool, *models.User, error) // HashPassword hashes the provided password using bcrypt. HashPassword(password string) (string, error) // CreateAccount creates a new user account with the given email and password. CreateAccount(email string, password string, verifyEmail bool) (*models.User, error) // UpdateAccountInfo updates the account information of the user with the given ID. UpdateAccountInfo(userId uint, info map[string]any) error // UpdateAccountName updates the first and last name of the user with the given ID. UpdateAccountName(userId uint, firstName string, lastName string) error // UpdateAccountEmail updates the email of the user with the given ID after verifying the password. UpdateAccountEmail(userId uint, email string, password string) error // UpdateAccountPassword updates the password of the user with the given ID after verifying the old password. UpdateAccountPassword(userId uint, password string, newPassword string) error // AddPubkeyToAccount adds a public key to the account of the user with the given ID. AddPubkeyToAccount(user models.User, pubkey string) error // SendEmailVerification sends an email verification email to the user with the given ID. // It returns an error if any. SendEmailVerification(userId uint) error // VerifyEmail verifies the email for the given email address and token. // It returns an error if any. VerifyEmail(email string, token string) error // IsAccountVerified checks if the email of the user with the given ID is verified. IsAccountVerified(userId uint) (bool, error) // DeleteAccount deletes the account of the user with the given ID. DeleteAccount(userId uint) error // RequestAccountDeletion requests the deletion of the account of the user with the given ID. RequestAccountDeletion(userId uint, userIP string) error // IsAccountPendingDeletion checks if the account deletion is pending for the user with the given ID. IsAccountPendingDeletion(userId uint) (bool, error) // GetAccountsPendingDeletion returns a list of accounts that are pending deletion. GetAccountsPendingDeletion() ([]*models.User, error) Service }
type VerifyTokenFunc ¶
type VerifyTokenFunc func(claim *jwt.RegisteredClaims) error
Source Files
¶
Click to show internal directories.
Click to hide internal directories.