gopypi: github.com/phonkee/gopypi Index | Files | Directories

package core

import "github.com/phonkee/gopypi"

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..

go:generate ./xmlrpcgen --file $GOFILE SearchService

Index

Package 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

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"
        = "" /* 736 byte string literal not displayed */+
        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 = "" /* 217 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)
)

func ApplyFilterFuncs Uses

func ApplyFilterFuncs(db *gorm.DB, funcs ...FilterFunc) *gorm.DB

ApplyFilterFuncs applies all FilterFuncs and returns db

func Asset Uses

func Asset(name string) ([]byte, error)

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 Uses

func AssetDir(name string) ([]string, error)

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 Uses

func AssetInfo(name string) (os.FileInfo, error)

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 AssetNames Uses

func AssetNames() []string

AssetNames returns the names of the assets.

func Atoui Uses

func Atoui(value string, def ...uint) uint

Atoui parses string and converts to uint, if error occures either 0 is returned or given default value (optional)

func BasicAuthLoginRequired Uses

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 Bind Uses

func Bind(r *http.Request, target interface{}) (err error)

Bind json unmarshals request body to target

func BindFilter Uses

func BindFilter(r *http.Request, filter Filter) (err error)

BindFilter binds filter to given url values

func CommonMiddleware Uses

func CommonMiddleware(cfg Config, router *mux.Router) alice.Constructor

func ContextSetTokenUser Uses

func ContextSetTokenUser(ctx context.Context, user User) (result context.Context)

Return token claims from request context

func CountQueryset Uses

func CountQueryset(db *gorm.DB, p paginator.Paginator) *gorm.DB

CountQueryset performs count query and sets paginator count

func CreateToken Uses

func CreateToken(db *gorm.DB, user User, secret string, expiration int) (result string, err error)

CreateToken creates auth token

func Exit Uses

func Exit(why interface{}, code ...int)

Exit exits with priting error message.

func GenerateSalt Uses

func GenerateSalt(length int) (result []byte)

GenerateSalt generates salt for hashing passwords

func GetPostAction Uses

func GetPostAction(r *http.Request) (result int, err error)

Return action from form

func GetRequestToken Uses

func GetRequestToken(r *http.Request) (result string, err error)

GetRequestToken returns token from request

func InitRouter Uses

func InitRouter(config Config) (chain alice.Chain, err error)

GetRouter instantiates router with all its registered routes

func IsEnabledOption Uses

func IsEnabledOption(option []bool) bool

IsEnabledOption returns whether last varargs option is enabled

func LimitQueryset Uses

func LimitQueryset(db *gorm.DB, p paginator.Paginator) *gorm.DB

LimitQueryset sets limits to queryset and returns it

func MD5 Uses

func MD5(input string) string

MD5 shortcut to create md5 hash

func Migrate Uses

func Migrate(config Config) (err error)

Migrate runs AutoMigrate on all models.

func MigrateAction Uses

func MigrateAction(c *cli.Context) (err error)

func MustAsset Uses

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func NewConfGen Uses

func NewConfGen() *confgen

NewConfGen returns ConfGen instance

func NormalizePackageName Uses

func NormalizePackageName(name string) string

NormalizePackageName normalizes package name by PEP 503

func PostEndpointCheckMiddleware Uses

func PostEndpointCheckMiddleware(cfg Config) alice.Constructor

PostEndpointCheckMiddleware custom middleware just for post package

func RestoreAsset Uses

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets Uses

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func RunserverAction Uses

func RunserverAction(c *cli.Context) (err error)

func StringListContains Uses

func StringListContains(where []string, what string) bool

StringListContains returns whether string is in stringlist

func StringMinMaxValidator Uses

func StringMinMaxValidator(min int, max int) func(field string, value *string, vr ValidationResult) bool

StringMinMaxValidator returns validator for length

func StringParseBool Uses

func StringParseBool(value string) (result *bool)

StringParseBool returns boolean value by given string value

func TerminalGetBoolValue Uses

func TerminalGetBoolValue(question string, def bool) (result bool)

func TerminalGetIntValue Uses

func TerminalGetIntValue(question string, def int) (result int)

GetTermIntValue waits for user input for number

func TerminalGetPasswordValue Uses

func TerminalGetPasswordValue(question string) (result string)

TerminalGetPasswordValue return password

func TerminalGetStringValue Uses

func TerminalGetStringValue(question string, defs ...string) (result string)

GetTermValue calls user input.

func TerminalGetStringValueChoices Uses

func TerminalGetStringValueChoices(question string, choices []string, defs ...string) (result string)

func TimeAlignMonth Uses

func TimeAlignMonth(t time.Time) time.Time

TimeAlignWeek aligns date to first day of month and strips time and timezone

func TimeAlignWeek Uses

func TimeAlignWeek(t time.Time) time.Time

TimeAlignWeek aligns date to first day of week and strips time and timezone

func TimeAlignYear Uses

func TimeAlignYear(t time.Time) time.Time

TimeAlignWeek aligns date to first day of year and strips time and timezone

func TimeStripTime Uses

func TimeStripTime(t time.Time) time.Time

TimeStripTime strips time part from time

func TokenAuthLoginRequired Uses

func TokenAuthLoginRequired(cfg Config, permissions ...func(User) error) alice.Constructor

TokenAuthLoginRequired is token auth verification. It reads `gopypi-token`from headers

func ValidateEmail Uses

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 Uses

func ValidateUsername(field string, value *string, vr ValidationResult) bool

ValidateUsername validates username and adds error if available

type ChangePasswordCommand Uses

type ChangePasswordCommand struct {
    Config Config
}

ChangePasswordCommand command line command to change password

func (*ChangePasswordCommand) Run Uses

func (c *ChangePasswordCommand) Run() (err error)

Run

type Classifier Uses

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 Uses

type ClassifierManager struct {
    DB *gorm.DB
}

ClassifierManager database manager

func (*ClassifierManager) ListOrCreate Uses

func (c *ClassifierManager) ListOrCreate(result *[]Classifier, cd []string) (err error)

ListOrCreate returns list of classifiers from given string list

func (*ClassifierManager) NormalizeName Uses

func (c *ClassifierManager) NormalizeName(name string) string

NormalizeName normalizes classifier name

type Command Uses

type Command interface {

    // Run runs command
    Run() error
}

Command interface that all commands use

type Config Uses

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 NewConfig Uses

func NewConfig(tree *toml.TomlTree) (result Config, err error)

Return config from string

func NewConfigFromFilename Uses

func NewConfigFromFilename(filename string) (result Config, err error)

NewConfigFromFilename returns configuration from filename

type CoreConfig Uses

type CoreConfig interface {
    // Listen returns listen address with port
    Listen() string

    // Host returns host when defined
    Host() string

    // SecretKey returns secret key for hashing and crypto
    SecretKey() string
}

type CreateAdminCommand Uses

type CreateAdminCommand struct {
    Config Config
}

CreateAdminCommand creates new admin in database

func (*CreateAdminCommand) Run Uses

func (c *CreateAdminCommand) Run() error

Run is method that runs the command

type DownloadStats Uses

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 Uses

type DownloadStatsConfig interface {

    // Returns how many weeks we should store weekly statistics
    ArchiveWeekly() int

    // Returns how many months we should store monthly statistics
    ArchiveMonthly() int
}

type DownloadStatsManager Uses

type DownloadStatsManager struct {
    DB     *gorm.DB
    Config Config
}

DownloadStatsManager database manager for all download stats

func (*DownloadStatsManager) AddDownload Uses

func (s *DownloadStatsManager) AddDownload(version *PackageVersion) (err error)

AddDownload adds download for given package version

func (*DownloadStatsManager) AddDownloadFile Uses

func (d *DownloadStatsManager) AddDownloadFile(versionfile *PackageVersionFile) (err error)

AddDownloadFile adds download by PackageVersionFile

func (*DownloadStatsManager) Cleanup Uses

func (d *DownloadStatsManager) Cleanup()

Cleanup deletes weekly and monthly stats from database, yearly stats will stay forever

func (*DownloadStatsManager) GetAllStats Uses

func (d *DownloadStatsManager) GetAllStats(target map[string][]StatsDownloadItem, filter ...FilterFunc) (err error)

Returns all download stats

func (*DownloadStatsManager) GetCount Uses

func (d *DownloadStatsManager) GetCount(target interface{}) (err error)

GetSum returns count of all downloads

func (*DownloadStatsManager) GetStats Uses

func (d *DownloadStatsManager) GetStats(aggregation StatsAggregation, target *[]StatsDownloadItem, filter ...FilterFunc) *gorm.DB

type DownloadStatsMonthly Uses

type DownloadStatsMonthly struct {
    DownloadStats
}

DownloadStatsMonthly represents download stats aggregated by month

func (*DownloadStatsMonthly) BeforeCreate Uses

func (s *DownloadStatsMonthly) BeforeCreate() error

BeforeSave aligns CreatedAt correctly

type DownloadStatsWeekly Uses

type DownloadStatsWeekly struct {
    DownloadStats
}

DownloadStatsWeekly represents download stats aggregated by week

func (*DownloadStatsWeekly) BeforeCreate Uses

func (s *DownloadStatsWeekly) BeforeCreate() error

BeforeSave aligns CreatedAt correctly

type DownloadStatsYearly Uses

type DownloadStatsYearly struct {
    DownloadStats
}

DownloadStatsYearly represents download stats aggregated by year

func (*DownloadStatsYearly) BeforeCreate Uses

func (s *DownloadStatsYearly) BeforeCreate() error

BeforeSave aligns CreatedAt correctly

type FallbackFileSystem Uses

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

func (*FallbackFileSystem) Open Uses

func (f *FallbackFileSystem) Open(name string) (result http.File, err error)

Open opens and reads file

type Feature Uses

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 Uses

type FeatureAPIViewSet struct {
    classy.SlugViewSet

    // config instance to access managers, etc..
    Config Config
}

FeatureAPIViewSet provides rest endpoints for features

func (*FeatureAPIViewSet) List Uses

func (f *FeatureAPIViewSet) List(w http.ResponseWriter, r *http.Request) response.Response

List returns list of all features

func (*FeatureAPIViewSet) Retrieve Uses

func (f *FeatureAPIViewSet) Retrieve(w http.ResponseWriter, r *http.Request) response.Response

Retrieve retrieves single feature from database

func (*FeatureAPIViewSet) Update Uses

func (f *FeatureAPIViewSet) Update(w http.ResponseWriter, r *http.Request) response.Response

Update updates given feature (just value)

type FeatureManager Uses

type FeatureManager struct {
    *Manager
}

FeatureManager database manager for model Feature

func (*FeatureManager) IsEnabledFeature Uses

func (f *FeatureManager) IsEnabledFeature(feature string) (result bool, err error)

IsEnabledFeature returns whether given feature is available

type FeatureSerializer Uses

type FeatureSerializer struct {
    Value bool `json:"value"`
}

FeatureSerializer enables/disables feature

type Filter Uses

type Filter interface {

    // returns list of filter funcs
    Apply(queryset *gorm.DB) *gorm.DB
}

Filter is interface to filter database querysets

func NewUserListFilter Uses

func NewUserListFilter(r *http.Request) Filter

NewUserListFilter returns new UserListFilter

type FilterFunc Uses

type FilterFunc func(*gorm.DB) *gorm.DB

FilterFunc is callback which is called in some methods (Get, List)

func FFDownloadStatsPackage Uses

func FFDownloadStatsPackage(pack *Package) FilterFunc

FFDownloadStatsPackage filters stats by package

func FFDownloadStatsPackageVersion Uses

func FFDownloadStatsPackageVersion(pv *PackageVersion) FilterFunc

FFDownloadStatsPackage filters stats by package

func FFID Uses

func FFID(id interface{}) FilterFunc

FFID adds clause to search by id

func FFOrderBy Uses

func FFOrderBy(order string) FilterFunc

FFOrderBy orders by

func FFPackagesFor Uses

func FFPackagesFor(user User) FilterFunc

FFPackagesFor filters packages by given user, user is either author or maintainer

func FFPreload Uses

func FFPreload(preloads ...string) FilterFunc

FFPreload add preloads to que

func FFUsername Uses

func FFUsername(username string) FilterFunc

FilterUsername filters user by username

func FFWhere Uses

func FFWhere(query interface{}, args ...interface{}) FilterFunc

FFWhere is shorthand for gorm Where

type InfoAPIView Uses

type InfoAPIView struct {
    classy.GenericView

    // store config instance
    Config Config
}

InfoAPIView serves GET request and returns information about gopypi server

func (*InfoAPIView) GET Uses

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 Uses

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 Uses

type LicenseAPIViewSet struct {
    classy.ViewSet

    // configuration
    Config Config
}

LicenseAPIViewSet provides rest apis for handling of license model

func (*LicenseAPIViewSet) List Uses

func (l *LicenseAPIViewSet) List(w http.ResponseWriter, r *http.Request) response.Response

List all licenses

func (*LicenseAPIViewSet) MetadataList Uses

func (l *LicenseAPIViewSet) MetadataList(w http.ResponseWriter, r *http.Request) response.Response

Metadata for list endpoints

func (*LicenseAPIViewSet) Retrieve Uses

func (l *LicenseAPIViewSet) Retrieve(w http.ResponseWriter, r *http.Request) response.Response

Retrieve single license from database

func (*LicenseAPIViewSet) Update Uses

func (l *LicenseAPIViewSet) Update(w http.ResponseWriter, r *http.Request) response.Response

Update updates license with serializer data

type LicenseManager Uses

type LicenseManager struct {
    DB *gorm.DB
}

LicenseManager database manager

func (*LicenseManager) GetByCode Uses

func (l *LicenseManager) GetByCode(code string) (license License, err error)

GetByCode returns license by code, if not exist create new one

type LicenseUpdateSerializer Uses

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 Uses

func (l *LicenseUpdateSerializer) UpdateLicense(license *License)

Update license with data form serializer

func (*LicenseUpdateSerializer) Validate Uses

func (l *LicenseUpdateSerializer) Validate(cfg Config, ID int) (result ValidationResult)

Validate runs validation on serializer fields

type LoginAPIView Uses

type LoginAPIView struct {
    classy.GenericView

    Config Config
}

LoginAPIView servers single POST method

func (*LoginAPIView) POST Uses

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 Uses

type LoginSerializer struct {
    Username string `json:"username"`
    Password string `json:"password"`
}

LoginSerializer is login form for json

func (*LoginSerializer) Validate Uses

func (l *LoginSerializer) Validate() (err error)

type Manager Uses

type Manager struct {
    DB *gorm.DB
}

Generic manager

Should have following methods:

* List * Get

func (*Manager) Get Uses

func (p *Manager) Get(target interface{}, filter ...FilterFunc) *gorm.DB

Get calls Where method from given pack with filter funcs applied

func (*Manager) List Uses

func (p *Manager) List(target interface{}, filter ...FilterFunc) *gorm.DB

List calls Where method from given pack with filter funcs applied

type ManagerConfig Uses

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 Uses

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

func (*MeAPIView) GET Uses

func (m *MeAPIView) GET(w http.ResponseWriter, r *http.Request) response.Response

GET returns information about user (from auth token)

func (*MeAPIView) POST Uses

func (m *MeAPIView) POST(w http.ResponseWriter, r *http.Request) response.Response

POST updates user information

type MeChangePasswordAPIView Uses

type MeChangePasswordAPIView struct {
    classy.GenericView

    // store config
    Config Config
}

MeChangePasswordAPIView provides api to change password for currently logged user

func (*MeChangePasswordAPIView) POST Uses

func (m *MeChangePasswordAPIView) POST(w http.ResponseWriter, r *http.Request) response.Response

POST method updates password for currently logged user

type MyPackageAPIView Uses

type MyPackageAPIView struct {
    classy.ListView

    // store config
    Config Config
}

MyPackageAPIView gives information about packages for currently logged in user

func (*MyPackageAPIView) List Uses

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 Uses

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 Uses

func GetPostedPackage(cfg Config, r *http.Request) (pack Package, err error)

GetPackage parses request form and returns package

func (*Package) BeforeCreate Uses

func (p *Package) BeforeCreate() error

BeforeCreate sets CreatedAt

func (*Package) BeforeSave Uses

func (p *Package) BeforeSave() error

BeforeSave sets UpdatedAt

type PackageAPIViewSet Uses

type PackageAPIViewSet struct {
    classy.ViewSet

    // store config
    Config Config
}

PackageAPIViewSet provides following methods

List - list packages Retrieve - retrieve single package

func (*PackageAPIViewSet) List Uses

func (p *PackageAPIViewSet) List(w http.ResponseWriter, r *http.Request) response.Response

List retrieves list of packages

func (*PackageAPIViewSet) Retrieve Uses

func (p *PackageAPIViewSet) Retrieve(w http.ResponseWriter, r *http.Request) response.Response

Retrieve returns single package

type PackageDetailView Uses

type PackageDetailView struct {
    classy.SlugDetailView

    // config instance
    Config Config
}

PackageDetailView returns detail of package

func (*PackageDetailView) Retrieve Uses

func (p *PackageDetailView) Retrieve(w http.ResponseWriter, r *http.Request) response.Response

Retrieve is GET method

type PackageDownloadView Uses

type PackageDownloadView struct {
    classy.BaseView

    Config Config
}

PackageDownloadView serves download

func (*PackageDownloadView) Download Uses

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 Uses

func (p *PackageDownloadView) Routes() (result map[string]classy.Mapping)

Routes returns list of routes with predefined method maps

type PackageListView Uses

type PackageListView struct {
    classy.ListView

    // config instance
    Config Config
}

PackageListView returns list of packages

func (*PackageListView) List Uses

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 Uses

type PackageMaintainerAPIViewSet struct {
    classy.ViewSet

    // config instance
    Config Config
}

PackageMaintainerAPIViewSet provides rest endpoints for maintainers of given package

func (*PackageMaintainerAPIViewSet) Delete Uses

func (p *PackageMaintainerAPIViewSet) Delete(w http.ResponseWriter, r *http.Request) response.Response

Delete removes association of maintainer to given package

func (*PackageMaintainerAPIViewSet) GetPackage Uses

func (p *PackageMaintainerAPIViewSet) GetPackage(r *http.Request) (result Package, err error)

GetPackage returns package from request

func (*PackageMaintainerAPIViewSet) List Uses

func (p *PackageMaintainerAPIViewSet) List(w http.ResponseWriter, r *http.Request) response.Response

List method lists all maintainers for given package

func (*PackageMaintainerAPIViewSet) Update Uses

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 Uses

type PackageManager struct {
    DB *gorm.DB
}

PackageManager database manager

func (*PackageManager) Get Uses

func (p *PackageManager) Get(pack *Package, filter ...FilterFunc) *gorm.DB

Get calls Where method from given pack with preloads

func (*PackageManager) IsMaintainer Uses

func (p *PackageManager) IsMaintainer(pack *Package, user *User) bool

check if user is maintainer

func (*PackageManager) List Uses

func (p *PackageManager) List(packages *[]Package, filter ...FilterFunc) *gorm.DB

Get calls Where method from given pack with preloads

func (*PackageManager) UpdateVersionOrder Uses

func (p *PackageManager) UpdateVersionOrder(pack Package) (err error)

UpdateVersionOrder updates order for all versions

type PackageVersion Uses

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 Uses

func GetPostedPackageVersion(cfg Config, pack Package, r *http.Request) (pv PackageVersion, err error)

Return package version

func (*PackageVersion) BeforeCreate Uses

func (p *PackageVersion) BeforeCreate() error

BeforeCreate sets CreatedAt

func (*PackageVersion) BeforeSave Uses

func (p *PackageVersion) BeforeSave() error

BeforeSave sets UpdatedAt

type PackageVersionFile Uses

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 Uses

func GetPostedPackageVersionFile(config Config, pv PackageVersion, r *http.Request) (result PackageVersionFile, filename string, err error)

Returns PackageVersionFile along with tempfile

func (*PackageVersionFile) BeforeCreate Uses

func (p *PackageVersionFile) BeforeCreate() error

BeforeCreate sets CreatedAt

func (PackageVersionFile) GenerateRelativePath Uses

func (p PackageVersionFile) GenerateRelativePath() string

GenerateRelativePath generates random relative path

type PackageVersionFileManager Uses

type PackageVersionFileManager struct {
    *Manager

    PackagesDir string
    Router      *mux.Router
}

PackageVersionFileManager database manager

func (*PackageVersionFileManager) GetAbsoluteFilename Uses

func (p *PackageVersionFileManager) GetAbsoluteFilename(pvf *PackageVersionFile) string

GetAbsoluteFilename returns full package filename

func (*PackageVersionFileManager) GetDownloadURL Uses

func (p *PackageVersionFileManager) GetDownloadURL(pvf *PackageVersionFile) string

GetDownloadURL returns full url for downloading package

func (*PackageVersionFileManager) GetRelativeFilename Uses

func (p *PackageVersionFileManager) GetRelativeFilename(pvf *PackageVersionFile) string

GetAbsoluteFilename returns full package filename

type PackageVersionManager Uses

type PackageVersionManager struct {
    *Manager
}

PackageVersionManager database manager

type PackageVersionPathInfo Uses

type PackageVersionPathInfo struct {
    FullPath         string
    RelativePath     string
    RelativeFilename string
    FullFilename     string
}

func GetPackageVersionFilePath Uses

func GetPackageVersionFilePath(packagedir, packagename, filename string) (pvi PackageVersionPathInfo, err error)

GetPackageRelativePath returns relative filename with added directory to packages dir

type PackagesConfig Uses

type PackagesConfig interface {
    // Directory returns full directory containint all packages
    Directory() string

    // JoinDirectory joins given parts with directory
    JoinDirectory(part ...string) string
}

type Platform Uses

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 Uses

type PlatformAPIViewSet struct {
    classy.ViewSet

    // configuration
    Config Config
}

PlatformAPIViewSet provides rest endpoints for platform (RU)

func (*PlatformAPIViewSet) List Uses

func (p *PlatformAPIViewSet) List(w http.ResponseWriter, r *http.Request) response.Response

List returns all platform stored in database

func (*PlatformAPIViewSet) Retrieve Uses

func (p *PlatformAPIViewSet) Retrieve(w http.ResponseWriter, r *http.Request) response.Response

Retrieve returns single platform

type PlatformManager Uses

type PlatformManager struct {
    DB *gorm.DB
}

PlatformManager database manager for model Platform

func (*PlatformManager) Get Uses

func (p *PlatformManager) Get(platform *Platform) *gorm.DB

Get returns platform by set fields

func (*PlatformManager) List Uses

func (p *PlatformManager) List(platforms *[]Platform, filter ...FilterFunc) *gorm.DB

List returns list of platforms

func (*PlatformManager) ListOrCreate Uses

func (p *PlatformManager) ListOrCreate(target *[]Platform, platforms []string) error

Return multiple platforms

type PostPackageView Uses

type PostPackageView struct {
    classy.GenericView

    Config Config
}

PostPackageView handles all methods on package

func (*PostPackageView) ActionFileUpload Uses

func (p *PostPackageView) ActionFileUpload(r *http.Request) response.Response

ActionFileUpload Handles file upload which is called with

`python setup.py upload`

func (*PostPackageView) Before Uses

func (p *PostPackageView) Before(w http.ResponseWriter, r *http.Request) (resp response.Response)

Before every request we need to check permissions

func (*PostPackageView) POST Uses

func (p *PostPackageView) POST(w http.ResponseWriter, r *http.Request) response.Response

POST method for handling package

type SearchResult Uses

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

SearchResult item

type SearchService Uses

type SearchService struct {
    Config Config
}

SearchService xml rpc service for searching packages

func (*SearchService) Dispatch Uses

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 Uses

func (s *SearchService) ListMethods() []string

ListMethods returns list of all available methods for given service

func (*SearchService) MethodExists Uses

func (s *SearchService) MethodExists(method string) (ok bool)

MethodExists returns whether rpc method is available on service

type Server Uses

type Server interface {
    // Config returns server config
    Config() Config

    // Router returns server router
    Router() *mux.Router

    // ListenAndServe runs http server
    ListenAndServe() error
}

func New Uses

func New(cfg Config) (result Server, err error)

New returns fresh gopypi server instance bound to config.

type Stats Uses

type Stats struct {
    Packages    int `json:"packages"`
    ActiveUsers int `json:"active_users"`
    Licenses    int `json:"licenses"`
    Downloads   int `json:"downloads"`
}

Stats result

type StatsAPIView Uses

type StatsAPIView struct {
    classy.GenericView

    Config Config
}

StatsAPIView returns some statistic information for admin dashboard.

func (*StatsAPIView) GET Uses

func (s *StatsAPIView) GET(w http.ResponseWriter, r *http.Request) response.Response

GET returns summary statistics about gopypi

type StatsAggregation Uses

type StatsAggregation int
const (
    STATS_DOWNLOAD_WEEKLY StatsAggregation = iota + 1
    STATS_DOWNLOAD_MONTHLY
    STATS_DOWNLOAD_ALL
)

type StatsDownloadAllAPIView Uses

type StatsDownloadAllAPIView struct {
    classy.ListView

    // config instance
    Config Config
}

StatsDownloadAllAPIView provides stats of package downloads

func (*StatsDownloadAllAPIView) List Uses

func (s *StatsDownloadAllAPIView) List(w http.ResponseWriter, r *http.Request) response.Response

List returns download stats about all packages (sums)

type StatsDownloadItem Uses

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 Uses

type StatsDownloadPackageAPIView struct {
    classy.DetailView

    // config instance
    Config Config
}

StatsDownloadPackageAPIView provides stats of package downloads

func (*StatsDownloadPackageAPIView) Retrieve Uses

func (s *StatsDownloadPackageAPIView) Retrieve(w http.ResponseWriter, r *http.Request) response.Response

List returns download stats about all packages (sum)

type StatsDownloadPackageVersionAPIView Uses

type StatsDownloadPackageVersionAPIView struct {
    classy.DetailView

    // config instance
    Config Config
}

StatsDownloadPackageVersionAPIView provides stats of package version downloads

func (*StatsDownloadPackageVersionAPIView) Retrieve Uses

func (s *StatsDownloadPackageVersionAPIView) Retrieve(w http.ResponseWriter, r *http.Request) response.Response

List returns download stats about all package versions (sum)

type Task Uses

type Task interface {

    // Run executes task
    Run(config Config) error
}

Task interface for background running tasks

type TemplateView Uses

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 Uses

func (t TemplateView) GET(w http.ResponseWriter, r *http.Request)

GET handles return rendered template

type TokenClaims Uses

type TokenClaims struct {
    UserID uint `json:"user_id"`
    jwt.StandardClaims
}

TokenClaims holds information for token

func ParseToken Uses

func ParseToken(r *http.Request, secret string) (claims *TokenClaims, err error)

ParseToken parses token and returns claims

type User Uses

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 Uses

func ContextGetTokenUser(ctx context.Context) (user User, err error)

Return token claims from request context

func (*User) BeforeCreate Uses

func (u *User) BeforeCreate() error

BeforeCreate sets CreatedAt

func (*User) BeforeSave Uses

func (u *User) BeforeSave() error

BeforeSave sets UpdatedAt

type UserAPIViewSet Uses

type UserAPIViewSet struct {
    classy.ViewSet

    // store config
    Config Config
}

UserAPIViewSet handles basic crud on users

func (*UserAPIViewSet) Create Uses

func (u *UserAPIViewSet) Create(w http.ResponseWriter, r *http.Request) response.Response

Create is called when new user is created

func (*UserAPIViewSet) List Uses

func (u *UserAPIViewSet) List(w http.ResponseWriter, r *http.Request) response.Response

List of users

func (*UserAPIViewSet) Retrieve Uses

func (u *UserAPIViewSet) Retrieve(w http.ResponseWriter, r *http.Request)

Retrieve single user

func (*UserAPIViewSet) Update Uses

func (u *UserAPIViewSet) Update(w http.ResponseWriter, r *http.Request) response.Response

Update is called when POST is called to update user

type UserAddSerializer Uses

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 Uses

func (u *UserAddSerializer) GetUser(cfg Config) (user User)

return user initialized with serializer values

func (*UserAddSerializer) Validate Uses

func (u *UserAddSerializer) Validate(cfg Config) (result ValidationResult)

Validate validates information about new user

@TODO: add ValidateUsername and ValidateEmail

type UserChangePasswordSerializer Uses

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 Uses

func (u *UserChangePasswordSerializer) ChangePassword(config Config, user *User) (err error)

ChangePassword changes password for given user

func (*UserChangePasswordSerializer) Validate Uses

func (u *UserChangePasswordSerializer) Validate(cfg Config) (result ValidationResult)

Validate validates serializer data

type UserListFilter Uses

type UserListFilter struct {
    IsActive *bool
}

UserListFilter filters users from url

func (UserListFilter) Apply Uses

func (u UserListFilter) Apply(queryset *gorm.DB) *gorm.DB

Apply applies filter to queryset

type UserManager Uses

type UserManager struct {
    DB        *gorm.DB
    SecretKey string
}

UserManager groups functionality to query user model instances

func (*UserManager) ExistsEmail Uses

func (u *UserManager) ExistsEmail(email string) bool

ExistsEmail returns whether user with given email exists in database

func (*UserManager) ExistsUsername Uses

func (u *UserManager) ExistsUsername(username string) bool

ExistsUsername returns whether user with given username exists in database

func (*UserManager) Get Uses

func (u *UserManager) Get(user *User) *gorm.DB

Get

func (*UserManager) SetPassword Uses

func (u *UserManager) SetPassword(user *User, password string)

SetPassword sets password for given user

func (*UserManager) VerifyPassword Uses

func (u *UserManager) VerifyPassword(user User, password string) bool

VerifyPassword verifies password for user

type UserProfileSerializer Uses

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 Uses

func (u *UserProfileSerializer) Validate(cfg Config) (result ValidationResult)

Validate validates serializer

type UserUpdateSerializer Uses

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 Uses

func (u *UserUpdateSerializer) UpdateUser(cfg Config, user *User)

UpdateUser updates user with serializer data

func (*UserUpdateSerializer) Validate Uses

func (u *UserUpdateSerializer) Validate(cfg Config) (result ValidationResult)

Validate validates data in serializer

type ValidationError Uses

type ValidationError struct {
    Code  string `json:"code,omitempty"`
    Error string `json:"error"`
}

type ValidationResult Uses

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 Uses

func NewValidationResult() ValidationResult

Directories

PathSynopsis
gopypi
templates

Package core imports 51 packages (graph) and is imported by 1 packages. Updated 2016-12-15. Refresh now. Tools for package owners.