diff --git a/internal/api/nats.go b/internal/api/nats.go index e02e424..1bfe905 100644 --- a/internal/api/nats.go +++ b/internal/api/nats.go @@ -13,6 +13,7 @@ import ( "time" "github.com/ClusterCockpit/cc-backend/internal/archiver" + "github.com/ClusterCockpit/cc-backend/internal/config" "github.com/ClusterCockpit/cc-backend/internal/importer" "github.com/ClusterCockpit/cc-backend/internal/repository" "github.com/ClusterCockpit/cc-backend/pkg/nats" @@ -20,13 +21,6 @@ import ( "github.com/ClusterCockpit/cc-lib/schema" ) -// NATS subject constants for Job and Node APIs. -const ( - SubjectJobStart = "cc.job.start" - SubjectJobStop = "cc.job.stop" - SubjectNodeState = "cc.node.state" -) - // NatsAPI provides NATS subscription-based handlers for Job and Node operations. // It mirrors the functionality of the REST API but uses NATS messaging. type NatsAPI struct { @@ -52,19 +46,24 @@ func (api *NatsAPI) StartSubscriptions() error { return nil } - if err := client.Subscribe(SubjectJobStart, api.handleStartJob); err != nil { - return err - } + if config.Keys.APISubjects != nil { - if err := client.Subscribe(SubjectJobStop, api.handleStopJob); err != nil { - return err - } + s := config.Keys.APISubjects - if err := client.Subscribe(SubjectNodeState, api.handleNodeState); err != nil { - return err - } + if err := client.Subscribe(s.SubjectJobStart, api.handleStartJob); err != nil { + return err + } - cclog.Info("NATS API subscriptions started") + if err := client.Subscribe(s.SubjectJobStop, api.handleStopJob); err != nil { + return err + } + + if err := client.Subscribe(s.SubjectNodeState, api.handleNodeState); err != nil { + return err + } + + cclog.Info("NATS API subscriptions started") + } return nil } diff --git a/internal/config/config.go b/internal/config/config.go index 69a4444..25ca27e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -22,6 +22,8 @@ type ProgramConfig struct { // Addresses from which secured admin API endpoints can be reached, can be wildcard "*" APIAllowedIPs []string `json:"apiAllowedIPs"` + APISubjects *NATSConfig `json:"apiSubjects"` + // Drop root permissions once .env was read and the port was taken. User string `json:"user"` Group string `json:"group"` @@ -87,6 +89,12 @@ type ResampleConfig struct { Trigger int `json:"trigger"` } +type NATSConfig struct { + SubjectJobStart string `json:"subjectJobStart"` + SubjectJobStop string `json:"subjectJobStop"` + SubjectNodeState string `json:"subjectNodeState"` +} + type IntRange struct { From int `json:"from"` To int `json:"to"`