gistfile1.txt
· 720 B · Text
Raw
package conftest
import json
# Funkcja do sprawdzania struktury JSON
is_valid_json(input) {
# Sprawdź, czy input jest łańcuchem znaków
is_string(input)
# Parsuj JSON
json.parse(input) != null
}
# Funkcja do sprawdzania struktury connectionstring
is_valid_connection_string(input) {
# Sprawdź, czy input jest łańcuchem znaków
is_string(input)
# Parsuj JSON
json_data := json.parse(input)
# Sprawdź, czy JSON zawiera określone pola
json_data["required_field1"] != null
json_data["required_field2"] != null
}
# Reguła walidacji
deny[msg] {
input.connectionstring != null
not is_valid_connection_string(input.connectionstring)
msg := "Invalid connection string JSON structure"
}
| 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 | } |