mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-03 02:56:52 +00:00
yaml: add new option to ignore "!ansible" tags
This new option for the yaml checker modify ruamel to remove the "!" from the "!vault" tag if it is found. Removing that part allows the file to be parsed correctly, so other errors could be found. fixes: #273
This commit is contained in:
parent
6336b8e792
commit
f60596972c
2 changed files with 37 additions and 0 deletions
|
|
@ -52,11 +52,29 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|||
'Implies --allow-multiple-documents'
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--ignore-ansible-vault', action='store_true',
|
||||
help=(
|
||||
'Ignore keys that look like ansible vault encrypted values. '
|
||||
'This works by removing the "!" from the "!vault" value prefix.'
|
||||
),
|
||||
)
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
load_fn = LOAD_FNS[Key(multi=args.multi, unsafe=args.unsafe)]
|
||||
|
||||
if args.ignore_ansible_vault:
|
||||
def ignore_ansible_vault(loader: ruamel.yaml.Loader,
|
||||
node: ruamel.yaml.Node) -> Any:
|
||||
if node.value.startswith('!vault'):
|
||||
node.value = node.value[1:]
|
||||
return loader.construct_yaml_str(node)
|
||||
|
||||
ruamel.yaml.add_constructor(u'!vault',
|
||||
ignore_ansible_vault,
|
||||
constructor=ruamel.yaml.SafeConstructor)
|
||||
|
||||
retval = 0
|
||||
for filename in args.filenames:
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue