service

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenTypeAccess  = "access"
	TokenTypeRefresh = "refresh"
)
View Source
const QUERY_GET_EXPIRED_SUBSCRIPTIONS = `` /* 508-byte string literal not displayed */

Variables

View Source
var (
	ErrTokenNotFound = errors.New("token not found")
	ErrNotOwner      = errors.New("unauthorized token revocation")
	ErrBeginTx       = errors.New("failed to begin transaction")
	ErrGetToken      = errors.New("failed to get token")
	ErrRevokeToken   = errors.New("failed to revoke token")
	ErrCommitTx      = errors.New("failed to commit transaction")
)

Token-related errors

View Source
var (
	ErrNotEligible    = errors.New("not eligible to report: no installation found")
	ErrCooldownActive = errors.New("cooldown active")
)

Functions

This section is empty.

Types

type AuthService

type AuthService struct {
	JWTSecret []byte
	// contains filtered or unexported fields
}

func NewAuthService

func NewAuthService(secret string, db storage.DatabaseStorage, logger *logrus.Logger) *AuthService

NewAuthService creates a new authentication service

func (*AuthService) GenerateToken

func (a *AuthService) GenerateToken(ctx context.Context, publicKey string) (string, error)

GenerateToken creates a new JWT token and stores it in the database Deprecated: Use GenerateTokenPair instead

func (*AuthService) GenerateTokenPair added in v0.1.19

func (a *AuthService) GenerateTokenPair(ctx context.Context, publicKey string) (*TokenPair, error)

GenerateTokenPair creates both access and refresh tokens

func (*AuthService) GetActiveTokens

func (a *AuthService) GetActiveTokens(ctx context.Context, publicKey string) ([]types.VaultToken, error)

GetActiveTokens returns all active tokens for a public key

func (*AuthService) RefreshToken

func (a *AuthService) RefreshToken(ctx context.Context, refreshTokenStr string) (*TokenPair, error)

RefreshToken validates refresh token and issues new access token

func (*AuthService) RevokeAllTokens

func (a *AuthService) RevokeAllTokens(ctx context.Context, publicKey string) error

RevokeAllTokens revokes all tokens for a specific public key

func (*AuthService) RevokeToken

func (a *AuthService) RevokeToken(ctx context.Context, vaultKey, tokenID string) error

RevokeToken revokes a specific token

func (*AuthService) ValidateToken

func (a *AuthService) ValidateToken(ctx context.Context, tokenStr string) (*Claims, error)

ValidateToken validates a JWT token and checks its revocation status

type Claims

type Claims struct {
	jwt.RegisteredClaims
	PublicKey string `json:"public_key"`
	TokenID   string `json:"token_id"`
	TokenType string `json:"token_type"`
}

type FeeService

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

func NewFeeService

func NewFeeService(db storage.DatabaseStorage,
	client *asynq.Client, logger *logrus.Logger, feeConfig config.FeesConfig) (*FeeService, error)

func (*FeeService) GetUserFees

func (s *FeeService) GetUserFees(ctx context.Context, publicKey string) (*vtypes.UserFeeStatus, error)

func (*FeeService) IssueCredit

func (s *FeeService) IssueCredit(ctx context.Context, publicKey string, amount uint64, reason string) error

IssueCredit for promo, bonuses, etc.

func (*FeeService) MarkFeesCollected

func (s *FeeService) MarkFeesCollected(ctx context.Context, feeIDs []uint64, network, txHash string, amount uint64) error

func (*FeeService) PublicKeyGetFeeInfo

func (s *FeeService) PublicKeyGetFeeInfo(ctx context.Context, publicKey string) ([]*vtypes.Fee, error)

type Fees

type Fees interface {
	PublicKeyGetFeeInfo(ctx context.Context, publicKey string) ([]*vtypes.Fee, error)
	MarkFeesCollected(ctx context.Context, feeIDs []uint64, network, txHash string, amount uint64) error
	IssueCredit(ctx context.Context, publicKey string, amount uint64, reason string) error
	GetUserFees(ctx context.Context, publicKey string) (*vtypes.UserFeeStatus, error)
}

type Plugin

