Documentation
¶
Index ¶
- Constants
- Variables
- type AuthService
- func (a *AuthService) GenerateToken(ctx context.Context, publicKey string) (string, error)
- func (a *AuthService) GenerateTokenPair(ctx context.Context, publicKey string) (*TokenPair, error)
- func (a *AuthService) GetActiveTokens(ctx context.Context, publicKey string) ([]types.VaultToken, error)
- func (a *AuthService) RefreshToken(ctx context.Context, refreshTokenStr string) (*TokenPair, error)
- func (a *AuthService) RevokeAllTokens(ctx context.Context, publicKey string) error
- func (a *AuthService) RevokeToken(ctx context.Context, vaultKey, tokenID string) error
- func (a *AuthService) ValidateToken(ctx context.Context, tokenStr string) (*Claims, error)
- type Claims
- type FeeService
- func (s *FeeService) GetUserFees(ctx context.Context, publicKey string) (*vtypes.UserFeeStatus, error)
- func (s *FeeService) IssueCredit(ctx context.Context, publicKey string, amount uint64, reason string) error
- func (s *FeeService) MarkFeesCollected(ctx context.Context, feeIDs []uint64, network, txHash string, amount uint64) error
- func (s *FeeService) PublicKeyGetFeeInfo(ctx context.Context, publicKey string) ([]*vtypes.Fee, error)
- type Fees
- type Plugin
- type PluginService
- func (s *PluginService) CreatePluginReviewWithRating(ctx context.Context, reviewDto types.ReviewCreateDto, pluginId string) (*types.ReviewDto, error)
- func (s *PluginService) GetPluginRecipeFunctions(ctx context.Context, pluginID string) (types.RecipeFunctions, error)
- func (s *PluginService) GetPluginRecipeSpecification(ctx context.Context, pluginID string) (*rtypes.RecipeSchema, error)
- func (s *PluginService) GetPluginRecipeSpecificationSuggest(ctx context.Context, pluginID string, configuration map[string]any) (*rtypes.PolicySuggest, error)
- func (s *PluginService) GetPluginSkills(ctx context.Context, pluginID string) (*PluginSkills, error)
- func (s *PluginService) GetPluginTitlesByIDs(ctx context.Context, ids []string) (map[string]string, error)
- func (s *PluginService) GetPluginWithRating(ctx context.Context, pluginId string) (*types.PluginWithRatings, error)
- type PluginServiceStorage
- type PluginSkills
- type Policy
- type PolicyService
- func (s *PolicyService) CreatePolicy(ctx context.Context, policy types.PluginPolicy) (*types.PluginPolicy, error)
- func (s *PolicyService) DeleteAllPolicies(ctx context.Context, pluginID types.PluginID, publicKey string) error
- func (s *PolicyService) DeletePolicy(ctx context.Context, policyID uuid.UUID, pluginID types.PluginID, ...) error
- func (s *PolicyService) GetPluginInstallationsCount(ctx context.Context, pluginID types.PluginID) (itypes.PluginTotalCount, error)
- func (s *PolicyService) GetPluginPolicies(ctx context.Context, publicKey string, pluginID types.PluginID, take int, ...) (*itypes.PluginPolicyPaginatedList, error)
- func (s *PolicyService) GetPluginPolicy(ctx context.Context, policyID uuid.UUID) (*types.PluginPolicy, error)
- func (s *PolicyService) HandlePolicyDeactivate(ctx context.Context, task *asynq.Task) error
- func (s *PolicyService) HandleScheduledFees(ctx context.Context, task *asynq.Task) error
- func (s *PolicyService) UpdatePolicy(ctx context.Context, policy types.PluginPolicy) (*types.PluginPolicy, error)
- type ReportService
- type ReportServiceStorage
- type SafetySyncer
- type TokenPair
Constants ¶
const ( TokenTypeAccess = "access" TokenTypeRefresh = "refresh" )
const QUERY_GET_EXPIRED_SUBSCRIPTIONS = `` /* 508-byte string literal not displayed */
Variables ¶
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
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 ¶
GenerateToken creates a new JWT token and stores it in the database Deprecated: Use GenerateTokenPair instead
func (*AuthService) GenerateTokenPair ¶ added in v0.1.19
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 ¶
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 ¶
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 (*FeeService) PublicKeyGetFeeInfo ¶
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 (*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
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 (*PolicyService) DeletePolicy ¶
func (*PolicyService) GetPluginInstallationsCount ¶
func (s *PolicyService) GetPluginInstallationsCount(ctx context.Context, pluginID types.PluginID) (itypes.PluginTotalCount, error)
func (*PolicyService) GetPluginPolicies ¶
func (*PolicyService) GetPluginPolicy ¶
func (s *PolicyService) GetPluginPolicy(ctx context.Context, policyID uuid.UUID) (*types.PluginPolicy, error)
func (*PolicyService) HandlePolicyDeactivate ¶ added in v0.1.16
HandlePolicyDeactivate handles deferred policy deactivation tasks. The task payload contains the policy ID as a raw string.
func (*PolicyService) HandleScheduledFees ¶
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
}