Documentation ¶
Overview ¶
Set of commands that can be run from command line.
Various database (gorm) helpers ¶
Features ¶
gopypi provides optional features that can be enabled/disabled directly from administration
List of features:
* auto_maintainers - automatically assign maintainers from package emails (users must exist in database) * download_stats - enable download statistics for downloads
filter provides set of FilterFunc functions.
Filter maintains various filters from http forms (get/post)
Managers is set of manager structs that provide querying methods ¶
parser package handles parsing of submitted packages.
Various string helpers ¶
tasks is set of background tasks
timeutil is set of functions to work with time.Time such as: alignment, stripping of time values etc..
Index ¶
- Constants
- Variables
- func ApplyFilterFuncs(db *gorm.DB, funcs ...FilterFunc) *gorm.DB
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func Atoui(value string, def ...uint) uint
- func BasicAuthLoginRequired(cfg Config, bypassAuth func(r *http.Request) bool, ...) alice.Constructor
- func Bind(r *http.Request, target interface{}) (err error)
- func BindFilter(r *http.Request, filter Filter) (err error)
- func CommonMiddleware(cfg Config, router *mux.Router) alice.Constructor
- func ContextSetTokenUser(ctx context.Context, user User) (result context.Context)
- func CountQueryset(db *gorm.DB, p paginator.Paginator) *gorm.DB
- func CreateToken(db *gorm.DB, user User, secret string, expiration int) (result string, err error)
- func Exit(why interface{}, code ...int)
- func GenerateSalt(length int) (result []byte)
- func GetPostAction(r *http.Request) (result int, err error)
- func GetRequestToken(r *http.Request) (result string, err error)
- func InitRouter(config Config) (chain alice.Chain, err error)
- func IsEnabledOption(option []bool) bool
- func LimitQueryset(db *gorm.DB, p paginator.Paginator) *gorm.DB
- func MD5(input string) string
- func Migrate(config Config) (err error)
- func MigrateAction(c *cli.Context) (err error)
- func MustAsset(name string) []byte
- func NewConfGen() *confgen
- func NormalizePackageName(name string) string
- func PostEndpointCheckMiddleware(cfg Config) alice.Constructor
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- func RunserverAction(c *cli.Context) (err error)
- func StringListContains(where []string, what string) bool
- func StringMinMaxValidator(min int, max int) func(field string, value *string, vr ValidationResult) bool
- func StringParseBool(value string) (result *bool)
- func TerminalGetBoolValue(question string, def bool) (result bool)
- func TerminalGetIntValue(question string, def int) (result int)
- func TerminalGetPasswordValue(question string) (result string)
- func TerminalGetStringValue(question string, defs ...string) (result string)
- func TerminalGetStringValueChoices(question string, choices []string, defs ...string) (result string)
- func TimeAlignMonth(t time.Time) time.Time
- func TimeAlignWeek(t time.Time) time.Time
- func TimeAlignYear(t time.Time) time.Time
- func TimeStripTime(t time.Time) time.Time
- func TokenAuthLoginRequired(cfg Config, permissions ...func(User) error) alice.Constructor
- func ValidateEmail(field string, value *string, vr ValidationResult, required ...bool) bool
- func ValidateUsername(field string, value *string, vr ValidationResult) bool
- type ChangePasswordCommand
- type Classifier
- type ClassifierManager
- type Command
- type Config
- type CoreConfig
- type CreateAdminCommand
- type DownloadStats
- type DownloadStatsConfig
- type DownloadStatsManager
- func (s *DownloadStatsManager) AddDownload(version *PackageVersion) (err error)
- func (d *DownloadStatsManager) AddDownloadFile(versionfile *PackageVersionFile) (err error)
- func (d *DownloadStatsManager) Cleanup()
- func (d *DownloadStatsManager) GetAllStats(target map[string][]StatsDownloadItem, filter ...FilterFunc) (err error)
- func (d *DownloadStatsManager) GetCount(target interface{}) (err error)
- func (d *DownloadStatsManager) GetStats(aggregation StatsAggregation, target *[]StatsDownloadItem, ...) *gorm.DB
- type DownloadStatsMonthly
- type DownloadStatsWeekly
- type DownloadStatsYearly
- type FallbackFileSystem
- type Feature
- type FeatureAPIViewSet
- type FeatureManager
- type FeatureSerializer
- type Filter
- type FilterFunc
- func FFDownloadStatsPackage(pack *Package) FilterFunc
- func FFDownloadStatsPackageVersion(pv *PackageVersion) FilterFunc
- func FFID(id interface{}) FilterFunc
- func FFOrderBy(order string) FilterFunc
- func FFPackagesFor(user User) FilterFunc
- func FFPreload(preloads ...string) FilterFunc
- func FFUsername(username string) FilterFunc
- func FFWhere(query interface{}, args ...interface{}) FilterFunc
- type InfoAPIView
- type License
- type LicenseAPIViewSet
- func (l *LicenseAPIViewSet) List(w http.ResponseWriter, r *http.Request) response.Response
- func (l *LicenseAPIViewSet) MetadataList(w http.ResponseWriter, r *http.Request) response.Response
- func (l *LicenseAPIViewSet) Retrieve(w http.ResponseWriter, r *http.Request) response.Response
- func (l *LicenseAPIViewSet) Update(w http.ResponseWriter, r *http.Request) response.Response
- type LicenseManager
- type LicenseUpdateSerializer
- type LoginAPIView
- type LoginSerializer
- type Manager
- type ManagerConfig
- type MeAPIView
- type MeChangePasswordAPIView
- type MyPackageAPIView
- type Package
- type PackageAPIViewSet
- type PackageDetailView
- type PackageDownloadView
- type PackageListView
- type PackageMaintainerAPIViewSet
- func (p *PackageMaintainerAPIViewSet) Delete(w http.ResponseWriter, r *http.Request) response.Response
- func (p *PackageMaintainerAPIViewSet) GetPackage(r *http.Request) (result Package, err error)
- func (p *PackageMaintainerAPIViewSet) List(w http.ResponseWriter, r *http.Request) response.Response
- func (p *PackageMaintainerAPIViewSet) Update(w http.ResponseWriter, r *http.Request) response.Response
- type PackageManager
- type PackageVersion
- type PackageVersionFile
- type PackageVersionFileManager
- type PackageVersionManager
- type PackageVersionPathInfo
- type PackagesConfig
- type Platform
- type PlatformAPIViewSet
- type PlatformManager
- type PostPackageView
- type SearchResult
- type SearchService
- type Server
- type Stats
- type StatsAPIView
- type StatsAggregation
- type StatsDownloadAllAPIView
- type StatsDownloadItem
- type StatsDownloadPackageAPIView
- type StatsDownloadPackageVersionAPIView
- type Task
- type TemplateView
- type TokenClaims
- type User
- type UserAPIViewSet
- func (u *UserAPIViewSet) Create(w http.ResponseWriter, r *http.Request) response.Response
- func (u *UserAPIViewSet) List(w http.ResponseWriter, r *http.Request) response.Response
- func (u *UserAPIViewSet) Retrieve(w http.ResponseWriter, r *http.Request)
- func (u *UserAPIViewSet) Update(w http.ResponseWriter, r *http.Request) response.Response
- type UserAddSerializer
- type UserChangePasswordSerializer
- type UserListFilter
- type UserManager
- type UserProfileSerializer
- type UserUpdateSerializer
- type ValidationError
- type ValidationResult
Constants ¶
const ( FEATURE_AUTO_MAINTAINERS = "auto_maintainers" FEATURE_DOWNLOAD_STATS = "download_stats" )
const ( DESCRIPTION_FEATURE_AUTO_MAINTAINERS = "Automatically assign maintainers on uploading package" DESCRIPTION_FEATURE_DOWNLOAD_STATS = "Store download statistics of packages" )
const ( VERSION = "0.5.3" LOGO = ` o _<|>_ o__ __o/ o__ __o \o_ __o o o \o_ __o o /v | /v v\ | v\ <|> <|> | v\ <|> /> / \ /> <\ / \ <\ < > < > / \ <\ / \ \ \o/ \ / \o/ / \o o/ \o/ / \o/ o | o o | o v\ /v | o | <\__ < > <\__ __/> / \ __/> <\/> / \ __/> / \ | \o/ / \o/ o__ o | o | <\__ __/> / \ __/> / \ v ` + VERSION )
const ( TOKEN_HEADER_NAME = "Authorization" TOKEN_ISSUER = "gopypi" TOKEN_EXPIRATION = 24 * 3600 )
token related constants
const ( CONTEXT_TOKEN_USER = iota + 1000 CONTEXT_ROUTE_NAME )
Context constants
const ( POST_PACKAGE_ACTION_VERIFY = iota + 1 POST_PACKAGE_ACTION_SUBMIT POST_PACKAGE_ACTION_DOC_UPLOAD POST_PACKAGE_ACTION_REMOVE_PKG POST_PACKAGE_ACTION_FILE_UPLOAD // find out how this works POST_PACKAGE_ACTION_USER POST_PACKAGE_ACTION_PASSWORD_RESET )
WHen setup.py calls gopypi it can define following actions
const ( PASSWORD_SALT_BYTES = 32 PASSWORD_HASH_BYTES = 128 PASSWORD_ITERATIONS = 16384 )
constants for pasword hashing
const ( PASSWORD_MIN_LENGTH = 5 PASSWORD_MAX_LENGTH = 20 USERNAME_MIN_LENGTH = 5 USERNAME_MAX_LENGTH = 20 )
Model related constants
const (
CONFGEN_SECRET_KEY_LENGTH = 64
)
confgen constants
const CONF_TEMPLATE = `` /* 215-byte string literal not displayed */
template used for confgen
Variables ¶
var ( // Config ErrUnknownDBDriver = errors.New("Unknown database driver") // Auth ErrInvalidAuthHeader = errors.New("Invalid authorization header") ErrLoginUsername = errors.New("invalid username") ErrLoginPassword = errors.New("invalid password") ErrTokenExpired = errors.New("token expired") ErrTokenInvalid = errors.New("invalid token") ErrTokenUserInvalid = errors.New("invalid user in token") // Model errors ErrUsernameAlreadyExists = errors.New("user with this username already exists") ErrPasswordsMustMatch = errors.New("passwords must match") ErrInvalidEmail = errors.New("invalid email address") ErrEmailAlreadyExists = errors.New("user with this email already exists") ErrLicenseNotFound = errors.New("license not found") ErrPlatformNotFound = errors.New("license not found") ErrPackageNotFound = errors.New("package not found") // http errors ErrUserCannotRetrievePackages = errors.New("user cannot retrieve packages") ErrUserCannotDownloadPackages = errors.New("user cannot download packages") // Post package errors ErrPostPackageInvalidAction = errors.New("action not recognized") ErrPostPackageInvalidName = errors.New("invalid name") ErrPostPackageInvalidVersion = errors.New("invalid version") // generic error for all methods that return single object ErrObjectNotFound = errors.New("object not found") )
var ( AVAILABLE_DB_DRIVERS = []string{"postgres", "mysql"} DEFAULT_DB_DRIVER = "postgres" )
var (
CliApp *cli.App
)
var (
// Prepare common paginator for all api
CommonPaginator = paginator.NewFactory(
paginator.PerPage(20, 30),
)
)
var DoNotBypass = func(r *http.Request) bool { return false }
DoNotBypass is function that doesn't bypasses basic auth
var ( // when package is posted following actions can apply POST_PACKAGE_ACTIONS = map[string]int{ "verify": POST_PACKAGE_ACTION_VERIFY, "submit": POST_PACKAGE_ACTION_SUBMIT, "doc_upload": POST_PACKAGE_ACTION_DOC_UPLOAD, "remove_pkg": POST_PACKAGE_ACTION_REMOVE_PKG, "file_upload": POST_PACKAGE_ACTION_FILE_UPLOAD, "user": POST_PACKAGE_ACTION_USER, "password_reset": POST_PACKAGE_ACTION_PASSWORD_RESET, } )
var ( // ValidatePassword validate password ValidatePassword = StringMinMaxValidator(PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH) )
Functions ¶
func ApplyFilterFuncs ¶
func ApplyFilterFuncs(db *gorm.DB, funcs ...FilterFunc) *gorm.DB
ApplyFilterFuncs applies all FilterFuncs and returns db
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetInfo ¶
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func Atoui ¶
Atoui parses string and converts to uint, if error occures either 0 is returned or given default value (optional)
func BasicAuthLoginRequired ¶
func BasicAuthLoginRequired(cfg Config, bypassAuth func(r *http.Request) bool, permfuncs ...func(User) error) alice.Constructor
LoginRequired checks if username provided correct auth
bypassAuth is function that when returns true, auth is bypassed (!WARNING!)
func BindFilter ¶
BindFilter binds filter to given url values
func CommonMiddleware ¶
func CommonMiddleware(cfg Config, router *mux.Router) alice.Constructor
func ContextSetTokenUser ¶
Return token claims from request context
func CountQueryset ¶
CountQueryset performs count query and sets paginator count
func CreateToken ¶
CreateToken creates auth token
func GenerateSalt ¶
GenerateSalt generates salt for hashing passwords
func GetPostAction ¶
Return action from form
func GetRequestToken ¶
GetRequestToken returns token from request
func InitRouter ¶
GetRouter instantiates router with all its registered routes
func IsEnabledOption ¶
IsEnabledOption returns whether last varargs option is enabled
func LimitQueryset ¶
LimitQueryset sets limits to queryset and returns it
func MigrateAction ¶
func MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func NormalizePackageName ¶
NormalizePackageName normalizes package name by PEP 503
func PostEndpointCheckMiddleware ¶
func PostEndpointCheckMiddleware(cfg Config) alice.Constructor
PostEndpointCheckMiddleware custom middleware just for post package
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively
func RunserverAction ¶
func StringListContains ¶
StringListContains returns whether string is in stringlist
func StringMinMaxValidator ¶
func StringMinMaxValidator(min int, max int) func(field string, value *string, vr ValidationResult) bool
StringMinMaxValidator returns validator for length
func StringParseBool ¶
StringParseBool returns boolean value by given string value
func TerminalGetBoolValue ¶
func TerminalGetIntValue ¶
GetTermIntValue waits for user input for number
func TerminalGetPasswordValue ¶
TerminalGetPasswordValue return password
func TerminalGetStringValue ¶
GetTermValue calls user input.
func TimeAlignMonth ¶
TimeAlignWeek aligns date to first day of month and strips time and timezone
func TimeAlignWeek ¶
TimeAlignWeek aligns date to first day of week and strips time and timezone
func TimeAlignYear ¶
TimeAlignWeek aligns date to first day of year and strips time and timezone
func TimeStripTime ¶
TimeStripTime strips time part from time
func TokenAuthLoginRequired ¶
func TokenAuthLoginRequired(cfg Config, permissions ...func(User) error) alice.Constructor
TokenAuthLoginRequired is token auth verification. It reads `gopypi-token`from headers
func ValidateEmail ¶
func ValidateEmail(field string, value *string, vr ValidationResult, required ...bool) bool
ValidateEmail validates whether the value is valid email. Also it supports optional argument required.
func ValidateUsername ¶
func ValidateUsername(field string, value *string, vr ValidationResult) bool
ValidateUsername validates username and adds error if available
Types ¶
type ChangePasswordCommand ¶
type ChangePasswordCommand struct {
Config Config
}
ChangePasswordCommand command line command to change password
type Classifier ¶
type Classifier struct { ID uint `gorm:"primary_key" json:"id"` Approved bool `json:"approved"` Name string `gorm:"unique_index" json:"name"` }
Classifier model
We store just values for now, later we can do some sort of tree
type ClassifierManager ¶
ClassifierManager database manager
func (*ClassifierManager) ListOrCreate ¶
func (c *ClassifierManager) ListOrCreate(result *[]Classifier, cd []string) (err error)
ListOrCreate returns list of classifiers from given string list
func (*ClassifierManager) NormalizeName ¶
func (c *ClassifierManager) NormalizeName(name string) string
NormalizeName normalizes classifier name
type Command ¶
type Command interface { // Run runs command Run() error }
Command interface that all commands use
type Config ¶
type Config interface { // Core returns CoreConfig Core() CoreConfig // getter for database connection DB() *gorm.DB // logger instance Logger() zap.Logger // validates configuration Validate() error // parse html template ParseTemplate(name, filename string) (*gbht.Template, error) // parse multiple templates ParseTemplateFiles(name string, filenames ...string) (*gbht.Template, error) // render template with given data RenderTemplate(data interface{}, name, filename string) (string, error) // render templates with given data RenderTemplateFiles(data interface{}, name string, filenames ...string) (string, error) // return router Router() *mux.Router // DownloadStats return config for download stats DownloadStats() DownloadStatsConfig // packages returns configuration for packages Packages() PackagesConfig // Manager returns interface that supplies multiple db managers Manager(tx ...*gorm.DB) ManagerConfig }
Config interface
func NewConfigFromFilename ¶
NewConfigFromFilename returns configuration from filename
type CoreConfig ¶
type CreateAdminCommand ¶
type CreateAdminCommand struct {
Config Config
}
CreateAdminCommand creates new admin in database
func (*CreateAdminCommand) Run ¶
func (c *CreateAdminCommand) Run() error
Run is method that runs the command
type DownloadStats ¶
type DownloadStats struct { ID uint `gorm:"primary_key" json:"-"` PackageVersion *PackageVersion `gorm:"ForeignKey:PackageVersionID" json:"version,omitempty"` PackageVersionID uint `json:"-"` Downloads int `json:"downloads"` CreatedAt time.Time `json:"created_at"` }
DownloadStats is common structure for all of them
CreatedAt is aligned on every struct that embeds DownloadStats with given aggregation level. This assures that records are groupped correctly and no need to do grouping no database level.
type DownloadStatsConfig ¶
type DownloadStatsManager ¶
DownloadStatsManager database manager for all download stats
func (*DownloadStatsManager) AddDownload ¶
func (s *DownloadStatsManager) AddDownload(version *PackageVersion) (err error)
AddDownload adds download for given package version
func (*DownloadStatsManager) AddDownloadFile ¶
func (d *DownloadStatsManager) AddDownloadFile(versionfile *PackageVersionFile) (err error)
AddDownloadFile adds download by PackageVersionFile
func (*DownloadStatsManager) Cleanup ¶
func (d *DownloadStatsManager) Cleanup()
Cleanup deletes weekly and monthly stats from database, yearly stats will stay forever
func (*DownloadStatsManager) GetAllStats ¶
func (d *DownloadStatsManager) GetAllStats(target map[string][]StatsDownloadItem, filter ...FilterFunc) (err error)
Returns all download stats
func (*DownloadStatsManager) GetCount ¶
func (d *DownloadStatsManager) GetCount(target interface{}) (err error)
GetSum returns count of all downloads
func (*DownloadStatsManager) GetStats ¶
func (d *DownloadStatsManager) GetStats(aggregation StatsAggregation, target *[]StatsDownloadItem, filter ...FilterFunc) *gorm.DB
type DownloadStatsMonthly ¶
type DownloadStatsMonthly struct {
DownloadStats
}
DownloadStatsMonthly represents download stats aggregated by month
func (*DownloadStatsMonthly) BeforeCreate ¶
func (s *DownloadStatsMonthly) BeforeCreate() error
BeforeSave aligns CreatedAt correctly
type DownloadStatsWeekly ¶
type DownloadStatsWeekly struct {
DownloadStats
}
DownloadStatsWeekly represents download stats aggregated by week
func (*DownloadStatsWeekly) BeforeCreate ¶
func (s *DownloadStatsWeekly) BeforeCreate() error
BeforeSave aligns CreatedAt correctly
type DownloadStatsYearly ¶
type DownloadStatsYearly struct {
DownloadStats
}
DownloadStatsYearly represents download stats aggregated by year
func (*DownloadStatsYearly) BeforeCreate ¶
func (s *DownloadStatsYearly) BeforeCreate() error
BeforeSave aligns CreatedAt correctly
type FallbackFileSystem ¶
type FallbackFileSystem struct {
// contains filtered or unexported fields
}
FallbackFileSystem wraps http Filesystem which checks if requested file is not found, it falls back to given default. This is useful for SPA with html5 mode so it opens any url in index.html
type Feature ¶
type Feature struct { ID string `gorm:"primary_key" json:"id"` Description string `json:"description"` Value bool `json:"value"` }
Feature is model for enabling/disabling gopypi features
type FeatureAPIViewSet ¶
type FeatureAPIViewSet struct { classy.SlugViewSet // config instance to access managers, etc.. Config Config }
FeatureAPIViewSet provides rest endpoints for features
func (*FeatureAPIViewSet) List ¶
func (f *FeatureAPIViewSet) List(w http.ResponseWriter, r *http.Request) response.Response
List returns list of all features
func (*FeatureAPIViewSet) Retrieve ¶
func (f *FeatureAPIViewSet) Retrieve(w http.ResponseWriter, r *http.Request) response.Response
Retrieve retrieves single feature from database
func (*FeatureAPIViewSet) Update ¶
func (f *FeatureAPIViewSet) Update(w http.ResponseWriter, r *http.Request) response.Response
Update updates given feature (just value)
type FeatureManager ¶
type FeatureManager struct {
*Manager
}
FeatureManager database manager for model Feature
func (*FeatureManager) IsEnabledFeature ¶
func (f *FeatureManager) IsEnabledFeature(feature string) (result bool, err error)
IsEnabledFeature returns whether given feature is available
type FeatureSerializer ¶
type FeatureSerializer struct {
Value bool `json:"value"`
}
FeatureSerializer enables/disables feature
type Filter ¶
Filter is interface to filter database querysets
func NewUserListFilter ¶
NewUserListFilter returns new UserListFilter
type FilterFunc ¶
FilterFunc is callback which is called in some methods (Get, List)
func FFDownloadStatsPackage ¶
func FFDownloadStatsPackage(pack *Package) FilterFunc
FFDownloadStatsPackage filters stats by package
func FFDownloadStatsPackageVersion ¶
func FFDownloadStatsPackageVersion(pv *PackageVersion) FilterFunc
FFDownloadStatsPackage filters stats by package
func FFPackagesFor ¶
func FFPackagesFor(user User) FilterFunc
FFPackagesFor filters packages by given user, user is either author or maintainer
func FFUsername ¶
func FFUsername(username string) FilterFunc
FilterUsername filters user by username
func FFWhere ¶
func FFWhere(query interface{}, args ...interface{}) FilterFunc
FFWhere is shorthand for gorm Where
type InfoAPIView ¶
type InfoAPIView struct { classy.GenericView // store config instance Config Config }
InfoAPIView serves GET request and returns information about gopypi server
func (*InfoAPIView) GET ¶
func (i *InfoAPIView) GET(w http.ResponseWriter, r *http.Request) response.Response
GET method returns information about gopypi such as version, features, system info
type License ¶
type License struct { ID uint `gorm:"primary_key" json:"id"` Approved bool `json:"approved"` Code string `json:"code"` Content string `json:"content"` Name string `json:"name"` }
License model
Holds informations about available licenses.
type LicenseAPIViewSet ¶
type LicenseAPIViewSet struct { classy.ViewSet // configuration Config Config }
LicenseAPIViewSet provides rest apis for handling of license model
func (*LicenseAPIViewSet) List ¶
func (l *LicenseAPIViewSet) List(w http.ResponseWriter, r *http.Request) response.Response
List all licenses
func (*LicenseAPIViewSet) MetadataList ¶
func (l *LicenseAPIViewSet) MetadataList(w http.ResponseWriter, r *http.Request) response.Response
Metadata for list endpoints
func (*LicenseAPIViewSet) Retrieve ¶
func (l *LicenseAPIViewSet) Retrieve(w http.ResponseWriter, r *http.Request) response.Response
Retrieve single license from database
func (*LicenseAPIViewSet) Update ¶
func (l *LicenseAPIViewSet) Update(w http.ResponseWriter, r *http.Request) response.Response
Update updates license with serializer data
type LicenseManager ¶
LicenseManager database manager
type LicenseUpdateSerializer ¶
type LicenseUpdateSerializer struct { ID uint `json:"-"` Approved bool `json:"approved"` Name string `json:"name"` Content string `json:"content"` }
LicenseUpdateSerializer handles license update
func (*LicenseUpdateSerializer) UpdateLicense ¶
func (l *LicenseUpdateSerializer) UpdateLicense(license *License)
Update license with data form serializer
func (*LicenseUpdateSerializer) Validate ¶
func (l *LicenseUpdateSerializer) Validate(cfg Config, ID int) (result ValidationResult)
Validate runs validation on serializer fields
type LoginAPIView ¶
type LoginAPIView struct { classy.GenericView Config Config }
LoginAPIView servers single POST method
func (*LoginAPIView) POST ¶
func (l *LoginAPIView) POST(w http.ResponseWriter, r *http.Request) response.Response
POST checks for username and password in JSON format and returns appropriate json response. If succeeds, Authorization header is added with correct token
type LoginSerializer ¶
LoginSerializer is login form for json
func (*LoginSerializer) Validate ¶
func (l *LoginSerializer) Validate() (err error)
type Manager ¶
Generic manager
Should have following methods:
* List * Get
type ManagerConfig ¶
type ManagerConfig interface { // ClassifierManager returns new ClassifierManager instance Classifier(tx ...*gorm.DB) *ClassifierManager // DownloadStatsManager returns new DownloadStatsManager instance DownloadStats(tx ...*gorm.DB) *DownloadStatsManager // FeatureManager Feature(tx ...*gorm.DB) *FeatureManager // LicenseManager returns new LicenseManager instance License(tx ...*gorm.DB) *LicenseManager // PackageManager returns new PackageManager instance Package(tx ...*gorm.DB) *PackageManager // PackageVersionManager returns new PackageVersionManager instance PackageVersion(tx ...*gorm.DB) *PackageVersionManager // PackageVersionFileManager PackageVersionFile(tx ...*gorm.DB) *PackageVersionFileManager // PlatformManager returns new PlatformManager instance Platform(tx ...*gorm.DB) *PlatformManager // UserManager returns UserManager instance to query user data User(tx ...*gorm.DB) *UserManager }
type MeAPIView ¶
type MeAPIView struct { classy.GenericView // store config Config Config }
MeAPIView gives information about currently logged in user
GET method returns information about user from token POST method updates information
type MeChangePasswordAPIView ¶
type MeChangePasswordAPIView struct { classy.GenericView // store config Config Config }
MeChangePasswordAPIView provides api to change password for currently logged user
func (*MeChangePasswordAPIView) POST ¶
func (m *MeChangePasswordAPIView) POST(w http.ResponseWriter, r *http.Request) response.Response
POST method updates password for currently logged user
type MyPackageAPIView ¶
type MyPackageAPIView struct { classy.ListView // store config Config Config }
MyPackageAPIView gives information about packages for currently logged in user
func (*MyPackageAPIView) List ¶
func (m *MyPackageAPIView) List(w http.ResponseWriter, r *http.Request) response.Response
List returns list of packages for given logged user. User must be either author or maintainer of packege to be returned in list.
type Package ¶
type Package struct { ID uint `gorm:"primary_key" json:"id"` Name string `json:"name"` Versions []PackageVersion `gorm:"ForeignKey:PackageID" json:"versions,omitempty"` Maintainers []User `gorm:"many2many:package_maintainers;" json:"maintainers,omitempty"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` Author *User `gorm:"ForeignKey:AuthorID" json:"author,omitempty"` AuthorID uint `json:"-"` }
Package model.
func GetPostedPackage ¶
GetPackage parses request form and returns package
type PackageAPIViewSet ¶
type PackageAPIViewSet struct { classy.ViewSet // store config Config Config }
PackageAPIViewSet provides following methods
List - list packages Retrieve - retrieve single package
func (*PackageAPIViewSet) List ¶
func (p *PackageAPIViewSet) List(w http.ResponseWriter, r *http.Request) response.Response
List retrieves list of packages
func (*PackageAPIViewSet) Retrieve ¶
func (p *PackageAPIViewSet) Retrieve(w http.ResponseWriter, r *http.Request) response.Response
Retrieve returns single package
type PackageDetailView ¶
type PackageDetailView struct { classy.SlugDetailView // config instance Config Config }
PackageDetailView returns detail of package
func (*PackageDetailView) Retrieve ¶
func (p *PackageDetailView) Retrieve(w http.ResponseWriter, r *http.Request) response.Response
Retrieve is GET method
type PackageDownloadView ¶
type PackageDownloadView struct { classy.BaseView Config Config }
PackageDownloadView serves download
func (*PackageDownloadView) Download ¶
func (p *PackageDownloadView) Download(w http.ResponseWriter, r *http.Request) response.Response
Download returns content of requested file.
Aside of that, when download_stats feature is enabled, stats will be recorded to database.
func (*PackageDownloadView) Routes ¶
func (p *PackageDownloadView) Routes() (result map[string]classy.Mapping)
Routes returns list of routes with predefined method maps
type PackageListView ¶
type PackageListView struct { classy.ListView // config instance Config Config }
PackageListView returns list of packages
func (*PackageListView) List ¶
func (p *PackageListView) List(rw http.ResponseWriter, r *http.Request) response.Response
List (http GET) returns list of all packages
if `format` url query is set to json, json response will be returned
type PackageMaintainerAPIViewSet ¶
type PackageMaintainerAPIViewSet struct { classy.ViewSet // config instance Config Config }
PackageMaintainerAPIViewSet provides rest endpoints for maintainers of given package
func (*PackageMaintainerAPIViewSet) Delete ¶
func (p *PackageMaintainerAPIViewSet) Delete(w http.ResponseWriter, r *http.Request) response.Response
Delete removes association of maintainer to given package
func (*PackageMaintainerAPIViewSet) GetPackage ¶
func (p *PackageMaintainerAPIViewSet) GetPackage(r *http.Request) (result Package, err error)
GetPackage returns package from request
func (*PackageMaintainerAPIViewSet) List ¶
func (p *PackageMaintainerAPIViewSet) List(w http.ResponseWriter, r *http.Request) response.Response
List method lists all maintainers for given package
func (*PackageMaintainerAPIViewSet) Update ¶
func (p *PackageMaintainerAPIViewSet) Update(w http.ResponseWriter, r *http.Request) response.Response
Update association means that when it's not present, it's created, Update method doesn't handle request body.
type PackageManager ¶
PackageManager database manager
func (*PackageManager) Get ¶
func (p *PackageManager) Get(pack *Package, filter ...FilterFunc) *gorm.DB
Get calls Where method from given pack with preloads
func (*PackageManager) IsMaintainer ¶
func (p *PackageManager) IsMaintainer(pack *Package, user *User) bool
check if user is maintainer
func (*PackageManager) List ¶
func (p *PackageManager) List(packages *[]Package, filter ...FilterFunc) *gorm.DB
Get calls Where method from given pack with preloads
func (*PackageManager) UpdateVersionOrder ¶
func (p *PackageManager) UpdateVersionOrder(pack Package) (err error)
UpdateVersionOrder updates order for all versions
type PackageVersion ¶
type PackageVersion struct { ID uint `gorm:"primary_key" json:"id"` PackageID uint `json:"-"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` Author *User `gorm:"ForeignKey:AuthorID" json:"author,omitempty"` AuthorID uint `json:"-"` Comment string `json:"comment"` Description string `json:"description"` Summary string `json:"summary"` HomePage string `json:"home_page"` License *License `gorm:"ForeignKey:LicenseID" json:"license,omitempty"` LicenseID uint `json:"-"` Version string `gorm:"index" json:"version"` VersionOrder int `gorm:"index" json:"version_order"` Files []PackageVersionFile `gorm:"ForeignKey:PackageVersionID" json:"files,omitempty"` Classifiers []Classifier `gorm:"many2many:package_version_classifiers;" json:"classifiers,omitempty"` }
PackageVersion model that holds information about given package version
func GetPostedPackageVersion ¶
func GetPostedPackageVersion(cfg Config, pack Package, r *http.Request) (pv PackageVersion, err error)
Return package version
func (*PackageVersion) BeforeCreate ¶
func (p *PackageVersion) BeforeCreate() error
BeforeCreate sets CreatedAt
func (*PackageVersion) BeforeSave ¶
func (p *PackageVersion) BeforeSave() error
BeforeSave sets UpdatedAt
type PackageVersionFile ¶
type PackageVersionFile struct { ID uint `gorm:"primary_key" json:"id"` PackageVersionID uint `json:"-"` Filename string `json:"filename"` RelativePath string `json:"relative_path"` MD5Digest string `gorm:"column:md5_digest" json:"md5_digest"` Author *User `gorm:"ForeignKey:AuthorID" json:"author,omitempty"` AuthorID uint `json:"-"` CreatedAt time.Time `json:"created_at"` // this field is used to have pregenearated download url DownloadURL string `gorm:"-" json:"download_url,omitempty"` }
PackageVersionFile model
func GetPostedPackageVersionFile ¶
func GetPostedPackageVersionFile(config Config, pv PackageVersion, r *http.Request) (result PackageVersionFile, filename string, err error)
Returns PackageVersionFile along with tempfile
func (*PackageVersionFile) BeforeCreate ¶
func (p *PackageVersionFile) BeforeCreate() error
BeforeCreate sets CreatedAt
func (PackageVersionFile) GenerateRelativePath ¶
func (p PackageVersionFile) GenerateRelativePath() string
GenerateRelativePath generates random relative path
type PackageVersionFileManager ¶
PackageVersionFileManager database manager
func (*PackageVersionFileManager) GetAbsoluteFilename ¶
func (p *PackageVersionFileManager) GetAbsoluteFilename(pvf *PackageVersionFile) string
GetAbsoluteFilename returns full package filename
func (*PackageVersionFileManager) GetDownloadURL ¶
func (p *PackageVersionFileManager) GetDownloadURL(pvf *PackageVersionFile) string
GetDownloadURL returns full url for downloading package
func (*PackageVersionFileManager) GetRelativeFilename ¶
func (p *PackageVersionFileManager) GetRelativeFilename(pvf *PackageVersionFile) string
GetAbsoluteFilename returns full package filename
type PackageVersionManager ¶
type PackageVersionManager struct {
*Manager
}
PackageVersionManager database manager
type PackageVersionPathInfo ¶
type PackageVersionPathInfo struct { FullPath string RelativePath string RelativeFilename string FullFilename string }
func GetPackageVersionFilePath ¶
func GetPackageVersionFilePath(packagedir, packagename, filename string) (pvi PackageVersionPathInfo, err error)
GetPackageRelativePath returns relative filename with added directory to packages dir
type PackagesConfig ¶
type Platform ¶
type Platform struct { ID uint `json:"id"` Name string `json:"name"` Description string `json:"description"` }
Platform model tracks all platforms such as: Linux, Darwin even more esoteric.
type PlatformAPIViewSet ¶
type PlatformAPIViewSet struct { classy.ViewSet // configuration Config Config }
PlatformAPIViewSet provides rest endpoints for platform (RU)
func (*PlatformAPIViewSet) List ¶
func (p *PlatformAPIViewSet) List(w http.ResponseWriter, r *http.Request) response.Response
List returns all platform stored in database
func (*PlatformAPIViewSet) Retrieve ¶
func (p *PlatformAPIViewSet) Retrieve(w http.ResponseWriter, r *http.Request) response.Response
Retrieve returns single platform
type PlatformManager ¶
PlatformManager database manager for model Platform
func (*PlatformManager) Get ¶
func (p *PlatformManager) Get(platform *Platform) *gorm.DB
Get returns platform by set fields
func (*PlatformManager) List ¶
func (p *PlatformManager) List(platforms *[]Platform, filter ...FilterFunc) *gorm.DB
List returns list of platforms
func (*PlatformManager) ListOrCreate ¶
func (p *PlatformManager) ListOrCreate(target *[]Platform, platforms []string) error
Return multiple platforms
type PostPackageView ¶
type PostPackageView struct { classy.GenericView Config Config }
PostPackageView handles all methods on package
func (*PostPackageView) ActionFileUpload ¶
func (p *PostPackageView) ActionFileUpload(r *http.Request) response.Response
ActionFileUpload Handles file upload which is called with
`python setup.py upload`
func (*PostPackageView) Before ¶
func (p *PostPackageView) Before(w http.ResponseWriter, r *http.Request) (resp response.Response)
Before every request we need to check permissions
func (*PostPackageView) POST ¶
func (p *PostPackageView) POST(w http.ResponseWriter, r *http.Request) response.Response
POST method for handling package
type SearchResult ¶
type SearchResult struct {
// contains filtered or unexported fields
}
SearchResult item
type SearchService ¶
type SearchService struct {
Config Config
}
SearchService xml rpc service for searching packages
func (*SearchService) Dispatch ¶
func (s *SearchService) Dispatch(method string, root *etree.Element) (doc *etree.Document, err error)
Dispatch dispatches method on service, do not use this method directly. root is params *etree.Element (actually "methodCall/params"
func (*SearchService) ListMethods ¶
func (s *SearchService) ListMethods() []string
ListMethods returns list of all available methods for given service
func (*SearchService) MethodExists ¶
func (s *SearchService) MethodExists(method string) (ok bool)
MethodExists returns whether rpc method is available on service
type Server ¶
type Stats ¶
type Stats struct { Packages int `json:"packages"` ActiveUsers int `json:"active_users"` Licenses int `json:"licenses"` Downloads int `json:"downloads"` }
Stats result
type StatsAPIView ¶
type StatsAPIView struct { classy.GenericView Config Config }
StatsAPIView returns some statistic information for admin dashboard.
func (*StatsAPIView) GET ¶
func (s *StatsAPIView) GET(w http.ResponseWriter, r *http.Request) response.Response
GET returns summary statistics about gopypi
type StatsAggregation ¶
type StatsAggregation int
const ( STATS_DOWNLOAD_WEEKLY StatsAggregation = iota + 1 STATS_DOWNLOAD_MONTHLY STATS_DOWNLOAD_ALL )
type StatsDownloadAllAPIView ¶
type StatsDownloadAllAPIView struct { classy.ListView // config instance Config Config }
StatsDownloadAllAPIView provides stats of package downloads
func (*StatsDownloadAllAPIView) List ¶
func (s *StatsDownloadAllAPIView) List(w http.ResponseWriter, r *http.Request) response.Response
List returns download stats about all packages (sums)
type StatsDownloadItem ¶
type StatsDownloadItem struct { PackageVersion *PackageVersion `gorm:"ForeignKey:PackageVersionID" json:"version,omitempty"` PackageVersionID uint `json:"-"` Downloads int `json:"downloads"` CreatedAt time.Time `json:"created_at"` }
type StatsDownloadPackageAPIView ¶
type StatsDownloadPackageAPIView struct { classy.DetailView // config instance Config Config }
StatsDownloadPackageAPIView provides stats of package downloads
func (*StatsDownloadPackageAPIView) Retrieve ¶
func (s *StatsDownloadPackageAPIView) Retrieve(w http.ResponseWriter, r *http.Request) response.Response
List returns download stats about all packages (sum)
type StatsDownloadPackageVersionAPIView ¶
type StatsDownloadPackageVersionAPIView struct { classy.DetailView // config instance Config Config }
StatsDownloadPackageVersionAPIView provides stats of package version downloads
func (*StatsDownloadPackageVersionAPIView) Retrieve ¶
func (s *StatsDownloadPackageVersionAPIView) Retrieve(w http.ResponseWriter, r *http.Request) response.Response
List returns download stats about all package versions (sum)
type TemplateView ¶
type TemplateView struct { classy.GenericView // configuration Config Config // Data for template Data map[string]interface{} // TemplateFilename TemplateName string }
TemplateView can be directly instantiated when registering view. Be careful that template view needs Config and TemplateName.
Example how ::
classy.New(TemplateView{Config: cfg, TemplateName: "homepage.tpl.html"}).Register(router, "homepage")
func (TemplateView) GET ¶
func (t TemplateView) GET(w http.ResponseWriter, r *http.Request)
GET handles return rendered template
type TokenClaims ¶
type TokenClaims struct { UserID uint `json:"user_id"` jwt.StandardClaims }
TokenClaims holds information for token
func ParseToken ¶
func ParseToken(r *http.Request, secret string) (claims *TokenClaims, err error)
ParseToken parses token and returns claims
type User ¶
type User struct { ID uint `gorm:"primary_key" json:"id"` Username string `gorm:"type:varchar(20);unique_index" json:"username"` Email string `gorm:"type:varchar(100);index" json:"email"` Password string `gorm:"type:varchar(256)" json:"-"` FirstName string `gorm:"type:varchar(40)" json:"first_name"` LastName string `gorm:"type:varchar(40)" json:"last_name"` IsActive bool `json:"is_active"` IsAdmin bool `json:"is_admin"` // permissions CanList bool `json:"can_list"` CanCreate bool `json:"can_create"` CanDownload bool `json:"can_download"` CanUpdate bool `json:"can_update"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
User model
To set/verify user password please use UserManager
func ContextGetTokenUser ¶
Return token claims from request context
type UserAPIViewSet ¶
type UserAPIViewSet struct { classy.ViewSet // store config Config Config }
UserAPIViewSet handles basic crud on users
func (*UserAPIViewSet) Create ¶
func (u *UserAPIViewSet) Create(w http.ResponseWriter, r *http.Request) response.Response
Create is called when new user is created
func (*UserAPIViewSet) List ¶
func (u *UserAPIViewSet) List(w http.ResponseWriter, r *http.Request) response.Response
List of users
func (*UserAPIViewSet) Retrieve ¶
func (u *UserAPIViewSet) Retrieve(w http.ResponseWriter, r *http.Request)
Retrieve single user
func (*UserAPIViewSet) Update ¶
func (u *UserAPIViewSet) Update(w http.ResponseWriter, r *http.Request) response.Response
Update is called when POST is called to update user
type UserAddSerializer ¶
type UserAddSerializer struct { Username string `json:"username"` FirstName string `json:"first_name"` LastName string `json:"last_name"` Email string `json:"email"` Password string `json:"password"` Password2 string `json:"password2"` IsActive bool `json:"is_active"` IsAdmin bool `json:"is_admin"` CanList bool `json:"can_list"` CanDownload bool `json:"can_download"` CanCreate bool `json:"can_create"` CanUpdate bool `json:"can_update"` }
Serializer to create new user
func (*UserAddSerializer) GetUser ¶
func (u *UserAddSerializer) GetUser(cfg Config) (user User)
return user initialized with serializer values
func (*UserAddSerializer) Validate ¶
func (u *UserAddSerializer) Validate(cfg Config) (result ValidationResult)
Validate validates information about new user
@TODO: add ValidateUsername and ValidateEmail
type UserChangePasswordSerializer ¶
type UserChangePasswordSerializer struct { Current string `json:"current"` Password string `json:"password"` Password2 string `json:"password2"` User User `json:"-"` }
Serializer to change password for currently logged user
func (*UserChangePasswordSerializer) ChangePassword ¶
func (u *UserChangePasswordSerializer) ChangePassword(config Config, user *User) (err error)
ChangePassword changes password for given user
func (*UserChangePasswordSerializer) Validate ¶
func (u *UserChangePasswordSerializer) Validate(cfg Config) (result ValidationResult)
Validate validates serializer data
type UserListFilter ¶
type UserListFilter struct {
IsActive *bool
}
UserListFilter filters users from url
type UserManager ¶
UserManager groups functionality to query user model instances
func (*UserManager) ExistsEmail ¶
func (u *UserManager) ExistsEmail(email string) bool
ExistsEmail returns whether user with given email exists in database
func (*UserManager) ExistsUsername ¶
func (u *UserManager) ExistsUsername(username string) bool
ExistsUsername returns whether user with given username exists in database
func (*UserManager) SetPassword ¶
func (u *UserManager) SetPassword(user *User, password string)
SetPassword sets password for given user
func (*UserManager) VerifyPassword ¶
func (u *UserManager) VerifyPassword(user User, password string) bool
VerifyPassword verifies password for user
type UserProfileSerializer ¶
type UserProfileSerializer struct { FirstName string `json:"first_name"` LastName string `json:"last_name"` Email string `json:"email"` }
Serializer for updating user profile
func (*UserProfileSerializer) Validate ¶
func (u *UserProfileSerializer) Validate(cfg Config) (result ValidationResult)
Validate validates serializer
type UserUpdateSerializer ¶
type UserUpdateSerializer struct { ID uint `json:"-"` Username string `json:"username"` FirstName string `json:"first_name"` LastName string `json:"last_name"` Email string `json:"email"` Password string `json:"password"` Password2 string `json:"password2"` IsActive bool `json:"is_active"` IsAdmin bool `json:"is_admin"` CanList bool `json:"can_list"` CanDownload bool `json:"can_download"` CanCreate bool `json:"can_create"` CanUpdate bool `json:"can_update"` // contains filtered or unexported fields }
Serializer to update existing user
func (*UserUpdateSerializer) UpdateUser ¶
func (u *UserUpdateSerializer) UpdateUser(cfg Config, user *User)
UpdateUser updates user with serializer data
func (*UserUpdateSerializer) Validate ¶
func (u *UserUpdateSerializer) Validate(cfg Config) (result ValidationResult)
Validate validates data in serializer
type ValidationError ¶
type ValidationResult ¶
type ValidationResult interface { // add field related error AddFieldError(field string, err error, code ...string) ValidationResult // add not field related error AddUnboundError(err error, code ...string) ValidationResult // returns whether result is valid IsValid() bool // marshals result to json MarshalJSON() ([]byte, error) // returns whether field has error HasFieldError(field string) bool }
func NewValidationResult ¶
func NewValidationResult() ValidationResult
Source Files ¶
- admin_frontend.go
- cli.go
- commands.go
- common.go
- confgen.go
- config.go
- db.go
- errors.go
- features.go
- ffuncs.go
- filter.go
- managers.go
- middleware.go
- models.go
- parser.go
- router.go
- serializers.go
- server.go
- settings.go
- static.go
- stats.go
- strconv.go
- strings.go
- tasks.go
- term.go
- timeutil.go
- token.go
- utils.go
- validator.go
- views.go
- views_api.go
- xmlrpc.go
- xmlrpc_xmlrpc.go