From 758fb03a6d2b1e661f227f894d2a0b3fc8083522 Mon Sep 17 00:00:00 2001 From: nicky Date: Wed, 2 Aug 2023 15:03:37 +0530 Subject: [PATCH] sanitize influx queries --- cmd/services/filtersBlockService/go.mod | 2 +- pkg/model/db.go | 3 ++- pkg/model/filters.go | 5 +++-- pkg/model/quotation.go | 9 +++++---- pkg/model/supplies.go | 5 +++-- pkg/model/synthAssets.go | 5 +++-- pkg/model/trades.go | 3 ++- 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/cmd/services/filtersBlockService/go.mod b/cmd/services/filtersBlockService/go.mod index 4d493dd8c..a945c3fe2 100644 --- a/cmd/services/filtersBlockService/go.mod +++ b/cmd/services/filtersBlockService/go.mod @@ -3,7 +3,7 @@ module github.com/diadata-org/diadata/services/filtersBlockService go 1.17 require ( - github.com/diadata-org/diadata v1.4.297 + github.com/diadata-org/diadata v1.4.317-rc-1 github.com/segmentio/kafka-go v0.4.35 github.com/sirupsen/logrus v1.8.1 ) diff --git a/pkg/model/db.go b/pkg/model/db.go index f24544fa3..f79286692 100644 --- a/pkg/model/db.go +++ b/pkg/model/db.go @@ -11,6 +11,7 @@ import ( "github.com/diadata-org/diadata/pkg/dia" "github.com/go-redis/redis" clientInfluxdb "github.com/influxdata/influxdb1-client/v2" + "github.com/influxdata/influxql" ) type Datastore interface { @@ -312,7 +313,7 @@ func (datastore *DB) CopyInfluxMeasurements(dbOrigin string, dbDestination strin func (datastore *DB) SetVWAPFirefly(foreignName string, value float64, timestamp time.Time) error { tags := map[string]string{ - "foreignName": foreignName, + "foreignName": influxql.QuoteString(foreignName), } fields := map[string]interface{}{ "value": value, diff --git a/pkg/model/filters.go b/pkg/model/filters.go index e8c1f5826..211cc61fa 100644 --- a/pkg/model/filters.go +++ b/pkg/model/filters.go @@ -10,6 +10,7 @@ import ( "github.com/diadata-org/diadata/pkg/dia" "github.com/go-redis/redis" clientInfluxdb "github.com/influxdata/influxdb1-client/v2" + "github.com/influxdata/influxql" ) // SetFilter stores a filter point @@ -230,8 +231,8 @@ func (datastore *DB) SaveFilterInflux(filter string, asset dia.Asset, exchange s // Create a point and add to batch tags := map[string]string{ "filter": filter, - "symbol": asset.Symbol, - "address": asset.Address, + "symbol": influxql.QuoteString(asset.Symbol), + "address": influxql.QuoteString(asset.Address), "blockchain": asset.Blockchain, "exchange": exchange, } diff --git a/pkg/model/quotation.go b/pkg/model/quotation.go index 6b48c845b..f9db340b5 100644 --- a/pkg/model/quotation.go +++ b/pkg/model/quotation.go @@ -13,6 +13,7 @@ import ( "github.com/diadata-org/diadata/pkg/utils" "github.com/go-redis/redis" clientInfluxdb "github.com/influxdata/influxdb1-client/v2" + "github.com/influxdata/influxql" "github.com/jackc/pgx/v4" ) @@ -77,8 +78,8 @@ func (datastore *DB) GetAssetPriceUSD(asset dia.Asset, timestamp time.Time) (pri func (datastore *DB) AddAssetQuotationsToBatch(quotations []*AssetQuotation) error { for _, quotation := range quotations { tags := map[string]string{ - "symbol": quotation.Asset.Symbol, - "name": quotation.Asset.Name, + "symbol": influxql.QuoteString(quotation.Asset.Symbol), + "name": influxql.QuoteString(quotation.Asset.Name), "address": quotation.Asset.Address, "blockchain": quotation.Asset.Blockchain, } @@ -99,8 +100,8 @@ func (datastore *DB) AddAssetQuotationsToBatch(quotations []*AssetQuotation) err func (datastore *DB) SetAssetQuotation(quotation *AssetQuotation) error { // Write to influx tags := map[string]string{ - "symbol": quotation.Asset.Symbol, - "name": quotation.Asset.Name, + "symbol": influxql.QuoteString(quotation.Asset.Symbol), + "name": influxql.QuoteString(quotation.Asset.Name), "address": quotation.Asset.Address, "blockchain": quotation.Asset.Blockchain, } diff --git a/pkg/model/supplies.go b/pkg/model/supplies.go index a10a755a6..84a1f9412 100644 --- a/pkg/model/supplies.go +++ b/pkg/model/supplies.go @@ -11,6 +11,7 @@ import ( "github.com/diadata-org/diadata/pkg/dia/helpers" "github.com/go-redis/redis" clientInfluxdb "github.com/influxdata/influxdb1-client/v2" + "github.com/influxdata/influxql" ) func getKeySupply(asset dia.Asset) string { @@ -32,8 +33,8 @@ func (datastore *DB) SaveSupplyInflux(supply *dia.Supply) error { "source": supply.Source, } tags := map[string]string{ - "symbol": supply.Asset.Symbol, - "name": supply.Asset.Name, + "symbol": influxql.QuoteString(supply.Asset.Symbol), + "name": influxql.QuoteString(supply.Asset.Name), "address": supply.Asset.Address, "blockchain": supply.Asset.Blockchain, } diff --git a/pkg/model/synthAssets.go b/pkg/model/synthAssets.go index 9d253ba6b..1aa229b14 100644 --- a/pkg/model/synthAssets.go +++ b/pkg/model/synthAssets.go @@ -7,6 +7,7 @@ import ( "github.com/diadata-org/diadata/pkg/dia" clientInfluxdb "github.com/influxdata/influxdb1-client/v2" + "github.com/influxdata/influxql" ) // SaveSynthSupplyInflux stores a synth supply in influx. Flushed when more than maxPoints in batch. @@ -21,8 +22,8 @@ func (datastore *DB) SaveSynthSupplyInfluxToTable(t *dia.SynthAssetSupply, table // Create a point and add to batch tags := map[string]string{ - "synthassetsymbol": t.Asset.Symbol, - "underlyingassetsymbol": t.AssetUnderlying.Symbol, + "synthassetsymbol": influxql.QuoteString(t.Asset.Symbol), + "underlyingassetsymbol": influxql.QuoteString(t.AssetUnderlying.Symbol), "synthtokenaddress": t.Asset.Address, "underlyingtokenaddress": t.AssetUnderlying.Address, "blockchain": t.Asset.Blockchain, diff --git a/pkg/model/trades.go b/pkg/model/trades.go index 5fc3b61c6..bd064487f 100644 --- a/pkg/model/trades.go +++ b/pkg/model/trades.go @@ -10,6 +10,7 @@ import ( "github.com/diadata-org/diadata/pkg/dia" clientInfluxdb "github.com/influxdata/influxdb1-client/v2" + "github.com/influxdata/influxql" ) // SaveTradeInflux stores a trade in influx. Flushed when more than maxPoints in batch. @@ -24,7 +25,7 @@ func (datastore *DB) SaveTradeInfluxToTable(t *dia.Trade, table string) error { // Create a point and add to batch tags := map[string]string{ - "symbol": t.Symbol, + "symbol": influxql.QuoteString(t.Symbol), "pair": t.Pair, "exchange": t.Source, "verified": strconv.FormatBool(t.VerifiedPair),