Add --daemon-ca-path argument and establish HTTPS connection if specified.

This commit is contained in:
Jonathan Moody 2022-12-16 12:23:15 -06:00
parent 818822d98e
commit 8f6a8db681
2 changed files with 14 additions and 2 deletions

View file

@ -27,6 +27,7 @@ type Args struct {
DBPath string DBPath string
Chain *string Chain *string
DaemonURL *url.URL DaemonURL *url.URL
DaemonCAPath string
EsHost string EsHost string
EsPort int EsPort int
PrometheusPort int PrometheusPort int
@ -230,6 +231,7 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args {
chain := parser.Selector("", "chain", []string{chaincfg.MainNetParams.Name, chaincfg.TestNet3Params.Name, chaincfg.RegressionNetParams.Name, "testnet"}, chain := parser.Selector("", "chain", []string{chaincfg.MainNetParams.Name, chaincfg.TestNet3Params.Name, chaincfg.RegressionNetParams.Name, "testnet"},
&argparse.Options{Required: false, Help: "Which chain to use, default is 'mainnet'. Values 'regtest' and 'testnet' are for testing", Default: chaincfg.MainNetParams.Name}) &argparse.Options{Required: false, Help: "Which chain to use, default is 'mainnet'. Values 'regtest' and 'testnet' are for testing", Default: chaincfg.MainNetParams.Name})
daemonURLStr := parser.String("", "daemon-url", &argparse.Options{Required: false, Help: "URL for rpc to lbrycrd or lbcd, <rpcuser>:<rpcpassword>@<lbcd rpc ip><lbrcd rpc port>.", Validate: validateURL, Default: defaultDaemonURL}) daemonURLStr := parser.String("", "daemon-url", &argparse.Options{Required: false, Help: "URL for rpc to lbrycrd or lbcd, <rpcuser>:<rpcpassword>@<lbcd rpc ip><lbrcd rpc port>.", Validate: validateURL, Default: defaultDaemonURL})
daemonCAPath := parser.String("", "daemon-ca-path", &argparse.Options{Required: false, Help: "Path to the lbcd CA file. Use SSL certificate to verify connection to lbcd."})
esHost := parser.String("", "eshost", &argparse.Options{Required: false, Help: "elasticsearch host", Default: DefaultEsHost}) esHost := parser.String("", "eshost", &argparse.Options{Required: false, Help: "elasticsearch host", Default: DefaultEsHost})
esPort := parser.Int("", "esport", &argparse.Options{Required: false, Help: "elasticsearch port", Default: DefaultEsPort}) esPort := parser.Int("", "esport", &argparse.Options{Required: false, Help: "elasticsearch port", Default: DefaultEsPort})
prometheusPort := parser.Int("", "prometheus-port", &argparse.Options{Required: false, Help: "prometheus port", Default: DefaultPrometheusPort}) prometheusPort := parser.Int("", "prometheus-port", &argparse.Options{Required: false, Help: "prometheus port", Default: DefaultPrometheusPort})
@ -303,6 +305,7 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args {
DBPath: *dbPath, DBPath: *dbPath,
Chain: chain, Chain: chain,
DaemonURL: daemonURL, DaemonURL: daemonURL,
DaemonCAPath: *daemonCAPath,
EsHost: *esHost, EsHost: *esHost,
EsPort: *esPort, EsPort: *esPort,
PrometheusPort: *prometheusPort, PrometheusPort: *prometheusPort,

View file

@ -9,6 +9,7 @@ import (
"fmt" "fmt"
"hash" "hash"
"io" "io"
"io/ioutil"
golog "log" golog "log"
"net" "net"
"net/http" "net/http"
@ -291,6 +292,13 @@ func MakeHubServer(grp *stop.Group, args *Args) *Server {
var lbcdClient *lbcd.Client = nil var lbcdClient *lbcd.Client = nil
if args.DaemonURL != nil { if args.DaemonURL != nil {
var rpcCertificate []byte
if args.DaemonCAPath != "" {
rpcCertificate, err = ioutil.ReadFile(args.DaemonCAPath)
if err != nil {
log.Fatalf("failed to read SSL certificate from path: %v", args.DaemonCAPath)
}
}
log.Warnf("connecting to lbcd daemon at %v...", args.DaemonURL.Host) log.Warnf("connecting to lbcd daemon at %v...", args.DaemonURL.Host)
password, _ := args.DaemonURL.User.Password() password, _ := args.DaemonURL.User.Password()
cfg := &lbcd.ConnConfig{ cfg := &lbcd.ConnConfig{
@ -298,11 +306,12 @@ func MakeHubServer(grp *stop.Group, args *Args) *Server {
User: args.DaemonURL.User.Username(), User: args.DaemonURL.User.Username(),
Pass: password, Pass: password,
HTTPPostMode: true, HTTPPostMode: true,
DisableTLS: true, DisableTLS: rpcCertificate == nil,
Certificates: rpcCertificate,
} }
lbcdClient, err = lbcd.New(cfg, nil) lbcdClient, err = lbcd.New(cfg, nil)
if err != nil { if err != nil {
log.Fatalf("lbcd connection failed: %v", err) log.Fatalf("lbcd daemon connection failed: %v", err)
} }
} }