Skip to content

Configuration file manage#144

Merged
jfilak merged 1 commit intojfilak:masterfrom
filak-sap:configuration_file_manage
Mar 28, 2026
Merged

Configuration file manage#144
jfilak merged 1 commit intojfilak:masterfrom
filak-sap:configuration_file_manage

Conversation

@filak-sap
Copy link
Copy Markdown
Contributor

Add 8 new CLI subcommands to manage the sapcli configuration file: set-connection, delete-connection, get-connections, set-user, delete-user, get-users, set-context, and delete-context.

Design decisions:

Naming follows kubectl/git conventions (set-, delete-, get-). The set- commands use upsert semantics: they create the entry if it does not exist, or merge the provided fields into the existing entry if it does. This avoids the need for separate add/update commands and keeps the CLI surface minimal.

Merge/patch behavior means that when updating an existing entry, only the fields explicitly passed on the command line are changed; all other fields are preserved. This is achieved by collecting only non-None argument values and passing them to dict.update(). Boolean fields like --ssl need paired --ssl/--no-ssl flags with default=None so we can distinguish 'not specified' from an explicit True or False.

Referential integrity on delete: delete-connection and delete-user refuse to proceed if any context references the named entry, unless --force is passed. This prevents dangling references that would cause confusing errors at runtime. delete-context has no such constraint since contexts are leaf nodes in the reference graph. Deleting the current-context automatically unsets current-context.

Each field has its own --flag rather than key=value pairs, which provides better discoverability via --help, shell completion, and type validation (e.g. --port is typed as int).

The --user flag in set-user uses dest='user_value' and in set-context uses dest='user_ref' to avoid collisions with the global --user argument that argparse injects into the namespace. Similarly, set-context uses dest='ctx_password' for --password.

All new ConfigFile methods (_ensure_section, set_connection, set_user, set_context, find_referencing_contexts, delete_connection, delete_user, delete_context) are added to the model layer in sap/config.py, keeping the CLI layer thin: commands just parse arguments, delegate to ConfigFile, call save(), and print feedback.

Error handling uses SAPCliConfigError throughout, which the CLI entry point already intercepts to print a user-friendly message instead of a stack trace.

Also fixes a pre-existing mypy error by adding a type annotation to the summary variable in merge_into().

Add 8 new CLI subcommands to manage the sapcli configuration file:
set-connection, delete-connection, get-connections, set-user,
delete-user, get-users, set-context, and delete-context.

Design decisions:

Naming follows kubectl/git conventions (set-*, delete-*, get-*).
The set-* commands use upsert semantics: they create the entry if
it does not exist, or merge the provided fields into the existing
entry if it does. This avoids the need for separate add/update
commands and keeps the CLI surface minimal.

Merge/patch behavior means that when updating an existing entry,
only the fields explicitly passed on the command line are changed;
all other fields are preserved. This is achieved by collecting
only non-None argument values and passing them to dict.update().
Boolean fields like --ssl need paired --ssl/--no-ssl flags with
default=None so we can distinguish 'not specified' from an explicit
True or False.

Referential integrity on delete: delete-connection and delete-user
refuse to proceed if any context references the named entry, unless
--force is passed. This prevents dangling references that would
cause confusing errors at runtime. delete-context has no such
constraint since contexts are leaf nodes in the reference graph.
Deleting the current-context automatically unsets current-context.

Each field has its own --flag rather than key=value pairs, which
provides better discoverability via --help, shell completion, and
type validation (e.g. --port is typed as int).

The --user flag in set-user uses dest='user_value' and in
set-context uses dest='user_ref' to avoid collisions with the
global --user argument that argparse injects into the namespace.
Similarly, set-context uses dest='ctx_password' for --password.

All new ConfigFile methods (_ensure_section, set_connection,
set_user, set_context, find_referencing_contexts, delete_connection,
delete_user, delete_context) are added to the model layer in
sap/config.py, keeping the CLI layer thin: commands just parse
arguments, delegate to ConfigFile, call save(), and print feedback.

Error handling uses SAPCliConfigError throughout, which the CLI
entry point already intercepts to print a user-friendly message
instead of a stack trace.

Also fixes a pre-existing mypy error by adding a type annotation
to the summary variable in merge_into().
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3a266baa-40dd-4979-8571-382049260463

📥 Commits

Reviewing files that changed from the base of the PR and between e14381d and 8900126.

📒 Files selected for processing (5)
  • doc/configuration.md
  • sap/cli/config.py
  • sap/config.py
  • test/unit/test_sap_cli_config.py
  • test/unit/test_sap_config.py

📝 Walkthrough

Walkthrough

This PR extends the sapcli configuration subsystem with CRUD operations for managing connections, users, and contexts. It introduces CLI commands (set-*/get-*/delete-*) and ConfigFile API methods to create, update, list, and delete configuration entries with merge semantics, referential integrity checks, and optional force-delete capabilities.

Changes

Cohort / File(s) Summary
Configuration API
sap/config.py
Added ConfigFile methods for managing connections, users, and contexts: set_connection, set_user, set_context (with merge semantics), delete_connection, delete_user, delete_context (with referential integrity checks), and find_referencing_contexts for reference discovery. Added _ensure_section helper and improved type annotation for merge_into.
CLI Commands
sap/cli/config.py
Implemented 8 new config subcommands: set-connection, delete-connection, get-connections for connection management; set-user, delete-user, get-users for user management; and set-context, delete-context for context management. Added _collect_fields helper to extract CLI arguments into field dictionaries.
Documentation
doc/configuration.md
Added sections documenting the new connection, user, and context lifecycle management commands with explicit examples of create/update/list/delete workflows and upsert/merge semantics.
CLI Tests
test/unit/test_sap_cli_config.py
Comprehensive test coverage for new CLI commands including creation vs. update behavior, validation of required fields, error handling for referenced deletion, persistence checks via YAML reload, and output verification for list operations.
Configuration Tests
test/unit/test_sap_config.py
Unit tests for ConfigFile methods covering merge semantics, section initialization, referential integrity, deletion with/without force flag, current-context unsetting, and malformed entry handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Configuration file #142: Introduces the foundational ConfigFile model and basic config CLI commands that this PR extends with mutable set/delete operations and reference-aware deletion logic.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and generic, using a non-descriptive phrase 'Configuration file manage' that does not clearly convey the main change. Use a more specific title that clearly describes the main change, such as 'Add CLI commands for managing configuration entries' or 'Add set-/get-/delete- config subcommands'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the 8 new CLI subcommands, design decisions, and implementation details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@jfilak jfilak merged commit 4705aab into jfilak:master Mar 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants