config

package
v0.0.0-...-0f26d97 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPort        = 3143
	DefaultHost        = "0.0.0.0"
	DefaultBaseURL     = "nats://0.0.0.0:3143"
	DefaultUsername    = ""
	DefaultPassword    = ""
	DefaultTimeout     = 30 * time.Second
	CLIENT_CONFIG_FILE = "client.hcl"
)
View Source
const (
	CONFIG_DIR      = "hxe"
	CONFIG_FILE     = "config.hcl"
	PROGRAMS_DIR    = "programs"
	DEFAULT_SUBJECT = "hxe"
)
View Source
const (
	AGENT_CONFIG_FILE = "agent.hcl"
)
View Source
const (
	PROGRAM_CONFIG_DIR = "programs"
)
View Source
const YYYYMMDD = "2006/01/02"

Variables

View Source
var (
	//go:embed agent.hcl
	DefaultAgentConfig []byte

	//go:embed agent.db
	DefaultAgentSqlite []byte
)
View Source
var CtxFunctions *hcl.EvalContext = &hcl.EvalContext{
	Functions: map[string]function.Function{
		"seconds": SecondsFunc,
		"minutes": MinutesFunc,
		"hours":   HoursFunc,
		"days":    DaysFunc,
		"date":    DateFunc,
	},
}
View Source
var DateFunc = function.New(&function.Spec{
	Description: "Returns a date in int64 format",
	Params: []function.Parameter{
		{
			Name:             "date",
			Type:             cty.String,
			AllowDynamicType: true,
		},
	},
	Type: function.StaticReturnType(cty.Number),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		var date string
		if err := gocty.FromCtyValue(args[0], &date); err != nil {
			return cty.UnknownVal(cty.String), err
		}

		t, err := time.Parse(YYYYMMDD, date)
		if err != nil {
			return cty.UnknownVal(cty.String), err
		}

		return cty.NumberIntVal(t.Unix()), nil
	},
})
View Source
var DaysFunc = function.New(&function.Spec{
	Description: "Returns the given hours",
	Params: []function.Parameter{
		{
			Name:             "num",
			Type:             cty.Number,
			AllowDynamicType: true,
		},
	},
	Type: function.StaticReturnType(cty.Number),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		var days int64
		if err := gocty.FromCtyValue(args[0], &days); err != nil {
			return cty.UnknownVal(cty.String), err
		}

		return cty.NumberIntVal(int64(time.Duration(days) * (time.Hour * 24))), nil
	},
})
View Source
var DefaultClientConfig []byte
View Source
var (
	//go:embed program.hcl
	DefaultProgramConfig []byte
)
View Source
var HoursFunc = function.New(&function.Spec{
	Description: "Returns the given hours",
	Params: []function.Parameter{
		{
			Name:             "num",
			Type:             cty.Number,
			AllowDynamicType: true,
		},
	},
	Type: function.StaticReturnType(cty.Number),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		var hours int64
		if err := gocty.FromCtyValue(args[0], &hours); err != nil {
			return cty.UnknownVal(cty.String), err
		}

		return cty.NumberIntVal(int64(time.Duration(hours) * time.Hour)), nil
	},
})
View Source
var MinutesFunc = function.New(&function.Spec{
	Description: "Returns the given minutes",
	Params: []function.Parameter{
		{
			Name:             "num",
			Type:             cty.Number,
			AllowDynamicType: true,
		},
	},
	Type: function.StaticReturnType(cty.Number),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		var minutes int64
		if err := gocty.FromCtyValue(args[0], &minutes); err != nil {
			return cty.UnknownVal(cty.String), err
		}

		return cty.NumberIntVal(int64(time.Duration(minutes) * time.Minute)), nil
	},
})
View Source
var SecondsFunc = function.New(&function.Spec{
	Description: "Returns the given seconds",
	Params: []function.Parameter{
		{
			Name:             "num",
			Type:             cty.Number,
			AllowDynamicType: true,
		},
	},
	Type: function.StaticReturnType(cty.Number),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		var seconds int64
		if err := gocty.FromCtyValue(args[0], &seconds); err != nil {
			return cty.UnknownVal(cty.String), err
		}

		return cty.NumberIntVal(int64(time.Duration(seconds) * time.Second)), nil
	},
})

Functions

func AgentCliOpts

func AgentCliOpts(ctx context.Context, cmd *cli.Command) func(c *AgentConfig) error

