Skip to content

cscli lapi register: no error if the credentials file does not exist#4570

Merged
blotus merged 1 commit into
crowdsecurity:masterfrom
lopster568:lapi-register-no-credentials-file
Jul 23, 2026
Merged

cscli lapi register: no error if the credentials file does not exist#4570
blotus merged 1 commit into
crowdsecurity:masterfrom
lopster568:lapi-register-no-credentials-file

Conversation

@lopster568

Copy link
Copy Markdown
Contributor

cscli lapi register --token <token> --url <url> fails with loading api client: while reading yaml file: open <credentials_path>: no such file or directory when the credentials file does not exist yet, which defeats token-based bootstrap of a fresh log processor (the reporter was following the multiserver setup guide with only a token). The failure comes from the lapi command group's PersistentPreRunE, which loads the existing credentials before subcommands such as register and status run, and register is the one subcommand whose job is to create that file.

This skips the pre-load for register when a credentials path is configured, covering the missing, empty, and corrupt file states, since register overwrites the file on success and the reporter's empty-file workaround shows tolerating only the missing case is not enough. lapi status keeps requiring a loadable credentials file, and register initializes empty credentials when none were loaded. This is the lapi analogue of #3645, which made capi register tolerate a missing online_api_credentials.yaml; the group hook is kept here because it also serves status, and register still uses loaded credentials for the URL fallback when the file exists.

Adds two unit tests (register proceeds past loading with a missing file and fails only at the unreachable API; status still requires the file) and a bats case covering the full bootstrap roundtrip: register with no pre-existing credentials file, then a successful lapi status with the freshly written credentials.

Fixes #4237

The lapi command group's PersistentPreRunE loads the API client
credentials before subcommands such as register and status run, so
register failed with "no such file or directory" unless the file it
is meant to create already existed. Skip that requirement for register
when a credentials path is configured, keeping the strict behavior for
subcommands that read the LAPI.

Fixes crowdsecurity#4237
@github-actions

Copy link
Copy Markdown

@lopster568: There are no 'kind' label on this PR. You need a 'kind' label to generate the release automatically.

  • /kind feature
  • /kind enhancement
  • /kind refactoring
  • /kind fix
  • /kind chore
  • /kind dependencies
Details

I am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.

@github-actions

Copy link
Copy Markdown

@lopster568: There are no area labels on this PR. You can add as many areas as you see fit.

  • /area agent
  • /area local-api
  • /area cscli
  • /area appsec
  • /area security
  • /area configuration
Details

I am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.

@lopster568

Copy link
Copy Markdown
Contributor Author

/kind fix

@lopster568

Copy link
Copy Markdown
Contributor Author

/area cscli

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.27%. Comparing base (0a79ef8) to head (b2c6bc7).
⚠️ Report is 13 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4570      +/-   ##
==========================================
+ Coverage   63.75%   64.27%   +0.51%     
==========================================
  Files         507      490      -17     
  Lines       38652    37927     -725     
==========================================
- Hits        24644    24377     -267     
+ Misses      11650    11240     -410     
+ Partials     2358     2310      -48     
Flag Coverage Δ
bats 41.68% <100.00%> (+0.02%) ⬆️
unit-linux 40.53% <75.00%> (+0.47%) ⬆️
unit-windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@blotus blotus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks !

@blotus
blotus merged commit 95c8545 into crowdsecurity:master Jul 23, 2026
13 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cscli register lapi --token does not work without existing api.client.credentials_path file.

2 participants