models

package
v0.0.0-...-bcc45f8 Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NotFoundError error from server
	NotFoundError string = "Not found"
	// ActionNotAllowed error from server
	ActionNotAllowed string = "Action not allowed"
	// WrongLength error from server
	WrongLength string = "Wrong length"
	// ServerError error from server
	ServerError string = "Server Error"
	// WrongInputFormatError wrong user input
	WrongInputFormatError string = "Wrong inputFormat!"
	// InvalidTokenError token is not valid
	InvalidTokenError string = "Token not valid"
	// InvalidCallbackURL token is not valid
	InvalidCallbackURL string = "Callback url is invalid"
	// BatchSizeTooLarge batch is too large
	BatchSizeTooLarge string = "BatchSize soo large!"
	// WrongIntegerFormat integer is probably no integer
	WrongIntegerFormat string = "Number is string"
	// MultipleSourceNameErr err name already exists
	MultipleSourceNameErr string = "You can't have multiple sources with the same name"
	// UserIsInvalidErr err if user is invalid
	UserIsInvalidErr string = "user is invalid"
)
View Source
const (
	// HeaderStatus headername for status in response
	HeaderStatus string = "X-Response-Status"

	// HeaderStatusMessage headername for status in response
	HeaderStatusMessage string = "X-Response-Message"

	// HeaderContentType contenttype of response
	HeaderContentType string = "Content-Type"

	// HeaderFileName filename header
	HeaderFileName string = "X-Filename"

	// HeaderFileID fileid header
	HeaderFileID string = "X-FileID"

	// HeaderEncryption encryption header
	HeaderEncryption string = "X-Encryption"

	// HeaderRequest request content
	HeaderRequest string = "Request"

	// HeaderContentLength request content length
	HeaderContentLength string = "ContentLength"

	// HeaderChecksum files checksum
	HeaderChecksum string = "Checksum"
)
View Source
const SessionTokenLength = 64

SessionTokenLength length of session token

Variables

View Source
var ErrorUserAlreadyExists = errors.New("user already exists")

ErrorUserAlreadyExists error if user exists

Functions

func DirExists

func DirExists(path string) bool

DirExists return true if dir exists

func GetDefaultConfig

func GetDefaultConfig() string

GetDefaultConfig gets the default config path

Types

type Config

type Config struct {
	Server    configServer
	Webserver webserverConf
}

Config config for the server

func InitConfig

func InitConfig(confFile string, createMode bool) (*Config, bool)

InitConfig inits the config Returns true if system should exit

func (*Config) Check

func (config *Config) Check() bool

Check check the config file of logical errors

func (Config) GetDefaultRole

func (config Config) GetDefaultRole() *Role

GetDefaultRole return the path and file for an uploaded file

func (Config) GetHTMLFile

func (config Config) GetHTMLFile(fileName string) string

GetHTMLFile return path of html file

func (Config) GetStaticFile

func (config Config) GetStaticFile(fileName string) string

GetStaticFile return path of html file

func (Config) GetStorageFile

func (config Config) GetStorageFile(fileName string) string

GetStorageFile return the path and file for an uploaded file

func (Config) GetTemplateFile

func (config Config) GetTemplateFile(fileName string) string

GetTemplateFile return path of html file

func (Config) IsRawUseragent

func (config Config) IsRawUseragent(agent string) bool

IsRawUseragent return true if file should be raw depending on useragent

type CountResponse

type CountResponse struct {
	Count uint32 `json:"count"`
}

CountResponse response containing a count of changed items

type CredentialsRequest

type CredentialsRequest struct {
	MachineID string `json:"mid,omitempty"`
	Username  string `json:"username"`
	Password  string `json:"pass"`
}

CredentialsRequest request containing credentials

type IDsResponse

type IDsResponse struct {
	IDs []uint `json:"ids"`
}

IDsResponse response containing a list of ids

type LoginResponse