func AgentDefaultOpts

func AgentDefaultOpts() func(*AgentConfig) (err error)

func AgentFileOpts

func AgentFileOpts(path string) func(*AgentConfig) (err error)

func ClientCliOpts

func ClientCliOpts(ctx context.Context, cmd *cli.Command) func(c *ClientConfig) error

func ClientConfigOpts

func ClientConfigOpts(config *ClientConfig) func(*ClientConfig) (err error)

func ClientDefaultOptions

func ClientDefaultOptions() func(*ClientConfig) (err error)

func ClientFileOption

func ClientFileOption(path string) func(*ClientConfig) (err error)

func ClientProfileOpts

func ClientProfileOpts(profile string) func(*ClientConfig) (err error)

func LoadProgramConfig

func LoadProgramConfig(filename string) ([]*models.Program, error)

New creates a new configuration

Types

type AgentConfig

type AgentConfig struct {
	ID      string `hcl:"id,optional"`
	Debug   bool   `hcl:"debug,optional"`
	Version string `hcl:"version,optional"`
	Banner  bool   `hcl:"banner,optional"`

	Server   Server     `hcl:"server,block"`
	Services []*Service `hcl:"service,block"`
	// contains filtered or unexported fields
}

func NewAgentConfig

func NewAgentConfig(options ...func(*AgentConfig) error) (*AgentConfig, error)

New creates a new configuration

type Client

type Client struct {
	Name     string        `hcl:"name,label"`
	UseIPC   bool          `hcl:"ipc,optional"`
	Host     string        `hcl:"host,optional"`
	Url      string        `hcl:"url,optional"`
	Port     int           `hcl:"port,optional"`
	Debug    bool          `hcl:"debug,optional"`
	Token    string        `hcl:"token,optional"`
	Password string        `hcl:"password,optional"`
	Username string        `hcl:"username,optional"`
	Timeout  time.Duration `hcl:"timeout,optional"`
}

func NewClientConfig

func NewClientConfig(options ...func(*ClientConfig) error) (client *Client, err error)

New creates a new configuration

func (*Client) Options

func (c *Client) Options() (opts nats.Option)

type ClientConfig

type ClientConfig struct {
	Clients []*Client `hcl:"client,block"`
	// contains filtered or unexported fields
}

func (*ClientConfig) Profile

func (c *ClientConfig) Profile(names ...string) (*Client, error)

Profile returns the client configuration for the specified profile name

type ProgramConfig

type ProgramConfig struct {
	Programs []*models.Program `hcl:"program,block"`
}

type Server

type Server struct {
	Name   string `hcl:"name,label"`
	UseIPC bool   `hcl:"ipc,optional"`
	Host   string `hcl:"host,optional"`
	Port   int    `hcl:"port,optional"`
	// DontListen            bool   `hcl:"dont_listen"`
	// ClientAdvertise       string `hcl:",optional"`
	// Trace                 bool   `hcl:",optional"`
	Debug bool `hcl:"debug,optional"`
	// TraceVerbose          bool   `hcl:",optional"`
	// NoLog                 bool   `hcl:",optional"`
	// NoSigs                bool   `hcl:",optional"`
	// NoSublistCache        bool   `hcl:",optional"`
	// NoHeaderSupport       bool   `hcl:",optional"`
	// DisableShortFirstPing bool   `hcl:",optional"`
	// Logtime               bool   `hcl:",optional"`
	// LogtimeUTC            bool   `hcl:",optional"`
	// MaxConn               int    `hcl:"max_connections"`
	// MaxSubs               int    `hcl:"max_subscriptions,optional"`
	// MaxSubTokens          uint8  `hcl:",optional"`
	// // Nkeys                      []*NkeyUser   `hcl:",optional"`
	// // Users                      []*User       `hcl:",optional"`
	// // Accounts                   []*Account    `hcl:",optional"`
	// NoAuthUser      string `hcl:",optional"`
	// SystemAccount   string `hcl:",optional"`
	// NoSystemAccount bool   `hcl:",optional"`
	Username string `hcl:",optional"`
	Password string `hcl:",optional"`
}

type Service

type Service struct {
	ID        string `hcl:"id,label"`
	Directory string `hcl:"directory,optional"`
	Conn      *nats.Conn
	Config    hcl.Body `hcl:"config,remain"`
}

Jump to

Keyboard shortcuts

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