gozillalib

package module
v0.0.0-...-45452f1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2020 License: AGPL-3.0 Imports: 38 Imported by: 2

README

Gozilla-lib

Libraries for Gozilla components

In development

Documentation

Index

Constants

View Source
const (
	// UserColl users collection
	UserColl string = "user"
	// CustomerColl customers collection
	CustomerColl string = "customer"
	// PlanColl plan collection
	PlanColl string = "plan"
	// SubjectColl subjects collection
	SubjectColl string = "subject"
	// RepoColl repositories collection
	RepoColl string = "repo"
	// PackageColl package collection
	PackageColl string = "package"
	// PackageVersionColl package collection
	PackageVersionColl string = "packversion"
	// ProductColl product collection
	ProductColl string = "product"
	// ProductVersionColl product version collection
	ProductVersionColl string = "vproduct"
	// PackageVersionUpdateColl update collection
	PackageVersionUpdateColl string = "vpackupdate"
)
View Source
const TokenTTL time.Duration = 24 * time.Hour

TokenTTL is max TTL for a token, can be overiden with env variable GOZ_TOKEN_TTL

Variables

View Source
var ConfigFile string

ConfigFile config file path

Functions

func ConanInfo

func ConanInfo(goz GozContext, f FileObject) (map[string]interface{}, error)

ConanInfo reads conaninfo file and returns struct mapping

func ConsulDeclare

func ConsulDeclare(ctx GozContext, serviceName string) error

ConsulDeclare declare current service to consul

func CustomerStatSubjects

func CustomerStatSubjects(goz GozContext, customer string)

CustomerStatSubjects update customer subjects stat

func FernetDecode

func FernetDecode(config Config, token []byte, checkTTL bool) (msg []byte, err error)

FernetDecode tries to decode a fernet decode with available keys

func FernetEncode

func FernetEncode(config Config, msg []byte) (token []byte, err error)

FernetEncode encode creates a Fernet token from input message

func Random

func Random(length int) string

Random returns a random string of specified length

func StatDownload

func StatDownload(goz GozContext, subject string, repo string, pack string, kind PackageType)

StatDownload add a download stat for package

func StatQuota

func StatQuota(goz GozContext, subjectID string)

StatQuota records for subject used size

func StatUpload

func StatUpload(goz GozContext, subject string, repo string, pack string, kind PackageType)

StatUpload add an upload stat for package

Types

type AmqpHandler

type AmqpHandler struct {
	Conn         *amqp.Connection
	Ch           *amqp.Channel
	PublishQueue string
	DebianQueue  string
	RpmQueue     string
	// contains filtered or unexported fields
}

AmqpHandler manage amqp messages

func NewAmqpHandler

func NewAmqpHandler(cfg Config) (*AmqpHandler, error)

NewAmqpHandler returns a new AmqpHandler instance

func (*AmqpHandler) Handle

func (a *AmqpHandler) Handle() error

Handle initialize amqp echange and queue

type AuthConfig

type AuthConfig struct {
	CAS []CASServer
}

AuthConfig contains authentication config parameters

type CASServer

type CASServer struct {
	ID          string
	Customer    string // Link users authenticated via this CAS to an existing customer
	LoginURL    string
	ValidateURL string
}

CASServer define a CAS endpoint

type ConanFileObject

type ConanFileObject struct {
	RawFileObject
}

ConanFileObject describes a maven file

func (*ConanFileObject) GetPath

func (f *ConanFileObject) GetPath() string

GetPath builds file location

func (*ConanFileObject) Index

func (f *ConanFileObject) Index(goz GozContext) error

Index adds file info in elasticsearch

func (*ConanFileObject) UnIndex

func (f *ConanFileObject) UnIndex(goz GozContext) error

UnIndex remove file from index

type Config

type Config struct {
	Mongo MongoConfig `json:"mongo"`
	URL   string      `json:"url"`
	Proxy string      `json:"proxy"` // nginx web proxy
	Debug int         `json:"debug"` // (de)activate debug [0,1]
	// Secret string
	Fernet   []string      `json:"fernet"`
	Web      WebConfig     `json:"web"`
	Storage  StorageConfig `json:"storage"`
	Consul   string        `json:"consul"`
	Amqp     string        `json:"amqp"`     // rabbitmq url connection "amqp://guest:guest@localhost:5672/"
	Elastic  []string      `json:"elastic"`  // Elasticsearch host addresses
	Influxdb InfluxConfig  `json:"influxdb"` // Influxdb config (optional)
	Debian   DebianConfig
	Rpm      RpmConfig
	Gpg      GpgConfig
	Auth     AuthConfig
}

Config contains goterra configuration

func LoadConfig

func LoadConfig() Config

LoadConfig returns the singleton config object

type Content

type Content struct {
}

Content TODO

type ContentHandler

type ContentHandler interface {
}

ContentHandler interface for the different content handlers

func NewContent

func NewContent(ctx GozContext, kind ContentType) (ContentHandler, error)

NewContent returns a content handler based on ContentType

type ContentType

type ContentType int

ContentType defines the kind of content

