Skip to content

Commit 037d7f9

Browse files
LucaGuerrapoiana
authored andcommittedSep 16, 2024·
cleanup(falco): use a header file for rule json schema
Signed-off-by: Luca Guerra <[email protected]>
1 parent ed4fb33 commit 037d7f9

File tree

4 files changed

+176
-3
lines changed

4 files changed

+176
-3
lines changed
 

‎userspace/engine/falco_engine.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ limitations under the License.
4545

4646
#include "evttype_index_ruleset.h"
4747

48-
const std::string falco_engine::s_default_ruleset = "falco-default-ruleset";
48+
#include "rule_json_schema.h"
4949

50-
static const std::string rule_schema_string = R"({"$schema":"http://json-schema.org/draft-06/schema#","type":"array","items":{"$ref":"#/definitions/FalcoRule"},"definitions":{"FalcoRule":{"type":"object","additionalProperties":false,"properties":{"required_engine_version":{"type":"string"},"macro":{"type":"string"},"condition":{"type":"string"},"list":{"type":"string"},"items":{"type":"array","items":{"$ref":"#/definitions/Item"}},"rule":{"type":"string"},"desc":{"type":"string"},"enabled":{"type":"boolean"},"output":{"type":"string"},"append":{"type":"boolean"},"priority":{"$ref":"#/definitions/Priority"},"exceptions":{"type":"array","items":{"$ref":"#/definitions/Exception"}},"override":{"$ref":"#/definitions/Override"},"tags":{"type":"array","items":{"type":"string"}}},"required":[],"title":"FalcoRule"},"Item":{"anyOf":[{"type":"integer"},{"type":"string"}],"title":"Item"},"Exception":{"type":"object","additionalProperties":false,"properties":{"name":{"type":"string"},"fields":{},"comps":{},"values":{}},"required":["name","values"],"title":"Exception"},"Priority":{"type":"string","enum":["EMERGENCY","ALERT","CRITICAL","ERROR","WARNING","NOTICE","INFO","INFORMATIONAL","DEBUG"],"title":"Priority"},"OverriddenItem":{"type":"string","enum":["append","replace"],"title":"Priority"},"Override":{"type":"object","additionalProperties":false,"properties":{"items":{"$ref":"#/definitions/OverriddenItem"},"desc":{"$ref":"#/definitions/OverriddenItem"},"condition":{"$ref":"#/definitions/OverriddenItem"},"output":{"$ref":"#/definitions/OverriddenItem"},"priority":{"$ref":"#/definitions/OverriddenItem"},"enabled":{"$ref":"#/definitions/OverriddenItem"},"exceptions":{"$ref":"#/definitions/OverriddenItem"}},"minProperties":1,"title":"Override"}}})";
50+
const std::string falco_engine::s_default_ruleset = "falco-default-ruleset";
5151

5252
using namespace falco;
5353

‎userspace/engine/rule_json_schema.h

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
/*
3+
Copyright (C) 2024 The Falco Authors.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#define LONG_STRING_CONST(...) #__VA_ARGS__
21+
22+
const char rule_schema_string[] = LONG_STRING_CONST(
23+
24+
{
25+
"$schema": "http://json-schema.org/draft-06/schema#",
26+
"type": "array",
27+
"items": {
28+
"$ref": "#/definitions/FalcoRule"
29+
},
30+
"definitions": {
31+
"FalcoRule": {
32+
"type": "object",
33+
"additionalProperties": false,
34+
"properties": {
35+
"required_engine_version": {
36+
"type": "string"
37+
},
38+
"macro": {
39+
"type": "string"
40+
},
41+
"condition": {
42+
"type": "string"
43+
},
44+
"list": {
45+
"type": "string"
46+
},
47+
"items": {
48+
"type": "array",
49+
"items": {
50+
"$ref": "#/definitions/Item"
51+
}
52+
},
53+
"rule": {
54+
"type": "string"
55+
},
56+
"desc": {
57+
"type": "string"
58+
},
59+
"enabled": {
60+
"type": "boolean"
61+
},
62+
"output": {
63+
"type": "string"
64+
},
65+
"append": {
66+
"type": "boolean"
67+
},
68+
"priority": {
69+
"$ref": "#/definitions/Priority"
70+
},
71+
"exceptions": {
72+
"type": "array",
73+
"items": {
74+
"$ref": "#/definitions/Exception"
75+
}
76+
},
77+
"override": {
78+
"$ref": "#/definitions/Override"
79+
},
80+
"tags": {
81+
"type": "array",
82+
"items": {
83+
"type": "string"
84+
}
85+
}
86+
},
87+
"required": [],
88+
"title": "FalcoRule"
89+
},
90+
"Item": {
91+
"anyOf": [
92+
{
93+
"type": "integer"
94+
},
95+
{
96+
"type": "string"
97+
}
98+
],
99+
"title": "Item"
100+
},
101+
"Exception": {
102+
"type": "object",
103+
"additionalProperties": false,
104+
"properties": {
105+
"name": {
106+
"type": "string"
107+
},
108+
"fields": {},
109+
"comps": {},
110+
"values": {}
111+
},
112+
"required": [
113+
"name",
114+
"values"
115+
],
116+
"title": "Exception"
117+
},
118+
"Priority": {
119+
"type": "string",
120+
"enum": [
121+
"EMERGENCY",
122+
"ALERT",
123+
"CRITICAL",
124+
"ERROR",
125+
"WARNING",
126+
"NOTICE",
127+
"INFO",
128+
"INFORMATIONAL",
129+
"DEBUG"
130+
],
131+
"title": "Priority"
132+
},
133+
"OverriddenItem": {
134+
"type": "string",
135+
"enum": [
136+
"append",
137+
"replace"
138+
],
139+
"title": "Priority"
140+
},
141+
"Override": {
142+
"type": "object",
143+
"additionalProperties": false,
144+
"properties": {
145+
"items": {
146+
"$ref": "#/definitions/OverriddenItem"
147+
},
148+
"desc": {
149+
"$ref": "#/definitions/OverriddenItem"
150+
},
151+
"condition": {
152+
"$ref": "#/definitions/OverriddenItem"
153+
},
154+
"output": {
155+
"$ref": "#/definitions/OverriddenItem"
156+
},
157+
"priority": {
158+
"$ref": "#/definitions/OverriddenItem"
159+
},
160+
"enabled": {
161+
"$ref": "#/definitions/OverriddenItem"
162+
},
163+
"exceptions": {
164+
"$ref": "#/definitions/OverriddenItem"
165+
}
166+
},
167+
"minProperties": 1,
168+
"title": "Override"
169+
}
170+
}
171+
}
172+
173+
); // LONG_STRING_CONST macro
File renamed without changes.

‎userspace/falco/configuration.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ limitations under the License.
3636
#include "configuration.h"
3737
#include "logger.h"
3838

39-
#include "json_schema.h"
39+
#include "config_json_schema.h"
4040

4141
#include <re2/re2.h>
4242

0 commit comments

Comments
 (0)
Please sign in to comment.