keystore

package
v0.0.39 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UndefinedACL indicates that the control rule is undefined.
	// If all matching rules are `undefined`, KeyStore will return a reject decision.
	UndefinedACL = iota
	// Allow indicates that this policy is allowed.
	Allow = iota
	// Deny indicates that this policy is denied.
	Deny = iota

	// InvokeAction indicates invoke type of requests.
	InvokeAction = iota
	// ListenAction indicates listen type of requests.
	ListenAction = iota
)

Variables

This section is empty.

Functions

func HashKey

func HashKey(key []byte) string

HashKey returns a hashed salted key, which will store on disk.

Types

type ACLRule

type ACLRule struct {
	// Controls the ability to listen to a channel.
	ListenControl int `json:"listen" default:"0"`
	// Controls the ability to invoke services on a channel.
	InvokeControl int `json:"invoke" default:"0"`
	// Specifies the regular expression matching rules.
	ChannelRegexp string `json:"channel_regexp"`
}

ACLRule stores an access control rule to all channels matched with `ChannelRegexp`.

type KeyStore

type KeyStore struct {
	Table map[string]*SessionKey `json:"table"`
	// contains filtered or unexported fields
}

KeyStore - A structure to store a set of keys. This structure is thread-compatible.

func CreateKeyStore

func CreateKeyStore() *KeyStore

CreateKeyStore initializes a key store in memory.

func LoadKeyStore

func LoadKeyStore(FileName string) (*KeyStore, error)

LoadKeyStore will load configuration from disk.

func (*KeyStore) CheckPermission

func (store *KeyStore) CheckPermission(requestType int, channelName string, key []byte) bool

CheckPermission checks the permission of the header for given request type acting on the requested channel. We only examine the first key within the `header`.

func (*KeyStore) CleanUp

func (store *KeyStore) CleanUp()

CleanUp serves as a garbage collection function that will remove all expired keys and remove all entries within cache.

func (*KeyStore) GenerateKeyAndRegister

func (store *KeyStore) GenerateKeyAndRegister(name string, rules []ACLRule, duration time.Duration) string

GenerateKeyAndRegister generates a key and registers into the table.

func (*KeyStore) GetExpireTime

func (store *KeyStore) GetExpireTime(key []byte) time.Time

GetExpireTime returns the expiration time of the key, if key is not registered, a past time will be returned.

func (*KeyStore) GetSessionKey

func (store *KeyStore) GetSessionKey(key []byte) *SessionKey

GetSessionKey returns the matched key property.

func (*KeyStore) LoadKeyStore added in v0.0.27

func (store *KeyStore) LoadKeyStore(FileName string) error

LoadKeyStore replaces the keystore with the one on disk.

func (*KeyStore) RegisterKey

func (store *KeyStore) RegisterKey(Key []byte, property SessionKey) error

RegisterKey registers a key into the KeyStore. Returns error if there is an existing unexpired key.

func (*KeyStore) Save

func (store *KeyStore) Save(FileName string) error

Save dumps all configuration to the disk in JSON format WITHOUT any encryption.

func (*KeyStore) UpdateKey

func (store *KeyStore) UpdateKey(Key []byte, property SessionKey)

UpdateKey updates the property of the Key, will create a new entry if Key does not exist.

type SessionKey

type SessionKey struct {
	// Expiration time of the key.
	Expire time.Time `json:"expire"`
	// If there are multiple matching rules, takes the later one in the array.
	Rules []ACLRule `json:"rules"`
	// ID of this key, just for identification.
	ID string `json:"id"`
	// Description of this key.
	Description string `json:"description"`
}

SessionKey represents the property of the key.

Jump to

Keyboard shortcuts

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