const (
	// ContentRaw used for simple file management
	ContentRaw ContentType = 0
)

type CustomProfile

type CustomProfile struct {
	CanReadSubject   bool
	CanWriteSubject  bool
	CanDeleteSubject bool
	CanReadRepo      bool
	CanWriteRepo     bool
	CanDeleteRepo    bool
	CanWritePackage  bool
	CanDeletePackage bool
}

CustomProfile TODO (not yet used)

type Customer

type Customer struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Address     string `json:"address"`
	City        string `json:"city"`
	Country     string `json:"country"`
	Email       string `json:"email"`
	Phone       string `json:"phone"`
	Plan        string `json:"plan"` // name of plan, if empty, use *free* plan

	History []PlanHistory `json:"history"`

	Created     int64 `json:"created"`
	LastUpdated int64 `json:"last_updated"`
}

Customer is needed for billing

func (*Customer) Create

func (c *Customer) Create(goz GozContext) error

Create a customer

func (*Customer) Delete

func (c *Customer) Delete(goz GozContext) error

Delete removes customer from db

func (*Customer) Exists

func (c *Customer) Exists(goz GozContext) (Customer, error)

Exists checks if customer exists

func (*Customer) GetNbSubjects

func (c *Customer) GetNbSubjects(goz GozContext) (int64, error)

GetNbSubjects counts number of subjects owned by customer

func (*Customer) List

func (c *Customer) List(goz GozContext) ([]Customer, error)

List returns all customers

func (*Customer) OwnedSubjects

func (c *Customer) OwnedSubjects(goz GozContext) ([]Subject, error)

OwnedSubjects get repos owner by customer (org subjects)

func (*Customer) Save

func (c *Customer) Save(goz GozContext) error

Save updates customer info

func (*Customer) Users

func (c *Customer) Users(goz GozContext) ([]User, error)

Users returns users linked to customer

type DebianConfig

type DebianConfig struct {
	Script string `json:"script"`
	Aptly  string `json:"aptly"` // aptly directory
}

DebianConfig contains configuration for debian repos

type DebianFileObject

type DebianFileObject struct {
	RawFileObject
}

DebianFileObject describes a debian file

func (*DebianFileObject) Index

func (f *DebianFileObject) Index(goz GozContext) error

Index adds file info in elasticsearch

func (*DebianFileObject) UnIndex

func (f *DebianFileObject) UnIndex(goz GozContext) error

UnIndex remove file from index

type DebianRepoFileObject

type DebianRepoFileObject struct {
	RawFileObject
}

DebianRepoFileObject describes a debian repo file

func (*DebianRepoFileObject) GetPath

func (f *DebianRepoFileObject) GetPath() string

GetPath builds file location

func (*DebianRepoFileObject) Index

func (f *DebianRepoFileObject) Index(goz GozContext) error

Index adds file info in elasticsearch

func (*DebianRepoFileObject) UnIndex

func (f *DebianRepoFileObject) UnIndex(goz GozContext) error

UnIndex remove file from index

type FileACL

type FileACL int

FileACL allowed acls

const (
	// FileACLNone no access
	FileACLNone FileACL = 0
	// FileACLRead read only
	FileACLRead FileACL = 1
	// FileACLWrite read/write/delete
	FileACLWrite FileACL = 2
)

type FileInfo

type FileInfo struct {
	LastUpdated int64  `json:"last_updated"`
	Size        int64  `json:"size"`
	MD5         string `json:"md5"`
}

FileInfo represent a file

type FileObject

type FileObject interface {
	GetSubject() string
	GetRepo() string
	GetPackage() string
	GetPackageType() PackageType
	GetVersion() string
	SetVersion(v string)
	GetName() string
	GetType() PackageType
	SetType(t PackageType)
	GetPath() string
	SetName(n string)
	Index(goz GozContext) error
	UnIndex(goz GozContext) error
	SetMeta(m FileInfo)
	GetMeta() FileInfo
	GetExtras() map[string]interface{}
	SetExtra(string, interface{})
	SetExtras(map[string]interface{})
	ShouldSkipIndex() bool
	DoSkipIndex(bool)
}

FileObject is a generic file object interface

func NewConanFileObject

func NewConanFileObject(subject, repo, pack, version, name string) FileObject

NewConanFileObject gets a conan FileObject

func NewDebianFileObject

func NewDebianFileObject(subject, repo, pack, version, name string) FileObject

NewDebianFileObject gets a debian FileObject

func NewDebianRepoFileObject

func NewDebianRepoFileObject(subject, repo, pack, name string) FileObject

NewDebianRepoFileObject gets a debian FileObject

func NewMavenFileObject

func NewMavenFileObject(subject, repo, pack, version, name string) FileObject

NewMavenFileObject gets a maven FileObject

func NewRawFileObject

func NewRawFileObject(subject, repo, pack, version, name string) FileObject

NewRawFileObject gets a raw FileObject

func NewRpmFileObject

func NewRpmFileObject(subject, repo, pack, version, name string) FileObject

NewRpmFileObject gets a rpm FileObject

