Skip to content

Conversation

@RobGeada
Copy link
Contributor

@RobGeada RobGeada commented Aug 26, 2025

Summary by Sourcery

Select the HTTP scheme dynamically based on the presence of TLS certificates and propagate it to orchestrator requests

Enhancements:

  • Return the connection scheme (http or https) from build_orchestrator_client alongside the HTTP client
  • Pass the determined scheme through main into handle_generation for URL construction
  • Use the scheme when formatting orchestrator request URLs instead of hardcoding https

@sourcery-ai
Copy link

sourcery-ai bot commented Aug 26, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR refactors how the orchestrator client determines and uses its URI scheme by detecting the presence of TLS assets, returning both the HTTP client and the appropriate scheme, and propagating that scheme through the routing and request logic instead of hard-coding “https”.

Sequence diagram for scheme propagation in orchestrator request

sequenceDiagram
    participant Main
    participant build_orchestrator_client
    participant Router
    participant handle_generation

    Main->>build_orchestrator_client: Call with hostname
    build_orchestrator_client-->>Main: Return (client, scheme)
    Main->>Router: Pass client and scheme to route handler
    Router->>handle_generation: Call with scheme and client
    handle_generation->>handle_generation: Build URL using scheme
    handle_generation->>Orchestrator: Send request to constructed URL
Loading

Class diagram for orchestrator client and scheme propagation changes

classDiagram
    class Main {
        +build_orchestrator_client(hostname: &str) -> (reqwest::Client, String)
    }
    class build_orchestrator_client {
        +returns: (reqwest::Client, scheme: String)
        -detects TLS assets
        -sets scheme to "https" if TLS present, else "http"
    }
    class handle_generation {
        +scheme: String
        +orchestrator_client: Arc<reqwest::Client>
        +gateway_config: GatewayConfig
        +route_fallback_message: Option<String>
        +uses scheme to build orchestrator URL
    }
    Main --> build_orchestrator_client
    Main --> handle_generation
    build_orchestrator_client --> handle_generation : scheme
    build_orchestrator_client --> handle_generation : orchestrator_client
Loading

File-Level Changes

Change Details Files
Expose scheme from client builder based on TLS presence
  • Extend build_orchestrator_client signature to return (Client, scheme)
  • Initialize scheme="http" and switch to "https" when CA/cert identity is loaded
  • Adapt the Ok clause to return the client–scheme tuple
src/main.rs
Destructure and propagate scheme in main application setup
  • Destructure (client, scheme) from build_orchestrator_client
  • Wrap only the client in Arc and clone scheme
  • Pass scheme into each route handler closure
src/main.rs
Use dynamic scheme in orchestrator request URLs
  • Add scheme parameter to handle_generation signature
  • Replace hard-coded “https://” prefixes with format placeholders using scheme
  • Ensure both port and no-port branches use the scheme variable
src/main.rs

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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

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

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 there - I've reviewed your changes - here's some feedback:

  • Consider using an enum (e.g. Http vs Https) instead of a raw String for scheme to avoid typos and improve type safety.
  • Centralize the orchestrator base-URL and scheme logic inside a dedicated client abstraction so you don't have to pass scheme around in every handler.
  • Revisit the TLS detection logic—if you’re adding a custom CA you may still want to default to HTTPS even without a client identity, so ensure scheme matches your intended TLS scenarios.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider using an enum (e.g. Http vs Https) instead of a raw String for `scheme` to avoid typos and improve type safety.
- Centralize the orchestrator base-URL and scheme logic inside a dedicated client abstraction so you don't have to pass `scheme` around in every handler.
- Revisit the TLS detection logic—if you’re adding a custom CA you may still want to default to HTTPS even without a client identity, so ensure `scheme` matches your intended TLS scenarios.

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.

@github-actions
Copy link

PR image build completed successfully!

📦 PR image: quay.io/trustyai/guardrails-sidecar-gateway-ci:44759816f9068f2bc312e01191739f1db4b3f45f

@RobGeada RobGeada merged commit f9783b4 into trustyai-explainability:main Aug 26, 2025
1 of 2 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.

1 participant