Skip to content

Commit

Permalink
Allow user to set the datafile name
Browse files Browse the repository at this point in the history
  • Loading branch information
hpernu committed Oct 25, 2022
1 parent 4ae6873 commit 407be26
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 16 additions & 12 deletions reader/nordigen/nordigen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit 407be26

Please sign in to comment.