Added support for encrypted_regex
This commit is contained in:
@@ -7,6 +7,7 @@ import json
|
|||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
from ruamel.yaml.parser import ParserError
|
from ruamel.yaml.parser import ParserError
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
|
|
||||||
yaml = YAML(typ='safe')
|
yaml = YAML(typ='safe')
|
||||||
|
|
||||||
@@ -63,15 +64,26 @@ def check_file(filename, args):
|
|||||||
except ParserError:
|
except ParserError:
|
||||||
# All sops encrypted files are valid JSON or YAML
|
# All sops encrypted files are valid JSON or YAML
|
||||||
return False, f"{filename}: Not valid JSON or YAML, is not properly encrypted"
|
return False, f"{filename}: Not valid JSON or YAML, is not properly encrypted"
|
||||||
|
if not args.allow_multiple_documents:
|
||||||
|
docs = [doc]
|
||||||
|
else:
|
||||||
|
docs = doc
|
||||||
|
|
||||||
|
for doc in docs:
|
||||||
|
|
||||||
if 'sops' not in doc:
|
if 'sops' not in doc:
|
||||||
# sops puts a `sops` key in the encrypted output. If it is not
|
# sops puts a `sops` key in the encrypted output. If it is not
|
||||||
# present, very likely the file is not encrypted.
|
# present, very likely the file is not encrypted.
|
||||||
return False, f"{filename}: sops metadata key not found in file, is not properly encrypted"
|
return False, f"{filename}: sops metadata key not found in file, is not properly encrypted"
|
||||||
|
|
||||||
|
if 'encrypted_regex' in doc['sops']:
|
||||||
|
encrypted_regex = doc['sops']['encrypted_regex']
|
||||||
|
else:
|
||||||
|
encrypted_regex = '\S'
|
||||||
|
|
||||||
invalid_keys = []
|
invalid_keys = []
|
||||||
for k in doc:
|
for k in doc:
|
||||||
if k != 'sops':
|
if k != 'sops' and re.match(encrypted_regex, k):
|
||||||
# Values under the `sops` key are not encrypted.
|
# Values under the `sops` key are not encrypted.
|
||||||
if not validate_enc(doc[k]):
|
if not validate_enc(doc[k]):
|
||||||
# Collect all invalid keys so we can provide useful error message
|
# Collect all invalid keys so we can provide useful error message
|
||||||
|
|||||||
Reference in New Issue
Block a user