app

package
v0.0.0-...-4b98c26 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: AGPL-3.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ManifestMaxSize is the manifest maximum size
	ManifestMaxSize = 2 << (2 * 10) // 2MB
	// WebappManifestName is the name of the manifest at the root of the
	// client-side application directory
	WebappManifestName = "manifest.webapp"
	// KonnectorManifestName is the name of the manifest at the root of the
	// konnector application directory
	KonnectorManifestName = "manifest.konnector"
)
View Source
const (
	// Installing state
	Installing = "installing"
	// Upgrading state
	Upgrading = "upgrading"
	// Installed state, can be used to state that an application has been
	// installed but needs a user interaction to be activated and "ready".
	Installed = "installed"
	// Ready state
	Ready = "ready"
	// Errored state
	Errored = "errored"
)
View Source
const KonnectorArchiveName = "app.tar"

KonnectorArchiveName is the name of the archive created to store the konnectors sources.

Variables

View Source
var (
	// ErrInvalidSlugName is used when the given slug name is not valid
	ErrInvalidSlugName = errors.New("Invalid slug name")
	// ErrAlreadyExists is used when an application with the specified slug name
	// is already installed.
	ErrAlreadyExists = errors.New("Application with same slug already exists")
	// ErrNotFound is used when no application with specified slug name is
	// installed.
	// Used by Cloudery, don't modify it
	ErrNotFound = errors.New("Application is not installed")
	// ErrNotSupportedSource is used when the source transport or
	// protocol is not supported
	ErrNotSupportedSource = errors.New("Invalid or not supported source scheme")
	// ErrManifestNotReachable is used when the manifest of the
	// application is not reachable
	ErrManifestNotReachable = errors.New("Application manifest is not reachable")
	// ErrSourceNotReachable is used when the given source for
	// application is not reachable
	ErrSourceNotReachable = errors.New("Application source is not reachable")
	// ErrBadManifest when the manifest is not valid or malformed
	ErrBadManifest = errors.New("Application manifest is invalid or malformed")
	// ErrBadState is used when trying to use the application while in a
	// state that is not appropriate for the given operation.
	ErrBadState = errors.New("Application is not in valid state to perform this operation")
	// ErrMissingSource is used when installing an application, but there is no
	// source URL
	ErrMissingSource = errors.New("The source URL for the app is missing")
	// ErrBadChecksum is used when the application checksum does not match the
	// specified one.
	ErrBadChecksum = errors.New("Application checksum does not match")
	// ErrLinkedAppExists is used when an OAuth client is linked to this app
	ErrLinkedAppExists = errors.New("A linked OAuth client exists for this app")
)
View Source
var ManifestClient = &http.Client{
	Timeout: 60 * time.Second,
}

ManifestClient is the client used to HTTP resources from the git fetcher. It is exported for tests purposes only.

Functions

func ActivateMaintenance

func ActivateMaintenance(slug string, opts map[string]interface{}) error

ActivateMaintenance activates maintenance for the given konnector.

func AppsFileServer

func AppsFileServer(i *instance.Instance) appfs.FileServer

AppsFileServer returns the web-application file server associated to this instance.

func Copier

func Copier(appsType consts.AppType, inst *instance.Instance) appfs.Copier

Copier returns the application copier associated with the specified application type

func DeactivateMaintenance

func DeactivateMaintenance(slug string) error

DeactivateMaintenance disables maintenance for the given konnector.

func FSForAppDir

func FSForAppDir(slug string) appfs.FileServer

FSForAppDir returns a FS for the webapp in development.

func GetMaintenanceOptions

func GetMaintenanceOptions(slug string) (map[string]interface{}, error)

GetMaintenanceOptions will return the maintenance options for the given konnector if it is in maintenance on this stack.

func IsMoreRecent

func IsMoreRecent(a, b string) bool

IsMoreRecent returns true if b is greater than a

func KonnectorsFileServer

func KonnectorsFileServer(i *instance.Instance) appfs.FileServer

KonnectorsFileServer returns the web-application file server associated to this instance.

func ListMaintenance

func ListMaintenance() ([]map[string]interface{}, error)

ListMaintenance returns the list of konnectors in maintenance for the stack (not from apps registry).

func SetupAppsDir

func SetupAppsDir(apps map[string]string)

SetupAppsDir allow to load some webapps from directories for development.

func UpgradeInstalledState

func UpgradeInstalledState(inst *instance.Instance, man Manifest) error

