mongodb

package
v2.6.20 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 NewAccountContext added in v2.1.4

func NewAccountContext(ctx context.Context, user, org *Account) context.Context

func NewSessionContext

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

Types

type APIKey

type APIKey struct {
	Key       string
	Secret    string
	Owner     thread.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 thread.PubKey, keyType APIKeyType, secure bool) (*APIKey, error)

func (*APIKeys) DeleteByOwner

func (k *APIKeys) DeleteByOwner(ctx context.Context, owner thread.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 thread.PubKey) ([]APIKey, error)

type Account

type Account struct {
	Type      AccountType
	Key       thread.PubKey
	Secret    thread.Identity
	Name      string
	Username  string
	Email     string
	Token     thread.Token
	Members   []Member
	PowInfo   *PowInfo
	CreatedAt time.Time
}

type AccountCtx added in v2.1.4

type AccountCtx struct {
	User *Account
	Org  *Account
}

func AccountCtxForAccount added in v2.1.7

func AccountCtxForAccount(account *Account) *AccountCtx

func AccountFromContext added in v2.1.4

func AccountFromContext(ctx context.Context) (*AccountCtx, bool)

func (*AccountCtx) Owner added in v2.1.4

func (ac *AccountCtx) Owner() *Account

type AccountType

type AccountType int
const (
	Dev AccountType = iota
	Org
	User
)

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, powInfo *PowInfo) (*Account, error)

func (*Accounts) CreateOrg

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

func (*Accounts) CreateUser added in v2.1.4

func (a *Accounts) CreateUser(ctx context.Context, key thread.PubKey, powInfo *PowInfo) (*Account, error)

func (*Accounts) Delete

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

func (*Accounts) Get

func (a *Accounts) Get(ctx context.Context, key thread.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 thread.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 thread.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 thread.PubKey) ([]Account, error)

func (*Accounts) ListByOwner

func (a *Accounts) ListByOwner(ctx context.Context, owner thread.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 thread.PubKey) error

func (*Accounts) SetToken

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

func (*Accounts) UpdatePowInfo

func (a *Accounts) UpdatePowInfo(ctx context.Context, key thread.PubKey, powInfo *PowInfo) (*Account, 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"`
	Status     int        `bson:"status"`
	Aborted    bool       `bson:"aborted"`
	AbortedMsg string     `bson:"aborted_msg"`
	FailureMsg string     `bson:"failure_msg"`
	CreatedAt  int64      `bson:"created_at"`
	DealInfo   []DealInfo `bson:"deal_info"`
}

type ArchiveConfig added in v2.1.0

type ArchiveConfig struct {
	// RepFactor (ignored in Filecoin mainnet) indicates the desired amount of active deals
	// with different miners to store the data. While making deals
	// the other attributes of FilConfig are considered for miner selection.
	RepFactor int `bson:"rep_factor"`
	// DealMinDuration indicates the duration to be used when making new deals.
	DealMinDuration int64 `bson:"deal_min_duration"`
	// ExcludedMiners (ignored in Filecoin mainnet) is a set of miner addresses won't be ever be selected
	// when making new deals, even if they comply to other filters.
	ExcludedMiners []string `bson:"excluded_miners"`
	// TrustedMiners (ignored in Filecoin mainnet) is a set of miner addresses which will be forcibly used
	// when making new deals. An empty/nil list disables this feature.
	TrustedMiners []string `bson:"trusted_miners"`
	// CountryCodes (ignored in Filecoin mainnet) indicates that new deals should select miners on specific
	// countries.
	CountryCodes []string `bson:"country_codes"`
	// Renew indicates deal-renewal configuration.
	Renew ArchiveRenew `bson:"renew"`
	// MaxPrice is the maximum price that will be spent to store the data
	MaxPrice uint64 `bson:"max_price"`
	// FastRetrieval indicates that created deals should enable the
	// fast retrieval feature.
	FastRetrieval bool `bson:"fast_retrieval"`
	// DealStartOffset indicates how many epochs in the future impose a
	// deadline to new deals being active on-chain. This value might influence
	// if miners accept deals, since they should seal fast enough to satisfy
	// this constraint.
	DealStartOffset int64 `bson:"deal_start_offset"`
	// VerifiedDeal indicates that new deals should be marked as verified,
	// assuming the wallet address has enough data-cap.
	VerifiedDeal bool `bson:"verified_deal"`
}

ArchiveConfig is the desired state of a Cid in the Filecoin network.

type ArchiveRenew added in v2.1.0

