Skip to content

Commit

Permalink
feat: add flag to enable TLS (#28)
Browse files Browse the repository at this point in the history
* add config enable tls

* add config enable tls 2

* add enable TLS flag
  • Loading branch information
jgimeno authored Mar 15, 2023
1 parent b63e96f commit ba25316
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 25 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ FEEDER_MNEMONIC="guard cream sadness conduct invite crumble clock pudding hole g
EXCHANGE_SYMBOLS_MAP='{"bitfinex": {"ubtc:unusd": "tBTCUSD", "ueth:unusd": "tETHUSD", "uusd:unusd": "tUSTUSD"}}'
```

### Enabling TLS

To enable TLS, you need to set the following env vars:

```ini
TLS_ENABLED="true"
```

### Delegating post pricing

In order to be able to delegate the post pricing you need to set the
Expand Down
4 changes: 2 additions & 2 deletions cmd/feeder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ func main() {

c := config.MustGet()

eventStream := eventstream.Dial(c.WebsocketEndpoint, c.GRPCEndpoint, logger)
eventStream := eventstream.Dial(c.WebsocketEndpoint, c.GRPCEndpoint, c.EnableTLS, logger)
priceProvider := priceprovider.NewAggregatePriceProvider(c.ExchangesToPairToSymbolMap, c.DataSourceConfigMap, logger)
kb, valAddr, feederAddr := config.GetAuth(c.FeederMnemonic)

if c.ValidatorAddr != nil {
valAddr = *c.ValidatorAddr
}
pricePoster := priceposter.Dial(c.GRPCEndpoint, c.ChainID, kb, valAddr, feederAddr, logger)
pricePoster := priceposter.Dial(c.GRPCEndpoint, c.ChainID, c.EnableTLS, kb, valAddr, feederAddr, logger)

f := feeder.NewFeeder(eventStream, priceProvider, pricePoster, logger)
f.Run()
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func Get() (*Config, error) {
conf.GRPCEndpoint = os.Getenv("GRPC_ENDPOINT")
conf.WebsocketEndpoint = os.Getenv("WEBSOCKET_ENDPOINT")
conf.FeederMnemonic = os.Getenv("FEEDER_MNEMONIC")
conf.EnableTLS = os.Getenv("ENABLE_TLS") == "true"
exchangeSymbolsMapJson := os.Getenv("EXCHANGE_SYMBOLS_MAP")
exchangeSymbolsMap := map[string]map[string]string{}
err := json.Unmarshal([]byte(exchangeSymbolsMapJson), &exchangeSymbolsMap)
Expand Down Expand Up @@ -82,6 +83,7 @@ type Config struct {
FeederMnemonic string
ChainID string
ValidatorAddr *sdk.ValAddress
EnableTLS bool
}

func (c *Config) Validate() error {
Expand Down
22 changes: 11 additions & 11 deletions feeder/eventstream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package eventstream
import (
"context"
"crypto/tls"
"strings"
"sync"
"sync/atomic"
"time"
Expand All @@ -24,16 +23,17 @@ type wsI interface {
}

// Dial opens two connections to the given endpoint, one for the websocket and one for the oracle grpc.
func Dial(tendermintRPCEndpoint string, grpcEndpoint string, logger zerolog.Logger) *Stream {
transportDialOpt := grpc.WithTransportCredentials(
credentials.NewTLS(
&tls.Config{
InsecureSkipVerify: false,
},
),
)
if strings.Contains(grpcEndpoint, "localhost") {
transportDialOpt = grpc.WithInsecure()
func Dial(tendermintRPCEndpoint string, grpcEndpoint string, enableTLS bool, logger zerolog.Logger) *Stream {
transportDialOpt := grpc.WithInsecure()

if enableTLS {
transportDialOpt = grpc.WithTransportCredentials(
credentials.NewTLS(
&tls.Config{
InsecureSkipVerify: false,
},
),
)
}

conn, err := grpc.Dial(grpcEndpoint, transportDialOpt)
Expand Down
23 changes: 11 additions & 12 deletions feeder/priceposter/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package priceposter
import (
"context"
"crypto/tls"
"strings"
"time"

"github.com/NibiruChain/nibiru/app"
Expand Down Expand Up @@ -44,17 +43,17 @@ type deps struct {
chainID string
}

func Dial(grpcEndpoint string, chainID string, keyBase keyring.Keyring, validator sdk.ValAddress, feeder sdk.AccAddress, logger zerolog.Logger) *Client {

transportDialOpt := grpc.WithTransportCredentials(
credentials.NewTLS(
&tls.Config{
InsecureSkipVerify: false,
},
),
)
if strings.Contains(grpcEndpoint, "localhost") {
transportDialOpt = grpc.WithInsecure()
func Dial(grpcEndpoint string, chainID string, enableTLS bool, keyBase keyring.Keyring, validator sdk.ValAddress, feeder sdk.AccAddress, logger zerolog.Logger) *Client {
transportDialOpt := grpc.WithInsecure()

if enableTLS {
transportDialOpt = grpc.WithTransportCredentials(
credentials.NewTLS(
&tls.Config{
InsecureSkipVerify: false,
},
),
)
}

conn, err := grpc.Dial(grpcEndpoint, transportDialOpt)
Expand Down

0 comments on commit ba25316

Please sign in to comment.