Skip to content

Commit 46e8e30

Browse files
authored
Merge pull request #510 from nais/cleanup_audit
handle error messages
2 parents 1194ece + 96599f0 commit 46e8e30

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

pkg/postgres/audit.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"k8s.io/apimachinery/pkg/runtime/schema"
99
)
1010

11-
// this is used for all privileges and select, as it covers both cases
12-
1311
func EnableAuditLogging(ctx context.Context, appName, cluster, namespace string) error {
1412
return enableAuditAsAppUser(ctx, appName, namespace, cluster)
1513
}
@@ -30,16 +28,15 @@ func enableAuditAsAppUser(ctx context.Context, appName, namespace, cluster strin
3028
return fmt.Errorf("required flags missing for instance: %v", err)
3129
}
3230

33-
enablePGAudit := fmt.Sprintf("CREATE EXTENSION pgaudit; ALTER USER %s IN DATABASE %s SET pgaudit.log TO 'none';", connectionInfo.username, connectionInfo.dbName)
34-
3531
db, err := sql.Open("cloudsqlpostgres", connectionInfo.ProxyConnectionString())
3632
if err != nil {
3733
return err
3834
}
3935

4036
defer db.Close()
4137

42-
_, err = db.ExecContext(ctx, enablePGAudit)
38+
enableAudit := fmt.Sprintf(`CREATE EXTENSION IF NOT EXISTS pgaudit; ALTER USER %s IN DATABASE %s SET pgaudit.log TO 'none';`, connectionInfo.username, connectionInfo.dbName)
39+
_, err = db.ExecContext(ctx, enableAudit)
4340
if err != nil {
4441
return fmt.Errorf("enableAuditAsAppUser: error enabling pgaudit: %w", err)
4542
}

0 commit comments

Comments
 (0)