client

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

Documentation

Index

Constants

View Source
const (
	// DirType is the directory type name
	DirType = "directory"
	// FileType is the file type name
	FileType = "file"
)

Variables

View Source
var ErrWrongPassphrase = errors.New("Unauthorized: wrong passphrase")

ErrWrongPassphrase is used when the passphrase is wrong

Functions

This section is empty.

Types

type AppManifest

type AppManifest struct {
	ID    string `json:"id"`
	Rev   string `json:"rev"`
	Attrs struct {
		Name       string `json:"name"`
		NamePrefix string `json:"name_prefix,omitempty"`
		Editor     string `json:"editor"`
		Icon       string `json:"icon"`

		Type        string           `json:"type,omitempty"`
		License     string           `json:"license,omitempty"`
		Language    string           `json:"language,omitempty"`
		Category    string           `json:"category,omitempty"`
		VendorLink  interface{}      `json:"vendor_link"` // can be a string or []string
		Locales     *json.RawMessage `json:"locales,omitempty"`
		Langs       *json.RawMessage `json:"langs,omitempty"`
		Platforms   *json.RawMessage `json:"platforms,omitempty"`
		Categories  *json.RawMessage `json:"categories,omitempty"`
		Developer   *json.RawMessage `json:"developer,omitempty"`
		Screenshots *json.RawMessage `json:"screenshots,omitempty"`
		Tags        *json.RawMessage `json:"tags,omitempty"`

		Frequency    string           `json:"frequency,omitempty"`
		DataTypes    *json.RawMessage `json:"data_types,omitempty"`
		Doctypes     *json.RawMessage `json:"doctypes,omitempty"`
		Fields       *json.RawMessage `json:"fields,omitempty"`
		Folders      *json.RawMessage `json:"folders,omitempty"`
		Messages     *json.RawMessage `json:"messages,omitempty"`
		OAuth        *json.RawMessage `json:"oauth,omitempty"`
		TimeInterval *json.RawMessage `json:"time_interval,omitempty"`
		ClientSide   bool             `json:"clientSide,omitempty"`

		Slug        string `json:"slug"`
		State       string `json:"state"`
		Source      string `json:"source"`
		Version     string `json:"version"`
		Permissions *map[string]struct {
			Type        string   `json:"type"`
			Description string   `json:"description,omitempty"`
			Verbs       []string `json:"verbs,omitempty"`
			Selector    string   `json:"selector,omitempty"`
			Values      []string `json:"values,omitempty"`
		} `json:"permissions"`
		AvailableVersion string `json:"available_version,omitempty"`

		Parameters json.RawMessage `json:"parameters,omitempty"`

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

		Routes *map[string]struct {
			Folder string `json:"folder"`
			Index  string `json:"index"`
			Public bool   `json:"public"`
		} `json:"routes,omitempty"`

		Services *map[string]struct {
			Type           string `json:"type"`
			File           string `json:"file"`
			Debounce       string `json:"debounce"`
			TriggerOptions string `json:"trigger"`
			TriggerID      string `json:"trigger_id"`
		} `json:"services"`
		Notifications map[string]struct {
			Description     string            `json:"description,omitempty"`
			Collapsible     bool              `json:"collapsible,omitempty"`
			Multiple        bool              `json:"multiple,omitempty"`
			Stateful        bool              `json:"stateful,omitempty"`
			DefaultPriority string            `json:"default_priority,omitempty"`
			TimeToLive      time.Duration     `json:"time_to_live,omitempty"`
			Templates       map[string]string `json:"templates,omitempty"`
			MinInterval     time.Duration     `json:"min_interval,omitempty"`
		} `json:"notifications,omitempty"`

		CreatedAt time.Time `json:"created_at"`
		UpdatedAt time.Time `json:"updated_at"`

		Error string `json:"error,omitempty"`
	} `json:"attributes,omitempty"`
}

AppManifest holds the JSON-API representation of an application.

type AppOptions

type AppOptions struct {
	AppType             string
	Slug                string
	SourceURL           string
	Deactivated         bool
	OverridenParameters *json.RawMessage
}

AppOptions holds the options to install an application.

type Client

type Client struct {
	Addr   string
	Domain string
	Scheme string
	Client *http.Client

	AuthClient  *auth.Client
	AuthScopes  []string
	AuthAccept  auth.UserAcceptFunc
	AuthStorage auth.Storage
	Authorizer  request.Authorizer

	UserAgent string
	Retries   int
	Transport http.RoundTripper
	// contains filtered or unexported fields
}

