mongodb

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DuplicateErrMsg = "E11000 duplicate key error"
)

Variables

View Source
var (
	ErrInvalidThreadName = fmt.Errorf("name may only contain alphanumeric characters or non-consecutive hyphens, and cannot begin or end with a hyphen")
)
View Source
var (
	ErrInvalidUsername = fmt.Errorf("username may only contain alphanumeric characters or single hyphens, and cannot begin or end with a hyphen")
)

Functions

func NewAPIKeyContext

func NewAPIKeyContext(ctx context.Context, key *APIKey) context.Context

func NewDevContext

func NewDevContext(ctx context.Context, dev *Account) context.Context

func NewOrgContext

func NewOrgContext(ctx context.Context, org *Account) context.Context

func NewSessionContext

func NewSessionContext(ctx context.Context, session *Session) context.Context

func NewUserContext

func NewUserContext(ctx context.Context, user *User) context.Context

Types

type APIKey

type APIKey struct {
	Key       string
	Secret    string
	Owner     crypto.PubKey
	Type      APIKeyType
	Secure    bool
	Valid     bool
	CreatedAt time.Time
}

func APIKeyFromContext

func APIKeyFromContext(ctx context.Context) (*APIKey, bool)

type APIKeyType

type APIKeyType int
const (
	AccountKey APIKeyType = iota
	UserKey
)

type APIKeys

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

func NewAPIKeys

func NewAPIKeys(ctx context.Context, db *mongo.Database) (*APIKeys, error)

func (*APIKeys) Create

func (k *APIKeys) Create(ctx context.Context, owner crypto.PubKey, keyType APIKeyType, secure bool) (*APIKey, error)

func (*APIKeys) DeleteByOwner

func (k *APIKeys) DeleteByOwner(ctx context.Context, owner crypto.PubKey) error

func (*APIKeys) Get

func (k *APIKeys) Get(ctx context.Context, key string) (*APIKey, error)

func (*APIKeys) Invalidate

func (k *APIKeys) Invalidate(ctx context.Context, key string) error

func (*APIKeys) ListByOwner

func (k *APIKeys) ListByOwner(ctx context.Context, owner crypto.PubKey) ([]APIKey, error)

type Account

type Account struct {
	Type             AccountType
	Key              crypto.PubKey
	Secret           crypto.PrivKey
	Name             string
	Username         string
	Email            string
	Token            thread.Token
	Members          []Member
	BucketsTotalSize int64
	CreatedAt        time.Time
}

func DevFromContext

func DevFromContext(ctx context.Context) (*Account, bool)

func OrgFromContext

func OrgFromContext(ctx context.Context) (*Account, bool)

type AccountType

type AccountType int
const (
	Dev AccountType = iota
	Org
)

type Accounts

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

func NewAccounts

func NewAccounts(ctx context.Context, db *mongo.Database) (*Accounts, error)

func (*Accounts) AddMember

func (a *Accounts) AddMember(ctx context.Context, username string, member Member) error

func (*Accounts) CreateDev

func (a *Accounts) CreateDev(ctx context.Context, username, email string) (*Account, error)

func (*Accounts) CreateOrg

func (a *Accounts) CreateOrg(ctx context.Context, name string, members []Member) (*Account, error)

func (*Accounts) Delete

func (a *Accounts) Delete(ctx context.Context, key crypto.PubKey) error

func (*Accounts) Get

func (a *Accounts) Get(ctx context.Context, key crypto.PubKey) (*Account, error)

func (*Accounts) GetByUsername

func (a *Accounts) GetByUsername(ctx context.Context, username string) (*Account, error)

func (*Accounts) GetByUsernameOrEmail

func (a *Accounts) GetByUsernameOrEmail(ctx context.Context, usernameOrEmail string) (*Account, error)

func (*Accounts) IsMember

func (a *Accounts) IsMember(ctx context.Context, username string, member crypto.PubKey) (bool, error)

func (*Accounts) IsNameAvailable

func (a *Accounts) IsNameAvailable(ctx context.Context, name string) (s string, err error)

func (*Accounts) IsOwner

func (a *Accounts) IsOwner(ctx context.Context, username string, member crypto.PubKey) (bool, error)

func (*Accounts) IsUsernameAvailable

func (a *Accounts) IsUsernameAvailable(ctx context.Context, username string) error

func (*Accounts) ListByMember

func (a *Accounts) ListByMember(ctx context.Context, member crypto.PubKey) ([]Account, error)

func (*Accounts) ListByOwner

func (a *Accounts) ListByOwner(ctx context.Context, owner crypto.PubKey) ([]Account, error)

