blobcached

package
v0.0.0-...-575026b Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IdentitiesFilename = "IDENTITIES"
	ActionsFilename    = "ACTIONS"
	ObjectsFilename    = "OBJECTS"
	GrantsFilename     = "GRANTS"
)

Variables

View Source
var Everyone = inet256.Everyone()

Functions

func AwaitHealthy

func AwaitHealthy(ctx context.Context, svc blobcache.Service) error

func DefaultActionsFile

func DefaultActionsFile() (ret string)

func DefaultGrantsFile

func DefaultGrantsFile() (ret string)

func DefaultIdentitiesFile

func DefaultIdentitiesFile() (ret string)

func DefaultObjectsFile

func DefaultObjectsFile() (ret string)

func LoadPrivateKey

func LoadPrivateKey(p string) (inet256.PrivateKey, error)

func SavePrivateKey

func SavePrivateKey(p string, privKey inet256.PrivateKey) error

func WriteActionsFile

func WriteActionsFile(w io.Writer, actions []Membership[Action]) error

func WriteGrantsFile

func WriteGrantsFile(w io.Writer, grants []Grant) error

func WriteGroupsFile

func WriteGroupsFile[T any](w io.Writer, membership []Membership[T], format func(T) string) error

WriteGroupsFile writes the memberships to the writer, such that they can be parsed by ParseGroupsFile.

func WriteIdentitiesFile

func WriteIdentitiesFile(w io.Writer, membership []Membership[Identity]) error

WriteIdentitiesFile writes the memberships to the writer, such that they can be parsed by ParseIdentitiesFile. It inserts an extra newline every time the group changes from the previous membership.

func WriteObjectsFile

func WriteObjectsFile(w io.Writer, objects []Membership[ObjectSet]) error

Types

type Action

type Action string
const (
	Action_LOAD      Action = "LOAD"
	Action_SAVE      Action = "SAVE"
	Action_POST      Action = "POST"
	Action_GET       Action = "GET"
	Action_EXISTS    Action = "EXISTS"
	Action_DELETE    Action = "DELETE"
	Action_COPY_FROM Action = "COPY_FROM"
	Action_COPY_TO   Action = "COPY_TO"
	Action_LINK_FROM Action = "LINK_FROM"
	Action_LINK_TO   Action = "LINK_TO"
	Action_AWAIT     Action = "AWAIT"
	Action_CLONE     Action = "CLONE"
	Action_CREATE    Action = "CREATE"
)

func ParseAction

func ParseAction(x []byte) (Action, error)

func (Action) String

func (a Action) String() string

func (Action) ToSet

func (a Action) ToSet() blobcache.ActionSet

type Daemon

type Daemon struct {
	StateDir string
}

Daemon manages the state and configuration for running a Blobache node.

func RunTestDaemon

func RunTestDaemon(t testing.TB) (*Daemon, string)

RunTestDaemon launches a test daemon and returns it and the API address. This function will block until the daemon is healthy. The daemon will be stopped and cleaned up at the end of the test. The test will fail during cleanup if the daemon fails to stop, and The test will not complete until the daemon is successfully torn down.

func (*Daemon) EnsurePolicyFiles

func (d *Daemon) EnsurePolicyFiles() error

EnsurePolicyFiles ensures that the policy files exist. Creating default files if they don't exist.

func (*Daemon) EnsurePrivateKey

func (d *Daemon) EnsurePrivateKey() (inet256.PrivateKey, error)

EnsurePrivateKey generates a private key if it doesn't exist, and returns it.

func (*Daemon) GetPolicy

func (d *Daemon) GetPolicy() (*Policy, error)

func (*Daemon) Run

func (d *Daemon) Run(ctx context.Context, pc net.PacketConn, serveAPI net.Listener) error

Run runs the blobcache daemon, until the context is cancelled. If the context is cancelled, Run returns nil. Run returns an error if it returns for any other reason.

type Grant

type Grant struct {
	Subject Member[Identity]
	Action  Member[Action]
	Object  Member[ObjectSet]
}

func LoadGrantsFile

func LoadGrantsFile(p string) ([]Grant, error)

LoadGrantsFile loads the grants file from the filesystem. p should be the path to the grants file.

func ParseGrantsFile

func ParseGrantsFile(r io.Reader) (ret []Grant, _ error)