Client encapsulates the element representing a typical connection to the HTTP api of the cozy-stack.

It holds the elements to authenticate a user, as well as the transport layer used for all the calls to the stack.

func (*Client) ActivateMaintenance

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

ActivateMaintenance is used to activate the maintenance for a konnector

func (*Client) Authenticate

func (c *Client) Authenticate() (request.Authorizer, error)

Authenticate is used to authenticate a client via OAuth.

func (*Client) CountInstances

func (c *Client) CountInstances() (int, error)

CountInstances returns the number of instances.

func (*Client) CreateInstance

func (c *Client) CreateInstance(opts *InstanceOptions) (*Instance, error)

CreateInstance is used to create a new cozy instance of the specified domain and locale.

func (*Client) DeactivateMaintenance

func (c *Client) DeactivateMaintenance(slug string) error

DeactivateMaintenance is used to deactivate the maintenance for a konnector

func (*Client) DestroyInstance

func (c *Client) DestroyInstance(domain string) error

DestroyInstance is used to delete an instance and all its data.

func (*Client) DisableDebug

func (c *Client) DisableDebug(domain string) error

DisableDebug disables the debug mode for the logger of an instance.

func (*Client) DiskUsage

func (c *Client) DiskUsage(domain string, includeTrash bool) (map[string]interface{}, error)

DiskUsage returns the information about disk usage and quota

func (*Client) DownloadByID

func (c *Client) DownloadByID(id string) (io.ReadCloser, error)

DownloadByID is used to download a file's content given its ID. It returns a io.ReadCloser that you can read from.

func (*Client) DownloadByPath

func (c *Client) DownloadByPath(name string) (io.ReadCloser, error)

DownloadByPath is used to download a file's content given its path. It returns a io.ReadCloser that you can read from.

func (*Client) EnableDebug

func (c *Client) EnableDebug(domain string, ttl time.Duration) error

EnableDebug sets the logger of an instance in debug mode.

func (*Client) Export

func (c *Client) Export(domain string) error

Export launch the creation of a tarball to export data from an instance.

func (*Client) GetApp

func (c *Client) GetApp(opts *AppOptions) (*AppManifest, error)

GetApp is used to fetch an application manifest with specified slug

func (*Client) GetDebug

func (c *Client) GetDebug(domain string) (bool, error)

GetDebug is used to known if an instance has its logger in debug mode.

func (*Client) GetDirByID

func (c *Client) GetDirByID(id string) (*Dir, error)

GetDirByID returns a Dir given the specified ID

func (*Client) GetDirByPath

func (c *Client) GetDirByPath(name string) (*Dir, error)

GetDirByPath returns a Dir given the specified path

func (*Client) GetDirOrFileByPath

func (c *Client) GetDirOrFileByPath(name string) (*DirOrFile, error)

GetDirOrFileByPath returns a DirOrFile given the specified path

func (*Client) GetFileByID

func (c *Client) GetFileByID(id string) (*File, error)

GetFileByID returns a File given the specified ID

func (*Client) GetFileByPath

func (c *Client) GetFileByPath(name string) (*File, error)

GetFileByPath returns a File given the specified path

func (*Client) GetInstance

func (c *Client) GetInstance(domain string) (*Instance, error)

GetInstance returns the instance associated with the specified domain.

func (*Client) GetToken

func (c *Client) GetToken(opts *TokenOptions) (string, error)

GetToken is used to generate a token with the specified options.

func (*Client) GetTrigger

func (c *Client) GetTrigger(triggerID string) (*Trigger, error)

GetTrigger return the trigger with the specified ID.

func (*Client) GetTriggers

func (c *Client) GetTriggers(worker string) ([]*Trigger, error)

GetTriggers returns the list of all triggers with the specified worker type.

func (*Client) Import

func (c *Client) Import(domain string, opts *ImportOptions) error

Import launch the import of a tarball with data to put in an instance.

func (*Client) InstallApp

func (c *Client) InstallApp(opts *AppOptions) (*AppManifest, error)

InstallApp is used to install an application.

func (*Client) JobPush

func (c *Client) JobPush(r *JobOptions) (*Job, error)

JobPush is used to push a new job into the job queue.

func (*Client) ListApps

func (c *Client) ListApps(appType string) ([]*AppManifest, error)

