diff --git a/config.go b/config.go index 2b73a8e..073b35b 100644 --- a/config.go +++ b/config.go @@ -43,6 +43,9 @@ type Nordigen struct { // SecretKey is used to create requisition SecretKey string `envconfig:"NORDIGEN_SECRET_KEY"` + // Use named datafile instead of default (ynabber-NORDIGEN_BANKID.json) + Datafile string `envconfig:"NORDIGEN_DATAFILE"` + // PayeeSource is a list of sources for Payee candidates, the first // method that yields a result will be used. Valid options are: // unstructured and name. diff --git a/reader/nordigen/nordigen.go b/reader/nordigen/nordigen.go index 2aa35cd..7aa17a0 100644 --- a/reader/nordigen/nordigen.go +++ b/reader/nordigen/nordigen.go @@ -115,19 +115,23 @@ func BulkReader(cfg ynabber.Config) (t []ynabber.Transaction, err error) { } // Select persistent dataFile - dataFileBankSpecific := fmt.Sprintf("%s/%s-%s.json", cfg.DataDir, "ynabber", cfg.Nordigen.BankID) - dataFileGeneric := fmt.Sprintf("%s/%s.json", cfg.DataDir, "ynabber") - dataFile := dataFileBankSpecific - - _, err = os.Stat(dataFileBankSpecific) - if errors.Is(err, os.ErrNotExist) { - _, err := os.Stat(dataFileGeneric) + dataFile := "" + if cfg.Nordigen.Datafile != "" { + dataFile = cfg.Nordigen.Datafile + } else { + dataFileBankSpecific := fmt.Sprintf("%s/%s-%s.json", cfg.DataDir, "ynabber", cfg.Nordigen.BankID) + dataFileGeneric := fmt.Sprintf("%s/%s.json", cfg.DataDir, "ynabber") + dataFile = dataFileBankSpecific + _, err = os.Stat(dataFileBankSpecific) if errors.Is(err, os.ErrNotExist) { - // If bank specific does not exists and neither does generic, use dataFileBankSpecific - dataFile = dataFileBankSpecific - } else { - // Generic dataFile exists(old naming) but not the bank specific, use dataFileGeneric - dataFile = dataFileGeneric + _, err := os.Stat(dataFileGeneric) + if errors.Is(err, os.ErrNotExist) { + // If bank specific does not exists and neither does generic, use dataFileBankSpecific + dataFile = dataFileBankSpecific + } else { + // Generic dataFile exists(old naming) but not the bank specific, use dataFileGeneric + dataFile = dataFileGeneric + } } }