application

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler added in v0.3.3

func Handler(globalCtx context.Context, tracker stats.Recorder, platform Platform) *http.ServeMux

Expose lambda handlers by UID (/a/) and by links (/l/)

func HandlerByLinks(globalCtx context.Context, tracker stats.Recorder, platform Platform) http.HandlerFunc

Expose lambda over HTTP handler. First part of path will be used as lambda alias

func HandlerByUID added in v0.3.3

func HandlerByUID(globalCtx context.Context, tracker stats.Recorder, platform Platform) http.HandlerFunc

Expose lambda over HTTP handler. First part of path will be used as lambda UID

Types

type Actions added in v0.3.3

type Actions interface {
	// List of actions defined in Makefile as targets
	Actions() ([]string, error)
	// Do target defined in Makefile. Time limit, global env and out can be nil.
	Do(ctx context.Context, name string, timeLimit time.Duration, globalEnv map[string]string, out io.Writer) error
	// Do scheduled actions based on last run
	DoScheduled(ctx context.Context, lastRun time.Time, globalEnv map[string]string)
}

Lambda functions

type Cases added in v0.3.3

type Cases interface {
	// Create new lambda from remote Git repository. Will work only if SSH key set
	CreateFromGit(ctx context.Context, repo string) (string, error)
	// Create new lambda using provided template
	CreateFromTemplate(ctx context.Context, template templates.Template) (string, error)
	// Create empty lambda
	Create(ctx context.Context) (string, error)
	// Remove lamdba from index and definition
	Remove(uid string) error
	// Get underlying platform
	Platform() Platform
	// Run scheduled actions from all lambda. Saves last run
	RunScheduledActions(ctx context.Context)
	// List of all templates without availability check
	Templates() (map[string]*templates.Template, error)
	// Content of SSH public key if set
	PublicSSHKey() ([]byte, error)
}

High-level use-cases

type Config added in v0.3.3

type Config struct {
	User        string            `json:"user"`                  // user that will be used for jobs
	Environment map[string]string `json:"environment,omitempty"` // global environment
	Links       map[string]string `json:"links,omitempty"`       // links (alias -> uid)
}

func (*Config) ReadFile added in v0.3.3

func (cfg *Config) ReadFile(file string) error

func (Config) WithEnv added in v0.3.3

func (cfg Config) WithEnv(env map[string]string) Config

func (Config) WithUser added in v0.3.3

func (cfg Config) WithUser(user string) Config

func (*Config) WriteFile added in v0.3.3

func (cfg *Config) WriteFile(file string) error

type Definition added in v0.3.3

type Definition struct {
	UID      string              `json:"uid"`
	Aliases  types.JsonStringSet `json:"aliases"`
	Manifest types.Manifest      `json:"manifest"`
	Lambda   Lambda              `json:"-"`
}

type FileSystem added in v0.3.3

type FileSystem interface {
	// List files and dirs
	ListFiles(path string) ([]types.File, error)
	// Get content of file
	ReadFile(path string, output io.Writer) error
	// Write content to file
	WriteFile(path string, input io.Reader) error
	// Remove selected file
	RemoveFile(path string) error
	// Rename local file
	RenameFile(src, dest string) error
	// Pack content of lambda to tar.gz
	Content(tarball io.Writer) error
	// Set content of lambda from tar.gz and apply changes (re-index)
	SetContent(tarball io.Reader) error
}

type Lambda added in v0.3.3

type Lambda interface {
	FileSystem
	Actions
	// Manifest configuration
	Manifest() types.Manifest
	// Update manifest and apply changes (re-index)
	SetManifest(manifest types.Manifest) error
	// Running credentials
	Credentials() *types.Credential
	// Update credentials (could be null) (and apply ownership for files if needed)
	SetCredentials(creds *types.Credential) error
	// Remove lambda
	Remove() error
	// Invoke request, write response. Required header should be set by invoker
	Invoke(ctx context.Context, request types.Request, response io.Writer, globalEnv map[string]string) error
}

Basic invokable entity

Highlights:

  • can be executed
  • can be destroyed
  • can manage files
  • doesn't know about UID and alias

type Platform added in v0.3.3

type Platform interface {
	// Resolved user credentials (could be null)
	Credentials() *types.Credential
	// Platform configuration
	Config() Config
	// Update and apply new configuration
	SetConfig(config Config) error
	// List of all lambdas manifests (unordered) with UID and aliases
	List() []Definition
	// Get lambda by UID (if indexed)
	FindByUID(uid string) (*Definition, error)
	// Get lambda by link/alias (if indexed)
	FindByLink(link string) (*Definition, error)
	// Make link to target UID. Could fail if no target UID exists or link already bound to another lambda. Returns definition of lambda
	Link(targetUID string, linkName string) (*Definition, error)
	// Remove link by name. Returns old linked lambda or null
	Unlink(linkName string) (*Definition, error)
	// Put existent lambda to platform, index it and apply.
	Add(uid string, lambda Lambda) error
	// Remove existent lambda from platform and index (doesn't call underlying Remove() method)
	Remove(uid string)
	// Invoke lambda with platform global environment and logs results to tracker (if set)
	Invoke(ctx context.Context, lambda Lambda, request types.Request, out io.Writer) error
	// Do lambda action target defined in Makefile with platform global environment. Time limit and out can be nil
	Do(ctx context.Context, lambda Lambda, action string, timeLimit time.Duration, out io.Writer) error
}

Platform should index lambda, keep shared info (like env) and apply global configuration

Highlights:

  • should manage index lambda by UID
  • should manage index lambda by Alias
  • should keep shared info
  • remove from index doesn't destroy lambda

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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