type ArchiveRenew struct {
	// Enabled indicates that deal-renewal is enabled for this Cid.
	Enabled bool `bson:"enabled"`
	// Threshold indicates how many epochs before expiring should trigger
	// deal renewal. e.g: 100 epoch before expiring.
	Threshold int `bson:"threshold"`
}

ArchiveRenew contains renew configuration for a ArchiveConfig.

type ArchiveTracking

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

func NewArchiveTracking

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

func (*ArchiveTracking) CreateArchive added in v2.6.0

func (at *ArchiveTracking) CreateArchive(ctx context.Context, dbID thread.ID, dbToken thread.Token, bucketKey string, jid string, bucketRoot cid.Cid, owner thread.PubKey) error

func (*ArchiveTracking) CreateRetrieval added in v2.6.0

func (at *ArchiveTracking) CreateRetrieval(ctx context.Context, accKey, jobID, powToken string) error

func (*ArchiveTracking) Finalize

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

func (*ArchiveTracking) Get

func (at *ArchiveTracking) Get(ctx context.Context, jid string) (*TrackedJob, error)

func (*ArchiveTracking) GetReadyToCheck

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

func (*ArchiveTracking) Reschedule

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

type Archives

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

type BucketArchive

type BucketArchive struct {
	BucketKey            string         `bson:"_id"`
	Archives             Archives       `bson:"archives"`
	DefaultArchiveConfig *ArchiveConfig `bson:"default_archive_config"`
}

type BucketArchives

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

func NewBucketArchives

func NewBucketArchives(_ context.Context, db *mongo.Database) (*BucketArchives, error)

func (*BucketArchives) Create

func (k *BucketArchives) Create(ctx context.Context, bucketKey string) (*BucketArchive, error)

func (*BucketArchives) GetOrCreate

func (k *BucketArchives) GetOrCreate(ctx context.Context, bucketKey string) (*BucketArchive, error)

func (*BucketArchives) Replace

func (k *BucketArchives) Replace(ctx context.Context, ba *BucketArchive) error

type Collections

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

	Threads         *Threads
	APIKeys         *APIKeys
	IPNSKeys        *IPNSKeys
	BucketArchives  *BucketArchives
	ArchiveTracking *ArchiveTracking
	// contains filtered or unexported fields
}

func NewCollections

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

NewCollections gets or create store instances for active collections.

func (*Collections) Close

func (c *Collections) Close() error

type DealInfo added in v2.2.0

type DealInfo struct {
	ProposalCid string `bson:"proposal_cid"`
	StateID     uint64 `bson:"state_id"`
	StateName   string `bson:"state_name"`
	Miner       string `bson:"miner"`

	PieceCID string `bson:"piece_cid"`
	Size     uint64 `bson:"size"`

	PricePerEpoch uint64 `bson:"price_per_epoch"`
	StartEpoch    uint64 `bson:"start_epoch"`
	Duration      uint64 `bson:"duration"`

	DealID          uint64 `bson:"deal_id"`
	ActivationEpoch int64  `bson:"activation_epoch"`
	Message         string `bson:"message"`
}

type IPNSKey

type IPNSKey struct {
	Name      string
	Cid       string
	Path      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, pth string) 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) List added in v2.6.2

func (k *IPNSKeys) List(ctx context.Context) ([]IPNSKey, error)

func (*IPNSKeys) ListByThreadID

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

func (*IPNSKeys) SetPath added in v2.6.2

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

SetPath updates the latest path for the ipnskey

type Invite

type Invite struct {
	Token     string
	Org       string
	From      thread.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 thread.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 thread.PubKey) error

func (*Invites) DeleteByFromAndOrg

func (i *Invites) DeleteByFromAndOrg(ctx context.Context, from thread.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      thread.PubKey
	Username string
	Role     Role
}

type PowInfo

type PowInfo struct {
	ID    string
	Token string
}

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     thread.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 thread.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 thread.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     thread.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 thread.PubKey, isDB bool) (*Thread, error)

func (*Threads) Delete

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

func (*Threads) DeleteByOwner

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

func (*Threads) Get

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

func (*Threads) GetByName

func (t *Threads) GetByName(ctx context.Context, name string, owner thread.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 thread.PubKey) ([]Thread, error)

type TrackedJob added in v2.6.0

type TrackedJob struct {
	JID     string
	Type    archive.TrackedJobType
	ReadyAt time.Time
	Cause   string
	Active  bool

	// Set by TrackedJobTypeArchive type.
	DbID       thread.ID
	DbToken    thread.Token
	BucketKey  string
	BucketRoot cid.Cid
	Owner      thread.PubKey

	// Set by TrackedJobTypeRetrieval type.
	PowToken string
	AccKey   string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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