ListApps is used to get the list of all installed applications.

func (*Client) ListInstances

func (c *Client) ListInstances() ([]*Instance, error)

ListInstances returns the list of instances recorded on the stack.

func (*Client) ListMaintenances

func (c *Client) ListMaintenances(context string) ([]interface{}, error)

ListMaintenances returns a list of konnectors in maintenance

func (*Client) ListTriggers

func (c *Client) ListTriggers() ([]*Trigger, error)

ListTriggers returns the list of all triggers for an instance.

func (*Client) Mkdir

func (c *Client) Mkdir(name string) (*Dir, error)

Mkdir creates a directory with the specified path. If the directory's parent does not exist, an error is returned.

func (*Client) Mkdirall

func (c *Client) Mkdirall(name string) (*Dir, error)

Mkdirall creates a directory with the specified path. If the directory's parent does not exist, all intermediary parents are created.

func (*Client) ModifyInstance

func (c *Client) ModifyInstance(opts *InstanceOptions) (*Instance, error)

ModifyInstance is used to update an instance.

func (*Client) Move

func (c *Client) Move(from, to string) error

Move is used to move a file or directory from a given path to the other given path

func (*Client) RealtimeClient

func (c *Client) RealtimeClient(opts RealtimeOptions) (*RealtimeChannel, error)

RealtimeClient returns a new RealtimeChannel that instantiate a realtime connection with the client server.

func (*Client) RebuildRedis

func (c *Client) RebuildRedis() error

RebuildRedis puts the triggers in redis.

func (*Client) RegisterOAuthClient

func (c *Client) RegisterOAuthClient(opts *OAuthClientOptions) (map[string]interface{}, error)

RegisterOAuthClient register a new OAuth client associated to the specified instance.

func (*Client) Req

func (c *Client) Req(opts *request.Options) (*http.Response, error)

Req is used to perform a request to the stack given the ReqOptions passed.

func (*Client) RestoreByID

func (c *Client) RestoreByID(id string) error

RestoreByID is used to restore a file or directory from the trash given its ID

func (*Client) RestoreByPath

func (c *Client) RestoreByPath(name string) error

RestoreByPath is used to restore a file or directory from the trash given its path

func (*Client) TrashByID

func (c *Client) TrashByID(id string) error

TrashByID is used to move a file or directory specified by its ID to the trash

func (*Client) TrashByPath

func (c *Client) TrashByPath(name string) error

TrashByPath is used to move a file or directory specified by its path to the trash

func (*Client) TriggerLaunch

func (c *Client) TriggerLaunch(triggerID string) (*Job, error)

TriggerLaunch launches manually the trigger with the specified ID.

func (*Client) UninstallApp

func (c *Client) UninstallApp(opts *AppOptions) (*AppManifest, error)

UninstallApp is used to uninstall an application.

func (*Client) UpdateApp

func (c *Client) UpdateApp(opts *AppOptions, safe bool) (*AppManifest, error)

UpdateApp is used to update an application.

func (*Client) UpdateAttrsByID

func (c *Client) UpdateAttrsByID(id string, patch *FilePatch) (*DirOrFile, error)

UpdateAttrsByID is used to update the attributes of a file or directory of the specified ID

func (*Client) UpdateAttrsByPath

func (c *Client) UpdateAttrsByPath(name string, patch *FilePatch) (*DirOrFile, error)

UpdateAttrsByPath is used to update the attributes of a file or directory of the specified path

func (*Client) Updates

func (c *Client) Updates(opts *UpdatesOptions) error

Updates launch the updating process of the applications. When no Domain is specified, the updates are launched for all the existing instances.

func (*Client) Upload

func (c *Client) Upload(u *Upload) (*File, error)

Upload is used to upload a new file from an using a Upload instance. If the ContentMD5 field is not nil, the file integrity is checked.

func (*Client) WalkByPath

func (c *Client) WalkByPath(root string, walkFn WalkFn) error

WalkByPath is used to walk along the filesystem tree originated at the specified root path.

type Dir

type Dir struct {
	ID    string `json:"id"`
	Rev   string `json:"rev"`
	Attrs struct {
		Type      string    `json:"type"`
		Name      string    `json:"name"`
		DirID     string    `json:"dir_id"`
		Fullpath  string    `json:"path"`
		CreatedAt time.Time `json:"created_at"`
		UpdatedAt time.Time `json:"updated_at"`
		Tags      []string  `json:"tags"`
	} `json:"attributes"`
}

