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 HumanDuration(d time.Duration) string
- func IsFeatureAvailable(value string) bool
- func IsFeatureDefault(value string) bool
- func IsValidProvider(provider string) bool
- func Logout(resp http.ResponseWriter, sa *SessionAuthenticator)
- func MarshalUpload(upload *Upload, version int) (bytes []byte, err error)
- func ParseTTL(TTL string) (int, 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 UpdateUser(user *User, userParams *User) (err error)
- func ValidateCustomFeatureFlag(value string, possibleValues []string) (err error)
- func ValidateFeatureFlag(value string) (err error)
- func WriteJSONResponse(resp http.ResponseWriter, obj interface{})
- type BuildInfo
- type CleaningStats
- type Client
- type Configuration
- func (config *Configuration) AutoClean(value bool)
- func (config *Configuration) EnvironmentOverride() (err error)
- func (config *Configuration) GetDownloadDomain() *url.URL
- func (config *Configuration) GetPath() string
- func (config *Configuration) GetServerURL() *url.URL
- func (config *Configuration) GetSessionTimeout() int
- func (config *Configuration) GetTlsVersion() uint16
- func (config *Configuration) GetUploadWhitelist() []*net.IPNet
- func (config *Configuration) Initialize() (err error)
- func (config *Configuration) IsAutoClean() bool
- func (config *Configuration) IsValidDownloadDomain(host string) bool
- func (config *Configuration) IsWhitelisted(ip net.IP) bool
- func (config *Configuration) NewLogger() (log *logger.Logger)
- func (config *Configuration) String() string
- 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 PlikMetrics
- func (m *PlikMetrics) GetRegistry() *prometheus.Registry
- func (m *PlikMetrics) Register(collectors ...prometheus.Collector)
- func (m *PlikMetrics) UpdateCleaningStatistics(stats *CleaningStats, elapsed time.Duration)
- func (m *PlikMetrics) UpdateHTTPMetrics(method string, path string, statusCode int, elapsed time.Duration)
- func (m *PlikMetrics) UpdateServerStatistics(stats *ServerStats, elapsed time.Duration)
- type Release
- 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) ExtendExpirationDate()
- func (upload *Upload) GenerateID()
- func (upload *Upload) GenerateUploadToken()
- func (upload *Upload) GetFile(ID string) (file *File)
- func (upload *Upload) GetFileByReference(ref string) (file *File)
- func (upload *Upload) InitializeForTests()
- func (upload *Upload) IsExpired() bool
- func (upload *Upload) NewFile() (file *File)
- func (upload *Upload) Sanitize(config *Configuration)
- type UploadV1
- type User
- type UserStats
Constants ¶
const AuthenticationSignatureKeySettingKey = "authentication_signature_key"
AuthenticationSignatureKeySettingKey setting key for authentication_signature_key
const FeatureDefault = "default"
FeatureDefault feature is opt-out
const FeatureDisabled = "disabled"
FeatureDisabled feature is always off
const FeatureEnabled = "enabled"
FeatureEnabled feature is opt-in
const FeatureForced = "forced"
FeatureForced feature is always on
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
const SessionCookieName = "plik-session"
SessionCookieName Cookie key
const XSRFCookieName = "plik-xsrf"
XSRFCookieName Cookie key
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 HumanDuration ¶
HumanDuration displays duration with days and years
func IsFeatureAvailable ¶
IsFeatureAvailable return true is the feature is available
func IsFeatureDefault ¶
IsFeatureDefault return true is the feature is enabled by default
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 UpdateUser ¶
UpdateUser update a user object with the params
- prevent to update provider, user ID or login
- only update password if a new one is provided
func ValidateCustomFeatureFlag ¶
ValidateCustomFeatureFlag validates a feature flag string value against a list of possible values
func ValidateFeatureFlag ¶
ValidateFeatureFlag validates a feature flag string value
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 BuildInfo ¶
type BuildInfo struct { Version string `json:"version"` Date int64 `json:"date"` User string `json:"user,omitempty"` Host string `json:"host,omitempty"` GitShortRevision string `json:"gitShortRevision,omitempty"` GitFullRevision string `json:"gitFullRevision,omitempty"` IsRelease bool `json:"isRelease"` IsMint bool `json:"isMint"` GoVersion string `json:"goVersion,omitempty"` Clients []*Client `json:"clients"` Releases []*Release `json:"releases"` }
BuildInfo export build related variables
type CleaningStats ¶
type CleaningStats struct { RemovedUploads int DeletedFiles int DeletedUploads int OrphanFilesCleaned int OrphanTokensCleaned int }
CleaningStats cleaning statistics
type Client ¶
type Client struct { Name string `json:"name"` Md5 string `json:"md5"` Path string `json:"path"` OS string `json:"os"` ARCH string `json:"arch"` }
Client export client build related variables
type Configuration ¶
type Configuration struct { Debug bool `json:"-"` DebugRequests bool `json:"-"` LogLevel string `json:"-"` ListenAddress string `json:"-"` ListenPort int `json:"-"` MetricsAddress string `json:"-"` MetricsPort int `json:"-"` Path string `json:"-"` MaxFileSizeStr string `json:"-"` MaxFileSize int64 `json:"maxFileSize"` MaxUserSizeStr string `json:"-"` MaxUserSize int64 `json:"maxUserSize"` MaxFilePerUpload int `json:"maxFilePerUpload"` DefaultTTLStr string `json:"-"` DefaultTTL int `json:"defaultTTL"` MaxTTLStr string `json:"-"` MaxTTL int `json:"maxTTL"` SslEnabled bool `json:"-"` SslCert string `json:"-"` SslKey string `json:"-"` TlsVersion string `json:"-"` NoWebInterface bool `json:"-"` DownloadDomain string `json:"downloadDomain"` DownloadDomainAlias []string `json:"downloadDomainAlias"` EnhancedWebSecurity bool `json:"-"` SessionTimeout string `json:"-"` AbuseContact string `json:"abuseContact"` WebappDirectory string `json:"-"` ClientsDirectory string `json:"-"` ChangelogDirectory string `json:"-"` SourceIPHeader string `json:"-"` UploadWhitelist []string `json:"-"` // Feature Flags FeatureAuthentication string `json:"feature_authentication"` FeatureOneShot string `json:"feature_one_shot"` FeatureRemovable string `json:"feature_removable"` FeatureStream string `json:"feature_stream"` FeaturePassword string `json:"feature_password"` FeatureComments string `json:"feature_comments"` FeatureSetTTL string `json:"feature_set_ttl"` FeatureExtendTTL string `json:"feature_extend_ttl"` FeatureClients string `json:"feature_clients"` FeatureGithub string `json:"feature_github"` FeatureText string `json:"feature_text"` // Deprecated Feature Flags Authentication bool `json:"authentication"` // Deprecated: >1.3.6 NoAnonymousUploads bool `json:"noAnonymousUploads"` // Deprecated: >1.3.6 OneShot bool `json:"oneShot"` // Deprecated: >1.3.6 Removable bool `json:"removable"` // Deprecated: >1.3.6 Stream bool `json:"stream"` // Deprecated: >1.3.6 ProtectedByPassword bool `json:"protectedByPassword"` // Deprecated: >1.3.6 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(path 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) EnvironmentOverride ¶
func (config *Configuration) EnvironmentOverride() (err error)
EnvironmentOverride override config from environment variables Environment variables must match config params in screaming snake case ( DebugRequests -> PLIKD_DEBUG_REQUESTS )
func (*Configuration) GetDownloadDomain ¶
func (config *Configuration) GetDownloadDomain() *url.URL
GetDownloadDomain return the parsed download domain URL
func (*Configuration) GetPath ¶
func (config *Configuration) GetPath() string
GetPath return the web API/UI root path
func (*Configuration) GetServerURL ¶
func (config *Configuration) GetServerURL() *url.URL
GetServerURL is a helper to get the server HTTP URL
func (*Configuration) GetSessionTimeout ¶
func (config *Configuration) GetSessionTimeout() int
GetSessionTimeout return parsed session timeout
func (*Configuration) GetTlsVersion ¶
func (config *Configuration) GetTlsVersion() uint16
GetTlsVersion is a helper to get the TLS version
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) IsValidDownloadDomain ¶
func (config *Configuration) IsValidDownloadDomain(host string) bool
IsValidDownloadDomain return weather or not the host is a valid download domain
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
func (*Configuration) String ¶
func (config *Configuration) String() string
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:"size:256;constraint:OnUpdate:RESTRICT,OnDelete: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
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 PlikMetrics ¶
type PlikMetrics struct {
// contains filtered or unexported fields
}
PlikMetrics handles Prometheus metrics
func (*PlikMetrics) GetRegistry ¶
func (m *PlikMetrics) GetRegistry() *prometheus.Registry
GetRegistry returns the dedicated Prometheus Registry
func (*PlikMetrics) Register ¶
func (m *PlikMetrics) Register(collectors ...prometheus.Collector)
Register a set of collectors to the dedicated Prometheus registry This can be used by modules to register dedicated metrics
func (*PlikMetrics) UpdateCleaningStatistics ¶
func (m *PlikMetrics) UpdateCleaningStatistics(stats *CleaningStats, elapsed time.Duration)
UpdateCleaningStatistics update metrics about plik cleaning
func (*PlikMetrics) UpdateHTTPMetrics ¶
func (m *PlikMetrics) UpdateHTTPMetrics(method string, path string, statusCode int, elapsed time.Duration)
UpdateHTTPMetrics update metrics about HTTP requests/responses
func (*PlikMetrics) UpdateServerStatistics ¶
func (m *PlikMetrics) UpdateServerStatistics(stats *ServerStats, elapsed time.Duration)
UpdateServerStatistics update metrics about plik metadata
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 ¶
type SessionAuthenticator struct { SignatureKey string SecureCookies bool SessionTimeout int Path string }
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 a new random key
type Token ¶
type Token struct { Token string `json:"token" gorm:"primary_key"` Comment string `json:"comment,omitempty"` UserID string `json:"-" gorm:"size:256;constraint:OnUpdate:RESTRICT,OnDelete:RESTRICT;"` 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"` ExtendTTL bool `json:"extend_ttl"` DownloadDomain string `json:"downloadDomain" gorm:"-"` 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" gorm:"-"` 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 gorm.DeletedAt `json:"-" gorm:"index:idx_upload_deleted_at"` ExpireAt *time.Time `json:"expireAt" gorm:"index:idx_upload_expire_at"` }
Upload object
func (*Upload) ExtendExpirationDate ¶
func (upload *Upload) ExtendExpirationDate()
ExtendExpirationDate extends the upload expiration date by TTL
func (*Upload) GenerateID ¶
func (upload *Upload) GenerateID()
GenerateID generate a new Upload ID and UploadToken
func (*Upload) GenerateUploadToken ¶
func (upload *Upload) GenerateUploadToken()
GenerateUploadToken generate a new UploadToken
func (*Upload) GetFileByReference ¶
GetFileByReference get file with Reference from upload files. Return nil if not found
func (*Upload) InitializeForTests ¶
func (upload *Upload) InitializeForTests()
InitializeForTests initialize upload for database insert without config checks and override for testing purpose
func (*Upload) Sanitize ¶
func (upload *Upload) Sanitize(config *Configuration)
Sanitize clear some fields to hide sensible information from the API.
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"` MaxFileSize int64 `json:"maxFileSize"` MaxUserSize int64 `json:"maxUserSize"` MaxTTL int `json:"maxTTL"` Tokens []*Token `json:"tokens,omitempty"` CreatedAt time.Time `json:"createdAt"` }
User is a Plik user
func CreateUserFromParams ¶
CreateUserFromParams return a user object ready to be inserted in the metadata backend