-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CWS] Move JSON schemas to secl package (#30913)
- Loading branch information
Showing
57 changed files
with
1,593 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
//go:generate go run github.com/DataDog/datadog-agent/pkg/security/generators/schemas/policy -output ../../../secl/schemas/policy.schema.json | ||
|
||
// Package main holds main related files | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"flag" | ||
"os" | ||
"reflect" | ||
"time" | ||
|
||
"github.com/invopop/jsonschema" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/security/secl/rules" | ||
) | ||
|
||
func main() { | ||
var output string | ||
flag.StringVar(&output, "output", "", "output file") | ||
flag.Parse() | ||
|
||
if output == "" { | ||
panic("an output file argument is required") | ||
} | ||
|
||
reflector := jsonschema.Reflector{ | ||
ExpandedStruct: true, | ||
Mapper: func(t reflect.Type) *jsonschema.Schema { | ||
switch t { | ||
case reflect.TypeOf(time.Duration(0)): | ||
return &jsonschema.Schema{ | ||
OneOf: []*jsonschema.Schema{ | ||
{ | ||
Type: "string", | ||
Format: "duration", | ||
Description: "Duration in Go format (e.g. 1h30m, see https://pkg.go.dev/time#ParseDuration)", | ||
}, | ||
{ | ||
Type: "integer", | ||
Description: "Duration in nanoseconds", | ||
}, | ||
}, | ||
} | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
if err := reflector.AddGoComments("github.com/DataDog/datadog-agent/pkg/security/secl/rules/model.go", "../../../secl/rules"); err != nil { | ||
panic(err) | ||
} | ||
|
||
schema := reflector.Reflect(&rules.PolicyDef{}) | ||
schema.ID = "https://github.com/DataDog/datadog-agent/tree/main/pkg/security/secl/rules" | ||
|
||
data, err := json.MarshalIndent(schema, "", " ") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := os.WriteFile(output, data, 0644); err != nil { | ||
panic(err) | ||
} | ||
} |
Oops, something went wrong.