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

Added support for https connections #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,49 @@
package neoism

import (
"crypto/tls"
"net/http"
"net/url"

"crypto/x509"
"errors"
"github.com/jmcvetta/napping"
"io/ioutil"
"log"
"os"
)

// Connect setups parameters for the Neo4j server
// and calls ConnectWithRetry()
func Connect(uri string) (*Database, error) {
h := http.Header{}
h.Add("User-Agent", "neoism")

tcc := &tls.Config{}

caCertFile := os.Getenv("CACERTSFILE")
if caCertFile != "" {
log.Println("CA Cert file was specified, appending it into the Cert pool...")
caCert, err := ioutil.ReadFile(caCertFile)
if err != nil {
return nil, err
}
caCertPool := x509.NewCertPool()
ok := caCertPool.AppendCertsFromPEM(caCert)
if !ok {
return nil, errors.New("Unable to append the certificate to the CA certs pool.")
}

tcc.RootCAs = caCertPool
} else {
tcc.InsecureSkipVerify = true
}

client := &http.Client{Transport: &http.Transport{TLSClientConfig: tcc}}

db := &Database{
Session: &napping.Session{
Client: client,
Header: &h,
},
}
Expand Down