config

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: GPL-3.0 Imports: 23 Imported by: 5

Documentation

Overview

Package config provides a simple config management implementation based on JSON files.

Index

Constants

View Source
const (
	UpdateDefaultChannel   = "stable"
	UpdateDefaultServerUrl = "https://updatecells.pydio.com/"
	UpdateDefaultPublicKey = "" /* 424-byte string literal not displayed */
)

Variables

View Source
var ServiceConfig = &service.Config{
	Name:        "com.pydio.CellsSync",
	DisplayName: "Cells Sync",
	Description: "Synchronization tool for Pydio Cells",
	Arguments:   []string{"start", "--headless"},
	Option: map[string]interface{}{
		"RunAtLoad": true,
	},
}

Functions

func AllowedServiceCmd added in v0.8.0

func AllowedServiceCmd(s string) bool

AllowedServiceCmd returns a list of acceptable commands for ControlAppService function.

func ClearKeyring added in v0.9.0

func ClearKeyring(a *Authority) error

ClearKeyring removes tokens from local keychain, if they are present

func ControlAppService added in v0.8.0

func ControlAppService(cmd ServiceCmd) error

ControlAppService sends a command to the service.

func GetAppService added in v0.8.0

func GetAppService(runner func()) (service.Service, error)

GetAppService returns a usable kardianos Service.

func GetHttpAddress added in v0.8.0

func GetHttpAddress() (string, error)

GetHttpAddress tries to bind to an available port between 3636 and 3666 and returns the first port available. This range of port is important for the OAuth2 authentication mechanism as the associated redirect_uris are automatically registered inside the server.

func GetHttpProtocol added in v0.8.0

func GetHttpProtocol() string

GetHttpProtocol returns the protocol to use for binding. Currently only http is supported.

func GetLogsDir added in v0.9.3

func GetLogsDir() (string, error)

func ProcessName added in v0.8.0

func ProcessName(name string) string

ProcessName computes the actual path to current process.

func RunningAsService added in v0.8.0

func RunningAsService() bool

NotRunningAsService overrides service.Interactive() function by additionally checking if service is really installed, as on MacOS the .app is launched by "launchd" just like the service.

func Save

func Save() error

Save writes the config to the JSON file.

func ServiceInstalled added in v0.8.0

func ServiceInstalled() bool

ServiceInstalled checks if background service is installed.

func SetMacService added in v0.8.0

func SetMacService(s bool)

func Status added in v0.8.0

func Status() (service.Status, error)

Status returns the status of the background service.

func SyncClientDataDir

func SyncClientDataDir() string

SyncClientDataDir finds the user directory where to store all application data

func Watch

func Watch() chan interface{}

Watch provides a chan emitting events on config changes.

func WriteToFile

func WriteToFile(config *Global) error

WriteToFile stores a Global config JSON-encoded.

Types

type AuthChange added in v0.8.0

type AuthChange struct {
	Type      string
	Authority *Authority
}

AuthChange is an event emitted when an Authority is updated.

type Authority added in v0.8.0

type Authority struct {
	Id                 string `json:"id"`
	URI                string `json:"uri"`
	InsecureSkipVerify bool   `json:"insecureSkipVerify"`

	ServerLabel   string         `json:"serverLabel"`
	Username      string         `json:"username"`
	LoginDate     time.Time      `json:"loginDate"`
	RefreshDate   time.Time      `json:"refreshDate"`
	TokenStatus   string         `json:"token_status,omitempty"` // Kept for backward compat
	RefreshStatus *RefreshStatus `json:"refreshStatus,omitempty"`
	TasksCount    int            `json:"tasksCount"`

	IdToken      string `json:"id_token"`
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresAt    int    `json:"expires_at"`
}

Authority represent an active account where user has logged in using the OpenID Connect workflow.

func AuthFromKeyring added in v0.9.0

func AuthFromKeyring(a Authority) (Authority, error)

AuthFromKeyring tries to find tokens inside local keychain and feed the conf with them

func AuthToKeyring added in v0.9.0

func AuthToKeyring(a Authority) (Authority, error)

AuthToKeyring tries to store tokens in local keychain and remove them from the conf

func (*Authority) AfterLoad added in v0.9.0

func (a *Authority) AfterLoad()

AfterLoad tries to read tokens from keyring and replace them in the Authority

func (*Authority) BeforeSave added in v0.9.0

func (a *Authority) BeforeSave() *Authority

BeforeSave tries to save tokens in keyring and returns a copy of the Authority without tokens

func (*Authority) LoadInfo added in v0.8.0

func (a *Authority) LoadInfo()

LoadInfo performs a REST query to the server to read the application title, and parses the JWT unsafely to just get a display name for the current user.

func (*Authority) Refresh added in v0.8.0

func (a *Authority) Refresh() error

Refresh uses the RefreshToken to ask for a new IdToken/AccessToken/RefreshToken truple.

func (*Authority) RefreshRequired added in v0.8.0

func (a *Authority) RefreshRequired() (in time.Duration, now bool)

