Documentation ¶
Index ¶
- Constants
- Variables
- func CreateModelFormEnforcerState(state EnforcerState) (model2.Model, error)
- func IsNewNode(raftDir string) bool
- func SnapshotHdr() []byte
- type AssertionState
- type AssertionStateMap
- type BackupFormat
- type ClusterState
- type EnforcerState
- type FSMEnforceResponse
- type FSMResponse
- type ListNamespacesResponse
- type ListPoliciesOptions
- type ListPoliciesResponse
- type Listener
- type ModelState
- type PrintModelResponse
- type Server
- type Servers
- type Store
- func (s *Store) AddPolicies(ctx context.Context, ns string, sec string, pType string, rules [][]string) ([][]string, error)
- func (s *Store) Addr() string
- func (s *Store) Apply(l *raft.Log) (e interface{})
- func (s *Store) AuthType() auth.AuthType
- func (s *Store) Check(username, password string) bool
- func (s *Store) ClearPolicy(ctx context.Context, ns string) error
- func (s *Store) Close(wait bool) error
- func (s *Store) CreateNamespace(ctx context.Context, ns string) error
- func (s *Store) Enforce(ctx context.Context, ns string, level command.EnforcePayload_Level, ...) (bool, error)
- func (s *Store) ID() string
- func (s *Store) InitAuth(ctx context.Context, rootUsername string) error
- func (s *Store) InitRoot(username, password string) error
- func (s *Store) IsLeader() bool
- func (s *Store) Join(id, addr string, voter bool, metadata map[string]string) error
- func (s *Store) LeaderAddr() string
- func (s *Store) LeaderID() (string, error)
- func (s *Store) ListNamespace(ctx context.Context) ([]string, error)
- func (s *Store) ListPolicies(ctx context.Context, namespace, cursor string, skip, limit int64, reverse bool) ([][]string, error)
- func (s *Store) Metadata(id, key string) string
- func (s *Store) Nodes() ([]*Server, error)
- func (s *Store) Open(enableBootstrap bool) error
- func (s *Store) Path() string
- func (s *Store) Policies(ctx context.Context, ns string, options *ListPoliciesOptions) ([][]string, error)
- func (s *Store) PrintModel(ctx context.Context, namespace string) (string, error)
- func (s *Store) Remove(id string) error
- func (s *Store) RemoveFilteredPolicy(ctx context.Context, ns string, sec string, pType string, fi int32, ...) ([][]string, error)
- func (s *Store) RemovePolicies(ctx context.Context, ns string, sec string, pType string, rules [][]string) ([][]string, error)
- func (s *Store) Restore(closer io.ReadCloser) error
- func (s *Store) SetMetadata(md map[string]string) error
- func (s *Store) SetModelFromString(ctx context.Context, ns string, text string) error
- func (s *Store) Snapshot() (raft.FSMSnapshot, error)
- func (s *Store) State() ClusterState
- func (s *Store) Stats() (map[string]interface{}, error)
- func (s *Store) UpdatePolicies(ctx context.Context, ns string, sec string, pType string, nr, or [][]string) (bool, error)
- func (s *Store) WaitForApplied(timeout time.Duration) error
- func (s *Store) WaitForAppliedIndex(idx uint64, timeout time.Duration) error
- func (s *Store) WaitForLeader(timeout time.Duration) (string, error)
- type StoreConfig
- type Transport
Constants ¶
const ( // BackupBinary is a file backup format. BackupBinary = iota )
const (
SystemEnforce = ".system"
)
Variables ¶
var ( NamespaceExisted = errors.New("namespace already existed") ModelUnsetYet = errors.New("model unset yet") // NamespaceNotExist namespace not exist NamespaceNotExist = errors.New("namespace not exist") // UnmarshalFailed unmarshal failed UnmarshalFailed = errors.New("unmarshal failed") // Transaction failed StateTransactionFailed = errors.New("state transaction failed") )
var ( // ErrNotLeader is returned when a node attempts to execute a leader-only // operation. ErrNotLeader = errors.New("not leader") // ErrStaleRead is returned if the executing the query would violate the // requested freshness. ErrStaleRead = errors.New("stale read") // ErrOpenTimeout is returned when the Store does not apply its initial // logs within the specified time. ErrOpenTimeout = errors.New("timeout waiting for initial logs application") // ErrInvalidBackupFormat is returned when the requested backup format // is not valid. ErrInvalidBackupFormat = errors.New("invalid backup format") )
Functions ¶
func CreateModelFormEnforcerState ¶
func CreateModelFormEnforcerState(state EnforcerState) (model2.Model, error)
CreateModelFormEnforcerState creates enforcer state and links rule groups
func IsNewNode ¶
IsNewNode returns whether a node using raftDir would be a brand new node. It also means that the window this node joining a different cluster has passed.
func SnapshotHdr ¶
func SnapshotHdr() []byte
SnapshotHdr is used to identify the snapshot protocol version. length 8 bytes
Types ¶
type AssertionState ¶
type AssertionStateMap ¶
type AssertionStateMap map[string]AssertionState
type ClusterState ¶
type ClusterState int
ClusterState defines the possible Raft states the current node can be in
const ( Leader ClusterState = iota Follower Candidate Shutdown Unknown )
Represents the Raft cluster states
type EnforcerState ¶
type EnforcerState struct {
Model ModelState
}
func CreateEnforcerState ¶
func CreateEnforcerState(e *casbin.DistributedEnforcer) (EnforcerState, error)
CreateEnforcerState transfers enforce state to a persistable enforce state
type FSMEnforceResponse ¶
type FSMEnforceResponse struct {
// contains filtered or unexported fields
}
type FSMResponse ¶
type FSMResponse struct {
// contains filtered or unexported fields
}
type ListNamespacesResponse ¶
type ListNamespacesResponse struct {
// contains filtered or unexported fields
}
type ListPoliciesOptions ¶
type ListPoliciesResponse ¶
type ListPoliciesResponse struct {
// contains filtered or unexported fields
}
type Listener ¶
type Listener interface { net.Listener Dial(address string, timeout time.Duration) (net.Conn, error) }
Listener is the interface expected by the Store for Transports.
type ModelState ¶
type ModelState map[string]AssertionStateMap
type PrintModelResponse ¶
type PrintModelResponse struct {
// contains filtered or unexported fields
}
type Store ¶
type Store struct { ShutdownOnRemove bool SnapshotThreshold uint64 SnapshotInterval time.Duration LeaderLeaseTimeout time.Duration HeartbeatTimeout time.Duration ElectionTimeout time.Duration ApplyTimeout time.Duration RaftLogLevel string // contains filtered or unexported fields }
Store is casbin memory data, where all changes are made via Raft consensus.
func (*Store) AddPolicies ¶
func (s *Store) AddPolicies(ctx context.Context, ns string, sec string, pType string, rules [][]string) ([][]string, error)
AddPolicies implements the casbin.Adapter interface.
func (*Store) ClearPolicy ¶
ClearPolicy implements the casbin.Adapter interface.
func (*Store) CreateNamespace ¶
CreateNamespace creates a new namespace.
func (*Store) Enforce ¶
func (s *Store) Enforce(ctx context.Context, ns string, level command.EnforcePayload_Level, freshness int64, params ...interface{}) (bool, error)
Enforce executes enforcement.
func (*Store) Join ¶
Join joins a node, identified by id and located at addr, to this store. The node must be ready to respond to Raft communications at that address.
func (*Store) LeaderAddr ¶
LeaderAddr returns the address of the current leader. Returns a blank string if there is no leader.
func (*Store) LeaderID ¶
LeaderID returns the node ID of the Raft leader. Returns a blank string if there is no leader, or an error.
func (*Store) ListPolicies ¶
func (*Store) Open ¶
Open opens the Store. If enableBootstrap is set, then this node becomes a standalone node. If not set, then the calling layer must know that this node has pre-existing state, or the calling layer will trigger a join operation after opening the Store.
func (*Store) Policies ¶
func (s *Store) Policies(ctx context.Context, ns string, options *ListPoliciesOptions) ([][]string, error)
Policies list policies
func (*Store) PrintModel ¶
func (*Store) RemoveFilteredPolicy ¶
func (s *Store) RemoveFilteredPolicy(ctx context.Context, ns string, sec string, pType string, fi int32, fv []string) ([][]string, error)
RemoveFilteredPolicy implements the casbin.Adapter interface.
func (*Store) RemovePolicies ¶
func (s *Store) RemovePolicies(ctx context.Context, ns string, sec string, pType string, rules [][]string) ([][]string, error)
RemovePolicies implements the casbin.Adapter interface.
func (*Store) Restore ¶
func (s *Store) Restore(closer io.ReadCloser) error
Restore restores form a preexisted states
func (*Store) SetMetadata ¶
SetMetadata adds the metadata md to any existing metadata for this node.
func (*Store) SetModelFromString ¶
SetModelFromString sets casbin model from string.
func (*Store) Snapshot ¶
func (s *Store) Snapshot() (raft.FSMSnapshot, error)
Snapshot creates a persistable state for application
func (*Store) State ¶
func (s *Store) State() ClusterState
State returns the current node's Raft state
func (*Store) UpdatePolicies ¶
func (s *Store) UpdatePolicies(ctx context.Context, ns string, sec string, pType string, nr, or [][]string) (bool, error)
UpdatePolicies implements the casbin.Adapter interface.
func (*Store) WaitForApplied ¶
WaitForApplied waits for all Raft log entries to to be applied to the underlying database.
func (*Store) WaitForAppliedIndex ¶
WaitForAppliedIndex blocks until a given log index has been applied, or the timeout expires.
type StoreConfig ¶
type StoreConfig struct { Dir string // The working directory for raft. Tn Transport // The underlying Transport for raft. ID string // Node ID. Logger *log.Logger // The logger to use to log stuff. AuthType auth.AuthType *auth.CredentialsStore AdvAddr string }
StoreConfig represents the configuration of the underlying Store.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is the network service provided to Raft, and wraps a Listener.
func NewTransport ¶
NewTransport returns an initialized Transport.