Documentation
¶
Overview ¶
Package accesscontrollers decides who may write to a database.
It mirrors src/access-controllers in @orbitdb/core 4. An access controller has an address that goes into the database manifest, so every peer that opens the database enforces the same rules:
- "ipfs": an immutable write list stored as an IPFS block, /ipfs/<hash> of {type: "ipfs", write: [...]}. "*" lets anyone write.
- "orbitdb": a mutable list kept in a KeyValue database of its own, whose admins can grant and revoke write access.
Index ¶
- Constants
- func TypeOf(address string) string
- func UseAccessController(typ string, f Factory) error
- type AccessController
- type Factory
- type IPFSAccessController
- type IPFSOptions
- type OrbitDBAccessController
- func (a *OrbitDBAccessController) Address() string
- func (a *OrbitDBAccessController) CanAppend(ctx context.Context, entry *oplog.Entry) (bool, error)
- func (a *OrbitDBAccessController) Capabilities(ctx context.Context) (map[string][]string, error)
- func (a *OrbitDBAccessController) Close() error
- func (a *OrbitDBAccessController) Database() *databases.KeyValue
- func (a *OrbitDBAccessController) Drop(ctx context.Context) error
- func (a *OrbitDBAccessController) Events() *databases.Emitter
- func (a *OrbitDBAccessController) Get(ctx context.Context, capability string) ([]string, error)
- func (a *OrbitDBAccessController) Grant(ctx context.Context, capability, id string) error
- func (a *OrbitDBAccessController) HasCapability(ctx context.Context, capability, id string) (bool, error)
- func (a *OrbitDBAccessController) Revoke(ctx context.Context, capability, id string) error
- func (*OrbitDBAccessController) Type() string
- type OrbitDBOptions
- type Params
Constants ¶
const ( CapabilityWrite = "write" CapabilityAdmin = "admin" )
Capabilities of an OrbitDB access controller.
const IPFSType = "ipfs"
IPFSType is the type of IPFS access controllers.
const OrbitDBType = "orbitdb"
OrbitDBType is the type of OrbitDB access controllers.
Variables ¶
This section is empty.
Functions ¶
func TypeOf ¶
TypeOf returns the type part of an access controller address, e.g. "ipfs" for "/ipfs/zdpu...".
func UseAccessController ¶
UseAccessController registers the factory used to load access controllers of type typ from a manifest.
Types ¶
type AccessController ¶
type AccessController interface {
oplog.AccessController
// Type is the access controller type, e.g. "ipfs".
Type() string
// Address is stored in the database manifest.
Address() string
}
AccessController is an oplog.AccessController with an address.
type Factory ¶
type Factory func(ctx context.Context, p Params) (AccessController, error)
Factory creates a new access controller, or loads the one at Params.Address.
func GetAccessController ¶
GetAccessController returns the factory registered for typ.
func OrbitDB ¶
func OrbitDB(opts OrbitDBOptions) Factory
OrbitDB returns a factory for OrbitDB access controllers.
type IPFSAccessController ¶
type IPFSAccessController struct {
// contains filtered or unexported fields
}
IPFSAccessController allows a fixed list of writers.
func (*IPFSAccessController) Address ¶
func (a *IPFSAccessController) Address() string
Address implements AccessController.
func (*IPFSAccessController) Type ¶
func (*IPFSAccessController) Type() string
Type implements AccessController.
func (*IPFSAccessController) Write ¶
func (a *IPFSAccessController) Write() []string
Write returns the writers.
type IPFSOptions ¶
type IPFSOptions struct {
// Write lists the identity ids allowed to write; "*" allows anyone.
// Defaults to the local identity.
Write []string
// Storage holds the access controller block. Defaults to an LRU cache
// over the IPFS node's block storage.
Storage storage.Storage
}
IPFSOptions configures IPFS.
type OrbitDBAccessController ¶
type OrbitDBAccessController struct {
// contains filtered or unexported fields
}
OrbitDBAccessController keeps capabilities (lists of identity ids per capability) in a KeyValue database, so they can change over time. Grants and revocations are writes to that database, so only its writers (the Write list it was created with) can make them.
func (*OrbitDBAccessController) Address ¶
func (a *OrbitDBAccessController) Address() string
Address implements AccessController. It is the address of the capabilities database.
func (*OrbitDBAccessController) CanAppend ¶
CanAppend implements oplog.AccessController: writers and admins may write.
func (*OrbitDBAccessController) Capabilities ¶
Capabilities returns every capability and the ids that have it. The writers of the capabilities database are always admins.
func (*OrbitDBAccessController) Close ¶
func (a *OrbitDBAccessController) Close() error
Close closes the capabilities database.
func (*OrbitDBAccessController) Database ¶
func (a *OrbitDBAccessController) Database() *databases.KeyValue
Database returns the KeyValue database holding the capabilities.
func (*OrbitDBAccessController) Drop ¶
func (a *OrbitDBAccessController) Drop(ctx context.Context) error
Drop drops the capabilities database.
func (*OrbitDBAccessController) Events ¶
func (a *OrbitDBAccessController) Events() *databases.Emitter
Events returns the event emitter of the capabilities database.
func (*OrbitDBAccessController) Grant ¶
func (a *OrbitDBAccessController) Grant(ctx context.Context, capability, id string) error
Grant gives id capability.
func (*OrbitDBAccessController) HasCapability ¶
func (a *OrbitDBAccessController) HasCapability(ctx context.Context, capability, id string) (bool, error)
HasCapability reports whether id (or "*") has capability.
func (*OrbitDBAccessController) Revoke ¶
func (a *OrbitDBAccessController) Revoke(ctx context.Context, capability, id string) error
Revoke removes capability from id.
func (*OrbitDBAccessController) Type ¶
func (*OrbitDBAccessController) Type() string
Type implements AccessController.
type OrbitDBOptions ¶
type OrbitDBOptions struct {
// Write lists the identity ids that administer the list; they may also
// write. Defaults to the local identity.
Write []string
}
OrbitDBOptions configures OrbitDB.
type Params ¶
type Params struct {
// Identity is the local identity, the default sole writer.
Identity *identitytypes.Identity
// Identities resolves and verifies writer identities.
Identities *identities.Identities
// IPFS stores access controller blocks.
IPFS *ipfs.Node
// Address is set when opening an existing database: the access
// controller address from its manifest.
Address string
// Name is the database name when creating a database.
Name string
// OpenKeyValue opens a KeyValue database whose writes are controlled
// by access. The "orbitdb" access controller stores its list in one.
OpenKeyValue func(ctx context.Context, address string, access Factory) (*databases.KeyValue, error)
}
Params is what a Factory gets from OrbitDB.