plugin

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: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnimplemented = errors.New("unimplemented")

Functions

func ErrPlugin

func ErrPlugin(err string, args ...interface{}) error

func NewMiddleware

func NewMiddleware(p *Plugin, h http.Handler) http.Handler

func NoOverlay

func NoOverlay(db database.DB) database.DB

NoOverlay returns a copy of the database with all overlays removed if it is a PluginDB. This is needed for any queries that are run from object implementations

func UnmarshalObjectMeta

func UnmarshalObjectMeta(r *http.Request, obj interface{}) error

UnmarshalObjectMeta extracts the meta portion from the object, unmarshalling it into the given object. This is because the meta portion of the object is base64 encoded in the X-Heedy-Meta header to avoid unnecessary read queries to the database.

Types

type Middleware

type Middleware struct {
	P *Plugin
	H http.Handler
}

Middleware constructs a Heedy server context for an http handler, allowing to create API handlers compatible with the heedy builtin server. That is, a plugin that uses the middleware can in the future be embedded in Heedy without any changes.

func (*Middleware) ServeHTTP

func (m *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ObjectInfo

type ObjectInfo struct {
	Type         string
	ID           string
	Owner        string
	App          string
	ModifiedDate *string
	Meta         map[string]interface{}
	Access       database.ScopeArray
}

ObjectInfo holds the information sent from heedy as http headers about a object. These headers are only present in requests for object API

func GetObjectInfo

func GetObjectInfo(r *http.Request) (*ObjectInfo, error)

GetObjectInfo prepares all object details that come in as part of a object request

func (*ObjectInfo) AsObject

func (o *ObjectInfo) AsObject() string

AsObject returns the "As" of the object owner, be it a user or an app

type Plugin

type Plugin struct {
	Meta *run.Info
	ADB  *database.AdminDB
}

Plugin contains methods that can be used when generating golang heedy plugins it is the main interface with the main server

func Init

func Init() (*Plugin, error)

Init is to be run right at the start of the plugin, and it can only be run once. It parses the information incoming from heedy, and prepares the relevant methods

func (*Plugin) AdminDB

func (p *Plugin) AdminDB() (*database.AdminDB, error)

AdminDB returns the heedy adminsitrative database. Through the AdminDB, the plugin can make direct sql queries to the database. Be aware that the adminDB does not go through the heedy server at all - it operates directly upon the sql database. For this reason, it is recommended to use PluginDB for queries that can be handled by the heedy server, since the plugin version might not be exactly aligned with the server version, and it might cause compatibility issues. AdminDB is best used for raw sql queries to the database.

func (*Plugin) As

func (p *Plugin) As(entity string) *PluginDB

Returns the PluginDB acting as the given entity

func (*Plugin) Close

func (p *Plugin) Close()

func (*Plugin) InitSQL

func (p *Plugin) InitSQL(name string, version int, updater func(*database.AdminDB, *run.Info, run.BuiltinHelper, int) error) error

InitSQL initializes the plugin's sql portion

func (*Plugin) Logger

func (p *Plugin) Logger() *log.Entry

Logger returns a logger built to be compatible with heedy

func (*Plugin) String

func (p *Plugin) String() string

type PluginDB

type PluginDB struct {
	P       *Plugin
	Entity  string
	Overlay int

	RequestID string
	// contains filtered or unexported fields
}

func (*PluginDB) AdminDB

func (db *PluginDB) AdminDB() *database.AdminDB

func (*PluginDB) BasicRequest

func (db *PluginDB) BasicRequest(method, api string, body io.Reader) error

BasicRequest runs a basic query, and does not return the body unless there was an error

func (*PluginDB) CanCreateObject

func (db *PluginDB) CanCreateObject(s *database.Object) error

func (*PluginDB) CreateApp

func (db *PluginDB) CreateApp(c *database.App) (string, string, error)

func (*PluginDB) CreateObject

func (db *PluginDB) CreateObject(s *database.Object) (string, error)

func (*PluginDB) CreateUser

func (db *PluginDB) CreateUser(u *database.User) error

func (*PluginDB) DelApp

func (db *PluginDB) DelApp(id string) error

func (*PluginDB) DelObject

func (db *PluginDB) DelObject(id string) error

func (*PluginDB) DelUser

func (db *PluginDB) DelUser(name string) error

func (*PluginDB) DelUserSession

func (db *PluginDB) DelUserSession(username, sessionid string) error

func (*PluginDB) Fire

func (db *PluginDB) Fire(e *events.Event)

Fire allows PluginDB to conform to the events.Handler interface, which is used to fire events

func (*PluginDB) GetObjectShares

func (db *PluginDB) GetObjectShares(objectid string) (m map[string]*database.ScopeArray, err error)

func (*PluginDB) ID

func (db *PluginDB) ID() string

func (*PluginDB) ListApps

func (db *PluginDB) ListApps(o *database.ListAppOptions) ([]*database.App, error)

func (*PluginDB) ListObjects

func (db *PluginDB) ListObjects(o *database.ListObjectsOptions) ([]*database.Object, error)

ListObjects lists the given objects

func (*PluginDB) ListUserSessions

func (db *PluginDB) ListUserSessions(username string) (v []database.UserSession, err error)

func (*PluginDB) ListUsers

func (db *PluginDB) ListUsers(o *database.ListUsersOptions) ([]*database.User, error)

func (*PluginDB) NewRequest

func (db *PluginDB) NewRequest(method, path string, body io.Reader) (*http.Request, error)

func (*PluginDB) ReadApp

func (db *PluginDB) ReadApp(id string, o *database.ReadAppOptions) (*database.App, error)

func (*PluginDB) ReadObject

func (db *PluginDB) ReadObject(id string, o *database.ReadObjectOptions) (*database.Object, error)

func (*PluginDB) ReadUser

func (db *PluginDB) ReadUser(name string, o *database.ReadUserOptions) (*database.User, error)

func (*PluginDB) ReadUserPluginSettings

func (db *PluginDB) ReadUserPluginSettings(username string, plugin string) (v map[string]interface{}, err error)

func (*PluginDB) ReadUserSettings

func (db *PluginDB) ReadUserSettings(username string) (v map[string]map[string]interface{}, err error)

func (*PluginDB) ShareObject

func (db *PluginDB) ShareObject(objectid, userid string, sa *database.ScopeArray) error

func (*PluginDB) StringRequest

func (db *PluginDB) StringRequest(method, api string, body io.Reader) (string, error)

func (*PluginDB) Type

func (db *PluginDB) Type() database.DBType

func (*PluginDB) UnmarshalRequest

func (db *PluginDB) UnmarshalRequest(obj interface{}, method, api string, body io.Reader) error

func (*PluginDB) UnshareObject

func (db *PluginDB) UnshareObject(objectid string) error

func (*PluginDB) UnshareObjectFromUser

func (db *PluginDB) UnshareObjectFromUser(objectid, userid string) error

func (*PluginDB) UpdateApp

func (db *PluginDB) UpdateApp(c *database.App) error

func (*PluginDB) UpdateObject

func (db *PluginDB) UpdateObject(s *database.Object) error

func (*PluginDB) UpdateUser

func (db *PluginDB) UpdateUser(u *database.User) error

func (*PluginDB) UpdateUserPluginSettings

func (db *PluginDB) UpdateUserPluginSettings(username string, plugin string, settings map[string]interface{}) error

Jump to

Keyboard shortcuts

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