assets

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: Apache-2.0 Imports: 31 Imported by: 0

README

The asset manager handles the heedy assets.

Assets have the following directory structure:

/plugins - folder holding all plugins ./{plugin-name} ./assets - a folder mirroring the asset manager structure containing file replacements plugin.conf - plugin configuration file ./src - a folder holding python object code README.md - A readme file that holds the plugin description /www - The website to show non-logged-in users index.html (golang template) login.html (golang template - login page to show whenever login is required. Can be shown at other URLs) /app - the app to show logged-in users index.html (golang template - the core html that is served for ALL pages) /setup - the website to show in setup mode index.html (golang template - served for ALL pages) /database - Empty when starting, in this folder the database is held heedy.conf - The heedy configuration file. It is special, in that it is not replaced wholesale by plugins, but rather the options defined in each plugin are overlayed together into a full file.

The root directory of the database is the "final" overlay, in that it overwrites all plugins.

The Router gives the following format

/ <- loads /www/index.html for non-logged-in users, and /app/index.html for logged-in users /www/ - hosts the www folder /app/ - hosts the app folder /api/2/ - hosts the heedy API /api/2/p/{plugin-name}/ - hosts the API for the given plugin /api/2/c/ - hosts the heedy built-in Core API

The asset manager is given:

  • A list of active plugins
  • The path to the directory where heedy was initialized

It returns:

  1. The full configuration based on active plugins
  2. An overlay http.Filesystem for /www, /app, /setup that stays updated with plugin changes

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuiltinAssets

func BuiltinAssets() afero.Fs

BuiltinAssets prepares the assets built into the executable. If no such assets are found, it tries to find an assets folder, and use that, which is useful for debugging and development.

func CopyDir

func CopyDir(srcFs afero.Fs, srcDirPath string, destFs afero.Fs, destDirPath string) error

func CopyFile

func CopyFile(srcFs afero.Fs, srcFilePath string, destFs afero.Fs, destFilePath string) error

func CopyStructIfPtrSet

func CopyStructIfPtrSet(base interface{}, overlay interface{})

CopyStructIfPtrSet copies all pointer params from overlay to base Does not touch arrays and things that don't have identical types

func EnsureEmptyDatabaseFolder added in v0.5.0

func EnsureEmptyDatabaseFolder(dir string) error

func FS

func FS() afero.Fs

FS returns the current filesystem

func GetOutboundIP

func GetOutboundIP() string

https://stackoverflow.com/questions/23558425/how-do-i-get-the-local-ip-address-in-go Get preferred outbound ip of this machine

func MergeMap

func MergeMap(to, from map[string]interface{})

func MergeStringArrays

func MergeStringArrays(base *[]string, overlay *[]string) *[]string

MergeStringArrays allows merging arrays of strings, with the result having each element at most once, and special prefix of + being ignored, and - allowing removal from array

func ParseAddress

func ParseAddress(datadir string, uri string) (address string, err error)

Extracts the unix socket file and request path

func SetGlobal

func SetGlobal(a *Assets)

SetGlobal sets the global assets to the given values

func Validate

func Validate(c *Configuration) error

func WriteConfig

func WriteConfig(filename string, c *Configuration) error

WriteConfig writes the updates available in the given configuration to the given file. It overwrites just the updated values, leaving all others intact

Types

type App

type App struct {
	Name string `json:"name"`

	AutoCreate  *bool `json:"auto_create,omitempty" hcl:"auto_create"`
	Unique      *bool `json:"unique,omitempty" hcl:"unique"`
	AccessToken *bool `json:"access_token,omitempty" hcl:"access_token"`

	Description *string   `json:"description,omitempty" hcl:"description"`
	Icon        *string   `json:"icon,omitempty" hcl:"icon"`
	Scope       *string   `json:"scope,omitempty" hcl:"scope"`
	Enabled     *bool     `json:"enabled,omitempty" hcl:"enabled"`
	Readonly    *[]string `json:"readonly,omitempty" hcl:"readonly"`

	Settings       *map[string]interface{} `json:"settings,omitempty"`
	SettingsSchema *map[string]interface{} `json:"settings_schema,omitempty"`

	Objects map[string]*Object `json:"objects,omitempty"`

	On []Event `hcl:"on,block" json:"on,omitempty"`
}

App represents a app that is to be created on behalf of a plugin

func NewApp

func NewApp() *App

type Assets

