Documentation ¶
Index ¶
- Constants
- Variables
- func NewLicenseAndMaster() (string, string)
- type Channel
- type ChannelOption
- type Cipher
- type Contract
- type ContractProvider
- type HTTPContractProvider
- type ID
- type Key
- func (k Key) Contract() uint32
- func (k Key) Expires() time.Time
- func (k Key) HasPermission(flag uint32) bool
- func (k Key) IsEmpty() bool
- func (k Key) IsExpired() bool
- func (k Key) IsMaster() bool
- func (k Key) Master() uint16
- func (k Key) Permissions() uint32
- func (k Key) Salt() uint16
- func (k Key) SetContract(value uint32)
- func (k Key) SetExpires(value time.Time)
- func (k Key) SetMaster(value uint16)
- func (k Key) SetPermissions(value uint32)
- func (k Key) SetSalt(value uint16)
- func (k Key) SetSignature(value uint32)
- func (k Key) SetTarget(channel string) error
- func (k Key) Signature() uint32
- func (k Key) ValidateChannel(ch *Channel) bool
- type License
- type NoopContractProvider
- type SingleContractProvider
Constants ¶
const ( ChannelInvalid = uint8(iota) ChannelStatic ChannelWildcard )
Channel types
const ( ContractStateUnknown = uint8(iota) ContractStateAllowed ContractStateRefused )
The contract's state possible values.
const ( AllowNone = uint32(0) // Key has no privileges. AllowMaster = uint32(1 << 0) // Key should be allowed to generate other keys. AllowRead = uint32(1 << 1) // Key should be allowed to subscribe to the target channel. AllowWrite = uint32(1 << 2) // Key should be allowed to publish to the target channel. AllowStore = uint32(1 << 3) // Key should be allowed to write to the message history of the target channel. AllowLoad = uint32(1 << 4) // Key should be allowed to write to read the message history of the target channel. AllowPresence = uint32(1 << 5) // Key should be allowed to query the presence on the target channel. AllowReadWrite = AllowRead | AllowWrite // Key should be allowed to read and write to the target channel. AllowStoreLoad = AllowStore | AllowLoad // Key should be allowed to read and write the message history. )
Access types for a security key.
const ( LicenseTypeUnknown = iota LicenseTypeCloud LicenseTypeOnPremise )
Various license types
Variables ¶
var ( ErrTargetInvalid = errors.New("channel should end with `/` for strict types or `/#/` for multi level wildcard") ErrTargetTooLong = errors.New("channel can not have more than 23 parts") )
Key errors
Functions ¶
func NewLicenseAndMaster ¶
NewLicenseAndMaster generates a new license and master key.
Types ¶
type Channel ¶
type Channel struct { Key []byte // Gets or sets the API key of the channel. Channel []byte // Gets or sets the channel string. Query []uint32 // Gets or sets the full ssid. Options []ChannelOption // Gets or sets the options. ChannelType uint8 }
Channel represents a parsed MQTT topic.
func ParseChannel ¶
ParseChannel attempts to parse the channel from the underlying slice.
type ChannelOption ¶
ChannelOption represents a key/value pair option.
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
Cipher represents a security cipher which can encrypt/decrypt security keys.
func (*Cipher) DecryptKey ¶
DecryptKey decrypts the security key from a base64 encoded string.
func (*Cipher) EncryptKey ¶
EncryptKey encrypts the key and return a base-64 encoded string.
type Contract ¶
type Contract interface { Validate(key Key) bool // Validate checks the security key with the contract. Stats() usage.Meter // Gets the usage statistics. }
Contract represents an interface for a contract.
type ContractProvider ¶
type ContractProvider interface { config.Provider Create() (Contract, error) Get(id uint32) (Contract, bool) }
ContractProvider represents an interface for a contract provider.
type HTTPContractProvider ¶
type HTTPContractProvider struct {
// contains filtered or unexported fields
}
HTTPContractProvider provides contracts over http.
func NewHTTPContractProvider ¶
func NewHTTPContractProvider(license *License, metering usage.Metering) *HTTPContractProvider
NewHTTPContractProvider creates a new single contract provider.
func (*HTTPContractProvider) Configure ¶
func (p *HTTPContractProvider) Configure(config map[string]interface{}) (err error)
Configure configures the provider.
func (*HTTPContractProvider) Create ¶
func (p *HTTPContractProvider) Create() (Contract, error)
Create creates a contract, the HTTPContractProvider way.
func (*HTTPContractProvider) Get ¶
func (p *HTTPContractProvider) Get(id uint32) (Contract, bool)
Get returns a ContractData fetched by its id.
func (*HTTPContractProvider) Name ¶
func (p *HTTPContractProvider) Name() string
Name returns the name of the provider.
type Key ¶
type Key []byte
Key represents a security key.
func (Key) HasPermission ¶
HasPermission check whether the key provides some permission.
func (Key) SetExpires ¶
SetExpires sets the expiration date for the key.
func (Key) SetPermissions ¶
SetPermissions sets the permission flags.
func (Key) SetSignature ¶
SetSignature sets the signature of the contract.
func (Key) ValidateChannel ¶
ValidateChannel validates the channel string.
type License ¶
type License struct { EncryptionKey string // Gets or sets the encryption key. Contract uint32 // Gets or sets the contract id. Signature uint32 // Gets or sets the signature of the contract. Expires time.Time // Gets or sets the expiration date for the license. Type uint32 // Gets or sets the license type. }
License represents a security license for the service.
func ParseLicense ¶
ParseLicense decrypts the license and verifies it.
func (*License) NewMasterKey ¶
NewMasterKey generates a new master key.
type NoopContractProvider ¶
type NoopContractProvider struct{}
NoopContractProvider does not provide a contract.
func NewNoopContractProvider ¶
func NewNoopContractProvider() *NoopContractProvider
NewNoopContractProvider creates a new no-op contract provider.
func (*NoopContractProvider) Configure ¶
func (p *NoopContractProvider) Configure(config map[string]interface{}) error
Configure configures the provider.
func (*NoopContractProvider) Create ¶
func (p *NoopContractProvider) Create() (Contract, error)
Create creates a contract, the SingleContractProvider way.
func (*NoopContractProvider) Get ¶
func (p *NoopContractProvider) Get(id uint32) (Contract, bool)
Get returns a ContractData fetched by its id.
func (*NoopContractProvider) Name ¶
func (p *NoopContractProvider) Name() string
Name returns the name of the provider.
type SingleContractProvider ¶
type SingleContractProvider struct {
// contains filtered or unexported fields
}
SingleContractProvider provides contracts on premise.
func NewSingleContractProvider ¶
func NewSingleContractProvider(license *License, metering usage.Metering) *SingleContractProvider
NewSingleContractProvider creates a new single contract provider.
func (*SingleContractProvider) Configure ¶
func (p *SingleContractProvider) Configure(config map[string]interface{}) error
Configure configures the provider.
func (*SingleContractProvider) Create ¶
func (p *SingleContractProvider) Create() (Contract, error)
Create creates a contract, the SingleContractProvider way.
func (*SingleContractProvider) Get ¶
func (p *SingleContractProvider) Get(id uint32) (Contract, bool)
Get returns a ContractData fetched by its id.
func (*SingleContractProvider) Name ¶
func (p *SingleContractProvider) Name() string
Name returns the name of the provider.