func (*Accounts) ListMembers

func (a *Accounts) ListMembers(ctx context.Context, members []Member) ([]Account, error)

func (*Accounts) RemoveMember

func (a *Accounts) RemoveMember(ctx context.Context, username string, member crypto.PubKey) error

func (*Accounts) SetBucketsTotalSize

func (a *Accounts) SetBucketsTotalSize(ctx context.Context, key crypto.PubKey, newTotalSize int64) error

func (*Accounts) SetToken

func (a *Accounts) SetToken(ctx context.Context, key crypto.PubKey, token thread.Token) error

func (*Accounts) ValidateUsername

func (a *Accounts) ValidateUsername(username string) error

type Archive

type Archive struct {
	Cid        []byte `bson:"cid"`
	JobID      string `bson:"job_id"`
	JobStatus  int    `bson:"job_status"`
	Aborted    bool   `bson:"aborted"`
	AbortedMsg string `bson:"aborted_msg"`
	FailureMsg string `bson:"failure_msg"`
	CreatedAt  int64  `bson:"created_at"`
}

type ArchiveTracking

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

func NewArchiveTracking

func NewArchiveTracking(ctx context.Context, db *mongo.Database) (*ArchiveTracking, error)

func (*ArchiveTracking) Create

func (at *ArchiveTracking) Create(ctx context.Context, dbID thread.ID, dbToken thread.Token, bucketKey string, jid ffs.JobID, bucketRoot cid.Cid) error

func (*ArchiveTracking) Finalize

func (at *ArchiveTracking) Finalize(ctx context.Context, jid ffs.JobID, cause string) error

func (*ArchiveTracking) Get

func (*ArchiveTracking) GetReadyToCheck

func (at *ArchiveTracking) GetReadyToCheck(ctx context.Context, n int64) ([]*TrackedArchive, error)

func (*ArchiveTracking) Reschedule

func (at *ArchiveTracking) Reschedule(ctx context.Context, jid ffs.JobID, dur time.Duration, cause string) error

type Archives

type Archives struct {
	Current Archive   `bson:"current"`
	History []Archive `bson:"history"`
}

type Collections

type Collections struct {
	Sessions *Sessions
	Accounts *Accounts
	Invites  *Invites

	Threads         *Threads
	APIKeys         *APIKeys
	IPNSKeys        *IPNSKeys
	FFSInstances    *FFSInstances
	ArchiveTracking *ArchiveTracking

	Users *Users
	// contains filtered or unexported fields
}

func NewCollections

func NewCollections(ctx context.Context, uri, dbName string, hub bool) (*Collections, error)

NewCollections gets or create store instances for active collections.

func (*Collections) Close

func (c *Collections) Close() error

type FFSInstance

type FFSInstance struct {
	BucketKey  string   `bson:"_id"`
	FFSToken   string   `bson:"ffs_token"`
	WalletAddr string   `bson:"ffs_walletaddr"`
	Archives   Archives `bson:"archives"`
}

type FFSInstances

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

func NewFFSInstances

func NewFFSInstances(_ context.Context, db *mongo.Database) (*FFSInstances, error)

func (*FFSInstances) Create

func (k *FFSInstances) Create(ctx context.Context, bucketKey, ffsToken, waddr string) error

func (*FFSInstances) Get

func (k *FFSInstances) Get(ctx context.Context, bucketKey string) (*FFSInstance, error)

func (*FFSInstances) Replace

func (k *FFSInstances) Replace(ctx context.Context, ffs *FFSInstance) error

type IPNSKey

type IPNSKey struct {
	Name      string
	Cid       string
	ThreadID  thread.ID
	CreatedAt time.Time
}

type IPNSKeys

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

func NewIPNSKeys

func NewIPNSKeys(ctx context.Context, db *mongo.Database) (*IPNSKeys, error)

func (*IPNSKeys) Create

func (k *IPNSKeys) Create(ctx context.Context, name, cid string, threadID thread.ID) error

func (*IPNSKeys) Delete

func (k *IPNSKeys) Delete(ctx context.Context, name string) error

func (*IPNSKeys) Get

func (k *IPNSKeys) Get(ctx context.Context, name string) (*IPNSKey, error)

func (*IPNSKeys) GetByCid

func (k *IPNSKeys) GetByCid(ctx context.Context, cid string) (*IPNSKey, error)

func (*IPNSKeys) ListByThreadID

func (k *IPNSKeys) ListByThreadID(ctx context.Context, threadID thread.ID) ([]IPNSKey, error)

type Invite

type Invite struct {
	Token     string
	Org       string
	From      crypto.PubKey
	EmailTo   string
	Accepted  bool
	ExpiresAt time.Time
}

