1
0
mirror of https://github.com/getsops/sops.git synced 2026-02-05 12:45:21 +01:00
This commit is contained in:
Adriano
2019-07-08 15:32:33 -07:00
parent 598b706613
commit 4b99fa18b3
22 changed files with 148 additions and 46 deletions

View File

@@ -9,7 +9,9 @@ import (
"github.com/pkg/errors"
// empty import as per https://godoc.org/github.com/lib/pq
_ "github.com/lib/pq"
"github.com/sirupsen/logrus"
"go.mozilla.org/sops/logging"
"gopkg.in/yaml.v2"
@@ -67,36 +69,46 @@ type config struct {
var auditors []Auditor
// SubmitEvent handles an event for all auditors
func SubmitEvent(event interface{}) {
for _, auditor := range auditors {
auditor.Handle(event)
}
}
// Register registers a new Auditor in the global auditor list
func Register(auditor Auditor) {
auditors = append(auditors, auditor)
}
// Auditor is notified when noteworthy events happen, for example when a file is encrypted or decrypted.
type Auditor interface {
Handle(event interface{})
}
// DecryptEvent contains fields relevant to a decryption event
type DecryptEvent struct {
File string
}
// EncryptEvent contains fields relevant to an encryption event
type EncryptEvent struct {
File string
}
// RotateEvent contains fields relevant to a key rotation event
type RotateEvent struct {
File string
}
// PostgresAuditor is a Postgres SQL DB implementation of the
// Auditor interface
type PostgresAuditor struct {
DB *sql.DB
}
// NewPostgresAuditor is the constructor for a new PostgresAuditor object
// initialized with the given db connection string
func NewPostgresAuditor(connStr string) (*PostgresAuditor, error) {
db, err := sql.Open("postgres", connStr)
pg := &PostgresAuditor{DB: db}
@@ -113,6 +125,8 @@ func NewPostgresAuditor(connStr string) (*PostgresAuditor, error) {
return pg, nil
}
// Handle is the PostgresAuditor implementation of the function required by the
// Auditor interface
func (p *PostgresAuditor) Handle(event interface{}) {
u, err := user.Current()
if err != nil {