// Transport helper function to get http transport
Transport helper function to get http transport
// Transport helper function to get http transport
func Transport(rootCAs string, verbose int) (*http.Transport, error) {
	certPool := x509.NewCertPool()
	files, err := ioutil.ReadDir(rootCAs)
	if err != nil {
		msg := fmt.Sprintf("Unable to list files in '%s', error: %v\n", rootCAs, err)
		if rootCAs == "" {
			msg = fmt.Sprintf("root CAs area is not provided")
		}
		log.Printf(msg)
		return nil, errors.New(msg)
	}
	var certs bool
	for _, finfo := range files {
		fname := fmt.Sprintf("%s/%s", rootCAs, finfo.Name())
		caCert, err := ioutil.ReadFile(fname)
		if err != nil {
			if verbose > 1 {
				log.Printf("Unable to read %s\n", fname)
			}
		}
		if ok := certPool.AppendCertsFromPEM(caCert); !ok {
			if verbose > 2 {
				log.Printf("invalid PEM format while importing trust-chain: %q", fname)
			}
		}
		if verbose > 2 {
			log.Println("Load CA file", fname)
		}
		certs = true
	}
	mTLSConfig := &tls.Config{
		InsecureSkipVerify: true,
	}
	if certs {
		mTLSConfig = &tls.Config{
			RootCAs: certPool,
		}
	}
	tr := &http.Transport{
		TLSClientConfig: mTLSConfig,
	}
	return tr, nil
}
func Transport ( rootCAs string , verbose int ) ( * http . Transport , error ) { certPool := x509 . NewCertPool ( ) files , err := ioutil . ReadDir ( rootCAs ) if err != nil { msg := fmt . Sprintf ( " \n " , rootCAs , err ) if rootCAs == " " { msg = fmt . Sprintf ( " " ) } log . Printf ( msg ) return nil , errors . New ( msg ) } var certs bool for _ , finfo := range files { fname := fmt . Sprintf ( " " , rootCAs , finfo . Name ( ) ) caCert , err := ioutil . ReadFile ( fname ) if err != nil { if verbose > 1 { log . Printf ( " \n " , fname ) } } if ok := certPool . AppendCertsFromPEM ( caCert ) ; ! ok { if verbose > 2 { log . Printf ( " " , fname ) } } if verbose > 2 { log . Println ( " " , fname ) } certs = true } mTLSConfig := & tls . Config { InsecureSkipVerify : true , } if certs { mTLSConfig = & tls . Config { RootCAs : certPool , } } tr := & http . Transport { TLSClientConfig : mTLSConfig , } return tr , nil }
Transport helper function to get http transport
Transport helper function to get http transport