type Invites

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

func NewInvites

func NewInvites(ctx context.Context, db *mongo.Database) (*Invites, error)

func (*Invites) Accept

func (i *Invites) Accept(ctx context.Context, token string) error

func (*Invites) Create

func (i *Invites) Create(ctx context.Context, from crypto.PubKey, org, emailTo string) (*Invite, error)

func (*Invites) Delete

func (i *Invites) Delete(ctx context.Context, token string) error

func (*Invites) DeleteByFrom

func (i *Invites) DeleteByFrom(ctx context.Context, from crypto.PubKey) error

func (*Invites) DeleteByFromAndOrg

func (i *Invites) DeleteByFromAndOrg(ctx context.Context, from crypto.PubKey, org string) error

func (*Invites) DeleteByOrg

func (i *Invites) DeleteByOrg(ctx context.Context, org string) error

func (*Invites) Get

func (i *Invites) Get(ctx context.Context, token string) (*Invite, error)

func (*Invites) ListByEmail

func (i *Invites) ListByEmail(ctx context.Context, email string) ([]Invite, error)

type Member

type Member struct {
	Key      crypto.PubKey
	Username string
	Role     Role
}

type Role

type Role int
const (
	OrgOwner Role = iota
	OrgMember
)

func (Role) String

func (r Role) String() (s string)

type Session

type Session struct {
	ID        string
	Owner     crypto.PubKey
	ExpiresAt time.Time
}

func SessionFromContext

func SessionFromContext(ctx context.Context) (*Session, bool)

type Sessions

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

func NewSessions

func NewSessions(ctx context.Context, db *mongo.Database) (*Sessions, error)

func (*Sessions) Create

func (s *Sessions) Create(ctx context.Context, owner crypto.PubKey) (*Session, error)

func (*Sessions) Delete

func (s *Sessions) Delete(ctx context.Context, id string) error

func (*Sessions) DeleteByOwner

func (s *Sessions) DeleteByOwner(ctx context.Context, owner crypto.PubKey) error

func (*Sessions) Get

func (s *Sessions) Get(ctx context.Context, id string) (*Session, error)

func (*Sessions) Touch

func (s *Sessions) Touch(ctx context.Context, id string) error

type Thread

type Thread struct {
	ID        thread.ID
	Owner     crypto.PubKey
	Name      string
	Key       string
	IsDB      bool
	CreatedAt time.Time
}

type Threads

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

func NewThreads

func NewThreads(ctx context.Context, db *mongo.Database) (*Threads, error)

func (*Threads) Create

func (t *Threads) Create(ctx context.Context, id thread.ID, owner crypto.PubKey, isDB bool) (*Thread, error)

func (*Threads) Delete

func (t *Threads) Delete(ctx context.Context, id thread.ID, owner crypto.PubKey) error

func (*Threads) DeleteByOwner

func (t *Threads) DeleteByOwner(ctx context.Context, owner crypto.PubKey) error

func (*Threads) Get

func (t *Threads) Get(ctx context.Context, id thread.ID, owner crypto.PubKey) (*Thread, error)

func (*Threads) GetByName

func (t *Threads) GetByName(ctx context.Context, name string, owner crypto.PubKey) (*Thread, error)

func (*Threads) ListByKey

func (t *Threads) ListByKey(ctx context.Context, key string) ([]Thread, error)

func (*Threads) ListByOwner

func (t *Threads) ListByOwner(ctx context.Context, owner crypto.PubKey) ([]Thread, error)

type TrackedArchive

type TrackedArchive struct {
	JID        ffs.JobID
	DbID       thread.ID
	DbToken    thread.Token
	BucketKey  string
	BucketRoot cid.Cid
	ReadyAt    time.Time
	Cause      string
	Active     bool
}

type User

type User struct {
	Key              crypto.PubKey
	BucketsTotalSize int64
	CreatedAt        time.Time
}

func UserFromContext

func UserFromContext(ctx context.Context) (*User, bool)

type Users

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

func NewUsers

func NewUsers(_ context.Context, db *mongo.Database) (*Users, error)

func (*Users) Create

func (u *Users) Create(ctx context.Context, key crypto.PubKey) error

func (*Users) Delete

func (u *Users) Delete(ctx context.Context, key crypto.PubKey) error

func (*Users) Get

func (u *Users) Get(ctx context.Context, key crypto.PubKey) (*User, error)

func (*Users) SetBucketsTotalSize

func (u *Users) SetBucketsTotalSize(ctx context.Context, key crypto.PubKey, newTotalSize int64) error

Jump to

Keyboard shortcuts

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