Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tilsor/ModSecIntl_wace_lib/llms.txt

Use this file to discover all available pages before exploring further.

The configstore package is responsible for loading, validating, and exposing WACElib’s runtime configuration. It enforces a singleton pattern: only one ConfigStore may exist per process. The package also defines the ModelPluginType enum that controls which portion of an HTTP transaction each model plugin is allowed to process.

ConfigFileData

ConfigFileData is the struct that YAML configuration files unmarshal into. Pass an instance to wace.Init after unmarshalling.
type ConfigFileData struct {
    Logpath         string
    Loglevel        string
    Modelplugins    []configFileModelPlugin
    Decisionplugins []configFileDecisionPlugin
    NatsURL         string
}
Logpath
string
required
Filesystem path for the WACElib log file. The path must be writable; if the file does not exist, WACElib attempts to create it during Init.
Loglevel
string
required
Log verbosity. Valid values: "DEBUG", "INFO", "WARN", "ERROR".
Modelplugins
[]configFileModelPlugin
Ordered list of model plugin configurations. Each entry identifies a .so plugin file, its type, weight, execution mode, and optional custom parameters.
Decisionplugins
[]configFileDecisionPlugin
List of decision plugin configurations.
NatsURL
string
NATS server address used for async and remote-sync plugins. Defaults to "localhost:4222" when not set.

YAML-to-Go mapping example

logpath: "/var/log/wace.log"
loglevel: "INFO"
natsurl: "nats://nats.internal:4222"

modelplugins:
  - id: "request-header-model"
    path: "/usr/lib/wace/plugins/header_model.so"
    plugintype: "RequestHeaders"
    weight: 1.0
    mode: sync
    params:
      threshold: "0.75"

decisionplugins:
  - id: "simple"
    path: "/usr/lib/wace/plugins/simple_decision.so"
    params:
      decision_balance: "0.5"
var conf configstore.ConfigFileData
yaml.Unmarshal(raw, &conf)
// conf.Logpath         == "/var/log/wace.log"
// conf.Loglevel        == "INFO"
// conf.NatsURL         == "nats://nats.internal:4222"
// conf.Modelplugins[0].ID == "request-header-model"

ConfigStore

ConfigStore is the runtime representation of the configuration after parsing and validation. Retrieve the singleton with configstore.Get().
type ConfigStore struct {
    ModelPlugins    map[string]modelPluginConfig
    DecisionPlugins map[string]decisionPluginConfig
    LogPath         string
    LogLevel        logging.LogLevel
    NatsURL         string
    ApplicationId   string
}
ModelPlugins
map[string]modelPluginConfig
Map from model plugin ID to its validated runtime configuration. Populated by SetConfig; keyed by configFileModelPlugin.ID.
DecisionPlugins
map[string]decisionPluginConfig
Map from decision plugin ID to its validated runtime configuration.
LogPath
string
Validated log file path resolved from ConfigFileData.Logpath.
LogLevel
logging.LogLevel
Parsed log level value converted from the Loglevel string.
NatsURL
string
NATS server URL. Set to "localhost:4222" if ConfigFileData.NatsURL was empty.
ApplicationId
string
Optional application identifier. Not set by SetConfig; reserved for runtime assignment.

Functions

New

func New() (*ConfigStore, error)
Creates and returns the singleton ConfigStore. Returns an error if a singleton already exists ("ConfigStore: an instance already exists"). Called internally by wace.Init; you do not need to call it directly under normal usage.

Get

func Get() (*ConfigStore, error)
Returns the existing singleton ConfigStore. Returns an error if New has not been called yet ("ConfigStore: Configuration was not loaded"). Safe to call from multiple goroutines after wace.Init completes.

Clean

func Clean()
Resets the singleton reference to nil, allowing a subsequent New() call to succeed. Intended for use in tests to prevent state leaking between test cases.
func TestSomething(t *testing.T) {
    defer configstore.Clean()
    // ... test code that calls wace.Init
}

IsAsync

func (c *ConfigStore) IsAsync(modelID string) bool
Returns true if the model plugin identified by modelID is configured with Mode == "async". Used internally by wace.Analyze to route plugin calls through NATS rather than direct function calls.
modelID
string
required
A model plugin ID that exists in ConfigStore.ModelPlugins.

ModelPluginType

ModelPluginType is an integer enum that describes which part of an HTTP transaction a model plugin is designed to analyse. It is used as the modelsTypeAsString parameter of wace.Analyze (via its string representation) and as the PluginType field in plugin configuration.
type ModelPluginType int

const (
    RequestHeaders  ModelPluginType = iota // 0
    RequestBody                            // 1
    AllRequest                             // 2
    ResponseHeaders                        // 3
    ResponseBody                           // 4
    AllResponse                            // 5
    Everything                             // 6
)
ConstantStringDescription
RequestHeaders"RequestHeaders"HTTP request headers only
RequestBody"RequestBody"HTTP request body only
AllRequest"AllRequest"Full HTTP request (headers + body)
ResponseHeaders"ResponseHeaders"HTTP response headers only
ResponseBody"ResponseBody"HTTP response body only
AllResponse"AllResponse"Full HTTP response (headers + body)
Everything"Everything"Any portion of request or response

StringToPluginType

func StringToPluginType(textType string) (ModelPluginType, error)
Converts the string representation back to a ModelPluginType constant. Returns an error for unrecognised strings.
t, err := configstore.StringToPluginType("AllRequest")
// t == configstore.AllRequest, err == nil

t, err = configstore.StringToPluginType("invalid")
// t == -1, err != nil

Build docs developers (and LLMs) love