func NewRpmRepoFileObject

func NewRpmRepoFileObject(subject, repo, pack, name string) FileObject

NewRpmRepoFileObject gets a rpm FileObject

type FileToken

type FileToken struct {
	Path   string
	Access FileACL
	Expire int64
}

FileToken is token message allowing file read/write

type GozContext

type GozContext struct {
	User        User // Id of connected user, empty if not connected
	Mongo       *mongo.Client
	Config      Config
	Storage     StorageHandler
	AmqpHandler *AmqpHandler
	Elastic     *elasticsearch.Client
}

GozContext is used to forwarded context data to requests

type GozElement

type GozElement struct {
	Name        string     `json:"name"`
	Description string     `json:"description"`
	LastUpdated int64      `json:"last_updated"`
	Type        GozEltType `json:"type"`
	Subject     string     `json:"subject"`
	Repo        string     `json:"repo"`
	Package     string     `json:"package"`
	Version     string     `json:"version"`
}

GozElement store element for subject,repo,etc. in elasticsearch

func (GozElement) Index

func (g GozElement) Index(goz GozContext) error

Index add element to elasticsearch

func (GozElement) Search

func (g GozElement) Search(goz GozContext, search string) ([]GozElement, error)

Search looks for search string in recorded elements

func (GozElement) UnIndex

func (g GozElement) UnIndex(goz GozContext) error

UnIndex remove element from index

type GozEltType

type GozEltType int

GozEltType type of element

const (
	// GozEltSubject subject
	GozEltSubject GozEltType = 0
	// GozEltRepo repository
	GozEltRepo GozEltType = 1
	// GozEltPackage package
	GozEltPackage GozEltType = 2
	// GozEltPackageVersion package version
	GozEltPackageVersion GozEltType = 3
	// GozEltProduct product
	GozEltProduct GozEltType = 4
)

type GpgConfig

type GpgConfig struct {
	Key        string
	Passphrase string
	Pubkeyfile string // Path to pub key file to export it
}

GpgConfig contains gpg key info

type InfluxConfig

type InfluxConfig struct {
	Address  string
	Login    string
	Password string
	Db       string
}

InfluxConfig defines influxdb connection info

type LocalFileHandler

type LocalFileHandler struct {
}

LocalFileHandler handles local storage files

func (LocalFileHandler) CreateBucket

func (h LocalFileHandler) CreateBucket(goz GozContext, bucket string) error

CreateBucket creates a bucket

func (LocalFileHandler) CreateRepo

func (h LocalFileHandler) CreateRepo(goz GozContext, bucket string, repo string) error

CreateRepo creates repository in bucket

func (LocalFileHandler) DeleteObject

func (h LocalFileHandler) DeleteObject(goz GozContext, f FileObject, expireMinutes int64) (string, error)

DeleteObject TODO

func (LocalFileHandler) GetObjectURL

func (h LocalFileHandler) GetObjectURL(goz GozContext, f FileObject, expireMinutes int64) (string, error)

GetObjectURL TODO

func (LocalFileHandler) GetQuota

func (h LocalFileHandler) GetQuota(goz GozContext, bucket string) (int64, error)

GetQuota returns used quota for bucket

func (LocalFileHandler) MD5

MD5 gets the md5sum of requested file

func (LocalFileHandler) SaveObject

func (h LocalFileHandler) SaveObject(goz GozContext, f FileObject, expireMinutes int64) (string, error)

SaveObject TODO

func (LocalFileHandler) SetQuota

func (h LocalFileHandler) SetQuota(goz GozContext, bucket string, plan PlanInfo) error

SetQuota update quota for bucket according to plan

func (LocalFileHandler) SetSecretKey

func (h LocalFileHandler) SetSecretKey(goz GozContext, bucket string) error

SetSecretKey update bucket secret key does nothing, do not applies to local handler

type LogMode

type LogMode int

LogMode defines how user logged in

const (
	// LogAnonymous not logged, i.e. anonymous
	LogAnonymous LogMode = -1
	// LogAPIKey user logged with api key
	LogAPIKey LogMode = 0
	// LogPassword user logged with password
	LogPassword LogMode = 1
)

type MavenFileObject

type MavenFileObject struct {
	RawFileObject
}

MavenFileObject describes a maven file

func (*MavenFileObject) GetPath

func (f *MavenFileObject) GetPath() string

GetPath builds file location

func (*MavenFileObject) Index

func (f *MavenFileObject) Index(goz GozContext) error

Index adds file info in elasticsearch

func (*MavenFileObject) UnIndex

func (f *MavenFileObject) UnIndex(goz GozContext) error

UnIndex remove file from index

type Member

type Member struct {
	User    string  `json:"user"` // user id
	Profile Profile `json:"profile"`
}

Member is a repository member

type MongoConfig

type MongoConfig struct {
	URL string `json:"url"`
	DB  string `json:"db"`
}

MongoConfig contains mongodb server connection info

type OpenstackConfig

