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

refactor(http): refactor http client to accept more customisable options #2414

Merged
merged 1 commit into from
May 6, 2024

Conversation

vrajashkr
Copy link
Contributor

What type of PR is this?
refactor

Which issue does this PR fix:
N/A

What does this PR do / Why do we need it:
This PR refactors the CreateHTTPClient function to take in a more customisable set of options for certificates and TLS. This is needed as we would like to re-use the same for scale out proxy which also needs the same functionality to automatically inherit per-host certificates and mTLS support. It also provides flexibility to allow users to customise the name and path for certificates for the sync feature in future.

If an issue # is not available please add repro steps and logs showing the issue:
Not a bug, but a helpful enhancement for the scale-out feature #2385
The feature requires use of functionalities such as per-host certificates and mTLS support.

Testing done on this change:
Existing tests should pass and new unit tests added. There should be no functional impact due to the change.

Automation added to e2e:
N/A

Will this break upgrades or downgrades?
No. This is a refactor which is expected to maintain the original behaviour.

Does this PR introduce any user-facing change?:
N/A

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

This commit updates the arguments for the `CreateHTTPClient`
function to consume a struct which can be extended as required.
It replaces the certPath argument with a struct of 3 paths for
client ertificate, client key, and ca cert. It also adds
a TLSEnabled option for when an HTTP Client is required
without any further TLS config.

Existing consumers of this function have been updated so that
they can work as they do today. This change is a no-op for
existing features.

This allows for certificate paths to be customised and
allows other modules to re-use the same HTTP client and get
the benefits of mTLS support and per-host certificates.

Signed-off-by: Vishwas Rajashekar <vrajashe@cisco.com>
@vrajashkr
Copy link
Contributor Author

I hit an error in the earlier run with this message:

Failures:

  * zotregistry.dev/zot/pkg/extensions/sync/sync_internal_test.go 
  Line 166:
  Expected: nil
  Actual:   'open ca.crt: no such file or directory'

This was due to a mistake I made in pkg/extensions/sync/httpclient/client.go where the cert file paths are only set when the CertDir is specified. In the incorrect code, the files were always being set which wasn't correct :)

I've fixed that. Hopefully the tests go through completely this time round.

Copy link

codecov bot commented May 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.86%. Comparing base (4671e41) to head (b4de28b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2414   +/-   ##
=======================================
  Coverage   92.86%   92.86%           
=======================================
  Files         167      167           
  Lines       22060    22077   +17     
=======================================
+ Hits        20485    20502   +17     
  Misses        982      982           
  Partials      593      593           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@rchincha rchincha left a comment

Choose a reason for hiding this comment

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

lgtm

@rchincha rchincha merged commit be5ad66 into project-zot:main May 6, 2024
35 checks passed
@vrajashkr vrajashkr deleted the refactor/http-client branch May 7, 2024 02:05
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.

None yet

2 participants