type LoginResponse struct {
	Token string `json:"token"`
}

LoginResponse response for login

type LoginSession

type LoginSession struct {
	gorm.Model
	User      *User `gorm:"association_autoupdate:false;association_autocreate:false"`
	UserID    uint
	Token     string
	Requests  int64
	MachineID string
}

LoginSession session for loggedin user

func NewSession

func NewSession(user *User, machineID string) *LoginSession

NewSession create new login session

type Namespaceinfo

type Namespaceinfo struct {
	Name   string   `json:"ns"`
	Groups []string `json:"groups"`
}

Namespaceinfo info for namespace

type Permission

type Permission uint8

Permission permission for roles

const (
	NoPermission Permission = iota
	ReadPermission
	Writepermission
)

Permissions

type PingRequest

type PingRequest struct {
	Payload string
}

PingRequest ping request

type ResponseStatus

type ResponseStatus uint8

ResponseStatus the status of response

const (
	//ResponseError if there was an error
	ResponseError ResponseStatus = 0
	//ResponseSuccess if the response is successful
	ResponseSuccess ResponseStatus = 1
)

type Role

type Role struct {
	ID                     uint       `gorm:"pk"`
	RoleName               string     `gorm:"not null"`
	IsAdmin                bool       `gorm:"default:false"`
	AccesForeignNamespaces Permission `gorm:"type:smallint"`
	MaxURLcontentSize      int64
	MaxUploadFileSize      int64
	CreateNamespaces       bool
}

Role roles for user

type StringResponse

type StringResponse struct {
	String string `json:"content"`
}

StringResponse response containing only one string

type StringSliceResponse

type StringSliceResponse struct {
	Slice []string `json:"slice"`
}

StringSliceResponse response containing only one string slice

type UploadType

type UploadType uint8

UploadType type of upload

const (
	FileUploadType UploadType = iota
	URLUploadType
)

Available upload types

type User

type User struct {
	gorm.Model
	Username string
	Password string
	RoleID   uint  `sql:"index"`
	Role     *Role `gorm:"association_autoupdate:false;association_autocreate:false"`
}

User user in db

func GetUserFromSession

func GetUserFromSession(db *gorm.DB, token string) (*User, error)

GetUserFromSession return user from session

func (User) AllowedToUploadURLs

func (user User) AllowedToUploadURLs() bool

AllowedToUploadURLs gets upload limit

func (User) CanCreateNamespaces

func (user User) CanCreateNamespaces() bool

CanCreateNamespaces return true if user can create user namespaces

func (User) CanReadForeignNamespace

func (user User) CanReadForeignNamespace() bool

CanReadForeignNamespace return true if user is allowed to read in foreign namespaces

func (User) CanUploadFiles

func (user User) CanUploadFiles() bool

CanUploadFiles return true if user can upload files

func (User) CanWriteForeignNamespace

func (user User) CanWriteForeignNamespace() bool

CanWriteForeignNamespace return true if user is allowed to write in foreign namespaces

func (*User) GetUsername

func (user *User) GetUsername() string

GetUsername Gets username of user

func (*User) Has

func (user *User) Has(db *gorm.DB, checkPass bool) (bool, error)

Has return true if user exists

func (User) HasUploadLimit

func (user User) HasUploadLimit() bool

HasUploadLimit gets upload limit

func (*User) Login

func (user *User) Login(db *gorm.DB, machineID string) (*LoginSession, error)

Login login user

func (User) Register

func (user User) Register(db *gorm.DB, config *Config) error

Register register user

type UserAttributeDataResponse

type UserAttributeDataResponse struct {
	Namespace []Namespaceinfo `json:"nsData"`
}

UserAttributeDataResponse response for userattribute data

type UserAttributesRequest

type UserAttributesRequest struct {
	Mode uint `json:"m"`
}

UserAttributesRequest request for getting namespaces and groups

Jump to

Keyboard shortcuts

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