UpgradeInstalledState is used to force the legacy "installed" state to "ready" for a webapp or a konnector manifest

Types

type Fetcher

type Fetcher interface {
	// FetchManifest should returns an io.ReadCloser to read the
	// manifest data
	FetchManifest(src *url.URL) (io.ReadCloser, error)
	// Fetch should download the application and install it in the given
	// directory.
	Fetch(src *url.URL, fs appfs.Copier, man Manifest) error
}

Fetcher interface should be implemented by the underlying transport used to fetch the application data.

type Installer

type Installer struct {
	// contains filtered or unexported fields
}

Installer is used to install or update applications.

func NewInstaller

func NewInstaller(in *instance.Instance, fs appfs.Copier, opts *InstallerOptions) (*Installer, error)

NewInstaller creates a new Installer

func (*Installer) Domain

func (i *Installer) Domain() string

Domain return the domain of instance associated with the installer.

func (*Installer) ManifestChannel

func (i *Installer) ManifestChannel() chan Manifest

ManifestChannel returns the channel that can be listened to get updates about the installer run.

func (*Installer) Poll

func (i *Installer) Poll() (Manifest, bool, error)

Poll should be used to monitor the progress of the Installer.

func (*Installer) ReadManifest

func (i *Installer) ReadManifest(state State) (Manifest, error)

ReadManifest will fetch the manifest and read its JSON content into the passed manifest pointer.

The State field of the manifest will be set to the specified state.

func (*Installer) Run

func (i *Installer) Run()

Run will install, update or delete the application linked to the installer, depending on specified operation. It will report its progress or error (see Poll method) and should be run asynchronously inside a new goroutine: `go installer.Run()`.

func (*Installer) RunSync

func (i *Installer) RunSync() (Manifest, error)

RunSync does the same work as Run but can be used synchronously.

func (*Installer) Slug

func (i *Installer) Slug() string

Slug return the slug of the application being installed.

type InstallerOptions

type InstallerOptions struct {
	Type             consts.AppType
	Operation        Operation
	Manifest         Manifest
	Slug             string
	SourceURL        string
	Deactivated      bool
	PermissionsAcked bool
	Registries       []*url.URL

	// Used to override the "Parameters" field of konnectors during installation.
	// This modification is useful to allow the parameterization of a konnector
	// at its installation as we do not have yet a registry up and running.
	OverridenParameters map[string]interface{}
}

InstallerOptions provides the slug name of the application along with the source URL.

type Intent

type Intent struct {
	Action string   `json:"action"`
	Types  []string `json:"type"`
	Href   string   `json:"href"`
}

Intent is a declaration of a service for other client-side apps

type KonnManifest

type KonnManifest struct {
	// contains filtered or unexported fields
}

KonnManifest contains all the informations associated with an installed konnector.

func GetKonnectorBySlug

func GetKonnectorBySlug(db prefixer.Prefixer, slug string) (*KonnManifest, error)

GetKonnectorBySlug fetch the manifest of a konnector from the database given a slug.

func GetKonnectorBySlugAndUpdate

func GetKonnectorBySlugAndUpdate(in *instance.Instance, slug string, copier appfs.Copier, registries []*url.URL) (*KonnManifest, error)

GetKonnectorBySlugAndUpdate fetch the KonnManifest and perform an update of the konnector if necessary and if the konnector was installed from the registry.

func ListKonnectorsWithPagination

func ListKonnectorsWithPagination(db prefixer.Prefixer, limit int, startKey string) ([]*KonnManifest, string, error)

ListKonnectorsWithPagination returns the list of installed konnectors with a pagination

func (*KonnManifest) AppType

func (m *KonnManifest) AppType() consts.AppType

AppType is part of the Manifest interface

func (*KonnManifest) AvailableVersion

func (m *KonnManifest) AvailableVersion() string

AvailableVersion is part of the Manifest interface

func (*KonnManifest) Checksum

func (m *KonnManifest) Checksum() string

Checksum is part of the Manifest interface

func (*KonnManifest) Clone

func (m *KonnManifest) Clone() couchdb.Doc

Clone is part of the Manifest interface

func (*KonnManifest) Create

func (m *KonnManifest) Create(db prefixer.Prefixer) error

Create is part of the Manifest interface

func (*KonnManifest) CreateTrigger

func (m *KonnManifest) CreateTrigger(db prefixer.Prefixer, accountID, createdByApp string) (job.Trigger, error)

CreateTrigger creates a @cron trigger with the parameter from the konnector manifest.

