Skip to content

Commit

Permalink
fix(alpacabkfeeder): override stocks_json URL by env var (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
dakimura authored Apr 4, 2022
1 parent e9b0670 commit 241c377
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion contrib/alpacabkfeeder/configs/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var testConfig = map[string]interface{}{
"api_secret_key": "world",
"symbols_update_time": "01:23:45",
"update_time": "12:34:56",
"stocks_json_url": "https://example.com/tradable_stocks.json",
"stocks_json_basic_auth": "foo:bar",
"exchanges": []string{"AMEX", "ARCA", "BATS", "NYSE", "NASDAQ", "NYSEARCA", "OTC"},
"index_groups": []string{"bar"},
Expand All @@ -32,13 +33,14 @@ func TestNewConfig(t *testing.T) {
want *configs.DefaultConfig
wantErr bool
}{
"ok/ API key ID, API secret key, UpdateTime, basicAuth can be overridden by env vars": {
"ok/ API key ID, API secret key, UpdateTime, stocksJson can be overridden by env vars": {
config: testConfig,
envVars: map[string]string{
"ALPACA_BROKER_FEEDER_API_KEY_ID": "yo",
"ALPACA_BROKER_FEEDER_API_SECRET_KEY": "yoyo",
"ALPACA_BROKER_FEEDER_SYMBOLS_UPDATE_TIME": "10:00:00",
"ALPACA_BROKER_FEEDER_UPDATE_TIME": "20:00:00",
"ALPACA_BROKER_FEEDER_STOCKS_JSON_URL": "https://example.com/overriden.json",
"ALPACA_BROKER_FEEDER_STOCKS_JSON_BASIC_AUTH": "akkie:mypassword",
},
want: &configs.DefaultConfig{
Expand All @@ -52,6 +54,7 @@ func TestNewConfig(t *testing.T) {
UpdateTime: time.Date(0, 1, 1, 20, 0, 0, 0, time.UTC),
APIKeyID: "yo",
APISecretKey: "yoyo",
StocksJSONURL: "https://example.com/overriden.json",
StocksJSONBasicAuth: "akkie:mypassword",
},
wantErr: false,
Expand All @@ -70,6 +73,7 @@ func TestNewConfig(t *testing.T) {
UpdateTime: time.Date(0, 1, 1, 12, 34, 56, 0, time.UTC),
APIKeyID: "hello",
APISecretKey: "world",
StocksJSONURL: "https://example.com/tradable_stocks.json",
StocksJSONBasicAuth: "foo:bar",
},
wantErr: false,
Expand Down
5 changes: 5 additions & 0 deletions contrib/alpacabkfeeder/configs/envconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ func envOverride(config *DefaultConfig) (*DefaultConfig, error) {
config.APISecretKey = apiSecretKey
}

// override the basic Auth of Stocks Json URL and basic auth
// override the basic Auth of Stocks Json URL
stocksJSONURL := os.Getenv("ALPACA_BROKER_FEEDER_STOCKS_JSON_URL")
if stocksJSONURL != "" {
config.StocksJSONURL = stocksJSONURL
}
stocksJSONBasicAuth := os.Getenv("ALPACA_BROKER_FEEDER_STOCKS_JSON_BASIC_AUTH")
if stocksJSONBasicAuth != "" {
config.StocksJSONBasicAuth = stocksJSONBasicAuth
Expand Down
1 change: 0 additions & 1 deletion contrib/alpacabkfeeder/feed/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package feed
import (
"time"


"github.com/alpacahq/marketstore/v4/contrib/alpacabkfeeder/api"
"github.com/alpacahq/marketstore/v4/contrib/alpacabkfeeder/symbols"
"github.com/alpacahq/marketstore/v4/contrib/alpacabkfeeder/writer"
Expand Down

0 comments on commit 241c377

Please sign in to comment.