func (*Grant) Equals

func (g *Grant) Equals(other Grant) bool

type GroupName

type GroupName string

func ParseGroupName

func ParseGroupName(x []byte) (GroupName, error)

type Identity

type Identity = blobcache.PeerID

func ParseIdentity

func ParseIdentity(x []byte) (Identity, error)

type Member

type Member[T any] struct {
	// Unit references a single element
	Unit *T
	// GroupRef references another group by name.
	GroupRef *GroupName
	// Empty is used to create empty groups.
	Empty *struct{}
}

Member is a member of a group. Members can either refer to another group by name, or to a single element of type T.

func GroupRef

func GroupRef[T any](subGroup GroupName) Member[T]

GroupRef creates a group member that references a group by name.

func ParseMember

func ParseMember[T any](data []byte, parse func([]byte) (T, error)) (Member[T], error)

func Unit

func Unit[T any](unit T) Member[T]

Unit creates a group member that references a single element.

func (Member[T]) Format

func (m Member[T]) Format(format func(T) string) string

type Membership

type Membership[T any] struct {
	Group  GroupName
	Member Member[T]
}

Membership says that a group contains a member.

func LoadActionsFile

func LoadActionsFile(p string) ([]Membership[Action], error)

LoadActionsFile loads the actions file from the filesystem. p should be the path to the actions file.

func LoadIdentitiesFile

func LoadIdentitiesFile(p string) ([]Membership[Identity], error)

LoadIdentitiesFile loads the identities file from the filesystem. p should be the path to the identities file.

func LoadObjectsFile

func LoadObjectsFile(p string) ([]Membership[ObjectSet], error)

LoadObjectsFile loads the objects file from the filesystem. p should be the path to the objects file.

func ParseActionsFile

func ParseActionsFile(r io.Reader) (ret []Membership[Action], _ error)

func ParseGroupsFile

func ParseGroupsFile[T any](r io.Reader, parse func([]byte) (T, error)) (ret []Membership[T], _ error)

func ParseIdentitiesFile

func ParseIdentitiesFile(r io.Reader) (ret []Membership[Identity], _ error)

ParseIdentitiesFiles parses a Group file into a list of identity group memberships.

func ParseObjectsFile

func ParseObjectsFile(r io.Reader) (ret []Membership[ObjectSet], _ error)

type ObjectSet

type ObjectSet struct {
	// ByOID is a specific OID
	ByOID *blobcache.OID
	// All refers to all possible objects
	All *struct{}
}

ObjectSet is something that Actions are performed on. It can be a specific OID, or a set of names defined by a regular expression.

func ParseObject

func ParseObject(x []byte) (ObjectSet, error)

func (ObjectSet) Equals

func (o ObjectSet) Equals(other ObjectSet) bool

func (ObjectSet) String

func (o ObjectSet) String() string

type Policy

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

func LoadPolicy

func LoadPolicy(stateDir string) (*Policy, error)

LoadPolicy loads the 4 policy files from the filesystem. stateDir should be the path to the state directory.

func NewPolicy

func NewPolicy(idens []Membership[Identity], actions []Membership[Action], objects []Membership[ObjectSet], grants []Grant) (*Policy, error)

func (*Policy) AllActionGroups

func (p *Policy) AllActionGroups() iter.Seq[string]

func (*Policy) AllGrants

func (p *Policy) AllGrants() iter.Seq[Grant]

func (*Policy) AllIdentityGroups

func (p *Policy) AllIdentityGroups() iter.Seq[string]

func (*Policy) AllObjectGroups

func (p *Policy) AllObjectGroups() iter.Seq[string]

func (*Policy) CanConnect

func (p *Policy) CanConnect(peer blobcache.PeerID) bool

func (*Policy) CanCreate

func (p *Policy) CanCreate(peer blobcache.PeerID) bool

func (*Policy) IdentityMembersOf

func (p *Policy) IdentityMembersOf(group string) iter.Seq[Identity]

func (*Policy) IsIdentityDefined

func (p *Policy) IsIdentityDefined(iden Identity) bool

IsDefined returns true if the identity is a defined group, or a peer.

func (*Policy) Open

func (p *Policy) Open(peer blobcache.PeerID, target blobcache.OID) blobcache.ActionSet

Jump to

Keyboard shortcuts

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