Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Installer Authentication to CLI #23

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

Conversation

stegm
Copy link
Owner

@stegm stegm commented Dec 4, 2024

credentials format:

User:

password=secret

Installer:

master-key=secret
service-code=secret

see also #21

Summary by Sourcery

Add installer authentication to the CLI, allowing login with a master key and service code. Refactor session management to support user identification and improve cache handling. Deprecate --password-file in favor of --credentials and update related documentation. Implement tests for credential handling and invalid option scenarios.

New Features:

  • Introduce installer authentication to the CLI, allowing users to log in using a master key and service code for enhanced access control.

Enhancements:

  • Refactor session management to include user identification, improving session handling and cache management.

Documentation:

  • Deprecate the use of --password-file in favor of --credentials for specifying login details, and update CLI documentation accordingly.

Tests:

  • Add tests for CLI credential handling, including scenarios for invalid global options and credential-based authentication.

@stegm stegm self-assigned this Dec 4, 2024
Copy link

sourcery-ai bot commented Dec 4, 2024

Reviewer's Guide by Sourcery

This PR implements installer authentication in the CLI by refactoring the session management system to support different user types (regular user and installer) and introducing new credential handling mechanisms. The implementation replaces the simple password-based authentication with a more flexible system that supports both user passwords and installer credentials (master key + service code).

Sequence diagram for CLI login process

sequenceDiagram
    actor User
    participant CLI
    participant ApiShell
    participant SessionCache
    participant ApiClient

    User->>CLI: Provide credentials
    CLI->>ApiShell: Initialize with credentials
    ApiShell->>SessionCache: Read session_id
    alt Session exists
        SessionCache-->>ApiShell: Return session_id
        ApiShell->>ApiClient: Use session_id
        ApiClient-->>ApiShell: Authentication success
    else No session
        ApiShell->>ApiClient: Login with key and service_code
        ApiClient-->>ApiShell: Return new session_id
        ApiShell->>SessionCache: Write session_id
    end
    ApiShell-->>CLI: Ready for commands
Loading

Updated class diagram for SessionCache and ApiShell

classDiagram
    class SessionCache {
        -Path _cache_file
        +__init__(host: str, user: str)
        +read_session_id() Union[str, None]
        +write_session_id(id: str)
        +remove()
    }

    class ApiShell {
        -ApiClient client
        -SessionCache _session_cache
        +__init__(client: ApiClient, user: str)
        +prepare_client(key: Optional[str], service_code: Optional[str])
        +print_exception()
        +run(key: Optional[str], service_code: Optional[str])
    }
Loading

File-Level Changes

Change Details Files
Refactor session management to support user identification
  • Add user type to session cache file name to separate user and installer sessions
  • Improve session file handling using Path objects
  • Add session removal functionality
  • Update session cache initialization to include user type
pykoplenti/cli.py
Implement new credential handling system
  • Add support for master key and service code authentication
  • Replace password parameter with key and service_code parameters
  • Add new --credentials option for file-based credential configuration
  • Deprecate --password-file in favor of --credentials
  • Add validation for conflicting credential options
pykoplenti/cli.py
Add comprehensive test suite for credential handling
  • Add tests for invalid credential option combinations
  • Implement smoke test for process data reading with credentials
  • Add session cache testing utilities
  • Add fixtures for credential file handling
tests/test_cli.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@stegm
Copy link
Owner Author

stegm commented Dec 5, 2024

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @stegm - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding explicit documentation of the credentials file format in the code (e.g. in the --credentials option help text or as a module docstring), including examples of both user and installer authentication formats.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

pykoplenti/cli.py Show resolved Hide resolved
tests/test_cli.py Show resolved Hide resolved
pykoplenti/cli.py Show resolved Hide resolved
@stegm stegm force-pushed the installer_auth_cli branch 3 times, most recently from 1d42c22 to f652043 Compare December 5, 2024 19:32
@stegm stegm force-pushed the installer_auth_cli branch from f652043 to 719abfb Compare December 5, 2024 19:57
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.

1 participant