3 D\@sdZddlZddlZddlmZddlmZddlZddlZddl Zddl Zddl m Z ej dZejjejjedZGdd d eZGd d d eZGd d d eZddZddZddZdddZddZddZddZddZdS) a Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. N)ValidationError)RulesCollection)REGIONScfnlintrulescs"eZdZdZdfdd ZZS)CfnLintExitExceptionz/Generic exception used when the cli should exitNcs*|dkrd|}tt|j|||_dS)Nz process failed with exit code %s)superr__init__ exit_code)selfmsgr ) __class__f/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/core.pyr "szCfnLintExitException.__init__)Nr)__name__ __module__ __qualname____doc__r __classcell__rr)rrr src@seZdZdZdS)InvalidRegionExceptionz.When an unsupported/invalid region is suppliedN)rrrrrrrrr)src@seZdZdZdS)UnexpectedRuleExceptionz1When processing a rule fails in an unexpected wayN)rrrrrrrrr-srcCs|rtjj|t||||S)zProcess args and run)rZhelpersZoverride_specs run_checks)filenametemplaterregionsZ override_specrrrrun_cli1s rcCsbd}xX|D]P}|jjddkr(|dB}q |jjddkrB|dB}q |jjddkr |dB}q W|S)z Determine exit code rIWE)ruleid)matchesr matchrrr get_exit_code:s    r'cCsRi}|rD|dkrtjj}qN|dkr0tjj}qN|dkrNtjj}n tjj}|S)z Get FormatterquietZ parseablejson)r formattersZQuietFormatterZParseableFormatterZ JsonFormatter Formatter)fmt formatterrrr get_formatterHs    r.Fc Csnt||||}tg|}yx|D]}|j|q WWn4tk rh}ztdt|dWYdd}~XnX|S)z Get rulesz*Tried to append rules but got an error: %srN)rDEFAULT_RULESDIRZcreate_from_directoryOSErrorrstr) ZrulesdirZ ignore_rulesZ include_rulesconfigure_rulesinclude_experimentalrZ rules_dirsZ rules_direrrr get_rulesYs  $r5cCstjdtjj|dS)z) Backwards compatibility for integrators zJUpdate your integrations to use "cfnlint.config.configure_logging" insteadN)LOGGERdebugrconfigconfigure_logging)Z debug_loggingrrrr9es r9cCsytjj|}Wn:tk rJ}ztjdt|tdWYdd}~XnX|j}t |}|j rrtj j tdtj j|j|j|j|j}|jrtj jggdddgid}tj j|td|jrtj jtd|jrt|td|js|jjtd||j|fS) z@ Get Template Configuration items and set them as default valueszError parsing config file: %srNrrr!rT)rr8Z ConfigMixInrr6errorr1exitformatr.Z update_specsZ maintenanceZupdate_resource_specscorer5 append_rules ignore_checksinclude_checksr2Zupdate_documentationZupdate_iam_policiesZ listrulesprintZ templatesparser print_help)Zcli_argsr8r4r,r-rZdocumentation_rulesrrrget_args_filenamesks:    rDcCsPtjj||j\}}|r"|g|fS||_tjj|j|j|j|j |j }||gfS)z@ Get Template Configuration items and set them as default values) rdecodeZignore_bad_templateZ template_argsr=r5r>r?r@r2r3)rargsrr%rrrrget_template_ruless rGc Cs|rBt|jttsBtt|jtt}d|tf}t|dg}tj||||}|j|j |sy|j|j Wn<t k r}z d|t |f}t |dWYdd}~XnX|jddd|S) zRun Checks against the templatez4Regions %s are unsupported. Supported regions are %s z6Tried to process rules on file %s but got an error: %srNcSs|j|j|jjfS)N)rZ linenumberr#r$)xrrrszrun_checks..)key)setissubsetrlist differencerrZRunnerextendZ transformrun Exceptionr1rsort) rrrrZunsupported_regionsr r%runnererrrrrrs   r)NF) rloggingosZjsonschema.exceptionsrrrZcfnlint.configZcfnlint.formattersZcfnlint.decodeZcfnlint.maintenanceZcfnlint.helpersr getLoggerr6pathjoindirname__file__r/rRrrrrr'r.r5r9rDrGrrrrrs,       ,