type OpenstackConfig struct {
	Domain         string `json:"domain"` // domain id
	Region         string `json:"region"`
	Project        string `json:"project"` // tenant id
	AccessKey      string `json:"access" yaml:"access"`
	AccessPassword string `json:"password" yaml:"password"`
	Secret         string `json:"secret"` // Secret key stored at account level for tempurl
}

OpenstackConfig defines openstack swift storage

type Package

type Package struct {
	ID          string            `json:"id"`
	Subject     string            `json:"subject"`
	Repo        string            `json:"repo"`
	Created     int64             `json:"created"`
	LastUpdated int64             `json:"last_updated"`
	Deleted     bool              `json:"deleted"`
	DeletedTime int64             `json:"deleted_ts"`
	Description string            `json:"description"`
	Type        PackageType       `json:"type"`
	Meta        map[string]string `json:"meta"` // Metadata package dependant
	Versions    []string          `json:"versions"`
}

Package represents a package

func (*Package) Create

func (p *Package) Create(goz GozContext) error

Create adds a new package

func (*Package) Delete

func (p *Package) Delete(goz GozContext) error

Delete removes package from db

func (*Package) Exists

func (p *Package) Exists(goz GozContext) (Package, error)

Exists checks if subject exists

func (Package) Files

func (p Package) Files(goz GozContext) ([]FileObject, error)

Files returns list of files for a package

func (*Package) Get

func (p *Package) Get(goz GozContext) (Package, error)

Get returns package information with all versions

func (*Package) GetVersions

func (p *Package) GetVersions(goz GozContext) ([]PackageVersion, error)

GetVersions get package available versions

func (*Package) Save

func (p *Package) Save(goz GozContext) error

Save update an existing package

type PackageType

type PackageType int

PackageType defines the kind of package

const (
	// RawPackage manages raw files
	RawPackage PackageType = 0
	// MavenPackage manages Maven repo
	MavenPackage PackageType = 1
	// DebianPackage manages Debian repo
	DebianPackage PackageType = 2
	// RpmPackage manages RPM repo
	RpmPackage PackageType = 3
	// DockerPackage manages Docker repo
	DockerPackage PackageType = 4
	// ConanPackage manages Conan repo
	ConanPackage PackageType = 5
)

type PackageVersion

type PackageVersion struct {
	Version       string            `json:"version"`
	Subject       string            `json:"subject"`
	Repo          string            `json:"repo"`
	Package       string            `json:"package"`
	Created       int64             `json:"created"`
	LastUpdated   int64             `json:"last_updated"`
	Published     bool              `json:"published"`
	PublishedTime int64             `json:"published_ts"`
	ToPublish     bool              `json:"to_publish"` // Should package be published
	Deleted       bool              `json:"deleted"`
	DeletedTime   int64             `json:"deleted_ts"`
	Meta          map[string]string `json:"meta"` // Metadata package dependant
	Description   string            `json:"description"`
}

PackageVersion represents a package version

func (*PackageVersion) Create

func (p *PackageVersion) Create(goz GozContext) error

Create adds a new package version

func (*PackageVersion) Delete

func (p *PackageVersion) Delete(goz GozContext) error

Delete removes package version from db

func (*PackageVersion) Exists

func (p *PackageVersion) Exists(goz GozContext) (PackageVersion, error)

Exists checks if subject exists

func (PackageVersion) Files

func (p PackageVersion) Files(goz GozContext) ([]FileObject, error)

Files returns list of files for a package version

func (*PackageVersion) Get

Get returns package version information

func (*PackageVersion) Latest

func (p *PackageVersion) Latest(goz GozContext) (string, error)

Latest returns latest version (last updated package)

func (*PackageVersion) Save

func (p *PackageVersion) Save(goz GozContext) error

Save update an existing package

func (PackageVersion) SetMetaFiles

func (p PackageVersion) SetMetaFiles(goz GozContext) ([]FileObject, error)

SetMetaFiles find files and update md5 etc...

type PackageVersionUpdate

type PackageVersionUpdate struct {
	ID          primitive.ObjectID `bson:"_id" json:"id,omitempty"`
	Subject     string             `bson:"subject" json:"subject"`
	Repo        string             `bson:"repo" json:"repo"`
	Package     string             `bson:"package" json:"package"`
	Version     string             `bson:"version" json:"version"`
	LastUpdated int64              `bson:"last_updated" json:"last_updated"`
}

PackageVersionUpdate is used when a package version is updated with new or update files to scan version files and update their metadata and update subject quota used size

func (*PackageVersionUpdate) Delete

func (p *PackageVersionUpdate) Delete(goz GozContext) error

Delete delete scan request

func (*PackageVersionUpdate) List

List returns list of pending updates Does not handle docker packages Handles packages last updated > 1 day (to wait for uploads to be over)

func (*PackageVersionUpdate) New

New adds a new scan request

func (*PackageVersionUpdate) Scan

func (p *PackageVersionUpdate) Scan(goz GozContext) error

Scan update files metadata and subject quota used size

type Plan

type Plan int

Plan is a pricing plan