type Assets struct {

	// FolderPath is the path where the database is installed.
	// it can be "" if we are running heedy in setup mode,
	// in which case it runs solely on builtin assets
	// This is the only thing that needs to be manually initialized.
	FolderPath string

	// An override to the configuration. It is merged on top of the root configuration
	// before any special processing
	ConfigOverride *Configuration

	// The active configuration. This is loaded automatically
	Config *Configuration

	// The overlay stack. index 0 represents built-in assets. Each index is just that stack element.
	Stack []afero.Fs

	// The overlay filesystems that include the builtin assets, as well as all
	// overrides from active plugins, and user overrides. It is loaded automatically
	FS afero.Fs

	// LogFile used for logging (if custom)
	LogFile *os.File
}

Assets holds the information that comes from loading the database folder, merging it with the built-in assets, and combining

func Create

func Create(opt CreateOptions) (*Assets, error)

Create takes a loaded configuration, as well as a target directory, and creates an associated heedy database. Can also optionally pass in the location of a configuration file which will be copied in, replacing the default config.

func Get

func Get() *Assets

Get returns global asset holder

func Open

func Open(configPath string, override *Configuration) (*Assets, error)

Open opens the assets in a given configuration path

func (*Assets) Abs

func (a *Assets) Abs(p string) string

Abs returns config-relative absolute paths

func (*Assets) AddAdmin

func (a *Assets) AddAdmin(username string) error

func (*Assets) Close added in v0.5.1

func (a *Assets) Close() error

func (*Assets) DataAbs

func (a *Assets) DataAbs(p string) string

DataAbs returns config-relative absolute paths

func (*Assets) DataDir

func (a *Assets) DataDir() string

DataDir returns the directory where data is stored

func (*Assets) IsAdmin

func (a *Assets) IsAdmin(username string) bool

func (*Assets) LogDir added in v0.5.1

func (a *Assets) LogDir() string

func (*Assets) PluginDir

func (a *Assets) PluginDir() string

PluginDir returns the directory where plugin data is stored

func (*Assets) Reload

func (a *Assets) Reload() error

Reload the assets from scratch

func (*Assets) RemAdmin

func (a *Assets) RemAdmin(username string) error

func (*Assets) SwapAdmin

func (a *Assets) SwapAdmin(username, newname string) error

type Configuration

type Configuration struct {
	sync.RWMutex

	Addr           *string   `hcl:"addr" json:"addr,omitempty"`
	URL            *string   `hcl:"url" json:"url,omitempty"`
	API            *string   `hcl:"api" json:"api,omitempty"`
	ActivePlugins  *[]string `hcl:"active_plugins" json:"active_plugins,omitempty"`
	AdminUsers     *[]string `hcl:"admin_users" json:"admin_users,omitempty"`
	ForbiddenUsers *[]string `hcl:"forbidden_users" json:"forbidden_users,omitempty"`

	Language         *string `hcl:"language" json:"language,omitempty"`
	FallbackLanguage *string `hcl:"fallback_language" json:"fallback_language,omitempty"`

	SQL *string `hcl:"sql" json:"sql,omitempty"`

	Frontend *string   `json:"frontend,omitempty"`
	Preload  *[]string `json:"preload,omitempty" hcl:"preload"`

	RunTimeout *string `json:"run_timeout,omitempty"`

	Scope *map[string]string `json:"scope,omitempty" hcl:"scope"`

	ObjectTypes map[string]ObjectType `json:"type,omitempty" hcl:"type"`
	RunTypes    map[string]RunType    `json:"runtype,omitempty"`

	RequestBodyByteLimit *int64 `hcl:"request_body_byte_limit" json:"request_body_byte_limit,omitempty"`
	AllowPublicWebsocket *bool  `hcl:"allow_public_websocket" json:"allow_public_websocket,omitempty"`

	WebsocketHeartbeat    *string `hcl:"websocket_heartbeat" json:"websocket_heartbeat,omitempty"`
	WebsocketWriteTimeout *string `hcl:"websocket_write_timeout" json:"websocket_write_timeout,omitempty"`

	Plugins map[string]*Plugin `json:"plugin,omitempty"`

	LogLevel *string `json:"log_level,omitempty" hcl:"log_level"`
	LogDir   *string `json:"log_dir,omitempty" hcl:"log_dir"`

	// Schema for the core heedy settings
	UserSettingsSchema map[string]interface{} `json:"user_settings_schema,omitempty"`

	// The verbose option is not possible to set in config, it is passed as an arg. It is only here so that it is passed to plugins
	Verbose bool `json:"verbose,omitempty"`
	// contains filtered or unexported fields
}

func Config

func Config() *Configuration

Config returns the global configuration

func LoadConfigBytes

func LoadConfigBytes(src []byte, filename string) (*Configuration, error)

