Skip to content

Commit b159310

Browse files
committed
Add RETENTION_DAYS and EXTERNAL_MONITOR support for server audit
- Add RetentionDaysAuditTargetOption AST type - Fix EXTERNAL_MONITOR target kind to return "ExternalMonitor" - Add URL target kind support
1 parent c0f133b commit b159310

5 files changed

Lines changed: 35 additions & 3 deletions

File tree

ast/server_audit_statement.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ type OnOffAuditTargetOption struct {
7979

8080
func (o *OnOffAuditTargetOption) auditTargetOption() {}
8181

82+
// RetentionDaysAuditTargetOption represents the RETENTION_DAYS option
83+
type RetentionDaysAuditTargetOption struct {
84+
OptionKind string
85+
Days ScalarExpression
86+
}
87+
88+
func (o *RetentionDaysAuditTargetOption) auditTargetOption() {}
89+
8290
// AuditOption is an interface for audit options
8391
type AuditOption interface {
8492
auditOption()

parser/marshal.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8564,6 +8564,15 @@ func auditTargetOptionToJSON(o ast.AuditTargetOption) jsonNode {
85648564
"Value": opt.Value,
85658565
"OptionKind": opt.OptionKind,
85668566
}
8567+
case *ast.RetentionDaysAuditTargetOption:
8568+
node := jsonNode{
8569+
"$type": "RetentionDaysAuditTargetOption",
8570+
"OptionKind": opt.OptionKind,
8571+
}
8572+
if opt.Days != nil {
8573+
node["Days"] = scalarExpressionToJSON(opt.Days)
8574+
}
8575+
return node
85678576
default:
85688577
return jsonNode{"$type": "UnknownAuditTargetOption"}
85698578
}

parser/parse_statements.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3617,14 +3617,18 @@ func convertAuditGroupName(name string) string {
36173617
func (p *Parser) parseAuditTarget() (*ast.AuditTarget, error) {
36183618
target := &ast.AuditTarget{}
36193619

3620-
// Parse target kind (FILE, APPLICATION_LOG, SECURITY_LOG)
3620+
// Parse target kind (FILE, APPLICATION_LOG, SECURITY_LOG, URL, EXTERNAL_MONITOR)
36213621
switch strings.ToUpper(p.curTok.Literal) {
36223622
case "FILE":
36233623
target.TargetKind = "File"
36243624
case "APPLICATION_LOG":
36253625
target.TargetKind = "ApplicationLog"
36263626
case "SECURITY_LOG":
36273627
target.TargetKind = "SecurityLog"
3628+
case "URL":
3629+
target.TargetKind = "Url"
3630+
case "EXTERNAL_MONITOR":
3631+
target.TargetKind = "ExternalMonitor"
36283632
default:
36293633
target.TargetKind = capitalizeFirst(p.curTok.Literal)
36303634
}
@@ -3726,6 +3730,17 @@ func (p *Parser) parseAuditTargetOption() (ast.AuditTargetOption, error) {
37263730
Value: value,
37273731
}, nil
37283732

3733+
case "RETENTION_DAYS":
3734+
// Parse the number of days
3735+
days, err := p.parseScalarExpression()
3736+
if err != nil {
3737+
return nil, err
3738+
}
3739+
return &ast.RetentionDaysAuditTargetOption{
3740+
OptionKind: "RetentionDays",
3741+
Days: days,
3742+
}, nil
3743+
37293744
default:
37303745
// Parse literal value (FILEPATH, etc.)
37313746
val, err := p.parseScalarExpression()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}

0 commit comments

Comments
 (0)