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

TLS dialer #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

TLS dialer #106

wants to merge 1 commit into from

Conversation

munakoiso
Copy link

Hello.

Here is an implementation of a dialer using tls connect.
Also I have added a function which returns a simple tls.Config. This is probably the most common way to create it, so I decided to put it in this library.

I think it might be useful.

Usage example:

	tlsConfig, err := zk.CreateTLSConfig(rootCAFile, crtFile, keyFile)
	if err != nil {
		fmt.Println(err)
		return
	}
	timeout := 1 * time.Second
	baseDialer := net.Dialer{Timeout: timeout}
	dialer, err := zk.GetTLSDialer([]string{"hostname:2281"}, &baseDialer, tlsConfig)
	if err != nil {
		fmt.Println(err)
		return
	}
	conn, _, err := zk.Connect([]string{"hostname:2281"}, timeout, zk.WithDialer(dialer))

@munakoiso
Copy link
Author

Hi, @nemith . Can you review this PR please?

@nemith
Copy link

nemith commented Apr 13, 2023

I am not longer a maintainer on this project

@munakoiso
Copy link
Author

@nemith
Oh, sorry, but I can't find any information about maintainers here.
Maybe you can tell me who are maintainers?

@@ -18,6 +18,22 @@ type DNSHostProvider struct {
lookupHost func(string) ([]string, error) // Override of net.LookupHost, for testing.
}

func addrsByHostname(server string) ([]string, error) {
Copy link

Choose a reason for hiding this comment

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

nit: since this is used in the function below, this function would be sorted below it.

"time"
)

func CreateTLSConfig(rootCAFile, certFile, keyFile string) (*tls.Config, error) {
Copy link

Choose a reason for hiding this comment

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

This should not assume files, and have io.Reader as input for all three inputs. This allows a better library experience having tests and callers pass in content as they see fit.

also the tls package allows this to work then with https://pkg.go.dev/crypto/tls#X509KeyPair

}, nil
}

func GetTLSDialer(servers []string, dialer *net.Dialer, tlsConfig *tls.Config) (Dialer, error) {
Copy link

Choose a reason for hiding this comment

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

is this function then used as the option to use as an option? The notion would normally be that the surrounding library would pass in this dialer themselves. If we wanted to support TLS Dial in the zk lib. I would want to have this outside the main zk package and in a supporting package

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.

3 participants