LoadConfigBytes loads the configuration from bytes

func LoadConfigFile

func LoadConfigFile(filename string) (*Configuration, error)

LoadConfigFile loads configuration from file

func MergeConfig

func MergeConfig(base *Configuration, overlay *Configuration) *Configuration

Merges two configurations together

func NewConfiguration

func NewConfiguration() *Configuration

func (*Configuration) Copy

func (c *Configuration) Copy() *Configuration

func (*Configuration) GetAPI

func (c *Configuration) GetAPI() string

func (*Configuration) GetActivePlugins

func (c *Configuration) GetActivePlugins() []string

func (*Configuration) GetAddr

func (c *Configuration) GetAddr() string

func (*Configuration) GetObjectScope

func (c *Configuration) GetObjectScope(objecttype string) (map[string]string, error)

GetObjectScope returns the map of scope

func (*Configuration) GetObjectType

func (c *Configuration) GetObjectType(objecttype string) (*ObjectType, bool)

GetObjectType returns the given object type

func (*Configuration) GetRequestBodyByteLimit

func (c *Configuration) GetRequestBodyByteLimit() int64

func (*Configuration) GetRunTimeout

func (c *Configuration) GetRunTimeout() time.Duration

GetRunTimeout gets timeout for exec

func (*Configuration) GetUserSettingsSchema

func (c *Configuration) GetUserSettingsSchema() map[string]interface{}

func (*Configuration) InsertUserSettingsDefaults

func (c *Configuration) InsertUserSettingsDefaults(prefs map[string]interface{}) (err error)

func (*Configuration) UserIsAdmin

func (c *Configuration) UserIsAdmin(username string) bool

UserIsAdmin checks if the given user is an admin

func (*Configuration) ValidateObjectMeta

func (c *Configuration) ValidateObjectMeta(objecttype string, meta *map[string]interface{}) error

ValidateObjectMeta makes sure that objects have valid metadata

func (*Configuration) ValidateObjectMetaUpdate

func (c *Configuration) ValidateObjectMetaUpdate(objecttype string, meta map[string]interface{}) error

ValidateObjectMetaUpdate makes sure that objects have valid metadata update queries

func (*Configuration) ValidateObjectMetaWithDefaults

func (c *Configuration) ValidateObjectMetaWithDefaults(objecttype string, meta map[string]interface{}) error

ValidateObjectMetaWithDefaults validates the object, additionally setting required values to defaults

func (*Configuration) ValidateUserSettingsUpdate

func (c *Configuration) ValidateUserSettingsUpdate(prefs map[string]interface{}) (err error)

type CreateOptions added in v0.5.1

type CreateOptions struct {
	Directory  string         `json:"directory,omitempty"`
	Config     *Configuration `json:"config,omitempty"`
	ConfigFile string         `json:"config_file,omitempty"`
	Plugins    []string       `json:"plugins,omitempty"`
}

type Event

type Event struct {
	Event  string  `hcl:"event,label" json:"event,omitempty"`
	Type   *string `hcl:"type" json:"type,omitempty"`
	Tags   *string `hcl:"tags" json:"tags,omitempty"`
	Plugin *string `hcl:"plugin" json:"plugin,omitempty"`
	Key    *string `hcl:"key" json:"key,omitempty"`
	Post   *string `hcl:"post" json:"post,omitempty"`
}

func (*Event) Validate

func (e *Event) Validate() error

type JSONSchema

type JSONSchema struct {
	Schema map[string]interface{}
	// contains filtered or unexported fields
}

func NewSchema

func NewSchema(schema map[string]interface{}) (*JSONSchema, error)

func (*JSONSchema) InsertDefaults

func (s *JSONSchema) InsertDefaults(data map[string]interface{})

func (*JSONSchema) Validate

func (s *JSONSchema) Validate(data map[string]interface{}) error

Validate ensures that the passed data conforms to the given schema

func (*JSONSchema) ValidateAndInsertDefaults

func (s *JSONSchema) ValidateAndInsertDefaults(data map[string]interface{}) (err error)

ValidateAndInsertDefaults both validates the given data, and inserts defaults for any missing values in the root object

func (*JSONSchema) ValidateUpdate

func (s *JSONSchema) ValidateUpdate(data map[string]interface{}) (err error)

ValidateUpdate checks an update struct for validity, and resets deleted defaults

func (*JSONSchema) ValidateWithDefaults

func (s *JSONSchema) ValidateWithDefaults(data map[string]interface{}) (err error)

ValidateWithDefaults assumes that defaults are given for missing entries for validation purposes. Does not modify the input data

