api

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2020 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const ClientUserAgent = "Virtual-VGO Client"
View Source
const CtxKeyVVGOIdentity = "vvgo_identity"
View Source
const LoginCookieDuration = 2 * 7 * 24 * 3600 * time.Second // 2 weeks
View Source
const MediaTypeUploadStatusesGob = "application/x.vvgo.pkg.api.upload_statuses.gob"
View Source
const MediaTypeUploadsGob = "application/x.vvgo.pkg.api.uploads.gob"
View Source
const UploadsTimeout = 5 * 60 * time.Second

Variables

View Source
var (
	ErrInvalidUploadType = errors.New("invalid upload type")
	ErrMissingProject    = errors.New("missing project")
	ErrMissingPartNames  = errors.New("missing part names")
	ErrEmptyFileBytes    = errors.New("empty file bytes")
)
View Source
var PublicFiles = "public"

Functions

func Version

func Version(w http.ResponseWriter, r *http.Request)

Types

type AsyncClient

type AsyncClient struct {
	*Client
	AsyncClientConfig
	// contains filtered or unexported fields
}

func NewAsyncClient

func NewAsyncClient(conf AsyncClientConfig) *AsyncClient

func (*AsyncClient) Close

func (x *AsyncClient) Close()

func (*AsyncClient) Status

func (x *AsyncClient) Status() <-chan UploadStatus

func (*AsyncClient) Upload

func (x *AsyncClient) Upload(uploads ...Upload)

type AsyncClientConfig

type AsyncClientConfig struct {
	MaxParallel int
	QueueLength int
	ClientConfig
}

type BackupHandler

type BackupHandler struct {
	Database *Database
	Backups  *storage.Bucket
}

func (BackupHandler) ServeHTTP