RefreshRequired checks if the current IdToken is still valid or requires renewal.

type Debugging added in v0.8.0

type Debugging struct {
	ShowPanels bool
}

Debugging is a simple section for showing/hiding special debug panels.

type Global

type Global struct {
	Tasks       []*Task
	Authorities []*Authority
	Logs        *Logs
	Updates     *Updates
	Debugging   *Debugging
	Service     *Service
	// contains filtered or unexported fields
}

Global is the main struct representing configs.

func Default

func Default() *Global

Default provides a usable config object. It is loaded from a JSON file.

func LoadFromFile

func LoadFromFile() (*Global, error)

LoadFromFile loads a Global config from a JSON file.

func (*Global) CreateAuthority added in v0.8.0

func (g *Global) CreateAuthority(a *Authority) error

CreateAuthority creates or updates an Authority in the config and emits an AuthChange event.

func (*Global) CreateTask

func (g *Global) CreateTask(t *Task) error

CreateTask adds a Task to the config and emits a TaskChange event "create".

func (*Global) Items

func (g *Global) Items() (items []string)

Items provides a readable list of labels representing sync tasks stored in config.

func (*Global) PublicAuthorities added in v0.8.0

func (g *Global) PublicAuthorities() []*Authority

PublicAuthorities returns the list of Authorities without any sensitive information, and counts the number of active sync tasks on each.

func (*Global) RemoveAuthority added in v0.8.0

func (g *Global) RemoveAuthority(a *Authority) error

RemoveAuthority removes an authority from the config and emits an AuthChange event.

func (*Global) RemoveTask

func (g *Global) RemoveTask(task *Task) error

RemoveTask removes a Task from the config and emits a TaskChange event "remove".

func (*Global) UpdateAuthority added in v0.8.0

func (g *Global) UpdateAuthority(a *Authority, isRefresh bool) error

UpdateAuthority updates an Authority in the config and emits an AuthChange event.

func (*Global) UpdateGlobals

func (g *Global) UpdateGlobals(logs *Logs, updates *Updates, debugging *Debugging, service *Service) error

UpdateGlobals updates various sections of config (each parameter can be nil).

func (*Global) UpdateTask

func (g *Global) UpdateTask(task *Task) error

UpdateTask updates a Task inside the config and emits a TaskChange event "update".

func (*Global) UpdateTaskPaused added in v0.9.2

func (g *Global) UpdateTaskPaused(taskUuid string, paused bool) error

type Logs

type Logs struct {
	Folder         string
	MaxFilesNumber int
	MaxFilesSize   int
	MaxAgeDays     int
}

Logs represents the logs configuration.

func NewLogs

func NewLogs() *Logs

NewLogs creates defaults for Logs.

type RefreshStatus added in v0.9.2

type RefreshStatus struct {
	Valid bool   `json:"valid"`
	Error string `json:"error,omitempty"`
}

type Service added in v0.8.0

type Service struct {
	AutoStart bool
}

Service is a simple section for enabling/disabling shortcuts or service (depending on OS).

type ServiceCmd added in v0.8.0

type ServiceCmd string
const ServiceCmdInstall ServiceCmd = "install"
const ServiceCmdRestart ServiceCmd = "restart"
const ServiceCmdStart ServiceCmd = "start"
const ServiceCmdStop ServiceCmd = "stop"
const ServiceCmdUninstall ServiceCmd = "uninstall"

type ServiceProgram added in v0.8.0

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

func (*ServiceProgram) Start added in v0.8.0

func (p *ServiceProgram) Start(s service.Service) error

Start should not block. Do the actual work async.

func (*ServiceProgram) Stop added in v0.8.0

func (p *ServiceProgram) Stop(s service.Service) error

Stop should not block. Return with a few seconds.

type ShortcutInstaller added in v0.8.0

type ShortcutInstaller interface {
	Install(options ShortcutOptions) error
	Uninstall() error
	IsInstalled() bool
}

ShortcutInstaller provides tools for installing / removing os-shortcuts for automatic startup.

func GetOSShortcutInstaller added in v0.8.0

func GetOSShortcutInstaller() ShortcutInstaller

type ShortcutOptions added in v0.8.0

type ShortcutOptions struct {
	Shortcut  bool
	AutoStart bool
}

ShortcutOptions defines where to create shortcuts.

type Task

type Task struct {
	Uuid           string
	Label          string
	LeftURI        string
	RightURI       string
	Direction      string
	SelectiveRoots []string

	Realtime       bool
	RealtimePaused bool

	LoopInterval string
	HardInterval string
}

Task represents a sync task configuration.

type TaskChange

type TaskChange struct {
	Type string
	Task *Task
}

TaskChange is an event sent when something changes inside the configs tasks.

type Updates

type Updates struct {
	Frequency       string
	DownloadAuto    bool
	UpdateChannel   string
	UpdateUrl       string
	UpdatePublicKey string
}

Updates represents the update-mechanism configuration.

func NewUpdates

func NewUpdates() *Updates

NewUpdates creates defaults for Updates.

Jump to

Keyboard shortcuts

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