type Object

type Object struct {
	Name        string                  `json:"name"`
	Type        string                  `json:"type"`
	Description *string                 `json:"description,omitempty"`
	Icon        *string                 `json:"icon,omitempty"`
	Meta        *map[string]interface{} `json:"meta,omitempty"`
	OwnerScope  *string                 `json:"owner_scope,omitempty"`
	Tags        *string                 `json:"tags,omitempty"`

	AutoCreate *bool `json:"auto_create,omitempty" hcl:"auto_create"`

	On []Event `hcl:"on,block" json:"on,omitempty"`
}

Object represents a object that is to be auto-created inside a app on behalf of a plugin

func NewObject

func NewObject() *Object

type ObjectType

type ObjectType struct {
	Frontend *string            `json:"frontend,omitempty" hcl:"frontend,block" cty:"frontend"`
	Routes   *map[string]string `json:"routes,omitempty" hcl:"routes" cty:"routes"`

	MetaSchema *map[string]interface{} `json:"meta_schema,omitempty"`

	Scope *map[string]string `json:"scope,omitempty" hcl:"scope" cty:"scope"`
	// contains filtered or unexported fields
}

func (*ObjectType) Copy

func (s *ObjectType) Copy() ObjectType

func (*ObjectType) ValidateMeta

func (s *ObjectType) ValidateMeta(meta *map[string]interface{}) (err error)

ValidateMeta checks the given metadata is valid

func (*ObjectType) ValidateMetaUpdate

func (s *ObjectType) ValidateMetaUpdate(meta map[string]interface{}) (err error)

ValidateMetaUpdate validates an update query

func (*ObjectType) ValidateMetaWithDefaults

func (s *ObjectType) ValidateMetaWithDefaults(meta map[string]interface{}) (err error)

ValidateMetaWithDefaults takes a meta value, and adds any required defaults to the root object if a default is provided.

type Plugin

type Plugin struct {
	Version      *string `hcl:"version" json:"version,omitempty"`
	Description  *string `hcl:"description" json:"description,omitempty"`
	Icon         *string `hcl:"icon" json:"icon,omitempty"`
	Homepage     *string `hcl:"homepage" json:"homepage,omitempty"`
	License      *string `hcl:"license" json:"license,omitempty"`
	HeedyVersion *string `hcl:"heedy_version" json:"heedy_version,omitempty"`

	Frontend *string   `json:"frontend,omitempty" hcl:"frontend,block" cty:"frontend"`
	Preload  *[]string `json:"preload,omitempty" hcl:"preload"`

	Routes *map[string]string `json:"routes,omitempty"`
	Events *map[string]string `json:"events,omitempty"`

	On []Event `hcl:"on,block" json:"on,omitempty"`

	Run                map[string]Run         `json:"run,omitempty"`
	Config             map[string]interface{} `json:"config,omitempty"`
	ConfigSchema       map[string]interface{} `json:"config_schema,omitempty"`
	UserSettingsSchema map[string]interface{} `json:"user_settings_schema,omitempty"`

	Apps map[string]*App `json:"apps,omitempty"`
	// contains filtered or unexported fields
}

func NewPlugin

func NewPlugin() *Plugin

func (*Plugin) Copy

func (p *Plugin) Copy() *Plugin

func (*Plugin) GetUserSettingsSchema

func (p *Plugin) GetUserSettingsSchema() map[string]interface{}

func (*Plugin) InsertUserSettingsDefaults

func (p *Plugin) InsertUserSettingsDefaults(prefs map[string]interface{}) (err error)

func (*Plugin) ValidateUserSettingsUpdate

func (p *Plugin) ValidateUserSettingsUpdate(prefs map[string]interface{}) (err error)

type PrintOpen

type PrintOpen struct {
	afero.Fs
}

func (PrintOpen) Open

func (r PrintOpen) Open(n string) (afero.File, error)

type Run

type Run struct {
	Type    *string                `hcl:"type" json:"type,omitempty"`
	Enabled *bool                  `hcl:"enabled" json:"enabled,omitempty"`
	Cron    *string                `hcl:"cron" json:"cron,omitempty"`
	Config  map[string]interface{} `json:"config,omitempty"`
}

type RunType

type RunType struct {
	ConfigSchema map[string]interface{} `json:"config_schema,omitempty" hcl:"schema" cty:"schema"`
	API          *string                `json:"api,omitempty" hcl:"api" cty:"api"`
}

func (*RunType) Copy

func (r *RunType) Copy() RunType

Jump to

Keyboard shortcuts

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