type Plugin interface {
	GetPluginWithRating(ctx context.Context, pluginId string) (*types.PluginWithRatings, error)
	CreatePluginReviewWithRating(ctx context.Context, reviewDto types.ReviewCreateDto, pluginId string) (*types.ReviewDto, error)
	GetPluginRecipeSpecification(ctx context.Context, pluginID string) (*rtypes.RecipeSchema, error)
	GetPluginRecipeSpecificationSuggest(
		ctx context.Context,
		pluginID string,
		configuration map[string]any,
	) (*rtypes.PolicySuggest, error)
	GetPluginRecipeFunctions(ctx context.Context, pluginID string) (types.RecipeFunctions, error)
	GetPluginTitlesByIDs(ctx context.Context, ids []string) (map[string]string, error)
	GetPluginSkills(ctx context.Context, pluginID string) (*PluginSkills, error)
}

type PluginService

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

func NewPluginService

func NewPluginService(db PluginServiceStorage, redis *storage.RedisStorage, logger *logrus.Logger) (*PluginService, error)

func (*PluginService) CreatePluginReviewWithRating

func (s *PluginService) CreatePluginReviewWithRating(ctx context.Context, reviewDto types.ReviewCreateDto, pluginId string) (*types.ReviewDto, error)

func (*PluginService) GetPluginRecipeFunctions

func (s *PluginService) GetPluginRecipeFunctions(ctx context.Context, pluginID string) (types.RecipeFunctions, error)

GetPluginRecipeFunctions fetches recipe functions from plugin server with caching

func (*PluginService) GetPluginRecipeSpecification

func (s *PluginService) GetPluginRecipeSpecification(ctx context.Context, pluginID string) (*rtypes.RecipeSchema, error)

GetPluginRecipeSpecification fetches recipe specification from plugin server with caching

func (*PluginService) GetPluginRecipeSpecificationSuggest

func (s *PluginService) GetPluginRecipeSpecificationSuggest(
	ctx context.Context,
	pluginID string,
	configuration map[string]any,
) (*rtypes.PolicySuggest, error)

GetPluginRecipeSpecificationSuggest fetches recipe suggest from plugin server with caching

func (*PluginService) GetPluginSkills added in v0.1.20

func (s *PluginService) GetPluginSkills(ctx context.Context, pluginID string) (*PluginSkills, error)

GetPluginSkills fetches skills from plugin server with caching

func (*PluginService) GetPluginTitlesByIDs added in v0.1.16

func (s *PluginService) GetPluginTitlesByIDs(ctx context.Context, ids []string) (map[string]string, error)

func (*PluginService) GetPluginWithRating

func (s *PluginService) GetPluginWithRating(ctx context.Context, pluginId string) (*types.PluginWithRatings, error)

type PluginServiceStorage

type PluginServiceStorage interface {
	WithTransaction(ctx context.Context, fn func(ctx context.Context, tx pgx.Tx) error) error

	FindRatingByPluginId(ctx context.Context, dbTx pgx.Tx, pluginId string) ([]types.PluginRatingDto, error)
	FindAvgRatingByPluginID(ctx context.Context, pluginId string) (types.PluginAvgRatingDto, error)
	CreateRatingForPlugin(ctx context.Context, dbTx pgx.Tx, pluginId string) error
	UpdateRatingForPlugin(ctx context.Context, dbTx pgx.Tx, pluginId string, reviewRating int) error
	ChangeRatingForPlugin(ctx context.Context, dbTx pgx.Tx, pluginId string, oldRating int, newRating int) error

	CreateReview(ctx context.Context, dbTx pgx.Tx, reviewDto types.ReviewCreateDto, pluginId string) (string, error)
	UpdateReview(ctx context.Context, dbTx pgx.Tx, reviewId string, reviewDto types.ReviewCreateDto) error
	FindReviews(ctx context.Context, pluginId string, take int, skip int, sort string) (types.ReviewsDto, error)
	FindReviewById(ctx context.Context, db pgx.Tx, id string) (*types.ReviewDto, error)
	FindReviewByUserAndPlugin(ctx context.Context, dbTx pgx.Tx, pluginId string, userAddress string) (*types.ReviewDto, error)

	FindPluginById(ctx context.Context, dbTx pgx.Tx, id ptypes.PluginID) (*types.Plugin, error)
	GetAPIKeyByPluginId(ctx context.Context, pluginId string) (*types.APIKey, error)
	GetPluginTitlesByIDs(ctx context.Context, ids []string) (map[string]string, error)
}

type PluginSkills added in v0.1.20

type PluginSkills struct {
	PluginID string `json:"plugin_id"`
	SkillsMD string `json:"skills_md"`
}

PluginSkills represents the skills returned from a plugin's /skills endpoint.

type Policy