const (
	// PlanGuest is a no create plan (user can read and be given repo access but cannot create repo)
	PlanGuest Plan = -1
	// PlanCustomer is a plan for a customer with specific quota rules
	PlanCustomer Plan = 0
)

func (Plan) String

func (p Plan) String() string

String gets textual representation of plan

type PlanHistory

type PlanHistory struct {
	Plan PlanInfo `json:"plan"`
	From int64    `json:"from"`
	To   int64    `json:"to"`
}

PlanHistory contains information about a plan usage (from/to date and plan info)

type PlanInfo

type PlanInfo struct {
	ID          string      `json:"id"`
	Description string      `json:"description"`
	Quota       Quota       `json:"quota"`
	Pricing     PricingPlan `json:"pricing"` // if empty = free
	Kind        Plan        `json:"kind"`    // plan type

	Created     int64 `json:"created"`
	LastUpdated int64 `json:"last_updated"`
}

PlanInfo gives info on a plan

func (*PlanInfo) Create

func (p *PlanInfo) Create(goz GozContext) error

Create a plan

func (*PlanInfo) Delete

func (p *PlanInfo) Delete(goz GozContext) error

Delete removes plan from db

func (*PlanInfo) Exists

func (p *PlanInfo) Exists(goz GozContext) (PlanInfo, error)

Exists checks if plan exists

func (*PlanInfo) List

func (p *PlanInfo) List(goz GozContext) ([]PlanInfo, error)

List returns all plans

func (*PlanInfo) Save

func (p *PlanInfo) Save(goz GozContext) error

Save updates plan info

func (*PlanInfo) UsedBy

func (p *PlanInfo) UsedBy(goz GozContext) ([]Customer, error)

UsedBy looks for customers using this plan

type PricingPlan

type PricingPlan struct {
	ID string `json:"id"`
}

PricingPlan determines the pricing of a plan

type Product

type Product struct {
	ID          string            `json:"id"`
	Description string            `json:"description"`
	Subject     string            `json:"subject"`
	Created     int64             `json:"created"`
	LastUpdated int64             `json:"last_updated"`
	Deleted     bool              `json:"deleted"`
	DeletedTime int64             `json:"deleted_ts"`
	Meta        map[string]string `json:"meta"` // Metadata
	Versions    []string          `json:"versions"`
}

Product represents a product ie a combination of package

func (*Product) Create

func (p *Product) Create(goz GozContext) error

Create a product

func (*Product) GetVersions

func (p *Product) GetVersions(goz GozContext) ([]ProductVersion, error)

GetVersions list product versions

func (*Product) List

func (p *Product) List(goz GozContext) ([]Product, error)

List returns products information

func (*Product) Save

func (p *Product) Save(goz GozContext) error

Save updates product info

type ProductVersion

type ProductVersion struct {
	Version      string `json:"version"`
	Description  string `json:"description"`
	ReleaseNotes string `json:"relnotes"`
	Product      string `json:"product"`
	Subject      string `json:"subject"`

	Components []PackageVersion `json:"components"`

	Created     int64             `json:"created"`
	LastUpdated int64             `json:"last_updated"`
	Deleted     bool              `json:"deleted"`
	DeletedTime int64             `json:"deleted_ts"`
	Meta        map[string]string `json:"meta"` // Metadata

}

ProductVersion defines a specific product release matching some package versions

func (*ProductVersion) Create

func (p *ProductVersion) Create(goz GozContext) error

Create a product

func (*ProductVersion) List

func (p *ProductVersion) List(goz GozContext) ([]ProductVersion, error)

List returns product versions information

func (*ProductVersion) Save

func (p *ProductVersion) Save(goz GozContext) error

Save updates product info

type Profile

type Profile int

Profile type

const (
	// ProfileUnknown not used
	ProfileUnknown Profile = -1
	// ProfileAnonymous describe an anonymous user (no access)
	ProfileAnonymous Profile = 0
	// ProfileAdmin describe a gozilla admin (*:rw, *:admin)
	ProfileAdmin Profile = 1
	// ProfileRepoAdmin describe a repository admin (repo:rw, repo:admin)
	ProfileRepoAdmin Profile = 10
	// ProfileReleaseManager (repo:rw, repo:release:rw)
	ProfileReleaseManager Profile = 20
	// ProfileDev describe a repository developper (repo:rw)
	ProfileDev Profile = 30
	// ProfileGuest describe a repository guest (repo:r)
	ProfileGuest Profile = 40
)

func (Profile) String

func (p Profile) String() string

String gets textual representation of profile

type Quota

type Quota struct {
	Subjects int    `json:"subjects"` // Max number of subjects, 0 = subject creation only by operators, not users. Personal subject is automatically created
	Size     string `json:"size"`     // Max size of repo (1G, 100M) 0 = unlimited
}

Quota manage subject quotas

type RawFileObject

type RawFileObject struct {
	Subject     string
	Repo        string
	Package     string
	PackageType PackageType
	Version     string
	//Request     *http.Request
	Name      string
	Path      string
	Meta      FileInfo
	Extras    map[string]interface{}
	SkipIndex bool // Index or not file

	IndexPackageVersion string `json:"ivpack"`
	IndexPackage        string `json:"ipack"`
	IndexRepo           string `json:"irepo"`
}

