Documentation ¶
Overview ¶
Package user contains package methods for user support.
Index ¶
- Constants
- type CreateEvent
- type UpdateAPISecretEvent
- type UpdateDisplayNameEvent
- type UpdatePasswordEvent
- type UpdateStatusEvent
- type User
- func (u *User) Decrypt(versionKey *security.VersionKey) error
- func (u *User) Encrypt(key []byte, keyVersion uuid.UUID) error
- func (u *User) GetID() models.ID
- func (u *User) GetOrg() models.ID
- func (u *User) GetUser() models.ID
- func (u User) Insert(ctx context.Context, conn *pgx.Conn, keyVersion uuid.UUID, key []byte) error
- func (u *User) ReEncrypt(ctx context.Context, conn *pgx.Conn, keyVersion uuid.UUID, ...) error
- func (u *User) Refresh(ctx context.Context, conn *pgx.Conn, versionKey *security.VersionKey) error
- func (u *User) UpdateAPISecret(ctx context.Context, conn *pgx.Conn, versionKey *security.VersionKey) error
- func (u *User) UpdateDisplayName(ctx context.Context, conn *pgx.Conn, versionKey *security.VersionKey, ...) error
- func (u *User) UpdatePassword(ctx context.Context, conn *pgx.Conn, versionKey *security.VersionKey, ...) error
- func (u *User) UpdateStatus(ctx context.Context, conn *pgx.Conn, versionKey *security.VersionKey, ...) error
Constants ¶
const SchemaVersion = 0
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CreateEvent ¶
type CreateEvent struct { DisplayName safe.VarChar `json:"display_name"` Email safe.VarChar `json:"email"` Org models.ID `json:"org"` Password safe.Password `json:"password"` // contains filtered or unexported fields }
func NewCreateEvent ¶
func NewCreateEvent(argon2Config *argon2.Config) (*CreateEvent, error)
func (*CreateEvent) UnmarshalJSON ¶
func (ev *CreateEvent) UnmarshalJSON(bs []byte) error
UnmarshalJSON assumes Password is cleartext and hashes it with argon2. This minimizes the window to access the cleartext password accidentally.
type UpdateAPISecretEvent ¶
type UpdateAPISecretEvent struct {
GenerateAPISecret bool `json:"generate_api_secret"`
}
type UpdateDisplayNameEvent ¶
type UpdatePasswordEvent ¶
type UpdateStatusEvent ¶
type User ¶
type User struct { models.Base // APISecret may be in both encrypted and decrypted states // so it is set as safe.VarChar, although it will be forged // from a models.ID instance. APISecret safe.VarChar `json:"api_secret"` APISecretDigest string `json:"api_secret_digest"` DisplayName safe.VarChar `json:"display_name"` DisplayNameDigest string `json:"display_name_digest"` Email safe.VarChar `json:"email"` EmailDigest string `json:"email_digest"` Org models.ID `json:"org"` Password safe.Password `json:"-"` // assumed derived KeyVersion uuid.UUID `json:"-"` // contains filtered or unexported fields }
User models a row of the users table.
func Create ¶
func Create( ctx context.Context, conn *pgx.Conn, displayName safe.VarChar, email safe.VarChar, org models.ID, password safe.Password, versionKey *security.VersionKey, ) (*User, error)
Create inserts a new org and org owner into the db. Performs validation.
func New ¶
func New( displayName safe.VarChar, email safe.VarChar, org models.ID, password safe.Password, ) (*User, error)
New returns a new unencrypted User. Org is not validated. Use Create for validation.
func (*User) Decrypt ¶
func (u *User) Decrypt(versionKey *security.VersionKey) error
Decrypt resets APISecret, DisplayName, Email to their decrypted forms.
func (User) Insert ¶
func (u User) Insert( ctx context.Context, conn *pgx.Conn, keyVersion uuid.UUID, key []byte, ) error
Insert a User into the db. Mutations to u in this method will not impact caller.
func (*User) ReEncrypt ¶
func (u *User) ReEncrypt(ctx context.Context, conn *pgx.Conn, keyVersion uuid.UUID, versionKey *security.VersionKey, ) error
ReEncrypt re-encrypts all encryptable fields with the new key. Assumes User is already in the db; updates the relevant fields.
The digests remain the same as they are the digests of the unencrypted fields.
func (*User) Refresh ¶
func (u *User) Refresh(ctx context.Context, conn *pgx.Conn, versionKey *security.VersionKey, ) error
Refresh will re-initialize data fields after an update, typically inside the same txn that performed the update.
func (*User) UpdateAPISecret ¶
func (u *User) UpdateAPISecret(ctx context.Context, conn *pgx.Conn, versionKey *security.VersionKey, ) error
UpdateAPISecret generates a new API secret on behalf of the user.
func (*User) UpdateDisplayName ¶
func (u *User) UpdateDisplayName(ctx context.Context, conn *pgx.Conn, versionKey *security.VersionKey, newDisplayName safe.VarChar, ) error
UpdateDisplayName changes the user display name and display name digest.
func (*User) UpdatePassword ¶
func (u *User) UpdatePassword(ctx context.Context, conn *pgx.Conn, versionKey *security.VersionKey, newPassword safe.Password, ) error
UpdatePassword changes the user password. Assumes password is already derived.
func (*User) UpdateStatus ¶
func (u *User) UpdateStatus(ctx context.Context, conn *pgx.Conn, versionKey *security.VersionKey, newStatus models.Status, ) error
UpdateStatus changes the user status.