{"modulePath":"github.com/Beyond-Technology/cozy-stack","version":"v0.0.0-20211207222605-4b98c26c30b6","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package instance\n\n## Constants\n\n```go\nconst (\n\tRegisterTokenLen      = 16\n\tPasswordResetTokenLen = 16\n\tSessionSecretLen      = 64\n\tOauthSecretLen        = 128\n)\n```\nThis is the lengths of our tokens (in bytes).\n\n```go\nconst DefaultTemplateTitle = \"Cozy\"\n```\nDefaultTemplateTitle represents the default template title. It could be overrided by configuring it in the instance context parameters\n\n```go\nconst PBKDF2_SHA256 = 0\n```\nPBKDF2\\_SHA256 is the value of kdf for using PBKDF2 with SHA256 to hash the password on client side.\n\n## Variables\n\n```go\nvar (\n\t// ErrNotFound is used when the seeked instance was not found\n\tErrNotFound = errors.New(\"Instance not found\")\n\t// ErrExists is used the instance already exists\n\tErrExists = errors.New(\"Instance already exists\")\n\t// ErrIllegalDomain is used when the domain named contains illegal characters\n\tErrIllegalDomain = errors.New(\"Domain name contains illegal characters\")\n\t// ErrMissingToken is returned by RegisterPassphrase if token is empty\n\tErrMissingToken = errors.New(\"Empty register token\")\n\t// ErrInvalidToken is returned by RegisterPassphrase if token is invalid\n\tErrInvalidToken = errors.New(\"Invalid register token\")\n\t// ErrMissingPassphrase is returned when the new passphrase is missing\n\tErrMissingPassphrase = errors.New(\"Missing new passphrase\")\n\t// ErrInvalidPassphrase is returned when the passphrase is invalid\n\tErrInvalidPassphrase = errors.New(\"Invalid passphrase\")\n\t// ErrInvalidTwoFactor is returned when the two-factor authentication\n\t// verification is invalid.\n\tErrInvalidTwoFactor = errors.New(\"Invalid two-factor parameters\")\n\t// ErrResetAlreadyRequested is returned when a passphrase reset token is already set and valid\n\tErrResetAlreadyRequested = errors.New(\"The passphrase reset has already been requested\")\n\t// ErrUnknownAuthMode is returned when an unknown authentication mode is\n\t// used.\n\tErrUnknownAuthMode = errors.New(\"Unknown authentication mode\")\n\t// ErrBadTOSVersion is returned when a malformed TOS version is provided.\n\tErrBadTOSVersion = errors.New(\"Bad format for TOS version\")\n\t// ErrInvalidSwiftLayout is returned when the Swift layout is unknown.\n\tErrInvalidSwiftLayout = errors.New(\"Invalid Swift layout\")\n\t// ErrDeletionAlreadyRequested is returned when a deletion has already been requested.\n\tErrDeletionAlreadyRequested = errors.New(\"The deletion has already been requested\")\n)\n```\n\n```go\nvar (\n\t// BlockedLoginFailed is used when a security issue has been detected on the instance\n\tBlockedLoginFailed = BlockingReason{Code: \"LOGIN_FAILED\", Message: \"Instance Blocked Login\"}\n\t// BlockedPaymentFailed is used when a payment is missing for the instance\n\tBlockedPaymentFailed = BlockingReason{Code: \"PAYMENT_FAILED\", Message: \"Instance Blocked Payment\"}\n\t// BlockedImporting is used when importing the data from another instance\n\tBlockedImporting = BlockingReason{Code: \"IMPORTING\", Message: \"Instance Blocked Importing\"}\n\t// BlockedMoving is used when moving data from another instance\n\tBlockedMoving = BlockingReason{Code: \"IMPORTING\", Message: \"Instance Blocked Moving\"}\n\t// BlockedUnknown is used when an instance is blocked but the reason is unknown\n\tBlockedUnknown = BlockingReason{Code: \"UNKNOWN\", Message: \"Instance Blocked Unknown\"}\n)\n```\n\n## Functions\n\n```go\nfunc APIManagerClient(inst *Instance) *manager.APIClient\n```\nAPIManagerClient returns a client to talk to the manager via its API.\n\n```go\nfunc AuthModeToString(authMode AuthMode) string\n```\nAuthModeToString encode authentication mode in a string\n\n```go\nfunc ForeachInstances(fn func(*Instance) error) error\n```\nForeachInstances execute the given callback for each instances.\n\n```go\nfunc ParseTOSVersion(v string) (major int, date time.Time, ok bool)\n```\nParseTOSVersion returns the \"major\" and the date encoded in a version string with the following format:\n\n\tparseTOSVersion(A.B.C-YYYYMMDD) -\u003e (A, YYYY, true)\n\n## Types\n\n```go\ntype AuthMode int\n```\nAuthMode defines the authentication mode chosen for the connection to this instance.\n\n```go\nconst (\n\t// Basic authentication mode, only passphrase\n\tBasic AuthMode = iota\n\t// TwoFactorMail authentication mode, with passcode sent via email\n\tTwoFactorMail\n)\n```\n\n```go\nfunc StringToAuthMode(authMode string) (AuthMode, error)\n```\nStringToAuthMode converts a string encoded authentication mode into a AuthMode int.\n\n```go\ntype BlockingReason struct {\n\tCode    string\n\tMessage string\n}\n```\nBlockingReason structs holds a reason why an instance had been blocked\n\n```go\ntype Instance struct {\n\tDocID          string   `json:\"_id,omitempty\"`  // couchdb _id\n\tDocRev         string   `json:\"_rev,omitempty\"` // couchdb _rev\n\tDomain         string   `json:\"domain\"`         // The main DNS domain, like example.cozycloud.cc\n\tDomainAliases  []string `json:\"domain_aliases,omitempty\"`\n\tPrefix         string   `json:\"prefix,omitempty\"`     // Possible database prefix\n\tLocale         string   `json:\"locale\"`               // The locale used on the server\n\tUUID           string   `json:\"uuid,omitempty\"`       // UUID associated with the instance\n\tOIDCID         string   `json:\"oidc_id,omitempty\"`    // An identifier to check authentication from OIDC\n\tContextName    string   `json:\"context,omitempty\"`    // The context attached to the instance\n\tTOSSigned      string   `json:\"tos,omitempty\"`        // Terms of Service signed version\n\tTOSLatest      string   `json:\"tos_latest,omitempty\"` // Terms of Service latest version\n\tAuthMode       AuthMode `json:\"auth_mode,omitempty\"`\n\tDeleting       bool     `json:\"deleting,omitempty\"`\n\tMoved          bool     `json:\"moved,omitempty\"`           // If the instance has been moved to a new place\n\tBlocked        bool     `json:\"blocked,omitempty\"`         // Whether or not the instance is blocked\n\tBlockingReason string   `json:\"blocking_reason,omitempty\"` // Why the instance is blocked\n\tNoAutoUpdate   bool     `json:\"no_auto_update,omitempty\"`  // Whether or not the instance has auto updates for its applications\n\n\tOnboardingFinished bool  `json:\"onboarding_finished,omitempty\"` // Whether or not the onboarding is complete.\n\tBytesDiskQuota     int64 `json:\"disk_quota,string,omitempty\"`   // The total size in bytes allowed to the user\n\tIndexViewsVersion  int   `json:\"indexes_version,omitempty\"`\n\n\t// Swift layout number:\n\t// - 0 for layout v1\n\t// - 1 for layout v2\n\t// - 2 for layout v3\n\t// It is called swift_cluster in CouchDB and indexed from 0 for legacy reasons.\n\t// See model/vfs/vfsswift for more details.\n\tSwiftLayout int `json:\"swift_cluster,omitempty\"`\n\n\t// PassphraseHash is a hash of a hash of the user's passphrase: the\n\t// passphrase is first hashed in client-side to avoid sending it to the\n\t// server as it also used for encryption on client-side, and after that,\n\t// hashed on the server to ensure robustness. For more informations on the\n\t// server-side hashing, see crypto.GenerateFromPassphrase.\n\tPassphraseHash       []byte     `json:\"passphrase_hash,omitempty\"`\n\tPassphraseResetToken []byte     `json:\"passphrase_reset_token,omitempty\"`\n\tPassphraseResetTime  *time.Time `json:\"passphrase_reset_time,omitempty\"`\n\n\t// Register token is used on registration to prevent from stealing instances\n\t// waiting for registration. The registerToken secret is only shared (in\n\t// clear) with the instance's user.\n\tRegisterToken []byte `json:\"register_token,omitempty\"`\n\t// SessSecret is used to authenticate session cookies\n\tSessSecret []byte `json:\"session_secret,omitempty\"`\n\t// OAuthSecret is used to authenticate OAuth2 token\n\tOAuthSecret []byte `json:\"oauth_secret,omitempty\"`\n\t// CLISecret is used to authenticate request from the CLI\n\tCLISecret []byte `json:\"cli_secret,omitempty\"`\n\n\t// FeatureFlags is the feature flags that are specific to this instance\n\tFeatureFlags map[string]interface{} `json:\"feature_flags,omitempty\"`\n\t// FeatureSets is a list of feature sets from the manager\n\tFeatureSets []string `json:\"feature_sets,omitempty\"`\n\t// contains filtered or unexported fields\n}\n```\nAn Instance has the informations relatives to the logical cozy instance, like the domain, the locale or the access to the databases and files storage It is a couchdb.Doc to be persisted in couchdb.\n\n```go\nfunc Get(domain string) (*Instance, error)\n```\nGet finds an instance from its domain by using CouchDB or the cache.\n\n```go\nfunc GetFromCouch(domain string) (*Instance, error)\n```\nGetFromCouch finds an instance in CouchDB from its domain.\n\n```go\nfunc List() ([]*Instance, error)\n```\nList returns the list of declared instances.\n\n```go\nfunc PaginatedList(limit int, startKey string, skip int) ([]*Instance, string, error)\n```\nPaginatedList can be used to list the instances, with pagination.\n\n```go\nfunc (i *Instance) BuildAppToken(slug, sessionID string) string\n```\nBuildAppToken is used to build a token to identify the app for requests made to the stack\n\n```go\nfunc (i *Instance) BuildKonnectorToken(slug string) string\n```\nBuildKonnectorToken is used to build a token to identify the konnector for requests made to the stack\n\n```go\nfunc (i *Instance) ChangePasswordURL() string\n```\nChangePasswordURL returns the URL of the settings page that can be used by the user to change their password.\n\n```go\nfunc (i *Instance) CheckInstanceBlocked() bool\n```\nCheckInstanceBlocked returns whether or not the instance is currently in a blocked state: meaning it should be accessible.\n\n```go\nfunc (i *Instance) CheckTOSNotSigned(args ...string) (notSigned bool)\n```\nCheckTOSNotSigned checks whether or not the current Term of Services have been signed by the user.\n\n```go\nfunc (i *Instance) CheckTOSNotSignedAndDeadline(args ...string) (notSigned bool, deadline TOSDeadline)\n```\nCheckTOSNotSignedAndDeadline checks whether or not the current Term of Services have been signed by the user and returns the deadline state to perform this signature.\n\n```go\nfunc (i *Instance) Clone() couchdb.Doc\n```\nClone implements couchdb.Doc\n\n```go\nfunc (i *Instance) ContextualDomain() string\n```\nContextualDomain returns the domain with regard to the current domain request.\n\n```go\nfunc (i *Instance) CreateShareCode(subject string) (string, error)\n```\nCreateShareCode returns a new sharecode to put the codes field of a permissions document\n\n```go\nfunc (i *Instance) DBPrefix() string\n```\nDBPrefix returns the prefix to use in database naming for the current instance\n\n```go\nfunc (i *Instance) DefaultRedirection() *url.URL\n```\nDefaultRedirection returns the URL where to redirect the user afer login (and in most other cases where we need a redirection URL)\n\n```go\nfunc (inst *Instance) Delete() error\n```\nDelete removes the instance document in CouchDB.\n\n```go\nfunc (i *Instance) DirName() string\n```\nDirName returns the name of the subdirectory where instance data are stored. On Posix systems, it's the instance domain name.\n\n```go\nfunc (i *Instance) DiskQuota() int64\n```\nDiskQuota returns the number of bytes allowed on the disk to the user.\n\n```go\nfunc (i *Instance) DocType() string\n```\nDocType implements couchdb.Doc\n\n```go\nfunc (i *Instance) DomainName() string\n```\nDomainName returns the main domain name of the instance.\n\n```go\nfunc (i *Instance) FromURL(u *url.URL) string\n```\nFromURL normalizes a given url with the scheme and domain of the instance.\n\n```go\nfunc (i *Instance) GenerateMailConfirmationCode() (string, error)\n```\nGenerateMailConfirmationCode generates a code for validating the user's email.\n\n```go\nfunc (i *Instance) GenerateTwoFactorSecrets() (token []byte, passcode string, err error)\n```\nGenerateTwoFactorSecrets generates a (token, passcode) pair that can be used as a two factor authentication secret value. The token is used to allow the two-factor form — meaning the user has correctly entered its passphrase and successfully done the first part of the two factor authentication.\n\nThe passcode should be send to the user by another mean (mail, SMS, ...)\n\n```go\nfunc (i *Instance) GenerateTwoFactorTrustedDeviceSecret(req *http.Request) ([]byte, error)\n```\nGenerateTwoFactorTrustedDeviceSecret generates a token that can be kept by the user on-demand to avoid having two-factor authentication on a specific machine.\n\n```go\nfunc (i *Instance) GetFromContexts(contexts map[string]interface{}) (interface{}, bool)\n```\nGetFromContexts returns the parameters specific to the instance context\n\n```go\nfunc (i *Instance) HasAuthMode(authMode AuthMode) bool\n```\nHasAuthMode returns whether or not the instance has the given authentication mode activated.\n\n```go\nfunc (i *Instance) HasDomain(domain string) bool\n```\nHasDomain returns whether or not the given domain name is owned by this instance, as part of its main domain name or its aliases.\n\n```go\nfunc (i *Instance) ID() string\n```\nID implements couchdb.Doc\n\n```go\nfunc (i *Instance) IsPasswordAuthenticationEnabled() bool\n```\nIsPasswordAuthenticationEnabled returns false only if the instance is in a context where the config says that the stack shouldn't allow to authenticate with the password.\n\n```go\nfunc (i *Instance) Logger() *logger.Entry\n```\nLogger returns the logger associated with the instance\n\n```go\nfunc (i *Instance) MakeJWT(audience, subject, scope, sessionID string, issuedAt time.Time) (string, error)\n```\nMakeJWT is a shortcut to create a JWT\n\n```go\nfunc (i *Instance) MakeVFS() error\n```\nMakeVFS is used to initialize the VFS linked to this instance\n\n```go\nfunc (i *Instance) ManagerURL(k ManagerURLKind) (string, error)\n```\nManagerURL returns an external string for the given ManagerURL kind. It is used for redirecting the user to a manager URL.\n\n```go\nfunc (i *Instance) MoveURL() string\n```\nMoveURL returns URL for move wizard.\n\n```go\nfunc (i *Instance) MovedError() *jsonapi.Error\n```\nMovedError is used to return an error when the instance has been moved to a new domain/hoster.\n\n```go\nfunc (i *Instance) NotesLock() lock.ErrorRWLocker\n```\nNotesLock returns a mutex for the notes on this instance.\n\n```go\nfunc (i *Instance) OnboardedRedirection() *url.URL\n```\nOnboardedRedirection returns the URL where to redirect the user after onboarding\n\n```go\nfunc (i *Instance) PageURL(path string, queries url.Values) string\n```\nPageURL returns the full URL for a path on the cozy stack\n\n```go\nfunc (i *Instance) PassphraseSalt() []byte\n```\nPassphraseSalt computes the salt for the client-side hashing of the master password. The rule for computing the salt is to create a fake email address \"me@\\\u003cdomain\u003e\".\n\n```go\nfunc (i *Instance) PickKey(audience string) ([]byte, error)\n```\nPickKey choose which of the Instance keys to use depending on token audience\n\n```go\nfunc (i *Instance) PublicName() (string, error)\n```\nPublicName returns the settings' public name or a default one if missing\n\n```go\nfunc (i *Instance) Registries() []*url.URL\n```\nRegistries returns the list of registries associated with the instance.\n\n```go\nfunc (i *Instance) Rev() string\n```\nRev implements couchdb.Doc\n\n```go\nfunc (i *Instance) Scheme() string\n```\nScheme returns the scheme used for URLs. It is https by default and http for development instances.\n\n```go\nfunc (i *Instance) SessionSecret() []byte\n```\nSessionSecret returns the session secret.\n\n```go\nfunc (i *Instance) SetID(v string)\n```\nSetID implements couchdb.Doc\n\n```go\nfunc (i *Instance) SetRev(v string)\n```\nSetRev implements couchdb.Doc\n\n```go\nfunc (i *Instance) SettingsContext() (map[string]interface{}, bool)\n```\nSettingsContext returns the map from the config that matches the context of this instance\n\n```go\nfunc (i *Instance) SettingsDocument() (*couchdb.JSONDoc, error)\n```\nSettingsDocument returns the document with the settings of this instance\n\n```go\nfunc (i *Instance) SettingsEMail() (string, error)\n```\nSettingsEMail returns the email address defined in the settings of this instance.\n\n```go\nfunc (i *Instance) SettingsPublicName() (string, error)\n```\nSettingsPublicName returns the public name defined in the settings of this instance.\n\n```go\nfunc (i *Instance) SlugAndDomain() (string, string)\n```\nSlugAndDomain returns the splitted slug and domain of the instance Ex: foobar.mycozy.cloud =\u003e \\[\"foobar\", \"mycozy.cloud\"]\n\n```go\nfunc (i *Instance) SubDomain(s string) *url.URL\n```\nSubDomain returns the full url for a subdomain of this instance useful with apps slugs\n\n```go\nfunc (i *Instance) SupportEmailAddress() string\n```\nSupportEmailAddress returns the email address that can be used to contact the support.\n\n```go\nfunc (i *Instance) TemplateTitle() string\n```\nTemplateTitle returns the specific-context instance template title (if there is one). Otherwise, returns the default one\n\n```go\nfunc (i *Instance) ThumbsFS() vfs.Thumbser\n```\nThumbsFS returns the hidden filesystem for storing the thumbnails of the photos/image\n\n```go\nfunc (i *Instance) Translate(key string, vars ...interface{}) string\n```\nTranslate is used to translate a string to the locale used on this instance\n\n```go\nfunc (inst *Instance) Update() error\n```\nUpdate saves the changes in CouchDB.\n\n```go\nfunc (i *Instance) VFS() vfs.VFS\n```\nVFS returns the storage provider where the binaries for the current instance are persisted\n\n```go\nfunc (i *Instance) ValidateMailConfirmationCode(passcode string) bool\n```\nValidateMailConfirmationCode returns true if the given passcode is valid.\n\n```go\nfunc (i *Instance) ValidateTwoFactorPasscode(token []byte, passcode string) bool\n```\nValidateTwoFactorPasscode validates the given (token, passcode) pair for two factor authentication.\n\n```go\nfunc (i *Instance) ValidateTwoFactorTrustedDeviceSecret(req *http.Request, token []byte) bool\n```\nValidateTwoFactorTrustedDeviceSecret validates the given token used to check if the computer is trusted to avoid two-factor authorization.\n\n```go\nfunc (i *Instance) Warnings() (warnings []*jsonapi.Error)\n```\nWarnings returns a list of possible warnings associated with the instance.\n\n```go\nfunc (i *Instance) WithContextualDomain(domain string) *Instance\n```\nWithContextualDomain the current instance context with the given hostname.\n\n```go\ntype ManagerURLKind int\n```\nManagerURLKind is an enum type for the different kinds of manager URLs.\n\n```go\nconst (\n\t// ManagerTOSURL is the kind for changes of TOS URL.\n\tManagerTOSURL ManagerURLKind = iota\n\t// ManagerPremiumURL is the kind for changing the account type of the\n\t// instance.\n\tManagerPremiumURL\n\t// ManagerBlockedURL is the kind for a redirection of a blocked instance.\n\tManagerBlockedURL\n)\n```\n\n```go\ntype TOSDeadline int\n```\nTOSDeadline represent the state for reaching the TOS deadline.\n\n```go\nconst (\n\t// TOSNone when no deadline is reached.\n\tTOSNone TOSDeadline = iota\n\t// TOSWarning when the warning deadline is reached, 2 weeks before the actual\n\t// activation of the CGU.\n\tTOSWarning\n\t// TOSBlocked when the deadline is reached and the access should be blocked.\n\tTOSBlocked\n)\n```\n\n","path":"github.com/Beyond-Technology/cozy-stack/model/instance","name":"instance","synopsis":"","isRedistributable":true}
