a 'Dg@sdZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z dZ ej ZeeZdddZdd d Zd d Zed kreee edS)z,Debug jinja template rendering of user-data.N)read_cfg_paths)JinjaLoadErrorJinjaSyntaxParsingException NotJinjaErrorrender_jinja_payload_from_fileZrendercCsR|stjttd}|jdtdd|jddtdtd|jdd d d d d |S)aBuild or extend and arg parser for jinja render utility. @param parser: Optional existing ArgumentParser instance representing the subcommand which will be extended to support the args of this utility. @returns: ArgumentParser with proper argument configuration. )prog description user_dataz$Path to the user-data file to render)typehelpz-iz--instance-dataz6Optional path to instance-data.json file. Defaults to z-dz--debug store_trueFz+Add verbose messages during template render)actiondefaultr )argparseArgumentParserNAME__doc__ add_argumentstrCLOUDINIT_RUN_DIR)parserr>/usr/lib/python3.9/site-packages/cloudinit/cmd/devel/render.py get_parsers* rFc Cs|r |}nNt}t}|d}|dkrT|d}tj|sXtd|||}n|}tj|sttd|dSz4t |}| }Wdn1s0YWn t ytd|YdS0zt ||||rd nd d } Wntt tfy"} ztd t| WYd} ~ dSd} ~ 0tyZ} z td |t| WYd} ~ dSd} ~ 00| srtd|dStj| dS)zRender the provided user-data template file using instance-data values. Also setup CLI log handlers to report to stderr since this is a development utility which should be run by a human on the CLI. @return 0 on success, 1 on failure. instance_datarZinstance_data_sensitivez4Missing root-readable %s. Using redacted %s instead.z#Missing instance-data.json file: %sNzMissing user-data file: %sTF)ZpayloadZ payload_fnZinstance_data_filedebugz5Cannot render from instance data due to exception: %sz2Failed to render templated user-data file '%s'. %sz#Unable to render user-data file: %s)rosgetuidZ get_runpathpathexistsLOGZwarningerroropenreadIOErrorrrrreprrrsysstdoutwrite) Zuser_data_pathZinstance_data_pathrZinstance_data_fnpathsuidZredacted_data_fnstreamr Zrendered_payloaderrrrender_template:s`      *     r.cCst|j|j|jS)N)r.r rr)_nameargsrrr handle_argsvsr1__main__)N)NF)rrZloggingrr'Zcloudinit.cmd.develrZ!cloudinit.handlers.jinja_templaterrrrrZrun_dirrZ getLogger__name__r!rr.r1exit parse_argsrrrrs   <