diff --git a/cmd/oipd/main.go b/cmd/oipd/main.go index 40ed882..08cf95e 100644 --- a/cmd/oipd/main.go +++ b/cmd/oipd/main.go @@ -46,8 +46,9 @@ func main() { host := viper.GetString("flod.host") user := viper.GetString("flod.user") pass := viper.GetString("flod.pass") + tls := viper.GetBool("flod.tls") - err := flo.WaitForFlod(tenMinuteCtx, host, user, pass) + err := flo.WaitForFlod(tenMinuteCtx, host, user, pass, tls) if err != nil { log.Error("Unable to connect to Flod", logger.Attrs{"host": host, "err": err}) shutdown(err) diff --git a/config/config.go b/config/config.go index 7d36391..5afee90 100644 --- a/config/config.go +++ b/config/config.go @@ -80,6 +80,7 @@ func loadDefaults() { defaultFlodDir := floutil.AppDataDir("flod", false) defaultFlodCert := filepath.Join(defaultFlodDir, "rpc.cert") viper.SetDefault("flod.certFile", defaultFlodCert) + viper.SetDefault("flod.tls", true) viper.SetDefault("flod.host", "127.0.0.1:8334") viper.SetDefault("flod.user", "user") viper.SetDefault("flod.pass", "pass") diff --git a/config/defaults/config.example.yml b/config/defaults/config.example.yml index 52ae9ba..b06a1e0 100644 --- a/config/defaults/config.example.yml +++ b/config/defaults/config.example.yml @@ -19,6 +19,8 @@ flod: # Flod RPC authentication user: user pass: pass + + tls: true # Flod RPC authorization certificate # By default reads certificate directly from Flod data directory # certFile: certs/rpc.cert diff --git a/flo/flo.go b/flo/flo.go index b648287..8828487 100644 --- a/flo/flo.go +++ b/flo/flo.go @@ -37,7 +37,7 @@ func AddCore(host, user, pass string) error { return err } -func WaitForFlod(ctx context.Context, host, user, pass string) error { +func WaitForFlod(ctx context.Context, host, user, pass string, tls bool) error { attempts := 0 a := logger.Attrs{"host": host, "attempts": attempts} b := backoff.NewWithoutJitter(10*time.Minute, 1*time.Second) @@ -47,7 +47,7 @@ func WaitForFlod(ctx context.Context, host, user, pass string) error { attempts++ a["attempts"] = attempts log.Info("attempting connection to flod", a) - err := AddFlod(host, user, pass) + err := AddFlod(host, user, pass, tls) if err != nil { a["err"] = err log.Error("unable to connect to flod", a) @@ -77,12 +77,15 @@ func WaitForFlod(ctx context.Context, host, user, pass string) error { return nil } -func AddFlod(host, user, pass string) error { - // Connect to flod RPC server using websockets. - certFile := config.GetFilePath("flod.certFile") - certs, err := ioutil.ReadFile(certFile) - if err != nil { - return errors.Wrap(err, "unable to read rpc.cert") +func AddFlod(host, user, pass string, tls bool) error { + var certs []byte + var err error + if tls { + certFile := config.GetFilePath("flod.certFile") + certs, err = ioutil.ReadFile(certFile) + if err != nil { + return errors.Wrap(err, "unable to read rpc.cert") + } } ntfnHandlers := rpcclient.NotificationHandlers{