Skip to content

Commit

Permalink
load LAPI config and nerf messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Jan 24, 2024
1 parent b75da76 commit 7594713
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/bouncers.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Note: This command requires database direct access, so is intended to be run on
DisableAutoGenTag: true,
PersistentPreRunE: func(_ *cobra.Command, _ []string) error {
var err error
if err = require.DB(cli.cfg()); err != nil {
if err = require.LAPI(cli.cfg()); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/require/require.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func LAPI(c *csconfig.Config) error {
if err := c.LoadAPIServer(); err != nil {
if err := c.LoadAPIServer(true); err != nil {
return fmt.Errorf("failed to load Local API: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ cscli support dump -f /tmp/crowdsec-support.zip
infos[SUPPORT_AGENTS_PATH] = []byte(err.Error())
}

if err := csConfig.LoadAPIServer(); err != nil {
if err := csConfig.LoadAPIServer(true); err != nil {
log.Warnf("could not load LAPI, skipping CAPI check")
skipLAPI = true
infos[SUPPORT_CAPI_STATUS_PATH] = []byte(err.Error())
Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func LoadConfig(configFile string, disableAgent bool, disableAPI bool, quiet boo
}

if !cConfig.DisableAPI {
if err := cConfig.LoadAPIServer(); err != nil {
if err := cConfig.LoadAPIServer(false); err != nil {
return nil, err
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/csconfig/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ type LocalApiServerCfg struct {
CapiWhitelists *CapiWhitelist `yaml:"-"`
}

func (c *Config) LoadAPIServer() error {
func (c *Config) LoadAPIServer(inCli bool) error {
if c.DisableAPI {
log.Warning("crowdsec local API is disabled from flag")
}
Expand Down Expand Up @@ -285,7 +285,7 @@ func (c *Config) LoadAPIServer() error {
}
}

if c.API.Server.OnlineClient == nil || c.API.Server.OnlineClient.Credentials == nil {
if (c.API.Server.OnlineClient == nil || c.API.Server.OnlineClient.Credentials == nil) && !inCli {
log.Printf("push and pull to Central API disabled")
}

Expand All @@ -297,7 +297,7 @@ func (c *Config) LoadAPIServer() error {
return err
}

if c.API.Server.CapiWhitelistsPath != "" {
if c.API.Server.CapiWhitelistsPath != "" && !inCli {
log.Infof("loaded capi whitelist from %s: %d IPs, %d CIDRs", c.API.Server.CapiWhitelistsPath, len(c.API.Server.CapiWhitelists.Ips), len(c.API.Server.CapiWhitelists.Cidrs))
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/csconfig/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func TestLoadAPIServer(t *testing.T) {
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := tc.input.LoadAPIServer()
err := tc.input.LoadAPIServer(true)
cstest.RequireErrorContains(t, err, tc.expectedErr)
if tc.expectedErr != "" {
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/csconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ type Config struct {
Hub *LocalHubCfg `yaml:"-"`
}

func NewConfig(configFile string, disableAgent bool, disableAPI bool, quiet bool) (*Config, string, error) {
func NewConfig(configFile string, disableAgent bool, disableAPI bool, inCli bool) (*Config, string, error) {
patcher := yamlpatch.NewPatcher(configFile, ".local")
patcher.SetQuiet(quiet)
patcher.SetQuiet(inCli)
fcontent, err := patcher.MergedPatchContent()
if err != nil {
return nil, "", err
Expand Down

0 comments on commit 7594713

Please sign in to comment.