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

git/gogit: Add support for per client proxying #575

Merged
merged 3 commits into from
May 30, 2023
Merged

git/gogit: Add support for per client proxying #575

merged 3 commits into from
May 30, 2023

Conversation

aryan9600
Copy link
Member

@aryan9600 aryan9600 commented May 30, 2023

Add WithProxy(), a ClientOption which configures the proxy settings for a gogit.Client. All remote operations performed by the client will then use the configured proxy.

Atm, the only way to use a proxy is to use the standard env vars, HTTP_PROXY, HTTPS_PROXY, etc. The problem with this is that its configuration at a global level, i.e. all clients will be forced to use these proxy settings. This PR allows for using different proxy settings for different clients, which is particularly helpful when working in multi tenant environments.

aryan9600 added 2 commits May 30, 2023 13:33
Add `WithProxy()`, a `ClientOption` which configures the proxy settings
for a `gogit.Client`. All remote operations performed by the client use
the configured proxy.

Signed-off-by: Sanskar Jaiswal <[email protected]>
@aryan9600 aryan9600 requested a review from hiddeco as a code owner May 30, 2023 08:04
Signed-off-by: Sanskar Jaiswal <[email protected]>
@hiddeco hiddeco added enhancement New feature or request area/git Git and SSH related issues and pull requests labels May 30, 2023
@aryan9600 aryan9600 merged commit c0c812b into main May 30, 2023
@aryan9600 aryan9600 deleted the gogit-proxy branch May 30, 2023 13:25
Comment on lines +411 to +412
func (g *Client) getRemoteHEAD(ctx context.Context, url string, ref plumbing.ReferenceName,
authMethod transport.AuthMethod) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the usage of getRemoteHEAD(), it looks like the authMethod can now be computed just once per client as it needs authOpts and useDefaultKnownHosts which are both properties of the client and don't seem to change in any of the operations.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking more about the other options like url, all of the g.clone*() methods set the g.repository at the very end. This repository contains the remote address with a default remote name "origin". If these clone operations store the repository info on the client, other methods of the client should be able to default to the available repository. So, the url can become optional for getRemoteHEAD(). It should be able to use the default repository when the passed in URL is empty. The benefit of keeping the URL input is to allow querying other remotes if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/git Git and SSH related issues and pull requests enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants