From f288d6f861ff5812444a5c723c3073cefbc6fc17 Mon Sep 17 00:00:00 2001 From: "kayos@tcp.direct" Date: Tue, 5 Oct 2021 05:35:09 -0700 Subject: [PATCH] init --- .gitignore | 1 + emailaccount.go | 36 ++++++++++++++++++++++++++++++++++++ emailstorage.go | 31 +++++++++++++++++++++++++++++++ user.go | 28 ++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 .gitignore create mode 100644 emailaccount.go create mode 100644 emailstorage.go create mode 100644 user.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a9133cf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/dumps/ diff --git a/emailaccount.go b/emailaccount.go new file mode 100644 index 0000000..a912915 --- /dev/null +++ b/emailaccount.go @@ -0,0 +1,36 @@ +package sso + +// EmailStorage represents where emails are stored for an EmailAccount. +type EmailStorage uint8 + +//goland:noinspection GoUnusedConst +const ( + // MailDirStorage uses traditional Maildir format to store emails. + MailDirStorage EmailStorage = iota + // BitcaskMailStorage bitcask to store emails. (unimplemented) + BitcaskMailStorage + // PostgresMailStorage uses Postgresql to store emails. (unimplemented) + PostgresMailStorage + // TemporaryMailStorage stores temporary, disposable emails. (unimplemented) + TemporaryMailStorage +) + +// EmailAccount represents an email inbox owned by a User. Aims to be partially compatible with Dovecot. +type EmailAccount struct { + // Domain is the internal email domain associated with this Maildir. + Domain string `json:"domain"` + // Quota is the maximum amount of email allowed to be stored in bytes. A quota of 0 means no quota. + Quota int `json:"quota"` + // Type represents the type of EmailStorage an email account uses. + Type EmailStorage `json:"storage"` + // DomainAdmin determines if the user has administrative permissions of the parent Domain. + DomainAdmin bool `json:"isadmin"` + + // MaildirDetails represents an EmailAccount's maildir if applicable. + MaildirDetails Maildir `json:"maildir,omitempty"` + + // BitcaskDetails represents an EmailAccount's BitcaskStore if applicable. + BitcaskDetails BitcaskStore `json:"bitcaskdb,omitempty"` + // BoltDetails represents an EmailAccount's BitcaskStore if applicable. + BoltDetails BoltStore `json:"boltdb,omitempty"` +} diff --git a/emailstorage.go b/emailstorage.go new file mode 100644 index 0000000..d65d4a6 --- /dev/null +++ b/emailstorage.go @@ -0,0 +1,31 @@ +package sso + +// TODO: Make interfaces for email stores. + +// BitcaskStore contains details of a bitcask backed email store. +type BitcaskStore struct { + // StoreNode is an identifying string pointing to what server the BitcaskStore is primarily stored on. + StoreNode string `json:"storage_node"` +} + +// BoltStore contains details of a Bolt backed email store. +type BoltStore struct { + // StoreNode is an identifying string pointing to what server the BoltStore is primarily stored on. + StoreNode string `json:"storage_node"` +} + +// TemporaryStore contains details of a temporary email store. +type TemporaryStore struct { + // StoreNode is an identifying string pointing to what server the BoltStore is primarily stored on. + StoreNode string `json:"storage_node"` +} + +// Maildir contains information about where a users email is stored. Aims to be partially compatible with Dovecot. +type Maildir struct { + // StoreNode is an identifying string pointing to what server the Maildir is primarily stored on. + StoreNode string `json:"storage_node"` + // StoreBaseDirectory is the base name of the Maildir directory. + StoreBaseDirectory string `json:"storage_base_directory"` + // StoreMailDir is the actual directory containing email messages. + StoreMaildir string `json:"maildir"` +} diff --git a/user.go b/user.go new file mode 100644 index 0000000..a24f5f3 --- /dev/null +++ b/user.go @@ -0,0 +1,28 @@ +package sso + +// User contains account information for an SSO user. +type User struct { + // UserID is a key that is likely cached in memory used to lookup GlobalUsers. + UserID string `json:"id"` + // PassHash should be a bcrypt hashed password used for authentication. + PassHash string `json:"password"` + // FriendlyName is a nickname that the user decides. + FriendlyName string `json:"friendly_name,omitempty"` + + // ExternalEmail is an email address to reach the user. + // Note that one can place the address of an internal email account here as well. + ExternalEmail string `json:"email,omitempty"` + + // EmailAccounts contains, if applicable, the details of a users internal email account. + EmailAccounts []EmailAccount `json:"email_accounts,omitempty"` + + // LegacyEmailAccountData is a place to temporarily store JSON exported from our old Mysql email database. + // Data should be removed after the user signs on for the first time and we rehash their password in Bcrypt. + LegacyEmailAccountData string `json:"legacy_email,omitempty"` + + // IRCAccount represents a users IRC account (not impemented) + IRCAccount string `json:"irc_account,omitempty"` + + // GlobalAdmin is a dangerous toggle which will pretty much bypass permissions checks everywhere. + GlobalAdmin bool `json:"global_admin"` +}