Dir is the JSON-API directory structure

type DirOrFile

type DirOrFile File

DirOrFile is the JSON-API file structure used to encapsulate a file or directory

type File

type File struct {
	ID    string `json:"id"`
	Rev   string `json:"rev"`
	Attrs struct {
		Type       string    `json:"type"`
		Name       string    `json:"name"`
		DirID      string    `json:"dir_id"`
		CreatedAt  time.Time `json:"created_at"`
		UpdatedAt  time.Time `json:"updated_at"`
		Size       int64     `json:"size,string"`
		MD5Sum     []byte    `json:"md5sum"`
		Mime       string    `json:"mime"`
		Class      string    `json:"class"`
		Executable bool      `json:"executable"`
		Tags       []string  `json:"tags"`
	} `json:"attributes"`
}

File is the JSON-API file structure

type FilePatch

type FilePatch struct {
	Rev   string         `json:"-"`
	Attrs FilePatchAttrs `json:"attributes"`
}

FilePatch is the structure used to modify file or directory metadata

type FilePatchAttrs

type FilePatchAttrs struct {
	Name       string    `json:"name,omitempty"`
	DirID      string    `json:"dir_id,omitempty"`
	Tags       []string  `json:"tags,omitempty"`
	UpdatedAt  time.Time `json:"updated_at,omitempty"`
	Executable bool      `json:"executable,omitempty"`
	MD5Sum     []byte    `json:"md5sum,omitempty"`
	Class      string    `json:"class,omitempty"`
}

FilePatchAttrs is the attributes in the JSON-API structure for modifying the metadata of a file or directory

type ImportOptions

type ImportOptions struct {
	ManifestURL string
}

ImportOptions is a struct with the options for importing a tarball.

type Instance

type Instance struct {
	ID   string `json:"id"`
	Meta struct {
		Rev string `json:"rev"`
	} `json:"meta"`
	Attrs struct {
		Domain               string    `json:"domain"`
		DomainAliases        []string  `json:"domain_aliases,omitempty"`
		Prefix               string    `json:"prefix,omitempty"`
		Locale               string    `json:"locale"`
		UUID                 string    `json:"uuid,omitempty"`
		OIDCID               string    `json:"oidc_id,omitempty"`
		ContextName          string    `json:"context,omitempty"`
		TOSSigned            string    `json:"tos,omitempty"`
		TOSLatest            string    `json:"tos_latest,omitempty"`
		AuthMode             int       `json:"auth_mode,omitempty"`
		NoAutoUpdate         bool      `json:"no_auto_update,omitempty"`
		Blocked              bool      `json:"blocked,omitempty"`
		OnboardingFinished   bool      `json:"onboarding_finished"`
		BytesDiskQuota       int64     `json:"disk_quota,string,omitempty"`
		IndexViewsVersion    int       `json:"indexes_version"`
		SwiftLayout          int       `json:"swift_cluster,omitempty"`
		PassphraseResetToken []byte    `json:"passphrase_reset_token"`
		PassphraseResetTime  time.Time `json:"passphrase_reset_time"`
		RegisterToken        []byte    `json:"register_token,omitempty"`
	} `json:"attributes"`
}

Instance is a struct holding the representation of an instance on the API.

func (*Instance) DBPrefix

func (i *Instance) DBPrefix() string

DBPrefix returns the database prefix for the instance

type InstanceOptions

type InstanceOptions struct {
	Domain             string
	DomainAliases      []string
	Locale             string
	UUID               string
	OIDCID             string
	TOSSigned          string
	TOSLatest          string
	Timezone           string
	ContextName        string
	Email              string
	PublicName         string
	Settings           string
	SwiftLayout        int
	DiskQuota          int64
	Apps               []string
	Passphrase         string
	KdfIterations      int
	Debug              *bool
	Blocked            *bool
	Deleting           *bool
	OnboardingFinished *bool
	Trace              *bool
}

InstanceOptions contains the options passed on instance creation.

type Job

