Skip to content

Commit 977d4a8

Browse files
committed
fix(plugins): parse the wrapped plugins.<name>.tenants config format
1 parent da2953b commit 977d4a8

7 files changed

Lines changed: 79 additions & 14 deletions

File tree

plugins/aws/config.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ type tenantYAML struct {
157157
Config map[string]string `yaml:",inline"`
158158
}
159159

160+
type pluginsFile struct {
161+
Plugins map[string]struct {
162+
Tenants []tenantYAML `yaml:"tenants"`
163+
} `yaml:"plugins"`
164+
}
165+
166+
const pluginKey = "aws"
167+
160168
var sensitiveKeys = map[string]bool{
161169
"aws_secret_access_key": true,
162170
}
@@ -173,11 +181,12 @@ func readConfig(path, encKey string) *ConfigurationSection {
173181
return nil
174182
}
175183

176-
var tenants []tenantYAML
177-
if err := yaml.Unmarshal(data, &tenants); err != nil {
184+
var pf pluginsFile
185+
if err := yaml.Unmarshal(data, &pf); err != nil {
178186
_ = catcher.Error("failed to parse config file", err, map[string]any{"process": processName, "file": path})
179187
return nil
180188
}
189+
tenants := pf.Plugins[pluginKey].Tenants
181190

182191
sec := &ConfigurationSection{
183192
ModuleActive: len(tenants) > 0,

plugins/azure/config.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ type tenantYAML struct {
170170
Config map[string]string `yaml:",inline"`
171171
}
172172

173+
type pluginsFile struct {
174+
Plugins map[string]struct {
175+
Tenants []tenantYAML `yaml:"tenants"`
176+
} `yaml:"plugins"`
177+
}
178+
179+
const pluginKey = "azure"
180+
173181
func readConfig(path, encKey string) *ConfigurationSection {
174182
data, err := os.ReadFile(path)
175183
if err != nil {
@@ -182,11 +190,12 @@ func readConfig(path, encKey string) *ConfigurationSection {
182190
return nil
183191
}
184192

185-
var tenants []tenantYAML
186-
if err := yaml.Unmarshal(data, &tenants); err != nil {
193+
var pf pluginsFile
194+
if err := yaml.Unmarshal(data, &pf); err != nil {
187195
_ = catcher.Error("failed to parse config file", err, map[string]any{"process": processName, "file": path})
188196
return nil
189197
}
198+
tenants := pf.Plugins[pluginKey].Tenants
190199

191200
sec := &ConfigurationSection{
192201
ModuleActive: len(tenants) > 0,

plugins/bitdefender/config/config.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ type tenantYAML struct {
167167
Config map[string]string `yaml:",inline"`
168168
}
169169

170+
// pluginsFile mirrors the backend's on-disk wrapper (tenant_store.go):
171+
// plugins.<pluginKey>.tenants: [...]. This plugin only ever reads its own key.
172+
type pluginsFile struct {
173+
Plugins map[string]struct {
174+
Tenants []tenantYAML `yaml:"tenants"`
175+
} `yaml:"plugins"`
176+
}
177+
178+
const pluginKey = "bitdefender"
179+
170180
var sensitiveKeys = map[string]bool{
171181
"connectionKey": true,
172182
}
@@ -183,11 +193,12 @@ func readConfig(path, encKey string) *ConfigurationSection {
183193
return nil
184194
}
185195

186-
var tenants []tenantYAML
187-
if err := yaml.Unmarshal(data, &tenants); err != nil {
196+
var pf pluginsFile
197+
if err := yaml.Unmarshal(data, &pf); err != nil {
188198
_ = catcher.Error("failed to parse config file", err, map[string]any{"process": processName, "file": path})
189199
return nil
190200
}
201+
tenants := pf.Plugins[pluginKey].Tenants
191202

192203
sec := &ConfigurationSection{
193204
ModuleActive: len(tenants) > 0,

plugins/crowdstrike/config.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ type tenantYAML struct {
163163
Config map[string]string `yaml:",inline"`
164164
}
165165

166+
type pluginsFile struct {
167+
Plugins map[string]struct {
168+
Tenants []tenantYAML `yaml:"tenants"`
169+
} `yaml:"plugins"`
170+
}
171+
172+
const pluginKey = "crowdstrike"
173+
166174
var sensitiveKeys = map[string]bool{
167175
"crowdstrike_client_secret": true,
168176
}
@@ -179,11 +187,12 @@ func readConfig(path, encKey string) *ConfigurationSection {
179187
return nil
180188
}
181189

182-
var tenants []tenantYAML
183-
if err := yaml.Unmarshal(data, &tenants); err != nil {
190+
var pf pluginsFile
191+
if err := yaml.Unmarshal(data, &pf); err != nil {
184192
_ = catcher.Error("failed to parse config file", err, map[string]any{"process": processName, "file": path})
185193
return nil
186194
}
195+
tenants := pf.Plugins[pluginKey].Tenants
187196

188197
sec := &ConfigurationSection{
189198
ModuleActive: len(tenants) > 0,

plugins/gcp/config.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ type tenantYAML struct {
163163
Config map[string]string `yaml:",inline"`
164164
}
165165

166+
type pluginsFile struct {
167+
Plugins map[string]struct {
168+
Tenants []tenantYAML `yaml:"tenants"`
169+
} `yaml:"plugins"`
170+
}
171+
172+
const pluginKey = "gcp"
173+
166174
// sensitiveKeys lists the configuration keys whose values are stored encrypted.
167175
var sensitiveKeys = map[string]bool{
168176
"jsonKey": true,
@@ -180,11 +188,12 @@ func readConfig(path, encKey string) *ConfigurationSection {
180188
return nil
181189
}
182190

183-
var tenants []tenantYAML
184-
if err := yaml.Unmarshal(data, &tenants); err != nil {
191+
var pf pluginsFile
192+
if err := yaml.Unmarshal(data, &pf); err != nil {
185193
_ = catcher.Error("failed to parse config file", err, map[string]any{"process": processName, "file": path})
186194
return nil
187195
}
196+
tenants := pf.Plugins[pluginKey].Tenants
188197

189198
sec := &ConfigurationSection{
190199
ModuleActive: len(tenants) > 0,

plugins/o365/config.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ type tenantYAML struct {
163163
Config map[string]string `yaml:",inline"`
164164
}
165165

166+
type pluginsFile struct {
167+
Plugins map[string]struct {
168+
Tenants []tenantYAML `yaml:"tenants"`
169+
} `yaml:"plugins"`
170+
}
171+
172+
const pluginKey = "o365"
173+
166174
var sensitiveKeys = map[string]bool{
167175
"office365_client_secret": true,
168176
}
@@ -179,11 +187,12 @@ func readConfig(path, encKey string) *ConfigurationSection {
179187
return nil
180188
}
181189

182-
var tenants []tenantYAML
183-
if err := yaml.Unmarshal(data, &tenants); err != nil {
190+
var pf pluginsFile
191+
if err := yaml.Unmarshal(data, &pf); err != nil {
184192
_ = catcher.Error("failed to parse config file", err, map[string]any{"process": processName, "file": path})
185193
return nil
186194
}
195+
tenants := pf.Plugins[pluginKey].Tenants
187196

188197
sec := &ConfigurationSection{
189198
ModuleActive: len(tenants) > 0,

plugins/sophos/config.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ type tenantYAML struct {
163163
Config map[string]string `yaml:",inline"`
164164
}
165165

166+
type pluginsFile struct {
167+
Plugins map[string]struct {
168+
Tenants []tenantYAML `yaml:"tenants"`
169+
} `yaml:"plugins"`
170+
}
171+
172+
const pluginKey = "sophos"
173+
166174
var sensitiveKeys = map[string]bool{
167175
"sophos_x_api_key": true,
168176
}
@@ -179,11 +187,12 @@ func readConfig(path, encKey string) *ConfigurationSection {
179187
return nil
180188
}
181189

182-
var tenants []tenantYAML
183-
if err := yaml.Unmarshal(data, &tenants); err != nil {
190+
var pf pluginsFile
191+
if err := yaml.Unmarshal(data, &pf); err != nil {
184192
_ = catcher.Error("failed to parse config file", err, map[string]any{"process": processName, "file": path})
185193
return nil
186194
}
195+
tenants := pf.Plugins[pluginKey].Tenants
187196

188197
sec := &ConfigurationSection{
189198
ModuleActive: len(tenants) > 0,

0 commit comments

Comments
 (0)