Documentation ¶
Index ¶
- Constants
- Variables
- func Abort(inst *instance.Instance, otherURL, token string)
- func CallFinalize(inst *instance.Instance, otherURL, token string, vault bool)
- func CheckImport(inst *instance.Instance, settingsURL string) error
- func CreateRequestClient(inst *instance.Instance) (*oauth.Client, error)
- func ExportCopyData(w io.Writer, inst *instance.Instance, exportDoc *ExportDoc, archiver Archiver, ...) error
- func Finalize(inst *instance.Instance, subdomainType string) error
- func Import(inst *instance.Instance, options ImportOptions) ([]string, error)
- func ImportIsFinished(inst *instance.Instance) bool
- func NotifySharings(inst *instance.Instance) error
- func ScheduleImport(inst *instance.Instance, options ImportOptions) error
- func SendExportFailureMail(inst *instance.Instance) error
- func SendImportDoneMail(inst *instance.Instance, status Status, notInstalled []string) error
- type Archiver
- type Cursor
- type ExportDoc
- func (e *ExportDoc) AcceptDoctype(doctype string) bool
- func (e *ExportDoc) CleanPreviousExports(archiver Archiver) error
- func (e *ExportDoc) Clone() couchdb.Doc
- func (e *ExportDoc) DocType() string
- func (e *ExportDoc) GenerateLink(i *instance.Instance) string
- func (e *ExportDoc) HasExpired() bool
- func (e *ExportDoc) ID() string
- func (e *ExportDoc) Included() []jsonapi.Object
- func (e *ExportDoc) Links() *jsonapi.LinksList
- func (e *ExportDoc) MarksAsFinished(i *instance.Instance, size int64, err error) error
- func (e *ExportDoc) NotifyRealtime()
- func (e *ExportDoc) NotifyTarget(inst *instance.Instance, to *MoveToOptions, token string, ignoreVault bool) error
- func (e *ExportDoc) Relationships() jsonapi.RelationshipMap
- func (e *ExportDoc) Rev() string
- func (e *ExportDoc) SendExportMail(inst *instance.Instance) error
- func (e *ExportDoc) SetID(id string)
- func (e *ExportDoc) SetRev(rev string)
- type ExportOptions
- type FromOptions
- type ImportOptions
- type MoveToOptions
- type Request
- type RequestCredentials
- type Status
- type Store
Constants ¶
const ( // ExportStateExporting is the state used when the export document is being // created. ExportStateExporting = "exporting" // ExportStateDone is used when the export document is finished, without // error. ExportStateDone = "done" // ExportStateError is used when the export document is finshed with error. ExportStateError = "error" )
const ( // ExportDataDir is the directory for storing the documents from CouchDB in // the export archive. ExportDataDir = "My Cozy/Data" // ExportFilesDir is the directory for storing the content of the files in // the export archive. ExportFilesDir = "My Cozy/Files" // ExportVersionsDir is the directory for storing the content of the old // versions of the files in the export archive. ExportVersionsDir = "My Cozy/Versions" )
const ( // MoveScope is the scope requested for a move (when we don't know yet if // the cozy will be the source or the target). MoveScope = consts.ExportsRequests + " " + consts.Imports // SourceClientID is the fake OAuth client ID used for some move endpoints. SourceClientID = "move" )
const DelayBeforeInstanceDeletionAfterMoved = 30 * 24 * time.Hour
DelayBeforeInstanceDeletionAfterMoved is the one month delay before an instance is deleted after it has been moved to a new address.
Variables ¶
var ( // ErrExportNotFound is used when a export document could not be found ErrExportNotFound = echo.NewHTTPError(http.StatusNotFound, "exports: not found") // ErrExportExpired is used when the export document has expired along with // its associated data. ErrExportExpired = echo.NewHTTPError(http.StatusNotFound, "exports: has expired") // ErrMACInvalid is used when the given MAC is not valid. ErrMACInvalid = echo.NewHTTPError(http.StatusUnauthorized, "exports: invalid mac") // ErrExportConflict is used when an export is already being perfomed. ErrExportConflict = echo.NewHTTPError(http.StatusConflict, "export: an archive is already being created") // ErrExportDoesNotContainIndex is used when we could not find the index data // in the archive. ErrExportDoesNotContainIndex = echo.NewHTTPError(http.StatusBadRequest, "export: archive does not contain index data") // ErrExportInvalidCursor is used when the given index cursor is invalid ErrExportInvalidCursor = echo.NewHTTPError(http.StatusBadRequest, "export: cursor is invalid") // ErrNotEnoughSpace is used when the quota is too small to import the files ErrNotEnoughSpace = echo.NewHTTPError(http.StatusRequestEntityTooLarge, "import: not enough disk space") )
Functions ¶
func Abort ¶
Abort will call the /move/abort endpoint on the other instance to unblock it after a failed export or import during a move.
func CallFinalize ¶
CallFinalize will call the /move/finalize endpoint on the other instance to unblock it after a successful move.
func CheckImport ¶
CheckImport returns an error if an exports cannot be found at the given URL, or if the instance has not enough disk space to import the files.
func CreateRequestClient ¶
CreateRequestClient creates an OAuth client that can be used for move requests.
func ExportCopyData ¶
func ExportCopyData(w io.Writer, inst *instance.Instance, exportDoc *ExportDoc, archiver Archiver, cursor Cursor) error
ExportCopyData does an HTTP copy of a part of the file indexes.
func Finalize ¶
Finalize makes the last steps on the source Cozy after the data has been successfully imported: - stop the konnectors - warn the OAuth clients - unblock the instance - ask the manager to delete the instance in one month
func Import ¶
func Import(inst *instance.Instance, options ImportOptions) ([]string, error)
Import downloads the documents and files from an export and add them to the local instance. It returns the list of slugs for apps/konnectors that have not been installed.
func ImportIsFinished ¶
ImportIsFinished returns true unless an import is running
func NotifySharings ¶
NotifySharings will notify other instances with a common sharing that this instance has moved, and will tell them to the new URL to use for the sharing.
func ScheduleImport ¶
func ScheduleImport(inst *instance.Instance, options ImportOptions) error
ScheduleImport blocks the instance and adds a job to import the data from the given URL.
func SendExportFailureMail ¶
SendExportFailureMail sends an email to the user when the export has failed.
func SendImportDoneMail ¶
SendImportDoneMail sends an email to the user when the import is done. The content will depend if the import has been successful or not, and if it was a move or just a import of a tarball.
Types ¶
type Archiver ¶
type Archiver interface { OpenArchive(inst *instance.Instance, exportDoc *ExportDoc) (io.ReadCloser, error) CreateArchive(exportDoc *ExportDoc) (io.WriteCloser, error) RemoveArchives(exportDocs []*ExportDoc) error }
Archiver is an interface describing an abstraction for storing archived data.
func SystemArchiver ¶
func SystemArchiver() Archiver
SystemArchiver returns the global system archiver, corresponding to the user's configuration.
type Cursor ¶
Cursor can be used to know which files must be included in a part.
func ParseCursor ¶
ParseCursor checks that the given cursor is part of our pre-defined list of cursors.
type ExportDoc ¶
type ExportDoc struct { DocID string `json:"_id,omitempty"` DocRev string `json:"_rev,omitempty"` Domain string `json:"domain"` PartsSize int64 `json:"parts_size,omitempty"` PartsCursors []string `json:"parts_cursors"` WithDoctypes []string `json:"with_doctypes,omitempty"` State string `json:"state"` CreatedAt time.Time `json:"created_at"` ExpiresAt time.Time `json:"expires_at"` TotalSize int64 `json:"total_size,omitempty"` CreationDuration time.Duration `json:"creation_duration,omitempty"` Error string `json:"error,omitempty"` }
ExportDoc is a documents storing the metadata of an export.
func CreateExport ¶
CreateExport is used to create a tarball with the data from an instance.
Note: the tarball is a .tar.gz and not a .zip to allow streaming from Swift to the stack, and from the stack to the client, as .tar.gz can be read sequentially and reading a .zip need to seek.
func GetExport ¶
GetExport returns an Export document associated with the given instance and with the given MAC message.
func GetExports ¶
GetExports returns the list of exported documents.
func (*ExportDoc) AcceptDoctype ¶
AcceptDoctype returns true if the documents of the given doctype must be exported.
func (*ExportDoc) CleanPreviousExports ¶
CleanPreviousExports ensures that we have no old exports (or clean them).
func (*ExportDoc) GenerateLink ¶
GenerateLink generates a link to download the export with a MAC.
func (*ExportDoc) HasExpired ¶
HasExpired returns whether or not the export document has expired.
func (*ExportDoc) MarksAsFinished ¶
MarksAsFinished saves the document when the export is done.
func (*ExportDoc) NotifyRealtime ¶
func (e *ExportDoc) NotifyRealtime()
func (*ExportDoc) NotifyTarget ¶
func (e *ExportDoc) NotifyTarget(inst *instance.Instance, to *MoveToOptions, token string, ignoreVault bool) error
NotifyTarget sends an HTTP request to the target so that it can start importing the tarballs.
func (*ExportDoc) Relationships ¶
func (e *ExportDoc) Relationships() jsonapi.RelationshipMap
Relationships implements the jsonapi.Object interface
func (*ExportDoc) SendExportMail ¶
SendExportMail sends a mail to the user with a link where they can download the export tarballs.
type ExportOptions ¶
type ExportOptions struct { PartsSize int64 `json:"parts_size"` MaxAge time.Duration `json:"max_age"` WithDoctypes []string `json:"with_doctypes,omitempty"` ContextualDomain string `json:"contextual_domain,omitempty"` TokenSource string `json:"token_source,omitempty"` IgnoreVault bool `json:"ignore_vault,omitempty"` MoveTo *MoveToOptions `json:"move_to,omitempty"` AdminReq bool `json:"admin_req,omitempty"` }
ExportOptions contains the options for launching the export worker.
type FromOptions ¶
FromOptions is used when the import finishes to notify the source Cozy.
type ImportOptions ¶
type ImportOptions struct { SettingsURL string `json:"url,omitempty"` ManifestURL string `json:"manifest_url,omitempty"` Vault bool `json:"vault,omitempty"` MoveFrom *FromOptions `json:"move_from,omitempty"` }
ImportOptions contains the options for launching the import worker.
type MoveToOptions ¶
type MoveToOptions struct { URL string `json:"url"` Token string `json:"token"` ClientID string `json:"client_id"` ClientSecret string `json:"client_secret"` }
MoveToOptions is used when the export must be sent to another Cozy.
func (*MoveToOptions) ImportsURL ¶
func (m *MoveToOptions) ImportsURL() string
ImportsURL returns the URL on the target for sending the download link to the export tarballs.
type Request ¶
type Request struct { IgnoreVault bool `json:"ignore_vault,omitempty"` SourceCreds RequestCredentials `json:"source_credentials"` TargetCreds RequestCredentials `json:"target_credentials"` Target string `json:"target"` Link string `json:"-"` }
Request is a struct for confirming a move to another Cozy.
func CreateRequest ¶
CreateRequest checks if the parameters are OK for moving, and if yes, it will persist them and return a link that can be used to confirm the move.
func StartMove ¶
StartMove checks that the secret is known, sends a request to the other Cozy to block it during the move, and pushs a job for the export.
func (*Request) ImportingURL ¶
ImportingURL returns the URL on the target for the page to wait until the move is done.
func (*Request) TargetHost ¶
TargetHost returns the host part of the target instance address.
type RequestCredentials ¶
type RequestCredentials struct { Token string `json:"token"` ClientID string `json:"client_id"` ClientSecret string `json:"client_secret"` }
RequestCredentials is struct for OAuth credentials (access_token, client_id and client_secret).
type Status ¶
type Status int
Status is a type for the status of an import.
const ( // StatusMoveSuccess is the status when a move has been successful. StatusMoveSuccess Status = iota + 1 // StatusImportSuccess is the status when a import of a tarball has been // successful. StatusImportSuccess // StatusMoveFailure is the status when the move has failed. StatusMoveFailure // StatusImportFailure is the status when the import has failed. StatusImportFailure )
type Store ¶
type Store interface { GetRequest(db prefixer.Prefixer, secret string) (*Request, error) SaveRequest(db prefixer.Prefixer, req *Request) (string, error) SetAllowDeleteAccounts(db prefixer.Prefixer) error ClearAllowDeleteAccounts(db prefixer.Prefixer) error AllowDeleteAccounts(db prefixer.Prefixer) bool }
Store is essentially an object to store and retrieve move requests