func (*KonnManifest) Delete

func (m *KonnManifest) Delete(db prefixer.Prefixer) error

Delete is part of the Manifest interface

func (*KonnManifest) DocType

func (m *KonnManifest) DocType() string

DocType is part of the Manifest interface

func (*KonnManifest) Error

func (m *KonnManifest) Error() error

Error is part of the Manifest interface

func (*KonnManifest) Fetch

func (m *KonnManifest) Fetch(field string) []string

Fetch is part of the Manifest interface

func (*KonnManifest) ID

func (m *KonnManifest) ID() string

ID is part of the Manifest interface

func (*KonnManifest) Icon

func (m *KonnManifest) Icon() string

Icon returns the konnector icon path.

func (*KonnManifest) Language

func (m *KonnManifest) Language() string

Language returns the programming language used for executing the konnector (only "node" for the moment).

func (*KonnManifest) LastUpdate

func (m *KonnManifest) LastUpdate() time.Time

LastUpdate is part of the Manifest interface

func (*KonnManifest) MarshalJSON

func (m *KonnManifest) MarshalJSON() ([]byte, error)

func (*KonnManifest) Name

func (m *KonnManifest) Name() string

Name returns the konnector name.

func (*KonnManifest) Notifications

func (m *KonnManifest) Notifications() Notifications

Notifications returns the notifications properties for this konnector.

func (*KonnManifest) OnDeleteAccount

func (m *KonnManifest) OnDeleteAccount() string

OnDeleteAccount can be used to specify a file path which will be executed when an account associated with the konnector is deleted.

func (*KonnManifest) Parameters

func (m *KonnManifest) Parameters() map[string]interface{}

Parameters returns the parameters for executing the konnector.

func (*KonnManifest) Permissions

func (m *KonnManifest) Permissions() permission.Set

Permissions is part of the Manifest interface

func (*KonnManifest) ReadManifest

func (m *KonnManifest) ReadManifest(r io.Reader, slug, sourceURL string) (Manifest, error)

ReadManifest is part of the Manifest interface

func (*KonnManifest) Rev

func (m *KonnManifest) Rev() string

Rev is part of the Manifest interface

func (*KonnManifest) SetAvailableVersion

func (m *KonnManifest) SetAvailableVersion(version string)

SetAvailableVersion is part of the Manifest interface

func (*KonnManifest) SetChecksum

func (m *KonnManifest) SetChecksum(shasum string)

SetChecksum is part of the Manifest interface

func (*KonnManifest) SetError

func (m *KonnManifest) SetError(err error)

SetError is part of the Manifest interface

func (*KonnManifest) SetID

func (m *KonnManifest) SetID(id string)

SetID is part of the Manifest interface

func (*KonnManifest) SetRev

func (m *KonnManifest) SetRev(rev string)

SetRev is part of the Manifest interface

func (*KonnManifest) SetSlug

func (m *KonnManifest) SetSlug(slug string)

SetSlug is part of the Manifest interface

func (*KonnManifest) SetSource

func (m *KonnManifest) SetSource(src *url.URL)

SetSource is part of the Manifest interface

func (*KonnManifest) SetState

func (m *KonnManifest) SetState(state State)

SetState is part of the Manifest interface

func (*KonnManifest) SetVersion

func (m *KonnManifest) SetVersion(version string)

SetVersion is part of the Manifest interface

func (*KonnManifest) Slug

func (m *KonnManifest) Slug() string

Slug is part of the Manifest interface

func (*KonnManifest) Source

func (m *KonnManifest) Source() string

Source is part of the Manifest interface

func (*KonnManifest) State

func (m *KonnManifest) State() State

State is part of the Manifest interface

func (*KonnManifest) Terms

func (m *KonnManifest) Terms() Terms

Terms is part of the Manifest interface

func (*KonnManifest) UnmarshalJSON

func (m *KonnManifest) UnmarshalJSON(j []byte) error

func (*KonnManifest) Update

func (m *KonnManifest) Update(db prefixer.Prefixer, extraPerms permission.Set) error

Update is part of the Manifest interface

func (m *KonnManifest) VendorLink() interface{}

VendorLink returns the vendor link.

func (*KonnManifest) Version

func (m *KonnManifest) Version() string

Version is part of the Manifest interface

type Locales

type Locales map[string]struct {
	Name string `json:"name"`
}

Locales is used for the translations of the application name.

type Manifest

