Add api key for coingecko api in notional jobs (#1259)

Co-authored-by: walker-16 <agpazos85@gmail.com>
This commit is contained in:
ftocal 2024-03-27 14:42:04 -03:00 committed by GitHub
parent e55f6e35e3
commit 36e6c0a715
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 39 additions and 14 deletions

View File

@ -6,4 +6,6 @@ metadata:
namespace: {{ .NAMESPACE }}
data:
aws-region: {{ .AWS_REGION }}
aws-bucket: {{ .AWS_BUCKET }}
aws-bucket: {{ .AWS_BUCKET }}
coingecko-url: {{ .COINGECKO_URL }}
coingecko-header-key: {{ .COINGECKO_HEADER_KEY }}

View File

@ -24,7 +24,20 @@ spec:
- name: JOB_ID
value: JOB_NOTIONAL_USD
- name: COINGECKO_URL
value: {{ .COINGECKO_URL }}
valueFrom:
configMapKeyRef:
name: jobs
key: coingecko-url
- name: COINGECKO_HEADER_KEY
valueFrom:
configMapKeyRef:
name: jobs
key: coingecko-header-key
- name: COINGECKO_API_KEY
valueFrom:
secretKeyRef:
name: jobs
key: coingecko-api-key
- name: NOTIONAL_CHANNEL
value: {{ .NOTIONAL_CHANNEL }}
- name: CACHE_URL

View File

@ -103,9 +103,9 @@ func main() {
}
// initNotionalJob initializes notional job.
func initNotionalJob(ctx context.Context, cfg *config.NotionalConfiguration, logger *zap.Logger) *notional.NotionalJob {
func initNotionalJob(_ context.Context, cfg *config.NotionalConfiguration, logger *zap.Logger) *notional.NotionalJob {
// init coingecko api client.
api := coingecko.NewCoingeckoAPI(cfg.CoingeckoURL, logger)
api := coingecko.NewCoingeckoAPI(cfg.CoingeckoURL, cfg.CoingeckoHeaderKey, cfg.CoingeckoApiKey, logger)
// init redis client.
redisClient := redis.NewClient(&redis.Options{Addr: cfg.CacheURL})
// init token provider.

View File

@ -9,14 +9,16 @@ type Configuration struct {
}
type NotionalConfiguration struct {
Environment string `env:"ENVIRONMENT,required"`
CoingeckoURL string `env:"COINGECKO_URL,required"`
CacheURL string `env:"CACHE_URL,required"`
CachePrefix string `env:"CACHE_PREFIX,required"`
NotionalChannel string `env:"NOTIONAL_CHANNEL,required"`
P2pNetwork string `env:"P2P_NETWORK,required"`
AwsRegion string `env:"AWS_REGION"`
AwsBucket string `env:"AWS_BUCKET"`
Environment string `env:"ENVIRONMENT,required"`
CoingeckoURL string `env:"COINGECKO_URL,required"`
CoingeckoHeaderKey string `env:"COINGECKO_HEADER_KEY"`
CoingeckoApiKey string `env:"COINGECKO_API_KEY"`
CacheURL string `env:"CACHE_URL,required"`
CachePrefix string `env:"CACHE_PREFIX,required"`
NotionalChannel string `env:"NOTIONAL_CHANNEL,required"`
P2pNetwork string `env:"P2P_NETWORK,required"`
AwsRegion string `env:"AWS_REGION"`
AwsBucket string `env:"AWS_BUCKET"`
}
type TransferReportConfiguration struct {

View File

@ -17,14 +17,18 @@ type CoingeckoAPI struct {
chunkSize int
client *http.Client
logger *zap.Logger
headerKey string
apiKey string
}
// NewCoingeckoAPI creates a new coingecko client
func NewCoingeckoAPI(url string, logger *zap.Logger) *CoingeckoAPI {
func NewCoingeckoAPI(url string, headerKey, apiKey string, logger *zap.Logger) *CoingeckoAPI {
return &CoingeckoAPI{
url: url,
chunkSize: 200,
client: http.DefaultClient,
headerKey: headerKey,
apiKey: apiKey,
logger: logger,
}
}
@ -45,12 +49,16 @@ func (c *CoingeckoAPI) GetNotionalUSD(ids []string) (map[string]NotionalUSD, err
// iterate over chunks of ids.
for i, chunk := range chunksIds {
notionalUrl := fmt.Sprintf("%s/simple/price?ids=%s&vs_currencies=usd", c.url, strings.Join(chunk, ","))
notionalUrl := fmt.Sprintf("%s/api/v3/simple/price?ids=%s&vs_currencies=usd", c.url, strings.Join(chunk, ","))
req, err := http.NewRequest(http.MethodGet, notionalUrl, nil)
if err != nil {
return response, err
}
if c.headerKey != "" && c.apiKey != "" {
req.Header.Add(c.headerKey, c.apiKey)
}
res, err := c.client.Do(req)
if err != nil {
return response, err