diff --git a/configs/config.default.yml b/configs/config.default.yml index 07034fbf..5ec509a6 100644 --- a/configs/config.default.yml +++ b/configs/config.default.yml @@ -12,3 +12,4 @@ ACHWebViewer: HelpfulLinks: Corrections: "https://moov-io.github.io/ach/changes/" Returns: "https://moov-io.github.io/ach/returns/" + AllowMissingBatchHeader: true diff --git a/pkg/filelist/achgateway.go b/pkg/filelist/achgateway.go index 070644d8..9c6f7eca 100644 --- a/pkg/filelist/achgateway.go +++ b/pkg/filelist/achgateway.go @@ -10,7 +10,6 @@ import ( "path/filepath" "time" - "github.com/moov-io/ach" "github.com/moov-io/ach-web-viewer/pkg/service" ) @@ -96,7 +95,7 @@ func (a *achgatewayLister) getFiles(shard string) ([]File, error) { return out, nil } -func (a *achgatewayLister) GetFile(path string) (*File, error) { +func (a *achgatewayLister) GetFile(path string, cfg service.DisplayConfig) (*File, error) { req, err := http.NewRequest("GET", a.endpoint+"/"+path, nil) if err != nil { return nil, err @@ -124,7 +123,7 @@ func (a *achgatewayLister) GetFile(path string) (*File, error) { return nil, err } - file, err := ach.NewReader(bytes.NewReader(contents)).Read() + file, err := readFile(bytes.NewReader(contents), cfg) if err != nil { return nil, err } @@ -132,7 +131,7 @@ func (a *achgatewayLister) GetFile(path string) (*File, error) { return &File{ Name: wrapper.Filename, StoragePath: dir, - Contents: &file, + Contents: file, CreatedAt: wrapper.ModTime, Size: int64(len(contents)), }, nil diff --git a/pkg/filelist/bucket.go b/pkg/filelist/bucket.go index a7097308..65b06ac9 100644 --- a/pkg/filelist/bucket.go +++ b/pkg/filelist/bucket.go @@ -82,7 +82,7 @@ func (ls *bucketLister) GetFiles(opts ListOpts) (Files, error) { return out, nil } -func (ls *bucketLister) GetFile(path string) (*File, error) { +func (ls *bucketLister) GetFile(path string, cfg service.DisplayConfig) (*File, error) { rdr, err := ls.buck.NewReader(context.Background(), path, nil) if err != nil { return nil, err @@ -97,7 +97,7 @@ func (ls *bucketLister) GetFile(path string) (*File, error) { _, name := filepath.Split(path) - file, err := readFile(bytes.NewReader(bs)) + file, err := readFile(bytes.NewReader(bs), cfg) return &File{ Name: name, diff --git a/pkg/filelist/common.go b/pkg/filelist/common.go index da5fd9ae..87f287be 100644 --- a/pkg/filelist/common.go +++ b/pkg/filelist/common.go @@ -5,12 +5,13 @@ import ( "strings" "github.com/moov-io/ach" + "github.com/moov-io/ach-web-viewer/pkg/service" ) -func readFile(r io.Reader) (*ach.File, error) { +func readFile(r io.Reader, cfg service.DisplayConfig) (*ach.File, error) { reader := ach.NewReader(r) reader.SetValidation(&ach.ValidateOpts{ - AllowMissingBatchHeader: true, + AllowMissingBatchHeader: cfg.AllowMissingBatchHeader, }) file, err := reader.Read() if err != nil { diff --git a/pkg/filelist/filesystem.go b/pkg/filelist/filesystem.go index 7ddc444b..f9923a94 100644 --- a/pkg/filelist/filesystem.go +++ b/pkg/filelist/filesystem.go @@ -61,7 +61,7 @@ func (ls *filesystemLister) GetFiles(opts ListOpts) (Files, error) { return out, nil } -func (ls *filesystemLister) GetFile(path string) (*File, error) { +func (ls *filesystemLister) GetFile(path string, cfg service.DisplayConfig) (*File, error) { path = filepath.Clean(path) if strings.Contains(path, "..") || strings.HasPrefix(path, "/") { @@ -75,7 +75,7 @@ func (ls *filesystemLister) GetFile(path string) (*File, error) { _, name := filepath.Split(fd.Name()) - file, err := readFile(fd) + file, err := readFile(fd, cfg) var stat fs.FileInfo if fd != nil { diff --git a/pkg/filelist/list.go b/pkg/filelist/list.go index cd6db76a..be2df461 100644 --- a/pkg/filelist/list.go +++ b/pkg/filelist/list.go @@ -27,7 +27,7 @@ type File struct { type Lister interface { SourceID() string - GetFile(path string) (*File, error) + GetFile(path string, cfg service.DisplayConfig) (*File, error) GetFiles(opts ListOpts) (Files, error) } @@ -71,10 +71,10 @@ func createLister(src service.Source) (Lister, error) { return nil, fmt.Errorf("unknown source: %#v", src) } -func (ls Listers) GetFile(sourceID, path string) (*File, error) { +func (ls Listers) GetFile(sourceID, path string, cfg service.DisplayConfig) (*File, error) { for i := range ls { if ls[i].SourceID() == sourceID { - return ls[i].GetFile(path) + return ls[i].GetFile(path, cfg) } } return nil, fmt.Errorf("%s not found for sourceID=%s", path, sourceID) diff --git a/pkg/service/model_config.go b/pkg/service/model_config.go index 80a9cbf8..4c05814a 100644 --- a/pkg/service/model_config.go +++ b/pkg/service/model_config.go @@ -37,9 +37,10 @@ type BindAddress struct { } type DisplayConfig struct { - Format string // e.g. "human-readable" - Masking MaskingConfig - HelpfulLinks HelpfulLinks + Format string // e.g. "human-readable" + Masking MaskingConfig + HelpfulLinks HelpfulLinks + AllowMissingBatchHeader bool } type MaskingConfig struct { diff --git a/pkg/web/web.go b/pkg/web/web.go index e48debb1..1fd31992 100644 --- a/pkg/web/web.go +++ b/pkg/web/web.go @@ -158,7 +158,7 @@ func getFile(logger log.Logger, cfg service.DisplayConfig, listers filelist.List sourceID := mux.Vars(r)["sourceID"] fullPath := strings.TrimPrefix(r.URL.Path, fmt.Sprintf("%s/sources/%s/", basePath, sourceID)) - file, err := listers.GetFile(sourceID, fullPath) + file, err := listers.GetFile(sourceID, fullPath, cfg) if err != nil { logger.Warn().Logf("ERROR: %v\n", err) w.WriteHeader(http.StatusInternalServerError)