func (x BackupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Client

type Client struct {
	ClientConfig
}

func NewClient

func NewClient(config ClientConfig) *Client

func (*Client) Authenticate

func (x *Client) Authenticate() error

Authenticate queries the api server to check that the client has the uploader role. An error returns if the query fails or if the client does not have the uploader role.

func (*Client) Backup

func (x *Client) Backup() error

Backup sends a request to the server to make a backup

func (*Client) GetProject

func (x *Client) GetProject(name string) (*projects.Project, error)

GetProject queries the api server for the project data.

func (*Client) Upload

func (x *Client) Upload(uploads ...Upload) []UploadStatus

type ClientConfig

type ClientConfig struct {
	ServerAddress string
	Token         string
}

type Database

type Database struct {
	Parts    *parts.RedisParts
	Distro   *storage.Bucket
	Sessions *login.Store
}

Database acts as the wrapper/driver for any stateful data.

func (*Database) Backup

func (x *Database) Backup(ctx context.Context) (DatabaseBackup, error)

Backup creates a new DatabaseBackup document.

func (*Database) Restore

func (x *Database) Restore(ctx context.Context, src DatabaseBackup) error

Restore restores the database from the given document. This is a destructive operation, and the first step is to truncate existing Parts data.

type DatabaseBackup

type DatabaseBackup struct {
	// Timestamp when the backup document was created.
	Timestamp time.Time `json:"timestamp"`

	// Parts is the slice of _all_ parts in the database.
	Parts []parts.Part `json:"parts"`

	// ApiVersion is the version of the api server when this database backup was created.
	ApiVersion json.RawMessage `json:"api_version"`
}

DatabaseBackup is a document containing a snapshot of the stateful data we want to backup.

type DownloadHandler

type DownloadHandler map[string]func(ctx context.Context, objectName string) (url string, err error)

Accepts query params `object` and `bucket`. The map key is the bucket param. The map value function should return the url of the object and any error encountered.

func (DownloadHandler) ServeHTTP

func (x DownloadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type IndexView

type IndexView struct{}

func (IndexView) ServeHTTP

func (x IndexView) ServeHTTP(w http.ResponseWriter, r *http.Request)

type LoginView

type LoginView struct {
	Sessions *login.Store
}

func (LoginView) ServeHTTP

func (x LoginView) ServeHTTP(w http.ResponseWriter, r *http.Request)

type LogoutHandler

type LogoutHandler struct {
	Sessions *login.Store
}

LogoutHandler deletes the login session from the incoming request, if it exists.

func (LogoutHandler) ServeHTTP

func (x LogoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type NavBarOpts struct {
	ShowLogin       bool
	ShowMemberLinks bool
	ShowAdminLinks  bool
	PartsActive     bool
	LoginActive     bool
	BackupsActive   bool
}

func NewNavBarOpts

func NewNavBarOpts(ctx context.Context) NavBarOpts

type PartView

type PartView struct {
	*Database
}

func (PartView) ServeHTTP

func (x PartView) ServeHTTP(w http.ResponseWriter, r *http.Request)

type PasswordLoginHandler

type PasswordLoginHandler struct {
	Sessions *login.Store

	// Logins is a map of login user and pass to a slice of roles for that login.
	Logins map[[2]string][]login.Role
}

PasswordLoginHandler authenticates requests using form values user and pass and a static map of valid combinations. If the user pass combo exists in the map, then a login cookie with the mapped roles is create and sent in the response.

func (PasswordLoginHandler) ServeHTTP

type ProjectsHandler

type ProjectsHandler struct{}

func (ProjectsHandler) ServeHTTP

func (x ProjectsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RBACMux

type RBACMux struct {
	Basic    map[[2]string][]login.Role
	Bearer   map[string][]login.Role
	Sessions *login.Store
	*http.ServeMux
}

Authenticate http requests using the sessions api If the request has a valid session or token with the required role, it is allowed access.

func (*RBACMux) Handle

func (auth *RBACMux) Handle(pattern string, handler http.Handler, role login.Role)

func (*RBACMux) HandleFunc

func (auth *RBACMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request), role login.Role)

HandleFunc registers the handler function for the given pattern.

type Server

type Server struct {
	*http.Server
	// contains filtered or unexported fields
}

func NewServer

func NewServer(ctx context.Context, config ServerConfig) *Server

type ServerConfig

type ServerConfig struct {
	ListenAddress     string       `split_words:"true" default:"0.0.0.0:8080"`
	MemberUser        string       `split_words:"true" default:"admin"`
	MemberPass        string       `split_words:"true" default:"admin"`
	UploaderToken     string       `split_words:"true" default:"admin"`
	DeveloperToken    string       `split_words:"true" default:"admin"`
	DistroBucketName  string       `split_words:"true" default:"vvgo-distro"`
	BackupsBucketName string       `split_words:"true" default:"backups"`
	RedisNamespace    string       `split_words:"true" default:"local"`
	Login             login.Config `envconfig:"login"`
}

type Upload

type Upload struct {
	UploadType  `json:"upload_type"`
	PartNames   []string `json:"part_names"`
	Project     string   `json:"project"`
	FileName    string   `json:"file_name"`
	FileBytes   []byte   `json:"file_bytes"`
	ContentType string   `json:"content_type"`
}

func (*Upload) File

func (upload *Upload) File() *storage.File

func (*Upload) Parts

func (upload *Upload) Parts() []parts.Part

func (*Upload) Validate

func (upload *Upload) Validate() error

type UploadHandler

type UploadHandler struct{ *Database }

func (UploadHandler) ServeHTTP

func (x UploadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*UploadHandler) ServeUploads

func (x *UploadHandler) ServeUploads(ctx context.Context, uploads Uploads) []UploadStatus

type UploadStatus

type UploadStatus struct {
	FileName string `json:"file_name"`
	Code     int    `json:"code"`
	Error    string `json:"error,omitempty"`
}

type UploadType

type UploadType string
const (
	UploadTypeClix   UploadType = "clix"
	UploadTypeSheets UploadType = "sheets"
)

func (UploadType) String

func (x UploadType) String() string

type Uploads

type Uploads []Upload

Jump to

Keyboard shortcuts

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