cscli lapi register: no error if the credentials file does not exist#4570
Conversation
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
|
@lopster568: There are no 'kind' label on this PR. You need a 'kind' label to generate the release automatically.
DetailsI 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: There are no area labels on this PR. You can add as many areas as you see fit.
DetailsI 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. |
|
/kind fix |
|
/area cscli |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
cscli lapi register --token <token> --url <url>fails withloading api client: while reading yaml file: open <credentials_path>: no such file or directorywhen 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 statuskeeps requiring a loadable credentials file, and register initializes empty credentials when none were loaded. This is the lapi analogue of #3645, which madecapi registertolerate 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 statuswith the freshly written credentials.Fixes #4237