type Job struct {
	ID    string `json:"id"`
	Rev   string `json:"rev"`
	Attrs struct {
		Domain    string          `json:"domain"`
		TriggerID string          `json:"trigger_id"`
		Message   json.RawMessage `json:"message"`
		Debounced bool            `json:"debounced"`
		Event     struct {
			Domain string          `json:"domain"`
			Verb   string          `json:"verb"`
			Doc    json.RawMessage `json:"doc"`
			OldDoc json.RawMessage `json:"old,omitempty"`
		} `json:"event"`
		Options   *jobOptions `json:"options"`
		QueuedAt  time.Time   `json:"queued_at"`
		StartedAt time.Time   `json:"started_at"`
		State     string      `json:"state"`
		Worker    string      `json:"worker"`
	} `json:"attributes"`
}

Job is a struct representing a job

type JobLog

type JobLog struct {
	Time    time.Time              `json:"time"`
	Message string                 `json:"message"`
	Level   string                 `json:"level"`
	Data    map[string]interface{} `json:"data"`
}

JobLog is a log being outputted by the running job.

type JobOptions

type JobOptions struct {
	Worker       string
	Arguments    interface{}
	MaxExecCount int
	Timeout      *time.Duration
	Logs         chan *JobLog
}

JobOptions is the options to run a job.

type OAuthClientOptions

type OAuthClientOptions struct {
	Domain                string
	RedirectURI           string
	ClientName            string
	SoftwareID            string
	AllowLoginScope       bool
	OnboardingSecret      string
	OnboardingApp         string
	OnboardingPermissions string
	OnboardingState       string
}

OAuthClientOptions is a struct holding all the options to generate an OAuth client associated to an instance.

type RealtimeChannel

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

RealtimeChannel is used to create a realtime connection with the server. The Channel method can be used to retrieve a channel on which the realtime events can be received.

func (*RealtimeChannel) Channel

func (r *RealtimeChannel) Channel() <-chan *RealtimeServerMessage

Channel returns the channel of realtime server messages received by the client from the server.

func (*RealtimeChannel) Close

func (r *RealtimeChannel) Close() error

Close will close the underlying connection of the realtime channel and close the channel of messages.

type RealtimeClientMessage

type RealtimeClientMessage struct {
	Method  string      `json:"method"`
	Payload interface{} `json:"payload"`
}

RealtimeClientMessage is a struct containing the structure of the client messages sent to the server.

type RealtimeOptions

type RealtimeOptions struct {
	DocTypes []string
}

RealtimeOptions contains the options to create the realtime subscription channel.

type RealtimeServerMessage

type RealtimeServerMessage struct {
	Event   string                `json:"event"`
	Payload RealtimeServerPayload `json:"payload"`
}

RealtimeServerMessage is a struct containing the structure of the server messages received by the client.

type RealtimeServerPayload

type RealtimeServerPayload struct {
	// Response payload
	Type string          `json:"type"`
	ID   string          `json:"id"`
	Doc  json.RawMessage `json:"doc"`

	// Error payload
	Status string `json:"status"`
	Code   string `json:"code"`
	Title  string `json:"title"`
}

RealtimeServerPayload is the payload content of the RealtimeServerMessage.

type TokenOptions

type TokenOptions struct {
	Domain   string
	Subject  string
	Audience string
	Scope    []string
	Expire   *time.Duration
}

TokenOptions is a struct holding all the options to generate a token.

type Trigger

type Trigger struct {
	ID    string `json:"id"`
	Rev   string `json:"rev"`
	Attrs struct {
		Domain     string          `json:"domain"`
		Type       string          `json:"type"`
		WorkerType string          `json:"worker"`
		Arguments  string          `json:"arguments"`
		Debounce   string          `json:"debounce"`
		Message    json.RawMessage `json:"message"`
		Options    *struct {
			MaxExecCount int           `json:"max_exec_count"`
			Timeout      time.Duration `json:"timeout"`
		} `json:"options"`
	} `json:"attributes"`
}

Trigger is a struct representing a trigger

type UpdatesOptions

type UpdatesOptions struct {
	Domain             string
	DomainsWithContext string
	Slugs              []string
	ForceRegistry      bool
	OnlyRegistry       bool
	Logs               chan *JobLog
}

UpdatesOptions is a struct holding all the options to launch an update.

type Upload

type Upload struct {
	Name          string
	DirID         string
	FileID        string
	FileRev       string
	ContentMD5    []byte
	Contents      io.Reader
	ContentType   string
	ContentLength int64
	Overwrite     bool
}

Upload is a struct containing the options of an upload

type WalkFn

type WalkFn func(name string, doc *DirOrFile, err error) error

WalkFn is the function type used by the walk function.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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