RawFileObject describes a raw file

func (*RawFileObject) DoSkipIndex

func (f *RawFileObject) DoSkipIndex(skip bool)

DoSkipIndex TODO

func (*RawFileObject) GetExtras

func (f *RawFileObject) GetExtras() map[string]interface{}

GetExtras return extra about file

func (*RawFileObject) GetMeta

func (f *RawFileObject) GetMeta() FileInfo

GetMeta add metadata about file

func (*RawFileObject) GetName

func (f *RawFileObject) GetName() string

GetName TODO

func (*RawFileObject) GetPackage

func (f *RawFileObject) GetPackage() string

GetPackage TODO

func (*RawFileObject) GetPackageType

func (f *RawFileObject) GetPackageType() PackageType

GetPackageType TODO

func (*RawFileObject) GetPath

func (f *RawFileObject) GetPath() string

GetPath builds file location

func (*RawFileObject) GetRepo

func (f *RawFileObject) GetRepo() string

GetRepo TODO

func (*RawFileObject) GetSubject

func (f *RawFileObject) GetSubject() string

GetSubject TODO

func (*RawFileObject) GetType

func (f *RawFileObject) GetType() PackageType

GetType TODO

func (*RawFileObject) GetVersion

func (f *RawFileObject) GetVersion() string

GetVersion TODO

func (*RawFileObject) Index

func (f *RawFileObject) Index(goz GozContext) error

Index adds file info in elasticsearch

func (*RawFileObject) SetExtra

func (f *RawFileObject) SetExtra(key string, value interface{})

SetExtra add extra about file

func (*RawFileObject) SetExtras

func (f *RawFileObject) SetExtras(m map[string]interface{})

SetExtras add extra about file

func (*RawFileObject) SetMeta

func (f *RawFileObject) SetMeta(m FileInfo)

SetMeta add metadata about file

func (*RawFileObject) SetName

func (f *RawFileObject) SetName(n string)

SetName TODO

func (*RawFileObject) SetType

func (f *RawFileObject) SetType(t PackageType)

SetType TODO

func (*RawFileObject) SetVersion

func (f *RawFileObject) SetVersion(v string)

SetVersion TODO

func (*RawFileObject) ShouldSkipIndex

func (f *RawFileObject) ShouldSkipIndex() bool

ShouldSkipIndex TODO

func (*RawFileObject) UnIndex

func (f *RawFileObject) UnIndex(goz GozContext) error

UnIndex remove file from index

type Repo

type Repo struct {
	ID          string            `json:"id"`
	Owner       string            `json:"owner"`
	Description string            `json:"description"`
	Members     []Member          `json:"members"`
	Subject     string            `json:"subject"` // subject id
	Visibility  VisibilityType    `json:"visibility"`
	Meta        map[string]string `json:"meta"` // Metadata package dependant
	Created     int64             `json:"created"`
	LastUpdated int64             `json:"last_updated"`
	HomePage    string            `json:"homepage"`
	IssuesPage  string            `json:"issues"`
	CodePage    string            `json:"code"`
}

Repo is a repository

func (*Repo) CanRead

func (r *Repo) CanRead(goz GozContext) bool

CanRead TODO

func (*Repo) CanWrite

func (r *Repo) CanWrite(goz GozContext) bool

CanWrite TODO

func (*Repo) Create

func (r *Repo) Create(goz GozContext) error

Create a repository

func (*Repo) Delete

func (r *Repo) Delete(goz GozContext) error

Delete removes subject from db

func (*Repo) Exists

func (r *Repo) Exists(goz GozContext) (Repo, error)

Exists checks if subjecrepot exists

func (Repo) Files

func (r Repo) Files(goz GozContext) ([]FileObject, error)

Files returns list of files for a repo

func (*Repo) Get

func (r *Repo) Get(goz GozContext) (Repo, error)

Get returns repository information

func (*Repo) List

func (r *Repo) List(goz GozContext) ([]Repo, error)

List returns repositories information

func (*Repo) ListPackages

func (r *Repo) ListPackages(goz GozContext) ([]Package, error)

ListPackages TODO

func (*Repo) MemberOf

func (r *Repo) MemberOf(goz GozContext, user User) (Profile, bool)

MemberOf checks if user member of repo or subject

func (*Repo) Save

func (r *Repo) Save(goz GozContext) error

Save updates repo info

type RpmConfig

type RpmConfig struct {
	Script string `json:"script"`
}

RpmConfig contains configuration for rpm repos

type RpmFileObject

type RpmFileObject struct {
	RawFileObject
}

RpmFileObject describes a rpm file

func (*RpmFileObject) Index

func (f *RpmFileObject) Index(goz GozContext) error

Index adds file info in elasticsearch

func (*RpmFileObject) UnIndex

func (f *RpmFileObject) UnIndex(goz GozContext) error

UnIndex remove file from index

type RpmRepoFileObject

type RpmRepoFileObject struct {
	RawFileObject
}

