MCPcopy Create free account
hub / github.com/RedisGraph/redisgraph-go / ExampleGraphNew_tls

Function ExampleGraphNew_tls

example_graph_test.go:48–107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46}
47
48func ExampleGraphNew_tls() {
49 // Consider the following helper methods that provide us with the connection details (host and password)
50 // and the paths for:
51 // tls_cert - A a X.509 certificate to use for authenticating the server to connected clients, masters or cluster peers. The file should be PEM formatted
52 // tls_key - A a X.509 private key to use for authenticating the server to connected clients, masters or cluster peers. The file should be PEM formatted
53 // tls_cacert - A PEM encoded CA's certificate file
54 host, password := getConnectionDetails()
55 tlsready, tls_cert, tls_key, tls_cacert := getTLSdetails()
56
57 // Skip if we dont have all files to properly connect
58 if tlsready == false {
59 return
60 }
61
62 // Load client cert
63 cert, err := tls.LoadX509KeyPair(tls_cert, tls_key)
64 if err != nil {
65 log.Fatal(err)
66 }
67
68 // Load CA cert
69 caCert, err := ioutil.ReadFile(tls_cacert)
70 if err != nil {
71 log.Fatal(err)
72 }
73 caCertPool := x509.NewCertPool()
74 caCertPool.AppendCertsFromPEM(caCert)
75
76 clientTLSConfig := &tls.Config{
77 Certificates: []tls.Certificate{cert},
78 RootCAs: caCertPool,
79 }
80
81 // InsecureSkipVerify controls whether a client verifies the
82 // server's certificate chain and host name.
83 // If InsecureSkipVerify is true, TLS accepts any certificate
84 // presented by the server and any host name in that certificate.
85 // In this mode, TLS is susceptible to man-in-the-middle attacks.
86 // This should be used only for testing.
87 clientTLSConfig.InsecureSkipVerify = true
88
89 pool := &redis.Pool{Dial: func() (redis.Conn, error) {
90 return redis.Dial("tcp", host,
91 redis.DialPassword(password),
92 redis.DialTLSConfig(clientTLSConfig),
93 redis.DialUseTLS(true),
94 redis.DialTLSSkipVerify(true),
95 )
96 }}
97
98 graph := redisgraph.GraphNew("social", pool.Get())
99
100 q := "CREATE (w:WorkPlace {name:'RedisLabs'}) RETURN w"
101 res, _ := graph.Query(q)
102
103 res.Next()
104 r := res.Record()
105 w := r.GetByIndex(0).(*redisgraph.Node)

Callers

nothing calls this directly

Calls 7

getConnectionDetailsFunction · 0.85
getTLSdetailsFunction · 0.85
GetMethod · 0.80
QueryMethod · 0.80
NextMethod · 0.80
RecordMethod · 0.80
GetByIndexMethod · 0.80

Tested by

no test coverage detected