3 D\-%@szdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ej e Z ddZ ddZddZd d ZdS) 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. NcCsddddddddd d d d d dddddddd}x|jD]\}}tjtd|}tjd||tj|}tj |j j d}t |d}t ||}t |d}tj||ddd!dWd QRXq8Wd S)"z Update Resource Specs z}https://s3.ap-east-1.amazonaws.com/cfn-resource-specifications-ap-east-1-prod/latest/CloudFormationResourceSpecification.jsonzZhttps://d33vqc0rt9ld30.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzZhttps://d1ane3fvebulky.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzZhttps://d2zq80gdmjim8k.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzZhttps://d2senuesg1djtx.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzYhttps://doigdx0kgq9el.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzZhttps://d2stg8d246z9di.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzZhttps://d2s8ygphhesbe7.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzZhttps://d1mta8qj7i28i2.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzYhttps://diy8iv58sj6ba.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzZhttps://d3teyb21fexa9r.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzZhttps://d1742qcu2c1ncx.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzZhttps://d2d0mfegowb3wk.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzZhttps://d3c9jyj3w509b0.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzZhttps://d1uauaxba7bl26.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzYhttps://dnwj8swjjbsbt.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzYhttps://d68hl49wbnanq.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzZhttps://d201a2mn26r7lk.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.jsonzhttps://s3.us-gov-east-1.amazonaws.com/cfn-resource-specifications-us-gov-east-1-prod/latest/CloudFormationResourceSpecification.jsonzhttps://s3.us-gov-west-1.amazonaws.com/cfn-resource-specifications-us-gov-west-1-prod/latest/CloudFormationResourceSpecification.json)z ap-east-1zap-northeast-1zap-northeast-2zap-northeast-3z ap-south-1zap-southeast-1zap-southeast-2z ca-central-1z eu-central-1z eu-north-1z eu-west-1z eu-west-2z eu-west-3z sa-east-1z us-east-1z us-east-2z us-west-1z us-west-2z us-gov-east-1z us-gov-west-1z/data/CloudSpecs/%s.jsonzDownloading template %s into %szutf-8allwT,: )indent sort_keys separatorsN)rr)items pkg_resourcesresource_filename__name__LOGGERdebugrequestsgetjsonloadscontentdecode patch_specopendump)Zregionsregionurlfilenamereqrfrm/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/maintenance.pyupdate_resource_specss>     r cCsxd}t|ddd}g}t|d4}|j}x$|rP|j||dkrFP|j}q.WWdQRXt|d}x|D]}|j|qpW|jd jt||jd |jd d }tj}d j dd|j D} |j|j|j |j |j dd| tj} d j dd| j D} |j|j| j | j | j dd| tj} d j dd| j D} |j|j| j | j | j dd| g} xv|D]n} | jr| j| qrd j dd| j D} dj dd| jjD}|j|j| j | j | j || j| qrW| rj|jd|jd|jdx`| D]X} d j dd| j D} dj dd| jjD}|j|j| j | j | j || j| qWWdQRXdS)zGenerate documentationz docs/rules.mdcSs|jS)N)id)objrrrQsz&update_documentation..)keyrz ## Rules Nrz8The following **{}** rules are applied by this linter: zU| Rule ID | Title | Description | Config
(Name:Type:Default) | Source | Tags | z@| -------- | ----- | ----------- | ---------- | ------ | ---- | zB| {0} | {1} | {2} | {3} | [Source]({4}) | {5} | rcss|]}dj|VqdS)z`{0}`N)format).0tagrrr rsz'update_documentation..css|]}dj|VqdS)z`{0}`N)r&)r'r(rrrr)wscss|]}dj|VqdS)z`{0}`N)r&)r'r(rrrr)|scss|]}dj|VqdS)z`{0}`N)r&)r'r(rrrr)sz
css,|]$\}}dj||jd|jdVqdS)z {0}:{1}:{2}typedefaultN)r&r)r'r$valuesrrrr)sz### Experimental rules z3| Rule ID | Title | Description | Source | Tags | z3| -------- | ----- | ----------- | ------ | ---- | css|]}dj|VqdS)z`{0}`N)r&)r'r(rrrr)scss,|]$\}}dj||jd|jdVqdS)z {0}:{1}:{2}r+r,N)r&r)r'r$r-rrrr)s)sortedrreadlineappendwriter&lencfnlint ParseErrorjointagsr!Z shortdesc descriptionZTransformErrorZ RuleErrorZ experimentalZconfig_definitionr Z source_url)rulesrZ sorted_rulesdataZ origial_filelineZnew_fileZ rule_outputZ parseerrorr6ZtransformerrorZ ruleerrorZexperimental_rulesZruleconfigrrrupdate_documentationJsZ       (    r<cCstjd|tjjtjjtdd|}xtj|D]\}}}|jxt j |dD]}tjd||t j t jjdj||}xn|D]f}yt j |gj|ddWqt jk rtjd ||Yqtjk rtjd ||YqXqWqRWq2W|S) zPatch the spec filez"Patching spec file for region "%s"r9Z ExtendedSpecsz*.jsonzProcessing %s (%s)zdata/ExtendedSpecs/{}/{}T)Zin_placez#Patch (%s) not applied in region %sz4Parent element not found for patch (%s) in region %s)rinfoospathr5dirname__file__walksortfnmatchfilter jsonpatchZ JsonPatchr3ZhelpersZload_resourcesr&applyZJsonPatchConflictr jsonpointerZJsonPointerException)rrZ append_dir_ filenamesrZ all_patchesZ all_patchrrrrs   rcCsd}tjtd}tjd||tj|}|jjd}|j dd}t j |}|ddd j d d g|dd d j d t|d}t j||ddddWdQRXdS)zupdate iam policies filez4https://awspolicygen.s3.amazonaws.com/js/policies.jsz#/data/AdditionalSpecs/Policies.jsonzDownloading policies %s into %szutf-8zapp.PolicyEditorConfig=Z serviceMapzManage Amazon API GatewayZActionsHEADOPTIONSzAmazon Kinesis Video StreamsZStartStreamEncryptionrrTr: )rrr N)rrN)r r r rrrrrrsplitrrextendr0rr)rrrrrrrrupdate_iam_policiess    rQ)__doc__rDrloggingr>rr rHrFr3 getLoggerr rr r<rrQrrrrs ,N