RpmRepoFileObject describes a rpm repo file

func (*RpmRepoFileObject) GetPath

func (f *RpmRepoFileObject) GetPath() string

GetPath builds file location

func (*RpmRepoFileObject) Index

func (f *RpmRepoFileObject) Index(goz GozContext) error

Index adds file info in elasticsearch

func (*RpmRepoFileObject) UnIndex

func (f *RpmRepoFileObject) UnIndex(goz GozContext) error

UnIndex remove file from index

type StorageConfig

type StorageConfig struct {
	Type      StorageType     `json:"type"`
	URL       string          `json:"url"`
	Prefix    string          `json:"prefix"`
	Openstack OpenstackConfig `json:"openstack"`
}

StorageConfig defines kind of used storage

type StorageHandler

type StorageHandler interface {
	CreateBucket(goz GozContext, bucket string) error
	SetSecretKey(goz GozContext, bucket string) error
	CreateRepo(goz GozContext, bucket string, repo string) error
	GetObjectURL(goz GozContext, f FileObject, expireMinutes int64) (string, error) // url to object
	SaveObject(goz GozContext, f FileObject, expireMinutes int64) (string, error)
	DeleteObject(goz GozContext, f FileObject, expireMinutes int64) (string, error)
	MD5(goz GozContext, f FileObject) (FileInfo, error)
	SetQuota(goz GozContext, bucket string, plan PlanInfo) error
	GetQuota(goz GozContext, bucket string) (int64, error)
}

StorageHandler interface to storage managers

func NewStorageHandler

func NewStorageHandler(cfg Config) (StorageHandler, error)

NewStorageHandler gets a storage handler according to config

type StorageType

type StorageType int

StorageType defiend kind of storage

const (
	// LocalStorage use local filesystem
	LocalStorage StorageType = 0
	// SwiftStorage use Openstack Swift
	SwiftStorage StorageType = 1
)

type Subject

type Subject struct {
	ID          string         `json:"id"`
	Type        SubjectType    `json:"type"`
	Owner       string         `json:"owner"`    // user id
	Members     []Member       `json:"members"`  // members of organization
	Customer    string         `json:"customer"` // customer id
	Visibility  VisibilityType `json:"visibility"`
	Description string         `json:"description"`
	Created     int64          `json:"created"`
	LastUpdated int64          `json:"last_updated"`
}

Subject is a user or an organization

func (*Subject) CanRead

func (s *Subject) CanRead(goz GozContext) bool

CanRead TODO

func (*Subject) CanRelease

func (s *Subject) CanRelease(goz GozContext) bool

CanRelease determines if user can create releases for this subject

func (*Subject) CanWrite

func (s *Subject) CanWrite(goz GozContext) bool

CanWrite TODO

func (*Subject) Create

func (s *Subject) Create(goz GozContext) error

Create a user or org root

func (*Subject) Delete

func (s *Subject) Delete(goz GozContext) error

Delete removes subject from db

func (*Subject) Exists

func (s *Subject) Exists(goz GozContext) (Subject, error)

Exists checks if subject exists

func (*Subject) GetRepo

func (s *Subject) GetRepo(goz GozContext, repoID string) (Repo, error)

GetRepo gets repository info in *subject*

func (*Subject) List

func (s *Subject) List(goz GozContext) ([]Subject, error)

List returns subjects user is owner or member of

func (*Subject) ListRepo

func (s *Subject) ListRepo(goz GozContext) ([]Repo, error)

ListRepo list repositories info in *subject*

func (*Subject) MemberOf

func (s *Subject) MemberOf(goz GozContext, user User) (Profile, bool)

MemberOf determines if user part of members

func (*Subject) Products

func (s *Subject) Products(goz GozContext) ([]Product, error)

Products list products in *subject*

func (*Subject) Save

func (s *Subject) Save(goz GozContext) error

Save updates subject info

type SubjectType

type SubjectType int

SubjectType defines the kind of subject

const (
	// SubjectPersonal is used for users
	SubjectPersonal SubjectType = 0
	// SubjectOrg is used for organizations
	SubjectOrg SubjectType = 1
)

type SwiftHandler

type SwiftHandler struct {
	LocalFileHandler
	// contains filtered or unexported fields
}

SwiftHandler TODO

func (SwiftHandler) CreateBucket

func (h SwiftHandler) CreateBucket(goz GozContext, bucket string) error

CreateBucket creates a bucket Account will have set the secret key

func (SwiftHandler) CreateRepo

func (h SwiftHandler) CreateRepo(goz GozContext, bucket string, repo string) error

CreateRepo creates repository in bucket

func (SwiftHandler) DeleteObject

func (h SwiftHandler) DeleteObject(goz GozContext, f FileObject, expireMinutes int64) (string, error)

DeleteObject TODO

func (SwiftHandler) GetObjectURL

func (h SwiftHandler) GetObjectURL(goz GozContext, f FileObject, expireMinutes int64) (string, error)

GetObjectURL TODO

func (SwiftHandler) GetQuota

