datastore

package
v0.0.0-...-f30a32e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// SaltLength is the length of the salt used when encrypting the invite signing key.
	SaltLength = 10
)

Variables

View Source
var (
	// ErrUserNotFound is used when a user is not found when looking up by a filter condition.
	ErrUserNotFound = errors.New("user not found")
	// ErrOrgNotFound is used when the org is not found when looking up by a filter condition.
	ErrOrgNotFound = errors.New("org not found")
	// ErrNoInviteKey is used when the org doesn't have a invite key set.
	ErrNoInviteKey = errors.New("org has no invite signing key")
	// ErrUserAttributesNotFound is used when no attributes can be found for the given user.
	ErrUserAttributesNotFound = errors.New("user attributes not found")
	// ErrUserSettingsNotFound is used when no settings can be found for the given user.
	ErrUserSettingsNotFound = errors.New("user settings not found")
	// ErrDuplicateOrgName is used when the given org name is already in use.
	ErrDuplicateOrgName = errors.New("cannot create org (name already in use)")
	// ErrDuplicateUser is used when the user creation violates unique constraints for auth_provider_id or email.
	ErrDuplicateUser = errors.New("cannot create duplicate user")
)

Functions

This section is empty.

Types

type Datastore

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

Datastore is a postgres backed storage for entities.

func NewDatastore

func NewDatastore(db *sqlx.DB, dbKey string) *Datastore

NewDatastore creates a Datastore.

func (*Datastore) AddIDEConfig

func (d *Datastore) AddIDEConfig(orgID uuid.UUID, config *IDEConfig) error

AddIDEConfig adds the IDE config to the org.

func (*Datastore) ApproveAllOrgUsers

func (d *Datastore) ApproveAllOrgUsers(orgID uuid.UUID) error

ApproveAllOrgUsers sets all users is_approved column to true in an org.

func (*Datastore) CreateInviteSigningKey

func (d *Datastore) CreateInviteSigningKey(id uuid.UUID) (string, error)

CreateInviteSigningKey creates an invite signing key for the given orgID.

func (*Datastore) CreateOrg

func (d *Datastore) CreateOrg(orgInfo *OrgInfo) (uuid.UUID, error)

CreateOrg creates a new organization, returning the created org ID.

func (*Datastore) CreateUser

func (d *Datastore) CreateUser(userInfo *UserInfo) (uuid.UUID, error)

CreateUser creates a new user.

func (*Datastore) CreateUserAndOrg

func (d *Datastore) CreateUserAndOrg(orgInfo *OrgInfo, userInfo *UserInfo) (uuid.UUID, uuid.UUID, error)

CreateUserAndOrg creates a new user and organization as needed for initial user/org creation.

func (*Datastore) DeleteIDEConfig

func (d *Datastore) DeleteIDEConfig(orgID uuid.UUID, name string) error

DeleteIDEConfig deletes the IDE config from the org.

func (*Datastore) DeleteOrgAndUsers

func (d *Datastore) DeleteOrgAndUsers(orgID uuid.UUID) error

DeleteOrgAndUsers deletes the org and users with a given org ID.

func (*Datastore) DeleteUser

func (d *Datastore) DeleteUser(userID uuid.UUID) error

DeleteUser deletes a user, but not the org.

func (*Datastore) GetIDEConfig

func (d *Datastore) GetIDEConfig(orgID uuid.UUID, name string) (*IDEConfig, error)

GetIDEConfig gets the IDE config for the IDE with the given name.

func (*Datastore) GetIDEConfigs

func (d *Datastore) GetIDEConfigs(orgID uuid.UUID) ([]*IDEConfig, error)

GetIDEConfigs gets all IDE configs for the org.

func (*Datastore) GetInviteSigningKey

func (d *Datastore) GetInviteSigningKey(id uuid.UUID) (string, error)

GetInviteSigningKey gets the invite signing key for the given orgID.

func (*Datastore) GetOrg

func (d *Datastore) GetOrg(id uuid.UUID) (*OrgInfo, error)

GetOrg gets org information by ID.

func (*Datastore) GetOrgByDomain

