bakerystorage

package
v0.0.0-...-bfa9622 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: AGPL-3.0 Imports: 11 Imported by: 8

Documentation

Overview

Package bakerystorage provides an implementation of the bakery Storage interface that uses MongoDB to store items.

This is based on github.com/go-macaroon-bakery/macaroon-bakery/v3/bakery/mgorootkeystore.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithMgoSession

func ContextWithMgoSession(ctx context.Context, s *mgo.Session) context.Context

ContextWithMgoSession adds the given mgo.Session to the given context.Context. Any operations requiring database access that are made using a context with an attached session will use the session from the context to access mongodb, rather than the session in the collection used when the RootKeyStore was created.

func MongoIndexes

func MongoIndexes() []mgo.Index

MongoIndexes returns the indexes to apply to the MongoDB collection.

Types

type BakeryConfig

type BakeryConfig interface {
	InitialiseBakeryConfigOp() (txn.Op, error)
	GetLocalUsersKey() (*bakery.KeyPair, error)
	GetLocalUsersThirdPartyKey() (*bakery.KeyPair, error)
	GetExternalUsersThirdPartyKey() (*bakery.KeyPair, error)
	GetOffersThirdPartyKey() (*bakery.KeyPair, error)
}

BakeryConfig defines methods used to access bakery configuration.

func NewBakeryConfig

func NewBakeryConfig(collection string, collectionGetter collectionGetterFunc) BakeryConfig

NewBakeryConfig returns an instance used to access bakery configuration.

type Config

type Config struct {
	// GetCollection returns a mongo.Collection and a function that
	// will close any associated resources.
	GetCollection func() (collection mongo.Collection, closer func())

	// GetStorage returns a bakery.Storage and a function that will close
	// any associated resources.
	GetStorage func(rootKeys *RootKeys, coll mongo.Collection, expireAfter time.Duration) (storage bakery.RootKeyStore)
}

Config contains configuration for creating bakery storage with New.

func (Config) Validate

func (c Config) Validate() error

Validate validates the configuration.

type ExpirableStorage

type ExpirableStorage interface {
	bakery.RootKeyStore

	// ExpireAfter returns a new ExpirableStorage that will expire
	// added items after the specified duration.
	ExpireAfter(time.Duration) ExpirableStorage
}

ExpirableStorage extends bakery.Storage with the ExpireAfter method, to expire data added at the specified time.

func New

func New(config Config) (ExpirableStorage, error)

New returns an implementation of bakery.Storage that stores all items in MongoDB with an expiry time.

type Policy

type Policy dbrootkeystore.Policy

Policy holds a store policy for root keys.

type RootKeys

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

RootKeys represents a cache of macaroon root keys.

func NewRootKeys

func NewRootKeys(maxCacheSize int) *RootKeys

NewRootKeys returns a root-keys cache that is limited in size to approximately the given size.

The NewStore method returns a store implementation that uses a specific mongo collection and store policy.

func (*RootKeys) EnsureIndex

func (s *RootKeys) EnsureIndex(c *mgo.Collection) error

EnsureIndex ensures that the required indexes exist on the collection that will be used for root key store. This should be called at least once before using NewStore.

func (*RootKeys) NewStore

func (s *RootKeys) NewStore(c *mgo.Collection, policy Policy) bakery.RootKeyStore

NewStore returns a new RootKeyStore implementation that stores and obtains root keys from the given collection.

Root keys will be generated and stored following the given store policy.

It is expected that all collections passed to a given Store's NewStore method should refer to the same underlying collection.

Jump to

Keyboard shortcuts

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