Ejemplo n.º 1
0
// TransportFor returns an http.RoundTripper that will provide the authentication
// or transport level security defined by the provided Config. Will return the
// default http.DefaultTransport if no special case behavior is needed.
func TransportFor(config *Config) (http.RoundTripper, error) {
	cfg, err := config.transportConfig()
	if err != nil {
		return nil, err
	}
	return transport.New(cfg)
}
Ejemplo n.º 2
0
func NewKubernetesConfig(certsPath, serviceHost, servicePort string) (*restclient.Config, error) {
	config, err := restclient.InClusterConfig()
	if err == nil {
		return config, nil
	}

	tlsTransport, err := transport.New(&transport.Config{
		TLS: transport.TLSConfig{
			CAFile:   fmt.Sprintf("%s/%s", certsPath, "ca.pem"),
			CertFile: fmt.Sprintf("%s/%s", certsPath, "cert.pem"),
			KeyFile:  fmt.Sprintf("%s/%s", certsPath, "key.pem"),
		},
	})
	if err != nil {
		return nil, errors.Wrap(err, "Couldn't set up tls transport")
	}

	return &restclient.Config{
		Host:      fmt.Sprintf("https://%s:%s", serviceHost, servicePort),
		Transport: tlsTransport,
	}, nil
}
Ejemplo n.º 3
0
// TransportFor returns an http.RoundTripper that will provide the authentication
// or transport level security defined by the provided Config. Will return the
// default http.DefaultTransport if no special case behavior is needed.
func TransportFor(config *Config) (http.RoundTripper, error) {
	return transport.New(config.transportConfig())
}