Documentation
¶
Overview ¶
Notes:
Index ¶
- Variables
- func CheckEnv[T any](key string, v T) any
- func EncodeSeed(public PrefixByte, src []byte) ([]byte, error)
- func NewPortInitialData(uuid string, sourceNode Node, sourceSubMethod Method, sourcePort string, ...) portInitialData
- func NewPortSortedBuffer() *portSortedBuffer
- func NewServer(configuration *Configuration, version string) (*server, error)
- type Configuration
- type Handler
- type HostACLsSerializedWithHash
- type Message
- type Method
- type MethodsAvailable
- type Node
- type PrefixByte
- type StartProcesses
- type Subject
Constants ¶
This section is empty.
Variables ¶
var ( ErrACKSubscribeRetry = errors.New("ctrl: retrying to subscribe for ack message") // TODO: Other errors are not used for anything other than printing. ErrOther = errors.New("other error") )
Functions ¶
func EncodeSeed ¶
func EncodeSeed(public PrefixByte, src []byte) ([]byte, error)
EncodeSeed will encode a raw key with the prefix and then seed prefix and crc16 and then base32 encoded. This is a slightly modified version of the function found in the nkeys package, just with less options.
func NewPortInitialData ¶
func NewPortInitialData(uuid string, sourceNode Node, sourceSubMethod Method, sourcePort string, destinationNode Node, destinationSubMethod Method, destinationPort string, maxSessionTimeout int) portInitialData
NewPortInitialData creates a new portInitialData struct.
func NewPortSortedBuffer ¶
func NewPortSortedBuffer() *portSortedBuffer
NewPortSortedBuffer creates a new portSortedBuffer.
func NewServer ¶
func NewServer(configuration *Configuration, version string) (*server, error)
newServer will prepare and return a server type
Types ¶
type Configuration ¶
type Configuration struct {
// Shell on the operating system to use when executing cliCommands
ShellOnNode string
// ConfigFolder, the location for the configuration folder on disk
ConfigFolder string `comment:"ConfigFolder, the location for the configuration folder on disk"`
// The folder where the socket file should live
SocketFolder string `comment:"The folder where the socket file should live"`
// The folder where the readfolder should live
ReadFolder string `comment:"The folder where the readfolder should live"`
// EnableReadFolder for enabling the read messages api from readfolder
EnableReadFolder bool `comment:"EnableReadFolder for enabling the read messages api from readfolder"`
// TCP Listener for sending messages to the system, <host>:<port>
TCPListener string `comment:"TCP Listener for sending messages to the system, <host>:<port>"`
// HTTP Listener for sending messages to the system, <host>:<port>
HTTPListener string `comment:"HTTP Listener for sending messages to the system, <host>:<port>"`
// The folder where the database should live
DatabaseFolder string `comment:"The folder where the database should live"`
// Unique string to identify this Edge unit
NodeName string `comment:"Unique string to identify this Edge unit"`
// NodeAlias for adding extra aliases for the node name
NodeAlias string `comment:"NodeAlias"`
// The address of the message broker, <address>:<port>
BrokerAddress string `comment:"The address of the message broker, <address>:<port>"`
// NatsConnOptTimeout the timeout for trying the connect to nats broker
NatsConnOptTimeout int `comment:"NatsConnOptTimeout the timeout for trying the connect to nats broker"`
// Nats connect retry interval in seconds
NatsConnectRetryInterval int `comment:"Nats connect retry interval in seconds"`
// NatsReconnectJitter in milliseconds
NatsReconnectJitter int `comment:"NatsReconnectJitter in milliseconds"`
// NatsReconnectJitterTLS in seconds
NatsReconnectJitterTLS int `comment:"NatsReconnectJitterTLS in seconds"`
// KeysUpdateInterval in seconds
KeysUpdateInterval int `comment:"KeysUpdateInterval in seconds"`
// AclUpdateInterval in seconds
AclUpdateInterval int `comment:"AclUpdateInterval in seconds"`
// The type of profiling
Profiling string
// The number of the profiling port
ProfilingPort string `comment:"The number of the profiling port"`
// Host and port for prometheus listener, e.g. localhost:2112
PromHostAndPort string `comment:"Host and port for prometheus listener, e.g. localhost:2112"`
// Comma separated list of additional streams to consume from.
JetstreamsConsume string `comment:"a comma separated list of other jetstream subjects to consume"`
// Jetstream MaxMsgsPerSubject
JetStreamMaxMsgsPerSubject int `comment:"max messages to keep on the broker for a jetstream subject"`
// Set to true if this is the node that should receive the error log's from other nodes
DefaultMessageTimeout int `comment:"Set to true if this is the node that should receive the error log's from other nodes"`
// Default value for how long can a request method max be allowed to run in seconds
DefaultMethodTimeout int `comment:"Default value for how long can a request method max be allowed to run in seconds"`
// Default amount of retries that will be done before a message is thrown away, and out of the system
DefaultMessageRetries int `comment:"Default amount of retries that will be done before a message is thrown away, and out of the system"`
// The path to the data folder
SubscribersDataFolder string `comment:"The path to the data folder"`
// Name of central node to receive logs, errors, key/acl handling
CentralNodeName string `comment:"Name of central node to receive logs, errors, key/acl handling"`
// The full path to the certificate of the root CA
RootCAPath string `comment:"The full path to the certificate of the root CA"`
// Full path to the NKEY's seed file
NkeySeedFile string `comment:"Full path to the NKEY's seed file"`
// The full path to the NKEY user file
NkeyPublicKey string `toml:"-"`
//
NkeyFromED25519SSHKeyFile string `` /* 185-byte string literal not displayed */
// NkeySeed
NkeySeed string `toml:"-"`
// The host and port to expose the data folder, <host>:<port>
ExposeDataFolder string `comment:"The host and port to expose the data folder, <host>:<port>"`
// Timeout in seconds for error messages
ErrorMessageTimeout int `comment:"Timeout in seconds for error messages"`
// Retries for error messages
ErrorMessageRetries int `comment:"Retries for error messages"`
// SetBlockProfileRate for block profiling
SetBlockProfileRate int `comment:"SetBlockProfileRate for block profiling"`
// EnableSocket for enabling the creation of a ctrl.sock file
EnableSocket bool `comment:"EnableSocket for enabling the creation of a ctrl.sock file"`
// EnableSignatureCheck to enable signature checking
EnableSignatureCheck bool `comment:"EnableSignatureCheck to enable signature checking"`
// EnableAclCheck to enable ACL checking
EnableAclCheck bool `comment:"EnableAclCheck to enable ACL checking"`
// LogLevel
LogLevel string `comment:"LogLevel error/info/warning/debug/none."`
LogConsoleTimestamps bool `comment:"LogConsoleTimestamps true/false for enabling or disabling timestamps when printing errors and information to stderr"`
// KeepPublishersAliveFor number of seconds
// Timer that will be used for when to remove the sub process
// publisher. The timer is reset each time a message is published with
// the process, so the sub process publisher will not be removed until
// it have not received any messages for the given amount of time.
KeepPublishersAliveFor int `` /* 309-byte string literal not displayed */
StartProcesses StartProcesses
}
Configuration are the structure that holds all the different configuration options used both with flags and the config file. If a new field is added to this struct there should also be added the same field to the ConfigurationFromFile struct, and an if check should be added to the checkConfigValues function to set default values when reading from config file.
func NewConfiguration ¶
func NewConfiguration() *Configuration
NewConfiguration will return a *Configuration.
func (*Configuration) CreateKeyPair ¶
func (c *Configuration) CreateKeyPair(prefix PrefixByte) (kp, error)
CreateKeyPair will create the key nkeys key pair. This is a slightly modified version of the function found in the nkeys package, just with less options.
type HostACLsSerializedWithHash ¶
type HostACLsSerializedWithHash struct {
// data is all the ACL's for a specific node serialized serialized into cbor.
Data []byte
// hash is the sha256 hash of the ACL's.
// With maps the order are not guaranteed, so A sorted appearance
// of the ACL map for a host node is used when creating the hash,
// so the hash stays the same unless the ACL is changed.
Hash [32]byte
}
HostACLsSerializedWithHash holds the serialized representation node specific ACL's in the authSchema. There is also a sha256 hash of the data.
type Message ¶
type Message struct {
// The node to send the message to.
ToNode Node `json:"toNode" yaml:"toNode"`
// ToNodes to specify several hosts to send message to in the
// form of an slice/array.
// The ToNodes field is only a concept that exists when messages
// are injected f.ex. on a socket, and there they are directly
//converted into separate node messages for each node, and from
// there the ToNodes field is not used any more within the system.
// With other words, a message that exists within ctrl is always
// for just for a single node.
ToNodes []Node `json:"toNodes,omitempty" yaml:"toNodes,omitempty"`
// JetstreamToNode, the topic used to prefix the stream name with
// with the format NODES.<JetstreamToNode> .
JetstreamToNode Node `json:"jetstreamToNode" yaml:"jetstreamToNode"`
// The Unique ID of the message
ID int `json:"id" yaml:"id"`
// The actual data in the message. This is typically where we
// specify the cli commands to execute on a node, and this is
// also the field where we put the returned data in a reply
// message.
Data []byte `json:"data" yaml:"data"`
// Method, what request type to use, like REQCliCommand, REQHttpGet..
Method Method `json:"method" yaml:"method"`
// Additional arguments that might be needed when executing the
// method. Can be f.ex. an ip address if it is a tcp sender, or the
// shell command to execute in a cli session.
MethodArgs []string `json:"methodArgs" yaml:"methodArgs"`
// ArgSignature is the ed25519 signature of the methodArgs.
ArgSignature []byte `json:"argSignature" yaml:"argSignature"`
// ReplyMethod, is the method to use for the reply message.
// By default the reply method will be set to log to file, but
// you can override it setting your own here.
ReplyMethod Method `json:"replyMethod" yaml:"replyMethod"`
// Additional arguments that might be needed when executing the reply
// method. Can be f.ex. an ip address if it is a tcp sender, or the
// shell command to execute in a cli session.
ReplyMethodArgs []string `json:"replyMethodArgs" yaml:"replyMethodArgs"`
// IsReply are used to tell that this is a reply message. By default
// the system sends the output of a request method back to the node
// the message originated from. If it is a reply method we want the
// result of the reply message to be sent to the central server, so
// we can use this value if set to swap the toNode, and fromNode
// fields.
IsReply bool `json:"isReply" yaml:"isReply"`
// From what node the message originated
FromNode Node `json:"fromNode" yaml:"fromNode"`
// ACKTimeout for waiting for an ack message
ACKTimeout int `json:"ACKTimeout" yaml:"ACKTimeout"`
// RetryWait specified the time in seconds to wait between retries.
RetryWait int `json:"retryWait" yaml:"retryWait"`
// IsSubPublishedMsg enables timeout of publishing process, and is used together with process.isSubProcess to be able to terminate the sub processes publishers.
IsSubPublishedMsg bool `json:"isSubPublishedMsg" yaml:"isSubPublishedMsg"`
// Resend retries
Retries int `json:"retries" yaml:"retries"`
// The ACK timeout of the new message created via a request event.
ReplyACKTimeout int `json:"replyACKTimeout" yaml:"replyACKTimeout"`
// The retries of the new message created via a request event.
ReplyRetries int `json:"replyRetries" yaml:"replyRetries"`
// Timeout for long a process should be allowed to operate
MethodTimeout int `json:"methodTimeout" yaml:"methodTimeout"`
// Timeout for long a process should be allowed to operate
ReplyMethodTimeout int `json:"replyMethodTimeout" yaml:"replyMethodTimeout"`
// Directory is a string that can be used to create the
//directory structure when saving the result of some method.
// For example "syslog","metrics", or "metrics/mysensor"
// The type is typically used in the handler of a method.
Directory string `json:"directory" yaml:"directory"`
// FileName is used to be able to set a wanted name
// on a file being saved as the result of data being handled
// by a method handler.
FileName string `json:"fileName" yaml:"fileName"`
// PreviousMessage are used for example if a reply message is
// generated and we also need a copy of the details of the the
// initial request message.
PreviousMessage *Message
// Schedule
Schedule []int `json:"schedule" yaml:"schedule"`
// Use auto detection of shell for cliCommands
UseDetectedShell bool `json:"useDetectedShell" yaml:"useDetectedShell"`
// MethodInstructions is a string that contains eventual extra instructions
// for the method that is used when the method is executed.
MethodInstructions []string `json:"methodInstructions" yaml:"methodInstructions"`
// ReplyMethodInstructions is a string that contains eventual extra instructions
// for the method that is used when the reply method is executed for the reply message.
ReplyMethodInstructions []string `json:"replyMethodInstructions" yaml:"replyMethodInstructions"`
// contains filtered or unexported fields
}
type Method ¶
type Method string
Method is used to specify the actual function/method that is represented in a typed manner.
const ( // Initial parent method used to start other processes. Initial Method = "initial" // Get a list of all the running processes. OpProcessList Method = "opProcessList" // Start up a process. OpProcessStart Method = "opProcessStart" // Stop up a process. OpProcessStop Method = "opProcessStop" // Execute a CLI command in for example bash or cmd. // This is an event type, where a message will be sent to a // node with the command to execute and an ACK will be replied // if it was delivered succesfully. The output of the command // ran will be delivered back to the node where it was initiated // as a new message. // The data field is a slice of strings where the first string // value should be the command, and the following the arguments. CliCommand Method = "cliCommand" // REQCliCommandCont same as normal Cli command, but can be used // when running a command that will take longer time and you want // to send the output of the command continually back as it is // generated, and not wait until the command is finished. CliCommandCont Method = "cliCommandCont" // Send text to be logged to the console. // The data field is a slice of strings where the first string // value should be the command, and the following the arguments. Console Method = "console" // Send text logging to some host by appending the output to a // file, if the file do not exist we create it. // A file with the full subject+hostName will be created on // the receiving end. // The data field is a slice of strings where the values of the // slice will be written to the log file. FileAppend Method = "fileAppend" // Send text to some host by overwriting the existing content of // the fileoutput to a file. If the file do not exist we create it. // A file with the full subject+hostName will be created on // the receiving end. // The data field is a slice of strings where the values of the // slice will be written to the file. File Method = "file" // Initiated by the user. CopySrc Method = "copySrc" // Initial request for file copying. // Generated by the source to send initial information to the destination. CopyDst Method = "copyDst" // Read the source file to be copied to some node. SUBCopySrc Method = "subCopySrc" // Write the destination copied to some node. SUBCopyDst Method = "subCopyDst" PortSrc Method = "portSrc" PortDst Method = "PortDst" SUBPortSrc Method = "subPortSrc" SUBPortDst Method = "subPortDst" DummySrc Method = "dummySrc" DummyDst Method = "dummyDst" SUBDummySrc Method = "subDummySrc" SUBDummyDst Method = "subDummyDst" // Hello I'm here message. Hello Method = "hello" HelloPublisher Method = "helloPublisher" // Error log methods to centralError node. ErrorLog Method = "errorLog" // Http Get HttpGet Method = "httpGet" // Tail file TailFile Method = "tailFile" // REQNone is used when there should be no reply. None Method = "none" // REQTest is used only for testing to be able to grab the output // of messages. Test Method = "test" // REQPublicKey will get the public ed25519 key from a node. PublicKey Method = "publicKey" // KeysUpdateRequest will receive all the messages of the current hash of all public keys // a node have stored, and send out an update if needed.. KeysUpdateRequest Method = "keysUpdateRequest" // KeysUpdateReceive,deliver the public key from central to a node. KeysUpdateReceive Method = "keysUpdateReceive" // REQKeysAllow KeysAllow Method = "keysAllow" // REQKeysDelete KeysDelete Method = "keysDelete" // REQAclRequestUpdate will get all node acl's from central if an update is available. AclRequestUpdate Method = "aclRequestUpdate" // REQAclDeliverUpdate will deliver the acl from central to a node. AclDeliverUpdate Method = "aclDeliverUpdate" // REQAclAddCommand AclAddCommand = "aclAddCommand" // REQAclDeleteCommand AclDeleteCommand = "aclDeleteCommand" // REQAclDeleteSource AclDeleteSource = "aclDeleteSource" // REQGroupNodesAddNode AclGroupNodesAddNode = "aclGroupNodesAddNode" // REQAclGroupNodesDeleteNode AclGroupNodesDeleteNode = "aclGroupNodesDeleteNode" // REQAclGroupNodesDeleteGroup AclGroupNodesDeleteGroup = "aclGroupNodesDeleteGroup" // REQAclGroupCommandsAddCommand AclGroupCommandsAddCommand = "aclGroupCommandsAddCommand" // REQAclGroupCommandsDeleteCommand AclGroupCommandsDeleteCommand = "aclGroupCommandsDeleteCommand" // REQAclGroupCommandsDeleteGroup AclGroupCommandsDeleteGroup = "aclGroupCommandsDeleteGroup" // REQAclExport AclExport = "aclExport" // REQAclImport AclImport = "aclImport" // WebUI is used to send messages to the web ui. WebUI Method = "webUI" )
------------------------------------------------------------ The constants that will be used throughout the system for when specifying what kind of Method to send or work with.
func (Method) GetMethodsAvailable ¶
func (m Method) GetMethodsAvailable() MethodsAvailable
The mapping of all the method constants specified, what type it references. The primary use of this table is that messages are not able to pass the actual type of the request since it is sent as a string, so we use the below table to find the actual type based on that string type.
type MethodsAvailable ¶
MethodsAvailable holds a map of all the different method types and the associated handler to that method type.
func (MethodsAvailable) CheckIfExists ¶
func (ma MethodsAvailable) CheckIfExists(m Method) (Handler, bool)
Check if exists will check if the Method is defined. If true the bool value will be set to true, and the methodHandler function for that type will be returned.
type Node ¶
type Node string
Node is the type definition for the node who receive or send a message.
type PrefixByte ¶
type PrefixByte byte
const PrefixByteSeed PrefixByte = 18 << 3 // Base32-encodes to 'S...'
PrefixByteSeed is the version byte used for encoded NATS Seeds
const PrefixByteUser PrefixByte = 20 << 3 // Base32-encodes to 'U...'
PrefixByteUser is the version byte used for encoded NATS Users
type StartProcesses ¶
type StartProcesses struct {
// StartPubHello, sets the interval in seconds for how often we send hello messages to central server
StartPubHello int `comment:"StartPubHello, sets the interval in seconds for how often we send hello messages to central server"`
// Enable the updates of public keys
EnableKeyUpdates bool `comment:"Enable the updates of public keys"`
// Enable the updates of acl's
EnableAclUpdates bool `comment:"Enable the updates of acl's"`
// Start the central error logger.
IsCentralErrorLogger bool `comment:"Start the central error logger."`
// Start subscriber for hello messages
StartSubHello bool `comment:"Start subscriber for hello messages"`
// Start subscriber for text logging
StartSubFileAppend bool `comment:"Start subscriber for text logging"`
// Start subscriber for writing to file
StartSubFile bool `comment:"Start subscriber for writing to file"`
// Start subscriber for reading files to copy
StartSubCopySrc bool `comment:"Start subscriber for reading files to copy"`
// Start subscriber for writing copied files to disk
StartSubCopyDst bool `comment:"Start subscriber for writing copied files to disk"`
// Start subscriber for Echo Request
StartSubCliCommand bool `comment:"Start subscriber for CLICommand"`
// Start subscriber for Console
StartSubConsole bool `comment:"Start subscriber for Console"`
// Start subscriber for HttpGet
StartSubHttpGet bool `comment:"Start subscriber for HttpGet"`
// Start subscriber for tailing log files
StartSubTailFile bool `comment:"Start subscriber for tailing log files"`
// Start subscriber for continously delivery of output from cli commands.
StartSubCliCommandCont bool `comment:"Start subscriber for continously delivery of output from cli commands."`
// IsCentralKey, will make the node the central key handler for public keys.
IsCentralKey bool
// IsCentralAcl, enable to make this instance take the role as the central
// server that holds all the ACL's, and the handling av the ACL's.
IsCentralAcl bool `comment:"IsCentralAcl, enable to make this instance take the role as the central auth server"`
}
type Subject ¶
type Subject struct {
// node, the name of the node to receive the message.
ToNode string `json:"node" yaml:"toNode"`
// method, what is this message doing, etc. CLICommand, Syslog, etc.
Method Method `json:"method" yaml:"method"`
}
subject contains the representation of a subject to be used with one specific process
Source Files
¶
- central_auth_acl_handling.go
- central_auth_key_handling.go
- central_auth_parser.go
- configuration_flags.go
- errorkernel.go
- message_and_subject.go
- message_readers.go
- metrics.go
- nkey_from_ssh_ed25519_key.go
- node_auth.go
- process.go
- processes.go
- requests.go
- requests_acl.go
- requests_cli.go
- requests_copy.go
- requests_file_handling.go
- requests_http.go
- requests_keys.go
- requests_operator.go
- requests_port.go
- requests_std.go
- requests_template.go
- server.go
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
ctrl
command
|
|
|
doc
|
|
|
concept/auth
command
|
|
|
scripts
|
|
|
nats-server/generate-nkeys
command
|
|