/
storage.go
51 lines (41 loc) · 1.44 KB
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2020 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package audittrail
import (
"context"
"errors"
"io"
"github.com/moov-io/achgateway/internal/service"
"github.com/go-kit/kit/metrics/prometheus"
stdprometheus "github.com/prometheus/client_golang/prometheus"
)
var (
uploadedFilesCounter = prometheus.NewCounterFrom(stdprometheus.CounterOpts{
Name: "audittrail_uploaded_files",
Help: "Counter of ACH files uploaded to audit trail storage",
}, []string{"type", "id"})
uploadFilesErrors = prometheus.NewCounterFrom(stdprometheus.CounterOpts{
Name: "audittrail_upload_errors",
Help: "Counter of errors encountered when attempting ACH files upload",
}, []string{"type", "id"})
)
// Storage is an interface for saving and encrypting ACH files for
// records retention. This is often a requirement of agreements.
//
// File retention after upload is not part of this storage.
type Storage interface {
// SaveFile will encrypt and copy the ACH file to the configured file storage.
SaveFile(ctx context.Context, filepath string, data []byte) error
GetFile(ctx context.Context, filepath string) (io.ReadCloser, error)
Close() error
}
func NewStorage(cfg *service.AuditTrail) (Storage, error) {
if cfg == nil {
return newMockStorage(), nil
}
if cfg.BucketURI != "" {
return newBlobStorage(cfg)
}
return nil, errors.New("unknown storage config")
}