func (h SwiftHandler) GetQuota(goz GozContext, bucket string) (int64, error)

GetQuota returns used quota for bucket

func (*SwiftHandler) Init

func (h *SwiftHandler) Init(goz GozContext) error

Init sets up openstack client

func (SwiftHandler) MD5

func (h SwiftHandler) MD5(goz GozContext, f FileObject) (FileInfo, error)

MD5 gets the md5sum of requested file

func (SwiftHandler) SaveObject

func (h SwiftHandler) SaveObject(goz GozContext, f FileObject, expireMinutes int64) (string, error)

SaveObject TODO

func (SwiftHandler) SetQuota

func (h SwiftHandler) SetQuota(goz GozContext, bucket string, plan PlanInfo) error

SetQuota update quota for bucket according to plan

func (SwiftHandler) SetSecretKey

func (h SwiftHandler) SetSecretKey(goz GozContext, bucket string) error

SetSecretKey update bucket secret key

type TokenMsg

type TokenMsg struct {
	User   User
	Expire int64
}

TokenMsg is a fernet token message data

func CheckTokenString

func CheckTokenString(goz GozContext, token string) (TokenMsg, error)

CheckTokenString decodes fernet token

type User

type User struct {
	ID       string `json:"id"`
	Email    string `json:"email"`
	Origin   string `json:"origin"` // User origin (local, ldap, cas:casid, openid:google, ...)
	Password string `json:"password"`
	APIKey   string `json:"apikey"`
	//Admin       bool        `json:"admin"`    // Is site admin
	Customer    string      `json:"customer"` // Customer id, if empty, will use Guest plan
	Profile     UserProfile `json:"profile"`  // admin, operator, user
	Created     int64       `json:"created"`
	LastUpdated int64       `json:"last_updated"`
	Status      UserStatus  `json:"status"` // 0: user active, 1: user deactivated
	LoginMode   LogMode     `bson:"-"`      // Log via apikey or password
}

User describes a gozilla user

func CheckToken

func CheckToken(goz GozContext, headers http.Header) (user User, err error)

CheckToken checks Fernet token

func CheckTokenOrAnonymous

func CheckTokenOrAnonymous(goz GozContext, headers http.Header, allowAnonymous bool) (user User, err error)

CheckTokenOrAnonymous checks token but can allow anonymous calls (no authorization header nor apikey headers)

func UserAuth

func UserAuth(goz GozContext, login string, apikey string) (user User, err error)

UserAuth authenticate user with his api key

func UserBind

func UserBind(goz GozContext, login string, password string) (user User, err error)

UserBind authenticate user against configured authentication systems

func (*User) Activate

func (u *User) Activate(goz GozContext) error

Activate reactive a user

func (*User) Active

func (u *User) Active() bool

Active checks user status

func (*User) Create

func (u *User) Create(goz GozContext) error

Create a user

func (*User) Deactivate

func (u *User) Deactivate(goz GozContext) error

Deactivate deactivate a user

func (*User) Exists

func (u *User) Exists(goz GozContext) (User, error)

Exists checks if user exists

func (*User) GetPlan

func (u *User) GetPlan(goz GozContext) (PlanInfo, error)

GetPlan returns user plan based on its customer, if no customer or plan defined, use *Guest* plan

func (*User) IsAdmin

func (u *User) IsAdmin() bool

IsAdmin checks if user is admin

func (*User) IsOperator

func (u *User) IsOperator() bool

IsOperator checks if user is an operator or admin

func (*User) OwnedRepos

func (u *User) OwnedRepos(goz GozContext) ([]Repo, error)

OwnedRepos get repos owner by user

func (*User) OwnedSubjects

func (u *User) OwnedSubjects(goz GozContext) ([]Subject, error)

OwnedSubjects get subjects owner by user

func (*User) Register

func (u *User) Register(goz GozContext) error

Register creates a new users

func (*User) Save

func (u *User) Save(goz GozContext) error

Save updates user info

type UserProfile

type UserProfile int

UserProfile type of type of user profile

const (
	// UserProfileUser is a standard user, default
	UserProfileUser UserProfile = 0
	// UserProfileOperator has some super priviledges
	UserProfileOperator UserProfile = 10
	// UserProfileAdmin is a site admin
	UserProfileAdmin UserProfile = 20
)

type UserStatus

type UserStatus int

UserStatus indicates user active/inactive status

const (
	// UserActive  user is active and can access api
	UserActive UserStatus = 0
	// UserInactive user is deactivated and cannot access api
	UserInactive UserStatus = 1
)

type VisibilityType

type VisibilityType int

VisibilityType defines the visibility levels

const (
	// VisibilityPublic visible for anyone
	VisibilityPublic VisibilityType = 0
	// VisibilityProtected accessible to any logged user
	VisibilityProtected VisibilityType = 1
	// VisibilityPrivate visible only by subject/repo members
	VisibilityPrivate VisibilityType = 2
)

type WebConfig

type WebConfig struct {
	Port   int    // 80
	Listen string // 0.0.0.0
}

WebConfig contains server info

Jump to

Keyboard shortcuts

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