Skip to content

Conversation

@kren-prog
Copy link

@kren-prog kren-prog commented Jul 17, 2025

This PR implements basic authentication for the Operaton client, enhancing the security of the connections.

issue #151

Changes

  • Base Operaton Client: Updated to include the username and password in the connection initialization.
  • External Task and Process Clients: Modified to support the new authentication parameters, ensuring that all client instances are properly authenticated.

This implementation ensures that all communications with the Operaton API are now authenticated for staging or production evironments, improving the overall security of the system.

Summary by CodeRabbit

  • New Features

    • Added support for optional username and password authentication for enhanced security when connecting to external services.
    • Introduced a new method to test connectivity with the engine endpoint.
  • Improvements

    • Authentication is now automatically applied when credentials are provided, except for local connections.
    • Enhanced HTTP request handling with improved logging and consistent content-type headers.

@kren-prog kren-prog requested a review from L-Zuluaga July 17, 2025 18:56
@kren-prog kren-prog self-assigned this Jul 17, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 17, 2025

"""

Walkthrough

The changes introduce optional basic authentication support to the BaseClient, ExternalTaskClient, and ProcessClient classes by allowing username and password parameters. HTTP requests now include authentication headers when applicable. Additionally, ProcessClient adds a new test_engine method to perform a GET request to the /engine endpoint.

Changes

File(s) Change Summary
lib/bas/utils/operaton/base_operaton_client.rb Added optional username and password to constructor; conditional basic auth; new basic_auth_required? and add_auth_headers methods; included response logger middleware; updated HTTP methods to add auth headers.
lib/bas/utils/operaton/external_task_client.rb Passes username and password to superclass constructor.
lib/bas/utils/operaton/process_client.rb Accepts username and password; passes them to superclass; adds new test_engine method performing GET /engine.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant ProcessClient
    participant BaseClient
    participant RemoteServer

    Caller->>ProcessClient: initialize(base_url, username, password)
    ProcessClient->>BaseClient: initialize(base_url, username, password)
    Caller->>ProcessClient: test_engine
    ProcessClient->>BaseClient: get("/engine")
    BaseClient->>RemoteServer: HTTP GET /engine (with optional Basic Auth)
    RemoteServer-->>BaseClient: Response
    BaseClient-->>ProcessClient: Response
    ProcessClient-->>Caller: Response
Loading

Possibly related issues

Possibly related PRs

Suggested reviewers

  • L-Zuluaga

Poem

In the warren where code does hop,
New credentials at each stop.
With username and password near,
Secure requests now appear.
Engine tests, connections tight—
Rabbits code it all just right!
🐇💻
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f32faf2 and 5a362ae.

📒 Files selected for processing (1)
  • lib/bas/utils/operaton/base_operaton_client.rb (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/bas/utils/operaton/base_operaton_client.rb
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🔭 Outside diff range comments (1)
lib/bas/utils/operaton/process_client.rb (1)

70-77: Critical issue: ProcessClient bypasses BaseClient authentication.

The ProcessClient overrides the build_conn method without including authentication logic, which means authentication configured in BaseClient will be bypassed for this client.

Either remove this override to use BaseClient's authentication-enabled connection, or add authentication support:

Option 1 (Recommended): Remove the override to use BaseClient's build_conn

-  def build_conn
-    Faraday.new(url: @base_url) do |f|
-      f.request :multipart
-      f.request :url_encoded
-      f.response :json, content_type: /\bjson$/
-      f.adapter Faraday.default_adapter
-    end
-  end

Option 2: Add authentication support to the override

 def build_conn
   Faraday.new(url: @base_url) do |f|
     f.request :multipart
     f.request :url_encoded
     f.response :json, content_type: /\bjson$/
     f.adapter Faraday.default_adapter
+    f.basic_auth(@username, @password) if @username && @password
   end
 end

However, Option 1 is preferred to avoid duplicating authentication logic.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d457757 and aa0d13b.

📒 Files selected for processing (3)
  • lib/bas/utils/operaton/base_operaton_client.rb (3 hunks)
  • lib/bas/utils/operaton/external_task_client.rb (1 hunks)
  • lib/bas/utils/operaton/process_client.rb (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
lib/bas/utils/operaton/base_operaton_client.rb (2)
lib/bas/utils/operaton/external_task_client.rb (2)
  • initialize (22-93)
  • initialize (23-31)
lib/bas/utils/operaton/process_client.rb (2)
  • initialize (18-78)
  • initialize (19-22)
🔇 Additional comments (7)
lib/bas/utils/operaton/base_operaton_client.rb (4)

5-5: LGTM - Base64 require added appropriately.

The Base64 require is correctly added to support credential encoding for basic authentication.


14-21: LGTM - Constructor properly accepts authentication parameters.

The constructor correctly accepts optional username and password parameters and stores them as instance variables for later use.


29-29: LGTM - Response logger added for debugging.

The response logger middleware will help with debugging HTTP requests and responses.


38-44: Reconsider the localhost exclusion logic for security.

The authentication bypass for localhost and 127.0.0.1 could be a security concern. This assumes local development environments don't need authentication, but this might not always be appropriate.

Consider if this exclusion is necessary for your use case. If authentication should be consistent across all environments, remove this condition:

 def basic_auth_required?
-  return false if @username.to_s.empty? || @password.to_s.empty?
-
-  uri = URI.parse(@base_url)
-  host = uri.host
-  !(host.nil? || host.include?("localhost") || host == "127.0.0.1")
+  !@username.to_s.empty? && !@password.to_s.empty?
 end
lib/bas/utils/operaton/external_task_client.rb (1)

26-31: LGTM - Authentication parameters properly forwarded to BaseClient.

The constructor correctly passes the username and password parameters to the parent BaseClient class, enabling authentication support for the ExternalTaskClient.

lib/bas/utils/operaton/process_client.rb (2)

19-22: LGTM - Constructor properly accepts and forwards authentication parameters.

The constructor correctly accepts optional username and password parameters and forwards them to the BaseClient superclass.


40-42: LGTM - Simple engine connectivity test method.

The test_engine method provides a straightforward way to test connectivity to the Operaton engine endpoint.

@coveralls
Copy link

coveralls commented Jul 17, 2025

Pull Request Test Coverage Report for Build 16355588610

Details

  • 16 of 23 (69.57%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.4%) to 97.773%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/bas/utils/operaton/process_client.rb 3 4 75.0%
lib/bas/utils/operaton/base_operaton_client.rb 12 18 66.67%
Totals Coverage Status
Change from base Build 16307043006: -0.4%
Covered Lines: 1712
Relevant Lines: 1751

💛 - Coveralls

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.

4 participants