func (d *Datastore) GetOrgByDomain(domainName string) (*OrgInfo, error)

GetOrgByDomain gets org information by domain.

func (*Datastore) GetOrgByName

func (d *Datastore) GetOrgByName(name string) (*OrgInfo, error)

GetOrgByName gets org information by domain.

func (*Datastore) GetOrgs

func (d *Datastore) GetOrgs() ([]*OrgInfo, error)

GetOrgs gets all orgs.

func (*Datastore) GetUser

func (d *Datastore) GetUser(id uuid.UUID) (*UserInfo, error)

GetUser gets user information by user ID.

func (*Datastore) GetUserAttributes

func (d *Datastore) GetUserAttributes(id uuid.UUID) (*UserAttributes, error)

GetUserAttributes fetches the settings for the given user and keys.

func (*Datastore) GetUserByAuthProviderID

func (d *Datastore) GetUserByAuthProviderID(id string) (*UserInfo, error)

GetUserByAuthProviderID gets userinfo by auth provider id.

func (*Datastore) GetUserByEmail

func (d *Datastore) GetUserByEmail(email string) (*UserInfo, error)

GetUserByEmail gets user info by email.

func (*Datastore) GetUserSettings

func (d *Datastore) GetUserSettings(id uuid.UUID) (*UserSettings, error)

GetUserSettings fetches the settings for the given user.

func (*Datastore) GetUsersInOrg

func (d *Datastore) GetUsersInOrg(orgID uuid.UUID) ([]*UserInfo, error)

GetUsersInOrg gets all users in the given org.

func (*Datastore) NumUsersInOrg

func (d *Datastore) NumUsersInOrg(orgID uuid.UUID) (int, error)

NumUsersInOrg gets the count of users in the given org.

func (*Datastore) SetUserAttributes

func (d *Datastore) SetUserAttributes(attributes *UserAttributes) error

SetUserAttributes updates the user attributes for the given user.

func (*Datastore) UpdateOrg

func (d *Datastore) UpdateOrg(orgInfo *OrgInfo) error

UpdateOrg updates the org in the database.

func (*Datastore) UpdateUser

func (d *Datastore) UpdateUser(userInfo *UserInfo) error

UpdateUser updates the user in the database.

func (*Datastore) UpdateUserSettings

func (d *Datastore) UpdateUserSettings(settings *UserSettings) error

UpdateUserSettings updates the user settings for the given user.

type IDEConfig

type IDEConfig struct {
	Name string `db:"ide_name"`
	Path string `db:"path"`
}

IDEConfig is an org-level configuration which defines the IDE paths which can be used to navigate to a given symbol.

type OrgInfo

type OrgInfo struct {
	ID              uuid.UUID `db:"id"`
	OrgName         string    `db:"org_name"`
	DomainName      *string   `db:"domain_name"`
	EnableApprovals bool      `db:"enable_approvals"`
}

OrgInfo tracks information about an organization.

func (*OrgInfo) GetDomainName

func (o *OrgInfo) GetDomainName() string

GetDomainName is a helper to nil check the DomainName column value and convert NULLs into empty strings for ease of use.

type UserAttributes

type UserAttributes struct {
	UserID   uuid.UUID `db:"user_id"`
	TourSeen *bool     `db:"tour_seen"`
}

UserAttributes is a set of attributes for a user.

type UserInfo

type UserInfo struct {
	ID               uuid.UUID  `db:"id"`
	OrgID            *uuid.UUID `db:"org_id"`
	FirstName        string     `db:"first_name"`
	LastName         string     `db:"last_name"`
	Email            string     `db:"email"`
	ProfilePicture   *string    `db:"profile_picture"`
	IsApproved       bool       `db:"is_approved"`
	IdentityProvider string     `db:"identity_provider"`
	AuthProviderID   string     `db:"auth_provider_id"`
}

UserInfo tracks information about a specific end-user.

type UserSettings

type UserSettings struct {
	UserID          uuid.UUID `db:"user_id"`
	AnalyticsOptout *bool     `db:"analytics_optout"`
}

UserSettings is a set of settings for a user.

Jump to

Keyboard shortcuts

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