@@ -321,7 +321,7 @@ client, err := nosqldb.NewClient(cfg)
321
321
322
322
To connect an application to a secure NoSQL database, you need to provide user
323
323
credentials used to authenticate with the server. If the Proxy server is configured
324
- with a self-signed certificate or a certificate that is not trusted by the
324
+ with a self-signed certificate or a certificate that is not trusted by
325
325
the default system CA, you also need to specifiy * CertPath* and * ServerName* for
326
326
the certificate path and server name used to verify server's certificate.
327
327
@@ -330,7 +330,7 @@ cfg := nosqldb.Config{
330
330
Mode : " onprem" ,
331
331
Endpoint : " https://exampleHostServer" ,
332
332
Username : " driverUser" ,
333
- Password : " ExamplePassword__123" ,
333
+ Password : [] byte ( " ExamplePassword__123" ) ,
334
334
HTTPConfig : httputil.HTTPConfig {
335
335
CertPath: " /path/to/server-certificate" ,
336
336
ServerName: " exampleHostServer" , // should match the CN subject value from the certificate
@@ -348,10 +348,80 @@ cfg := nosqldb.Config{
348
348
Mode : " onprem" ,
349
349
Endpoint : " https://exampleHostServer" ,
350
350
Username : " driverUser" ,
351
- Password : " ExamplePassword__123" ,
351
+ Password : [] byte ( " ExamplePassword__123" ) ,
352
352
HTTPConfig : httputil.HTTPConfig {
353
353
InsecureSkipVerify: true ,
354
354
},
355
355
}
356
356
client , err := nosqldb.NewClient (cfg)
357
357
```
358
+
359
+ #### Initialize configuration using a JSON file
360
+ The sections above describe how to create a ` nosqldb.Config ` object using Go's
361
+ struct literals, as an alternative, you can create and initialize a
362
+ ` nosqldb.Config ` object using a JSON file. Note that for the fields of byte
363
+ slice type, such as the ` Password ` field required for secure on-premise Oracle
364
+ NoSQL Database, you need to specify a base64 encoded string in JSON file.
365
+ For example, when connect to a secure on-premise Oracle NoSQL Database with
366
+ user credentials * driver_user/DriverUser__ 123456* , where the username is
367
+ * driver_user* , password is * DriverUser__ 123456* , base64 encoding of the
368
+ password is * RHJpdmVyVXNlcl9fMTIzNDU2* (` echo -n "DriverUser__123456" | base64 ` ),
369
+ use a sample JSON file * config.json* :
370
+
371
+ ``` json
372
+ {
373
+ "mode" : " onprem" ,
374
+ "endpoint" : " https://localhost:8091" ,
375
+ "username" : " driver_user" ,
376
+ "password" : " RHJpdmVyVXNlcl9fMTIzNDU2" ,
377
+ "httpConfig" : {
378
+ "certPath" : " /path/to/server_certificate.pem" ,
379
+ "serverName" : " localhost"
380
+ }
381
+ }
382
+ ```
383
+
384
+ Then create and initialize a ` nosqldb.Config ` object using the JSON file:
385
+ ``` go
386
+ package main
387
+
388
+ import (
389
+ " encoding/json"
390
+ " fmt"
391
+ " io/ioutil"
392
+
393
+ " github.com/oracle/nosql-go-sdk/nosqldb"
394
+ )
395
+
396
+ func createConfigFromJSON (configFile string ) (*nosqldb .Config , error ) {
397
+ data , err := ioutil.ReadFile (configFile)
398
+ if err != nil {
399
+ return nil , fmt.Errorf (" failed to read config file %s : %v " , configFile, err)
400
+ }
401
+
402
+ var cfg nosqldb.Config
403
+ err = json.Unmarshal (data, &cfg)
404
+ if err != nil {
405
+ return nil , fmt.Errorf (" failed to parse configurations from file %s : %v " , configFile, err)
406
+ }
407
+
408
+ return &cfg, nil
409
+ }
410
+
411
+ func main () {
412
+
413
+ cfg , err := createConfigFromJSON (" /path/to/config.json" )
414
+ if err != nil {
415
+ fmt.Printf (" failed to create config: %v " , err)
416
+ return
417
+ }
418
+
419
+ client , err := nosqldb.NewClient (*cfg)
420
+ if err != nil {
421
+ fmt.Printf (" failed to create client: %v " , err)
422
+ return
423
+ }
424
+ defer client.Close ()
425
+ ...
426
+ }
427
+ ```
0 commit comments