type Policy interface {
	CreatePolicy(ctx context.Context, policy types.PluginPolicy) (*types.PluginPolicy, error)
	UpdatePolicy(ctx context.Context, policy types.PluginPolicy) (*types.PluginPolicy, error)
	DeletePolicy(ctx context.Context, policyID uuid.UUID, pluginID types.PluginID, signature string) error
	GetPluginPolicies(ctx context.Context, publicKey string, pluginID types.PluginID, take int, skip int, activeFilter *bool) (*itypes.PluginPolicyPaginatedList, error)
	GetPluginPolicy(ctx context.Context, policyID uuid.UUID) (*types.PluginPolicy, error)
	GetPluginInstallationsCount(ctx context.Context, pluginID types.PluginID) (itypes.PluginTotalCount, error)
	DeleteAllPolicies(ctx context.Context, pluginID types.PluginID, publicKey string) error
}

type PolicyService

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

func NewPolicyService

func NewPolicyService(db storage.DatabaseStorage, syncer *syncer.Syncer) (*PolicyService, error)

func (*PolicyService) CreatePolicy

func (s *PolicyService) CreatePolicy(ctx context.Context, policy types.PluginPolicy) (*types.PluginPolicy, error)

func (*PolicyService) DeleteAllPolicies

func (s *PolicyService) DeleteAllPolicies(ctx context.Context, pluginID types.PluginID, publicKey string) error

func (*PolicyService) DeletePolicy

func (s *PolicyService) DeletePolicy(ctx context.Context, policyID uuid.UUID, pluginID types.PluginID, signature string) error

func (*PolicyService) GetPluginInstallationsCount

func (s *PolicyService) GetPluginInstallationsCount(ctx context.Context, pluginID types.PluginID) (itypes.PluginTotalCount, error)

func (*PolicyService) GetPluginPolicies

func (s *PolicyService) GetPluginPolicies(ctx context.Context, publicKey string, pluginID types.PluginID, take int, skip int, activeFilter *bool) (*itypes.PluginPolicyPaginatedList, error)

func (*PolicyService) GetPluginPolicy

func (s *PolicyService) GetPluginPolicy(ctx context.Context, policyID uuid.UUID) (*types.PluginPolicy, error)

func (*PolicyService) HandlePolicyDeactivate added in v0.1.16

func (s *PolicyService) HandlePolicyDeactivate(ctx context.Context, task *asynq.Task) error

HandlePolicyDeactivate handles deferred policy deactivation tasks. The task payload contains the policy ID as a raw string.

func (*PolicyService) HandleScheduledFees

func (s *PolicyService) HandleScheduledFees(ctx context.Context, task *asynq.Task) error

func (*PolicyService) UpdatePolicy

func (s *PolicyService) UpdatePolicy(ctx context.Context, policy types.PluginPolicy) (*types.PluginPolicy, error)

type ReportService added in v0.1.16

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

func NewReportService added in v0.1.16

func NewReportService(db ReportServiceStorage, syncer SafetySyncer, logger *logrus.Logger) (*ReportService, error)

func (*ReportService) SubmitReport added in v0.1.16

func (s *ReportService) SubmitReport(ctx context.Context, pluginID types.PluginID, publicKey, reason, details string) (*itypes.ReportSubmitResult, error)

type ReportServiceStorage added in v0.1.16

type ReportServiceStorage interface {
	UpsertReport(ctx context.Context, pluginID types.PluginID, publicKey, reason, details string, cooldown time.Duration) error
	GetReport(ctx context.Context, pluginID types.PluginID, publicKey string) (*itypes.PluginReport, error)
	CountReportsInWindow(ctx context.Context, pluginID types.PluginID, window time.Duration) (int, error)
	HasInstallation(ctx context.Context, pluginID types.PluginID, publicKey string) (bool, error)
	CountInstallations(ctx context.Context, pluginID types.PluginID) (int, error)
	IsPluginPaused(ctx context.Context, pluginID types.PluginID) (bool, error)
	PausePlugin(ctx context.Context, pluginID types.PluginID, record itypes.PauseHistoryRecord) error
}

type SafetySyncer added in v0.1.16

type SafetySyncer interface {
	SyncSafetyToPlugin(ctx context.Context, pluginID types.PluginID, flags []psafety.ControlFlag) error
}

type TokenPair added in v0.1.19

type TokenPair struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int    `json:"expires_in"`
}

Jump to

Keyboard shortcuts

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