Documentation ¶
Index ¶
- Constants
- Variables
- func AskConfirmation(defaultValue bool) (bool, error)
- func CheckHTTPServer(port int) (err error)
- func CheckPasswordHash(password, hash string) bool
- func EncodeAuthBasicHeader(login string, password string) (value string)
- func GenerateRandomID(length int) string
- func GetUserID(provider string, providerID string) string
- func HashPassword(password string) (string, error)
- func IsValidProvider(provider string) bool
- func Logout(resp http.ResponseWriter, sa *SessionAuthenticator)
- func MarshalUpload(upload *Upload, version int) (bytes []byte, err error)
- func RequireError(t *testing.T, err error, message string)
- func StartAPIMockServer(next http.Handler) (shutdown func(), err error)
- func StartAPIMockServerCustomPort(port int, next http.Handler) (shutdown func(), err error)
- func StripPrefix(prefix string, handler http.Handler) http.Handler
- func TestTimeout(f func(), duration time.Duration) (err error)
- func UnmarshalUpload(bytes []byte, upload *Upload) (version int, err error)
- func WriteJSONResponse(resp http.ResponseWriter, obj interface{})
- type Configuration
- func (config *Configuration) AutoClean(value bool)
- func (config *Configuration) GetDownloadDomain() *url.URL
- func (config *Configuration) GetServerURL() *url.URL
- func (config *Configuration) GetUploadWhitelist() []*net.IPNet
- func (config *Configuration) Initialize() (err error)
- func (config *Configuration) IsAutoClean() bool
- func (config *Configuration) IsWhitelisted(ip net.IP) bool
- func (config *Configuration) NewLogger() (log *logger.Logger)
- type ErrorReader
- type File
- type HTTPError
- type PagingQuery
- func (pq *PagingQuery) Paginator() *paginator.Paginator
- func (pq *PagingQuery) WithAfterCursor(cursor string) *PagingQuery
- func (pq *PagingQuery) WithBeforeCursor(cursor string) *PagingQuery
- func (pq *PagingQuery) WithLimit(limit int) *PagingQuery
- func (pq *PagingQuery) WithOrder(order string) *PagingQuery
- type PagingResponse
- type ServerStats
- type SessionAuthenticator
- func (sa *SessionAuthenticator) GenAuthCookies(user *User) (sessionCookie *http.Cookie, xsrfCookie *http.Cookie, err error)
- func (sa *SessionAuthenticator) Logout() (sessionCookie *http.Cookie, xsrfCookie *http.Cookie, err error)
- func (sa *SessionAuthenticator) ParseSessionCookie(value string) (uid string, xsrf string, err error)
- type Setting
- type Token
- type Upload
- func (upload *Upload) GetFile(ID string) (file *File)
- func (upload *Upload) GetFileByReference(ref string) (file *File)
- func (upload *Upload) IsExpired() bool
- func (upload *Upload) NewFile() (file *File)
- func (upload *Upload) PrepareInsert(config *Configuration) (err error)
- func (upload *Upload) PrepareInsertForTests()
- func (upload *Upload) Sanitize()
- type UploadV1
- type User
- type UserStats
Constants ¶
const AuthenticationSignatureKeySettingKey = "authentication_signature_key"
AuthenticationSignatureKeySettingKey setting key for authentication_signature_key
const FileDeleted = "deleted"
FileDeleted when a file has been deleted from the data backend
const FileMissing = "missing"
FileMissing when a file is waiting to be uploaded
const FileRemoved = "removed"
FileRemoved when a file has been removed and can't be downloaded anymore but has not yet been deleted
const FileUploaded = "uploaded"
FileUploaded when a file has been uploaded and is ready to be downloaded
const FileUploading = "uploading"
FileUploading when a file is being uploaded
const ProviderGoogle = "google"
ProviderGoogle for authentication
const ProviderLocal = "local"
ProviderLocal for authentication
const ProviderOVH = "ovh"
ProviderOVH for authentication
Variables ¶
var APIMockServerDefaultPort = 44142
APIMockServerDefaultPort is the default port to use for testing HTTP server
var DummyHandler = http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {})
DummyHandler is a dummy http.Handler
Functions ¶
func AskConfirmation ¶
AskConfirmation from process input
func CheckHTTPServer ¶
CheckHTTPServer for HTTP Server to be UP and running HTTP Server should must respond 404 to URL/not_found to be considered ok
func CheckPasswordHash ¶
CheckPasswordHash check password against bcrypt password hash
func EncodeAuthBasicHeader ¶
EncodeAuthBasicHeader return the base64 version of "login:password"
func GenerateRandomID ¶
GenerateRandomID generates a random string with specified length. Used to generate upload id, tokens, ...
func HashPassword ¶
HashPassword return bcrypt password hash ( with salt )
func IsValidProvider ¶
IsValidProvider return true if the provider string is valid
func Logout ¶
func Logout(resp http.ResponseWriter, sa *SessionAuthenticator)
Logout delete session cookies
func MarshalUpload ¶
MarshalUpload unmarshal upload if version is (1) marshal using UploadV1 format
func RequireError ¶
RequireError is a helper to test the error and it's message
func StartAPIMockServer ¶
StartAPIMockServer starts a new temporary API Server to be used in tests
func StartAPIMockServerCustomPort ¶
StartAPIMockServerCustomPort starts a new temporary API Server using a custom port Adds a middleware that handle the /not_found path called by the CheckHTTPServer function
func StripPrefix ¶
StripPrefix returns a handler that serves HTTP requests removing the given prefix from the request URL's Path It differs from http.StripPrefix by defaulting to "/" and not ""
func TestTimeout ¶
TestTimeout execute a function and return an error if the defined timeout happen before
func UnmarshalUpload ¶
UnmarshalUpload unmarshal upload, if that fails try again with UploadV1 format with files in a map instead of an array
func WriteJSONResponse ¶
func WriteJSONResponse(resp http.ResponseWriter, obj interface{})
WriteJSONResponse serialize the response to json and write it to the HTTP response body
Types ¶
type Configuration ¶
type Configuration struct { Debug bool `json:"-"` DebugRequests bool `json:"-"` LogLevel string `json:"-"` // DEPRECATED since 1.3 ListenAddress string `json:"-"` ListenPort int `json:"-"` Path string `json:"-"` MaxFileSize int64 `json:"maxFileSize"` MaxFilePerUpload int `json:"maxFilePerUpload"` DefaultTTL int `json:"defaultTTL"` MaxTTL int `json:"maxTTL"` SslEnabled bool `json:"-"` SslCert string `json:"-"` SslKey string `json:"-"` NoWebInterface bool `json:"-"` DownloadDomain string `json:"downloadDomain"` EnhancedWebSecurity bool `json:"-"` SourceIPHeader string `json:"-"` UploadWhitelist []string `json:"-"` Authentication bool `json:"authentication"` NoAnonymousUploads bool `json:"noAnonymousUploads"` OneShot bool `json:"oneShot"` Removable bool `json:"removable"` Stream bool `json:"stream"` ProtectedByPassword bool `json:"protectedByPassword"` ProtectedByPasswordForce bool `json:"protectedByPasswordForce"` GoogleAuthentication bool `json:"googleAuthentication"` GoogleAPISecret string `json:"-"` GoogleAPIClientID string `json:"-"` GoogleValidDomains []string `json:"-"` OvhAuthentication bool `json:"ovhAuthentication"` OvhAPIEndpoint string `json:"ovhApiEndpoint"` OvhAPIKey string `json:"-"` OvhAPISecret string `json:"-"` MetadataBackendConfig map[string]interface{} `json:"-"` DataBackend string `json:"-"` DataBackendConfig map[string]interface{} `json:"-"` // contains filtered or unexported fields }
Configuration object
func LoadConfiguration ¶
func LoadConfiguration(file string) (config *Configuration, err error)
LoadConfiguration creates a new empty configuration and try to load specified file with toml library to override default params
func NewConfiguration ¶
func NewConfiguration() (config *Configuration)
NewConfiguration creates a new configuration object with default values
func (*Configuration) AutoClean ¶
func (config *Configuration) AutoClean(value bool)
AutoClean enable or disables the periodical upload cleaning goroutine. This needs to be called before Plik server starts to have effect
func (*Configuration) GetDownloadDomain ¶
func (config *Configuration) GetDownloadDomain() *url.URL
GetDownloadDomain return the parsed download domain URL
func (*Configuration) GetServerURL ¶
func (config *Configuration) GetServerURL() *url.URL
GetServerURL is a helper to get the server HTTP URL
func (*Configuration) GetUploadWhitelist ¶
func (config *Configuration) GetUploadWhitelist() []*net.IPNet
GetUploadWhitelist return the parsed IP upload whitelist
func (*Configuration) Initialize ¶
func (config *Configuration) Initialize() (err error)
Initialize config internal parameters
func (*Configuration) IsAutoClean ¶
func (config *Configuration) IsAutoClean() bool
IsAutoClean return weather or not to start the cleaning goroutine
func (*Configuration) IsWhitelisted ¶
func (config *Configuration) IsWhitelisted(ip net.IP) bool
IsWhitelisted return weather or not the IP matches of the config upload whitelist
func (*Configuration) NewLogger ¶
func (config *Configuration) NewLogger() (log *logger.Logger)
NewLogger returns a new logger instance
type ErrorReader ¶
type ErrorReader struct {
// contains filtered or unexported fields
}
ErrorReader impement io.Reader and return err for every read call attempted
func NewErrorReader ¶
func NewErrorReader(err error) (reader *ErrorReader)
NewErrorReader return a new ErrorReader
func NewErrorReaderString ¶
func NewErrorReaderString(err string) (reader *ErrorReader)
NewErrorReaderString return a new ErrorReader from the provided string
type File ¶
type File struct { ID string `json:"id"` UploadID string `json:"-" gorm:"type:varchar(255) REFERENCES uploads(id) ON UPDATE RESTRICT ON DELETE RESTRICT"` Name string `json:"fileName"` Status string `json:"status"` Md5 string `json:"fileMd5"` Type string `json:"fileType"` Size int64 `json:"fileSize"` Reference string `json:"reference"` BackendDetails string `json:"-"` CreatedAt time.Time `json:"createdAt"` }
File object
func NewFile ¶
func NewFile() (file *File)
NewFile instantiate a new object and generate a random id
func (*File) PrepareInsert ¶
PrepareInsert prepares a new file object to be persisted in DB ( create file ID, link upload ID, check name, ... )
type HTTPError ¶
HTTPError allows to return an error and a HTTP status code
func NewHTTPError ¶
NewHTTPError return a new HTTPError
type PagingQuery ¶
type PagingQuery struct { Before *string `json:"before"` After *string `json:"after"` Limit *int `json:"limit"` Order *string `json:"order"` }
PagingQuery for the paging system
func NewPagingQuery ¶
func NewPagingQuery() (pq *PagingQuery)
NewPagingQuery return a new paging query
func (*PagingQuery) Paginator ¶
func (pq *PagingQuery) Paginator() *paginator.Paginator
Paginator return a new Paginator for the PagingQuery
func (*PagingQuery) WithAfterCursor ¶
func (pq *PagingQuery) WithAfterCursor(cursor string) *PagingQuery
WithAfterCursor set the paging query after cursor and unset the before cursor
func (*PagingQuery) WithBeforeCursor ¶
func (pq *PagingQuery) WithBeforeCursor(cursor string) *PagingQuery
WithBeforeCursor set the paging query before cursor and unset the after cursor
func (*PagingQuery) WithLimit ¶
func (pq *PagingQuery) WithLimit(limit int) *PagingQuery
WithLimit set the paging query limit if limit is a valid positive integer
func (*PagingQuery) WithOrder ¶
func (pq *PagingQuery) WithOrder(order string) *PagingQuery
WithOrder set the paging query order if oder is a valid order string "asc" or "desc"
type PagingResponse ¶
type PagingResponse struct { After *string `json:"after"` Before *string `json:"before"` Results []interface{} `json:"results"` }
PagingResponse for the paging system
func NewPagingResponse ¶
func NewPagingResponse(results interface{}, cursor *paginator.Cursor) (pr *PagingResponse)
NewPagingResponse create a new PagingResponse from query results ( results must be a slice )
type ServerStats ¶
type ServerStats struct { Users int `json:"users"` Uploads int `json:"uploads"` AnonymousUploads int `json:"anonymousUploads"` Files int `json:"files"` TotalSize int64 `json:"totalSize"` AnonymousSize int64 `json:"anonymousTotalSize"` }
ServerStats server statistics
type SessionAuthenticator ¶
SessionAuthenticator to generate and authenticate session cookies
func (*SessionAuthenticator) GenAuthCookies ¶
func (sa *SessionAuthenticator) GenAuthCookies(user *User) (sessionCookie *http.Cookie, xsrfCookie *http.Cookie, err error)
GenAuthCookies generate a sign a jwt session cookie to authenticate a user
func (*SessionAuthenticator) Logout ¶
func (sa *SessionAuthenticator) Logout() (sessionCookie *http.Cookie, xsrfCookie *http.Cookie, err error)
Logout generate logout session cookies
func (*SessionAuthenticator) ParseSessionCookie ¶
func (sa *SessionAuthenticator) ParseSessionCookie(value string) (uid string, xsrf string, err error)
ParseSessionCookie parse and validate the session cookie
type Setting ¶
Setting is a config object meant to be shard by all Plik instances using the metadata backend
func GenerateAuthenticationSignatureKey ¶
func GenerateAuthenticationSignatureKey() (s *Setting)
GenerateAuthenticationSignatureKey create an new random key
type Token ¶
type Token struct { Token string `json:"token" gorm:"primary_key"` Comment string `json:"comment,omitempty"` UserID string `json:"-" gorm:"type:varchar(255) REFERENCES users(id) ON UPDATE RESTRICT ON DELETE CASCADE"` CreatedAt time.Time `json:"createdAt"` }
Token provide a very basic authentication mechanism
func (*Token) Initialize ¶
func (t *Token) Initialize()
Initialize generate the token uuid and sets the creation date
type Upload ¶
type Upload struct { ID string `json:"id"` TTL int `json:"ttl"` DownloadDomain string `json:"downloadDomain"` RemoteIP string `json:"uploadIp,omitempty"` Comments string `json:"comments"` Files []*File `json:"files"` UploadToken string `json:"uploadToken,omitempty"` User string `json:"user,omitempty" gorm:"index:idx_upload_user"` Token string `json:"token,omitempty" gorm:"index:idx_upload_user_token"` IsAdmin bool `json:"admin"` Stream bool `json:"stream"` OneShot bool `json:"oneShot"` Removable bool `json:"removable"` ProtectedByPassword bool `json:"protectedByPassword"` Login string `json:"login,omitempty"` Password string `json:"password,omitempty"` CreatedAt time.Time `json:"createdAt"` DeletedAt *time.Time `json:"-" gorm:"index:idx_upload_deleted_at"` ExpireAt *time.Time `json:"expireAt" gorm:"index:idx_upload_expire_at"` }
Upload object
func (*Upload) GetFileByReference ¶
GetFileByReference get file with Reference from upload files. Return nil if not found
func (*Upload) PrepareInsert ¶
func (upload *Upload) PrepareInsert(config *Configuration) (err error)
PrepareInsert upload for database insert ( check configuration and default values, generate upload and file IDs, ... )
func (*Upload) PrepareInsertForTests ¶
func (upload *Upload) PrepareInsertForTests()
PrepareInsertForTests upload for database insert without config checks and override for testing purpose
type UploadV1 ¶
type UploadV1 struct { ID string `json:"id"` Creation int64 `json:"uploadDate"` TTL int `json:"ttl"` DownloadDomain string `json:"downloadDomain"` RemoteIP string `json:"uploadIp,omitempty"` Comments string `json:"comments"` Files map[string]*File `json:"files"` UploadToken string `json:"uploadToken,omitempty"` User string `json:"user,omitempty"` Token string `json:"token,omitempty"` IsAdmin bool `json:"admin"` Stream bool `json:"stream"` OneShot bool `json:"oneShot"` Removable bool `json:"removable"` ProtectedByPassword bool `json:"protectedByPassword"` Login string `json:"login,omitempty"` Password string `json:"password,omitempty"` ProtectedByYubikey bool `json:"protectedByYubikey"` Yubikey string `json:"yubikey,omitempty"` }
UploadV1 upload object compatible with Plik <1.3
type User ¶
type User struct { ID string `json:"id,omitempty"` Provider string `json:"provider"` Login string `json:"login,omitempty"` Password string `json:"-"` Name string `json:"name,omitempty"` Email string `json:"email,omitempty"` IsAdmin bool `json:"admin"` Tokens []*Token `json:"tokens,omitempty"` CreatedAt time.Time `json:"createdAt"` }
User is a plik user