【问题标题】:How exclude !Ref tag from check-yaml git hook?如何从 check-yaml git hook 中排除 !Ref 标签?
【发布时间】:2020-04-12 07:15:01
【问题描述】:

有一个serverless.yaml 文件包含这样的行:

VpcId: !Ref MyVpc

Yaml 文件由check-yaml git 钩子验证,该钩子由pre-commit 命令调用。所以pre-commit run --all-files 运行失败并出现错误:

could not determine a constructor for the tag '!Ref'
  in "serverless.yml", line 172, column 29

有没有办法配置check-yaml 来跳过这个错误?

【问题讨论】:

    标签: python git yaml pre-commit-hook


    【解决方案1】:
    hooks:
    - id: check-yaml
      args: ['--unsafe']
    

    应该可以解决问题。它只是检查语法而不是尝试加载 YAML。

    【讨论】:

    • 这行得通,但是,Using this option removes all guarantees of portability to other yaml implementations
    【解决方案2】:

    在您上面的具体示例中,建议使用 CloudFormation 模板,您也可以考虑cfn-python-lint's pre-commit hook

    【讨论】:

      猜你喜欢
      • 2019-04-27
      • 1970-01-01
      • 2011-01-02
      • 2020-02-25
      • 2012-04-15
      • 2021-09-03
      • 2021-10-11
      • 1970-01-01
      相关资源
      最近更新 更多