paramah revised this gist . Go to revision
1 file changed, 32 insertions
gistfile1.txt(file created)
| @@ -0,0 +1,32 @@ | |||
| 1 | + | package conftest | |
| 2 | + | ||
| 3 | + | import json | |
| 4 | + | ||
| 5 | + | # Funkcja do sprawdzania struktury JSON | |
| 6 | + | is_valid_json(input) { | |
| 7 | + | # Sprawdź, czy input jest łańcuchem znaków | |
| 8 | + | is_string(input) | |
| 9 | + | ||
| 10 | + | # Parsuj JSON | |
| 11 | + | json.parse(input) != null | |
| 12 | + | } | |
| 13 | + | ||
| 14 | + | # Funkcja do sprawdzania struktury connectionstring | |
| 15 | + | is_valid_connection_string(input) { | |
| 16 | + | # Sprawdź, czy input jest łańcuchem znaków | |
| 17 | + | is_string(input) | |
| 18 | + | ||
| 19 | + | # Parsuj JSON | |
| 20 | + | json_data := json.parse(input) | |
| 21 | + | ||
| 22 | + | # Sprawdź, czy JSON zawiera określone pola | |
| 23 | + | json_data["required_field1"] != null | |
| 24 | + | json_data["required_field2"] != null | |
| 25 | + | } | |
| 26 | + | ||
| 27 | + | # Reguła walidacji | |
| 28 | + | deny[msg] { | |
| 29 | + | input.connectionstring != null | |
| 30 | + | not is_valid_connection_string(input.connectionstring) | |
| 31 | + | msg := "Invalid connection string JSON structure" | |
| 32 | + | } | |
Newer
Older