type Manifest interface {
	couchdb.Doc
	Fetch(field string) []string
	ReadManifest(i io.Reader, slug, sourceURL string) (Manifest, error)

	Create(db prefixer.Prefixer) error
	Update(db prefixer.Prefixer, extraPerms permission.Set) error
	Delete(db prefixer.Prefixer) error

	AppType() consts.AppType
	Permissions() permission.Set
	Source() string
	Version() string
	AvailableVersion() string
	Checksum() string
	Slug() string
	State() State
	LastUpdate() time.Time
	Terms() Terms

	Name() string
	Icon() string
	Notifications() Notifications

	SetError(err error)
	Error() error

	SetSlug(slug string)
	SetSource(src *url.URL)
	SetState(state State)
	SetVersion(version string)
	SetAvailableVersion(version string)
	SetChecksum(shasum string)
}

Manifest interface is used by installer to encapsulate the manifest metadata that can represent either a webapp or konnector manifest

func DoLazyUpdate

func DoLazyUpdate(in *instance.Instance, man Manifest, copier appfs.Copier, registries []*url.URL) Manifest

DoLazyUpdate tries to update an application before using it

func GetBySlug

func GetBySlug(db prefixer.Prefixer, slug string, appType consts.AppType) (Manifest, error)

GetBySlug returns an app manifest identified by its slug

type Notifications

type Notifications map[string]notification.Properties

Notifications is a map to define the notifications properties used by the application.

type Operation

type Operation int

Operation is the type of operation the installer is created for.

const (
	// Install operation for installing an application
	Install Operation = iota + 1
	// Update operation for updating an application
	Update
	// Delete operation for deleting an application
	Delete
)

type Route

type Route struct {
	Folder string `json:"folder"`
	Index  string `json:"index"`
	Public bool   `json:"public"`
}

Route is a struct to serve a folder inside an app

func (*Route) NotFound

func (c *Route) NotFound() bool

NotFound returns true for a blank route (ie not found by FindRoute)

type Routes

type Routes map[string]Route

Routes is a map for routing inside an application.

type Service

type Service struct {
	Type           string `json:"type"`
	File           string `json:"file"`
	Debounce       string `json:"debounce"`
	TriggerOptions string `json:"trigger"`
	TriggerID      string `json:"trigger_id"`
	// contains filtered or unexported fields
}

Service is a struct to define a service executed by the stack.

type Services

type Services map[string]*Service

Services is a map to define services assciated with an application.

type State

type State string

State is the state of the application

type SubDomainer

type SubDomainer interface {
	SubDomain(s string) *url.URL
}

SubDomainer is an interface with a single method to build an URL from a slug

type Terms

type Terms struct {
	URL     string `json:"url"`
	Version string `json:"version"`
}

Terms of an application/webapp

type WebappManifest

type WebappManifest struct {
	FromAppsDir bool        `json:"-"` // Used in development
	Instance    SubDomainer `json:"-"` // Used for JSON-API links
	// contains filtered or unexported fields
}

WebappManifest contains all the informations associated with an installed web application.

func GetWebappBySlug

func GetWebappBySlug(db prefixer.Prefixer, slug string) (*WebappManifest, error)

GetWebappBySlug fetch the WebappManifest from the database given a slug.

func GetWebappBySlugAndUpdate

func GetWebappBySlugAndUpdate(in *instance.Instance, slug string, copier appfs.Copier, registries []*url.URL) (*WebappManifest, error)

GetWebappBySlugAndUpdate fetch the WebappManifest and perform an update of the application if necessary and if the application was installed from the registry.

func ListWebappsWithPagination

func ListWebappsWithPagination(db prefixer.Prefixer, limit int, startKey string) ([]*WebappManifest, string, error)

ListWebappsWithPagination returns the list of installed web applications with a pagination

func (*WebappManifest) AppType

func (m *WebappManifest) AppType() consts.AppType

AppType is part of the Manifest interface

func (*WebappManifest) AvailableVersion

func (m *WebappManifest) AvailableVersion() string

AvailableVersion is part of the Manifest interface

func (*WebappManifest) Checksum

func (m *WebappManifest) Checksum() string

Checksum is part of the Manifest interface

func (*WebappManifest) Clone

func (m *WebappManifest) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (*WebappManifest) Create

func (m *WebappManifest) Create(db prefixer.Prefixer) error

Create is part of the Manifest interface

func (*WebappManifest) Delete

func (m *WebappManifest) Delete(db prefixer.Prefixer) error

