Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

transport/ssh: allow passing SSH options #423

Merged
merged 2 commits into from
Jul 5, 2017
Merged

transport/ssh: allow passing SSH options #423

merged 2 commits into from
Jul 5, 2017

Conversation

smola
Copy link
Collaborator

@smola smola commented Jun 13, 2017

Adds the possibility of passing options to SSH transport.
Options have the form of functions modifying ssh.ClientConfig.

var DefaultClient = NewClient()

// NewClient creates a new SSH client with the given options.
func NewClient(opts ...ClientOption) transport.Transport {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just accepting a ssh.ClientConfig?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To play nice with other options that modify ssh.ClientConfig:

 	config := c.auth.clientConfig()
 	config.HostKeyCallback, err = c.auth.hostKeyCallback()
 	if err != nil {
 		return err
 	}

ssh.ClientConfig is created and initialized by client on each session. Some fields are set based on AuthMethod, which is not global, but per-session setting. Then setting the new options for ssh.ClientConfig are set globally for the transport, but applied per session after it has been created.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can archive the same just make a copy of the ssh.ClientConfig. And the API for the go-git user will be more simple and easy to use.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's right. The only difference is that global options could not override session values (e.g. adding a global override on every HostKeyCallback, such as an interceptor). Is that ok?

Copy link
Contributor

Choose a reason for hiding this comment

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

you can, checking if is zero value before assign the HostKeyCallback

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But you cannot use it to have a global wrapper (instead of a global override). As in:

if c.HostKeyCallback != nil {
    c.HostKeyCallback = globalWrapper(c.HostKeyCallback)
}

Note that we discussed about this offline and agreed to make the API simpler with just a default ssh.ClientConfig that is copied. I will update the PR accordingly.

smola added 2 commits June 23, 2017 19:51
Adds the possibility of passing options to SSH transport.
Options have the form of functions modifying ssh.ClientConfig.
A global *ssh.ClientConfig override can be set. It will be
use to override values of each SSH session.
@codecov
Copy link

codecov bot commented Jun 23, 2017

Codecov Report

Merging #423 into master will decrease coverage by 0.86%.
The diff coverage is 40%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #423      +/-   ##
==========================================
- Coverage   78.05%   77.19%   -0.87%     
==========================================
  Files         127      124       -3     
  Lines        9188     9023     -165     
==========================================
- Hits         7172     6965     -207     
- Misses       1236     1300      +64     
+ Partials      780      758      -22
Impacted Files Coverage Δ
plumbing/transport/ssh/common.go 3.38% <40%> (-47.52%) ⬇️
plumbing/transport/ssh/auth_method.go 33.33% <0%> (-24.77%) ⬇️
worktree_commit.go 70.49% <0%> (-3.43%) ⬇️
worktree_status.go 69.66% <0%> (-1.71%) ⬇️
storage/filesystem/internal/dotgit/writers.go 75.73% <0%> (-1.48%) ⬇️
worktree.go 64.52% <0%> (-1.42%) ⬇️
remote.go 70.91% <0%> (-0.74%) ⬇️
plumbing/revlist/revlist.go 80.59% <0%> (-0.57%) ⬇️
repository.go 72.87% <0%> (-0.3%) ⬇️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ad02bf0...7368129. Read the comment docs.

@smola
Copy link
Collaborator Author

smola commented Jun 23, 2017

@mcuadros Is this what you had in mind? Note that it's still not tested.

return
}

vo := reflect.ValueOf(*overrides)
Copy link
Contributor

Choose a reason for hiding this comment

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

For do the copy should be enough something like:

var config *ssh.ClientConfig
*config = *overrides

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But we don't want to override values set for the session, such as HostKeyCallback.

@mcuadros mcuadros merged commit 102d4b5 into src-d:master Jul 5, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants