Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions plugins/soc-ai/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"os"
"path/filepath"
"strings"
"sync"
"time"

Expand All @@ -13,13 +14,32 @@ import (
)

const (
processName = "plugin_com.utmstack.soc-ai"
pluginFile = "system_plugins_soc_ai.yaml"
pipelineDefault = "/workdir/pipeline"
reconnectDelay = 5 * time.Second
pollInterval = 30 * time.Second
processName = "plugin_com.utmstack.soc-ai"
pluginFile = "system_plugins_soc_ai.yaml"
pipelineDefault = "/workdir/pipeline"
instanceConfigPath = "/updates/instance-config.yml"
reconnectDelay = 5 * time.Second
pollInterval = 30 * time.Second
)

type instanceConfig struct {
Server string `yaml:"server"`
InstanceID string `yaml:"instance_id"`
InstanceKey string `yaml:"instance_key"`
}

func readInstanceConfig(path string) (*instanceConfig, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
var ic instanceConfig
if err := yaml.Unmarshal(data, &ic); err != nil {
return nil, err
}
return &ic, nil
}

type Config struct {
// Platform (from plugins.PluginCfg("com.utmstack"))
Backend string
Expand Down Expand Up @@ -233,13 +253,32 @@ func readConfig(path, encKey, backend, internalKey string) *Config {
if authType == "" {
authType = "bearer"
}
authHeaderName := fc.AuthHeaderName

if fc.Provider == "threatwinds" {
// ponytail: hit the CM proxy directly with id+key from /updates/instance-config.yml; user's API key is ignored.
ic, ierr := readInstanceConfig(instanceConfigPath)
if ierr != nil || ic.Server == "" || ic.InstanceID == "" || ic.InstanceKey == "" {
_ = catcher.Error("threatwinds provider requires instance-config.yml", ierr, map[string]any{"process": processName, "file": instanceConfigPath})
return c // inactive
}
url = strings.TrimRight(ic.Server, "/") + "/proxy/api/ai/v1/chat/completions"
apiKey = ""
authType = "none"
authHeaderName = ""
if customHeaders == nil {
customHeaders = make(map[string]string, 2)
}
customHeaders["id"] = ic.InstanceID
customHeaders["key"] = ic.InstanceKey
}

c.Provider = fc.Provider
c.URL = url
c.Model = fc.Model
c.APIKey = apiKey
c.AuthType = authType
c.AuthHeaderName = fc.AuthHeaderName
c.AuthHeaderName = authHeaderName
c.CustomHeaders = customHeaders
c.MaxTokens = maxTokens
c.MaxToolIterations = maxIters
Expand Down
Loading