Delete is part of the Manifest interface

func (*WebappManifest) DocType

func (m *WebappManifest) DocType() string

DocType is part of the Manifest interface

func (*WebappManifest) Editor

func (m *WebappManifest) Editor() string

Editor returns the webapp editor.

func (*WebappManifest) Error

func (m *WebappManifest) Error() error

Error is part of the Manifest interface

func (*WebappManifest) Fetch

func (m *WebappManifest) Fetch(field string) []string

Fetch is part of the Manifest interface

func (*WebappManifest) FindIntent

func (m *WebappManifest) FindIntent(action, typ string) *Intent

FindIntent returns an intent for the given action and type if the manifest has one

func (*WebappManifest) FindRoute

func (m *WebappManifest) FindRoute(vpath string) (Route, string)

FindRoute takes a path, returns the route which matches the best, and the part that remains unmatched

func (*WebappManifest) ID

func (m *WebappManifest) ID() string

ID is part of the Manifest interface

func (*WebappManifest) Icon

func (m *WebappManifest) Icon() string

Icon returns the webapp icon path.

func (*WebappManifest) LastUpdate

func (m *WebappManifest) LastUpdate() time.Time

LastUpdate is part of the Manifest interface

func (*WebappManifest) MarshalJSON

func (m *WebappManifest) MarshalJSON() ([]byte, error)

func (*WebappManifest) Name

func (m *WebappManifest) Name() string

Name returns the webapp name.

func (*WebappManifest) NameLocalized

func (m *WebappManifest) NameLocalized(locale string) string

NameLocalized returns the name of the app in the given locale

func (*WebappManifest) NamePrefix

func (m *WebappManifest) NamePrefix() string

NamePrefix returns the webapp name prefix.

func (*WebappManifest) Notifications

func (m *WebappManifest) Notifications() Notifications

Notifications returns the notifications properties for this webapp.

func (*WebappManifest) Permissions

func (m *WebappManifest) Permissions() permission.Set

Permissions is part of the Manifest interface

func (*WebappManifest) ReadManifest

func (m *WebappManifest) ReadManifest(r io.Reader, slug, sourceURL string) (Manifest, error)

ReadManifest is part of the Manifest interface

func (*WebappManifest) Rev

func (m *WebappManifest) Rev() string

Rev is part of the Manifest interface

func (*WebappManifest) Services

func (m *WebappManifest) Services() Services

func (*WebappManifest) SetAvailableVersion

func (m *WebappManifest) SetAvailableVersion(version string)

SetAvailableVersion is part of the Manifest interface

func (*WebappManifest) SetChecksum

func (m *WebappManifest) SetChecksum(shasum string)

SetChecksum is part of the Manifest interface

func (*WebappManifest) SetError

func (m *WebappManifest) SetError(err error)

SetError is part of the Manifest interface

func (*WebappManifest) SetID

func (m *WebappManifest) SetID(id string)

SetID is part of the Manifest interface

func (*WebappManifest) SetRev

func (m *WebappManifest) SetRev(rev string)

SetRev is part of the Manifest interface

func (*WebappManifest) SetSlug

func (m *WebappManifest) SetSlug(slug string)

SetSlug is part of the Manifest interface

func (*WebappManifest) SetSource

func (m *WebappManifest) SetSource(src *url.URL)

SetSource is part of the Manifest interface

func (*WebappManifest) SetState

func (m *WebappManifest) SetState(state State)

SetState is part of the Manifest interface

func (*WebappManifest) SetVersion

func (m *WebappManifest) SetVersion(version string)

SetVersion is part of the Manifest interface

func (*WebappManifest) Slug

func (m *WebappManifest) Slug() string

Slug is part of the Manifest interface

func (*WebappManifest) Source

func (m *WebappManifest) Source() string

Source is part of the Manifest interface

func (*WebappManifest) State

func (m *WebappManifest) State() State

State is part of the Manifest interface

func (*WebappManifest) Terms

func (m *WebappManifest) Terms() Terms

Terms is part of the Manifest interface

func (*WebappManifest) UnmarshalJSON

func (m *WebappManifest) UnmarshalJSON(j []byte) error

func (*WebappManifest) Update

func (m *WebappManifest) Update(db prefixer.Prefixer, extraPerms permission.Set) error

Update is part of the Manifest interface

func (*WebappManifest) Version

func (m *WebappManifest) Version() string

Version is part of the Manifest interface

Jump to

Keyboard shortcuts

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