f]dZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl mZddlmZddlmZddlmZdd lmZdd lmZdd lmZmZmZmZmZmZm Z m!Z!m"Z"ddl#Z#dd l$m%Z%m&Z&dd l'm(Z(ddl)m*Z*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3m4Z4m5Z5m6Z6 ddl7m8Z9e9Z8ejxe=Z>dZ?dZ@dZAddddZBdZCdZDdZEdZFdZGdZHd ZId!ZJeKe*jDcgc] }|dd"k(s |c}ZMerddlZdd#lNmOZOmPZPGd$d%ePZQneRZQGd&d'e8ZSGd(d)eZTeeTZUGd*d+eZVeVjd,e@ieVjd,eAiiZYGd-d.eZZGd/d0eZ[Gd1d2eZ\dd3d4d5eUd6ee]d7e]d8e]fd9Z^Gd:d;e_Z`Gd<d=e`Zad>Zb dd@eRd8e]fdAZcd8ee8fdBZdeSfd eedCeRdDe]dEe e;fdFZfeefd GZgeefdHGZheSfdEe e;fdIZieSfdEe e;fdJZjdKZkddCeRfdMZldNeRd8eemfdOZn ddNeRdPeedQeedReed8eef dSZodeVjd?d?dLd?fd@eRdCeeRdTeVdPeedUeedReedVeed8eefdWZpGdXdYZqdddZd[eRd\e]d]eRd^eeUd_eeUd8e!e]erff d`Zsdae]d8eeTfdbZt ddce]dae]dde]d8e\fdeZueVjd?dfdce]dCeRdTeVdQeedde]d8eef dfZvdgZwdhZxdieRdje]d8ee]fdkZydieRdleRd8e]fdmZzd8e]fdnZ{doeRdleRfdpZ|doeRfdqZ}dreRd8e]fdsZ~ddCeRdleRd8e]fdtZdueQd8e]fdvZdueQd8e]fdwZddueQdCeeRd8e]fdxZd8eRfdyZdzed8e]fd{Zd8e]fd|ZeVjfdTeVd8eRfd}Zdd~ZdZd8ee]ee[ffdZdZdZe=dk(rejeyy#e:$re;Z8YwxYwcc}w)zFschema.py: Set of module functions for processing cloud-config schema.N) defaultdict)Iterable)suppress)deepcopy)Enum)EACCES)partial)chain) TYPE_CHECKING DefaultDictList NamedTupleOptionalTupleTypeUnioncast)importersafeyaml)read_cfg_paths)INCLUSION_TYPES_MAPtype_from_starts_with)Paths)DataSourceNotFoundException)mkdtemp)errorget_modules_from_dirload_text_file write_file)ValidationErrorz!versions.schema.cloud-config.jsonzschema-cloud-config-v1.jsonzschema-network-config-v1.jsontruefalsenull)TFNap {name} {title_underbar} {title} .. tab-set:: {prefix3}.. tab-item:: Summary {description} {prefix6}**Internal name:** ``{id}`` {prefix6}**Module frequency:** {frequency} {prefix6}**Supported distros:** {distros} {prefix6}{activate_by_schema_keys} {prefix3}.. tab-item:: Config schema {property_doc} {prefix3}.. tab-item:: Examples {prefix6}:: {examples} z5{prefix}* **{prop_name}:** ({prop_type}){description}zJ{prefix}* Each object in **{prop_name}** list supports the following keys:z& # --- Example{example_count} --- deprecatedz DEPRECATED: #) NotRequired TypedDictceZdZUeed<eed<eed<eed<ej eed<ej eed<eed<eeeed<y ) MetaSchemanameidtitle descriptiondistrosexamples frequencyactivate_by_schema_keysN)__name__ __module__ __qualname__str__annotations__typingr r'9/usr/lib/python3/dist-packages/cloudinit/config/schema.pyr*r*|sI  S!!++c""!,T#Y!77r:r*c eZdZy)SchemaDeprecationErrorN)r3r4r5r9r:r;r=r=sr:r=c.eZdZUeed<eed<defdZy) SchemaProblempathmessagereturnc8|jd|jS)N: )r@rAselfs r;formatzSchemaProblem.formats))Bt||n--r:N)r3r4r5r6r7rGr9r:r;r?r?s I L..r:r?ceZdZdZdZdZy) SchemaTypeaSupported schema types are either cloud-config or network-config. Vendordata and Vendordata2 format adheres to cloud-config schema type. Cloud Metadata is unique schema to each cloud platform and likely will not be represented in this enum. z cloud-confignetwork-configN)r3r4r5__doc__ CLOUD_CONFIGNETWORK_CONFIGr9r:r;rIrIs"L%Nr:rIlatestc&eZdZdZdZdZdZdZdZy)InstanceDataTypez-Types of instance data provided to cloud-initz user-datarJz vendor-dataz vendor2-datac|jSNvaluerEs r;__str__zInstanceDataType.__str__s zzr:N) r3r4r5rKUSERDATArM VENDORDATA VENDOR2DATArUr9r:r;rPrPs7H%NJ Kr:rPc,eZdZUeed<eed<eed<y)InstanceDataPart config_type schema_type config_pathN)r3r4r5rPr7rIr6r9r:r;rZrZs!!r:rZc"eZdZUeed<eed<y)UserDataTypeAndDecodedContent userdata_typecontentN)r3r4r5r6r7r9r:r;r_r_s  Lr:r_, prefix separatorschema_problemsrdrerBcN|jtd|}|r||}|S)Nc"|jSrR)rG)ps r;z)_format_schema_problems..s QXXZr:)joinmap)rfrdre formatteds r;_format_schema_problemsrns1 s#7IJI hyk* r:cJeZdZdZ ddeedeeffd ZdefdZxZ S)SchemaValidationErrorz.handle_problemssB6!d3x=12H .xG GGOr:zCloud config schema errors: rv"Cloud config schema deprecations: N)rqrrsuper__init__)rFrqrrr{rA __class__s @r;r~zSchemaValidationError.__init__sH - 1 $3 7$   !r:rBc,t|jSrR)boolrqrEs r; has_errorsz SchemaValidationError.has_errorssD&&''r:)NN) r3r4r5rKrSchemaProblemsr~rr __classcell__)rs@r;rprps<F378< "/ "&n5 "D(D(r:rpceZdZdZy)"SchemaValidationInvalidHeaderErrorz>Raised when no valid header is declared in the user-data file.N)r3r4r5rKr9r:r;rrsHr:rc ddlm}|jj |dxst |t fS#t$rYywxYw)zWTYPE_CHECKER override allowing bytes for string type For jsonschema v. 3.0.0+ r)Draft4ValidatorFstring) jsonschemar ImportError TYPE_CHECKERis_type isinstancebytes)checkerinstancers r;is_schema_byte_stringrsO .  ' ' / /(  ( Huh '( s7 AAFconfigcdtffd }|r|ngd}djt||}jdd}||j S)zcombine description with new/changed/deprecated message deprecated/changed/new keys require a _version key (this is verified in a unittest), a _description key is optional keycj|syj|dd}j|dd|d}|jd|d|}rd|Sd |jd S) Nr$ _description_versionz z in version .  z **)get capitalizestrip)rkey_descriptionvmsgannotaters r;format_messagez:_add_deprecated_changed_or_new_msg..format_messageszzSE# **uL%92> JJe8 uC D !",qcO3DE se9 syy{m1%%r:)r%changednewr$r.)r6rkrlrrstrip)rr filter_keyr filter_keyschanged_new_deprecatedr.s`` r;"_add_deprecated_changed_or_new_msgrs` &C &"! &F  WWS%EF**]B/K]12 3 : : <>,#C#G#G$c&"ou sK(==%/ '',chhqkV3##C( ]j (    $ ]Z 'SXXJ5L)!* r:rr error_typec#DK|rt|d|g}||yyw)zJsonschema validator for `deprecated` items. It raises a instance of `error_type` if deprecated that must be handled, otherwise the instance is consider faulty. T)rrN)r) _validatorr% _instancerrrrs r;rrTs/0 Tzl o s )rrc# Kddlm}g}g}d}t|D]\} } t|j || | } tt fd| } tt fd| } | s|j | nrt|tr1d|vr-d| jd d vrd |d| d vr d }| Ed {|j | |s ||t|d||Ed {y 7@7w)aJsonschema validator for `anyOf`. It treats occurrences of `error_type` as non-errors, but yield them for external processing. Useful to process schema annotations, as `deprecated`. Cloud-init's network schema under the `config` key has a complexity of allowing each list dict item to declare it's type with a `type` key which can contain the values: bond, bridge, nameserver, physical, route, vlan. This schema 'flexibility' makes it hard for the default jsonschema.exceptions.best_match function to find the correct schema failure because it typically returns the failing schema error based on the schema of greatest match depth. Since each anyOf dict matches the same depth into the network schema path, `best_match` just returns the first set of schema errors, which is almost always incorrect. To find a better schema match when encountering schema validation errors, cloud-init network schema introduced schema $defs with the prefix `anyOf_type_`. If the object we are validating contains a 'type' key, and one of the failing schema objects in an anyOf clause has a name of the format anyOf_type_XXX, raise those schema errors instead of calling best_match. r) best_matchF schema_pathct| SrRrers r;rjz_anyOf..Az)B%Br:ct|SrRrrs r;rjz_anyOf..Z:6r:r anyOf_type$refr$ anyOf_type_TNz, is not valid under any of the given schemas)context) jsonschema.exceptionsr enumeraterxdescendfilterextendrrrr ) validatoranyOfr_schemarr all_errorsall_deprecationsskip_best_matchindex subschemaall_errserrs deprecationss ` r;_anyOfrls*<1JO%e, y   h u  E FBHMN 6 A   # #L 1  x &(" fb 99Xf-./9V3DD#'$+ .Z( (@H J     s$B.rr:ct|SrRrrs r;rjz_oneOf..rr:Nrbc32K|]}t|ywrR)repr).0rs r; z_oneOf..s@6$v,@z is valid under each of ) rrxrrrris_validrrkr )roneOfrrr subschemasrrrrrrr first_validis more_validreprss ` r;_oneOfrs05!JJ&Dy   h u  E FBHMN 6 A #K  # #L 1 $D.j(CCC *N1i.@.@1.M!NJN+& @Z@@.6 >  $## DN $s7BD !D" D +DD AD DD D cddlm}m}ddlm}t |j }ddi|dd<i}t|dr*d |d <|jjdt}d |i}n|j}ttf|d<d |i}t|j}t |t"<t$|d <t&|d<t(|d<|d||dd|}dd} | |_||fS)zGet metaschema validator and format checker Older versions of jsonschema require some compatibility changes. @returns: Tuple: (jsonschema.Validator, FormatChecker) @raises: ImportError when jsonschema is not present r)r FormatChecker)createrrrlabelrFadditionalProperties type_checker default_typesrrrdraft4) meta_schema validatorsversioncXtd|j||}t|dduS)zgOverride version of `is_valid`. It does ignore instances of `SchemaDeprecationError`. c$t|t SrR)rr=rs r;rjz.is_valid..s*)r:N)r iter_errorsnext)rFrr__rs r;rz*get_jsonschema_validator..is_valids9     Xw /   FD!T))r:r9rR)rrrjsonschema.validatorsrr META_SCHEMArrredefiner DEFAULT_TYPESr6rr VALIDATORS_validator_deprecatedDEPRECATED_KEY_validator_changedrrr) rrrrvalidator_kwargsrtypesrcloudinitValidatorrs r;get_jsonschema_validatorr s:, ?667K+1();K g&/.3 *+&33<< +  L   --,h+U3o001J!6J~.Jy Jw Jw   *#+  ..r:Tc 8ddlm} |j|y#|$rz}|rXtt dj |j Dcgc] }t|ncc}wc}|jg|tjd|Yd}~yd}~wwxYw)a Validate provided schema meets the metaschema definition. Return strict Validator and FormatChecker for use in validation @param validator: Draft4Validator instance used to validate the schema @param schema: schema to validate @param throw: Sometimes the validator and checker are required, even if the schema is invalid. Toggle for whether to raise SchemaValidationError or log warnings. @raises: ImportError when jsonschema is not present @raises: SchemaValidationError when the schema is invalid r) SchemaError.rqzGMeta-schema validation failed, attempting to validate config anyway: %sN) rr check_schemarpr?rkr@r6rALOGwarning)rrthrowrrris r;validate_cloudconfig_metaschemar%s2 v&   '!#((!;Q#a&!;!;dd}ndt:j<j>d}tjA|y#t$rtj dYywxYw#|$rX} | jt!d j#| j$| j& d | j(Yd } ~ Rd } ~ wwxYw)ajOn systems with netplan, validate network_config schema for file Leverage NetplanParser for error annotation line, column and detailed errors. @param network_config: Dict of network configuration settings validated against @param strict: Boolean, when True raise SchemaValidationErrors instead of logging warnings. @param annotate: Boolean, when True, print original network_config_file content with error annotations @param log_details: Boolean, when True logs details of validation errors. If there are concerns about logging sensitive userdata, this should be set to False. @return: True when schema validation was performed. False when not on a system with netplan and netplan python support. @raises: SchemaValidationError when netplan's parser raises NetplanParserExceptions. r)NetplanParserExceptionParserz8Skipping netplan schema validation. No netplan availableFzetc/netplan/network-config.yamlri)modeformat-l{line}.c{col}linecolzInvalid netplan schema. NrInvalid provided:  rcQ provided: Please run 'sudo cloud-init schema --system' to see the schema errors.T)!netplanrrrrdebugrosr@rkrrdumpsrload_yaml_hierarchyrr?rGr"columnrAexistsshutilrmtreeload_with_marksprintannotated_cloudconfig_filerprnrIrMrTr)rrrrrr parse_dir netplan_filenet_cfg src_contentparserrr_marksrAs r;netplan_validate_network_schemar;Os4: I77<< +LML~&Gg&..)K|[u5 XF F   ""9- ww~~i  i  #33K@5.#&, (/ / -z88>>?|L G:44::;<))  G   LM2 "  '..AFF.I*199+6    s*E4E?E<;E<?GA GGr\strict_metaschemalog_deprecationsc |tjk(rt|dk(rt|||ryy| t |} t \}}|rt ||d|||} g} g} t| j|d D]} d j| jD cgc] } t| c} }|sE| jd k(r6| j |k(r't#j$d | j&}|r|d }t)|| j&f}t+| t,r| |z } | |z } |r%| r#t/| dd}tj1||r| s| r t3| | | rD|rt/| d|j4dd}nd|j4d}tj7|y#t$rtjdYywxYwcc} w)a Validate provided config meets the schema definition. @param config: Dict of cloud configuration settings validated against schema. Ignored if strict_metaschema=True @param schema: jsonschema dict describing the supported schema definition for the cloud config module (config.cc_*). If None, validate against global schema. @param schema_type: Optional SchemaType. One of: SchemaType.CLOUD_CONFIG or SchemaType.NETWORK_CONFIG. Default: SchemaType.CLOUD_CONFIG @param strict: Boolean, when True raise SchemaValidationErrors instead of logging warnings. @param strict_metaschema: Boolean, when True validates schema using strict metaschema definition at runtime (currently unused) @param log_details: Boolean, when True logs details of validation errors. If there are concerns about logging sensitive userdata, this should be set to False. @param log_deprecations: Controls whether to log deprecations or not. @raises: SchemaValidationError when provided config does not validate against the provided schema. @raises: RuntimeError when provided config sourced from YAML is not a dict. @raises: ValueError on invalid schema_type not in CLOUD_CONFIG or NETWORK_CONFIG )rrrTF)rz5Ignoring schema validation. jsonschema is not present)format_checkerc|jSrR)r@rs r;rjz-validate_cloudconfig_schema..s QVVr:rrrz#.*\('(?P.*)' was unexpected\)r+z"Deprecated cloud-config provided: r&rcr$r%r')rIrMrr; get_schemar rrrr)rwrrkr@r6rrrematchrAr?rr=rnr%rprTr)rrr\rr<rr=r rrrr schema_errorrir@ prop_matchproblemrAdetailss r;validate_cloudconfig_schemarJsDj/// !& )Q ..%f+ ~K(.F.H+ ]  +"F% #6-/JIF#%Lf%+; xx):):;AQ;<&&*@@##v-6 8L8LJ!&) |';';<>  0  G #L g F+.L) 8  w 6\#FL99 -!+"3"3!4LAG;,,-.))  G q  IJtt}|D]\}}tjd|}|r1|j \}}|t |j |n#d}||j|j ||udj||}|S)Nz&format-l(?P\d+)\.c(?P\d+).*zLine {line} column {col}: {msg})r"r#r) rrxrDrEgroupsintrrSrG)rFrferrors_by_liner@rrEr"r#s r;_build_errors_by_linez _Annotator._build_errors_by_line-s=H=N( ID#HHFME!LLN cs4y)005t0067>>sC7>>3C? r:rzlabelsfooterr label_prefixcz|D]5}||}|j||jd|d||dz }7|S)NrUrD)r)rzr]r^rr_rHrs r; _add_problemsz_Annotator._add_problems=sV  G#nUG,E MM% MMBugRy1 2 QJE    r:linesr[deprecations_by_linec g}g}g}d}d}t|dD]y\} } || } || } | s| rUg} j| | ||d}j| | ||d}|j| dzdj| zi|j| {|j t fdt dd |fd |ff|S) NraE)r_Dz # ,c"j|SrR)rW)seqrFs r;rjz._Annotator._annotate_content..ls.D..4r:ct|dS)Nra)r)rjs r;rjz._Annotator._annotate_content..nsSV r:Errors Deprecations)rrbrrkrrlr)rFrcr[rdannotated_content error_footerdeprecation_footer error_indexdeprecation_index line_numberr"rrr]s` r;_annotate_contentz_Annotator._annotate_contentLs "$ (* !*5!!4 / K#K0F/ #7 yy*++r:N)r$)r3r4r5rr6r~ staticmethodr rWrr\rZrbrtrr9r:r;rLrLs((( (7S749777^   s) S  S       *!Cy*!*!# *! c *!X,%,,, ,r:rLrqrrrMrNrOrqrrcLt|||j|xsg|xsgS)aReturn contents of the cloud-config file annotated with schema errors. @param cloudconfig: YAML-loaded dict from the original_content or empty dict if unparsable. @param original_content: The contents of a cloud-config file @param schemamarks: Dict with schema marks. @param schema_errors: Instance of `SchemaProblems`. @param schema_deprecations: Instance of `SchemaProblems`. @return Annotated schema )rLr)rMrNrOrqrrs r;r3r3s1& k#3[ A J J06B r:rac ddlm}||vrgSg}t|jdD]F\}}|j |s|j t d|d|j|dH|S)aAnnotate and return schema validation errors in merged cloud-config.txt When merging multiple cloud-config parts cloud-init logs an error and ignores any user-data parts which are declared as #cloud-config but cannot be processed. the handler.cloud_config module also leaves comments in the final merged config for every invalid part file which begin with MERGED_CONFIG_SCHEMA_ERROR_PREFIX to aid in triage. r)MERGED_PART_SCHEMA_ERROR_PREFIXrazformat-lz.c1zIgnored invalid user-data: )cloudinit.handlers.cloud_configr{r splitlines startswithrr?replace)rar{rline_numr"s r;)process_merged_cloud_config_part_problemsrsP&g5 "$F#G$6$6$8!< $ ??: ; MMxj,LL75   Mr:r]instance_data_pathc ddlm}m}m}m}t |}d}|dk(r ||||}d }t |}|sG|jd \} } } tt|d |d | ddjtg|dk7rtd|dt||S#|$r} t t|dg| d} ~ w|$r#} tdt| zd Yd} ~ d} ~ w|$r } tt| d Yd} ~ d} ~ wwxYw)a Return tuple of user-data-type and rendered content. When encountering jinja user-data, render said content. :return: UserDataTypeAndDecodedContent :raises: SchemaValidationError when non-jinja content found but header declared ## template: jinja. :raises JinjaSyntaxParsingException when jinja syntax error found. :raises JinjaLoadError when jinja template fails to load. r)JinjaLoadErrorJinjaSyntaxParsingException NotJinjaErrorrender_jinja_payload_from_filez format-l1.c1z text/jinja2zRDetected type '{user_data_type}' from header. But, content is not a jinja templateNz&Failed to render templated user-data. Tsys_exitz format-l2.c1r&z!Unrecognized user-data header in z: "z%". Expected first line to be one of: rbtext/cloud-configzUser-data type 'z.' not currently evaluated by cloud-init schema)!cloudinit.handlers.jinja_templaterrrrrrpr?rr6 partitionrrkUSERDATA_VALID_HEADERSr2r_) r]rarrrrruser_data_typeschema_positionr header_liner9s r;&_get_config_type_and_rendered_userdatarsb +73N$O& )4&8G().w7 #--d3 Q0#7 }E$ &&&*ii0F&G%HJ    . . ~./$ $  ) AAI '!'? +  83q6A   ) #a&4 ( ( )s/ B D %B<<D C""D *DD c 6t|}|std|jd|dy|tjfvrt |j|}n t |||}|jdvry|j}t|} |rtj|\} } ntj|} i} t5| t6s|st9|jd|d|tjk(rZ| j;d| s tdyt=| }|dk(rt?| d|ry|dk7rtdt=| y tA| |ddstd|jdy y#tj$r} dx} } d}t| drt!| dr t!| d}n$t| d rt!| d r t!| d }|r|j"dz} |j$dz} |j't)d j+| | d j+|t-| t/|}|r"tt1i|i|j2 || d} ~ wwxYw#t.$r} | jCr|| j2z }|r$tt1| || || jDn/| jDr#tG| jDdd}t||r t/| | Yd} ~ yd} ~ wwxYw)aValidate cloudconfig file adheres to a specific jsonschema. @param config_path: Path to the yaml cloud-config file to parse, or None to default to system userdata from Paths object. @param schema: Dict describing a valid jsonschema to validate against. @param schema_type: One of SchemaType.NETWORK_CONFIG or CLOUD_CONFIG @param annotate: Boolean set True to print original config file with error annotations on the offending lines. @param instance_data_path: Path to instance_data JSON, used for text/jinja rendering. :return: True when validation was performed successfully :raises SchemaValidationError containing any of schema_errors encountered. :raises RuntimeError when config_path does not exist. zEmpty 'z ' found at z. Nothing to validate.F)rJrraN context_mark problem_markr r!zFile {0} is not valid YAML. {1}rrz is not a YAML dict.rz:Skipping network-config schema validation on empty config.r?T)rrrzJSkipping network-config schema validation. No network schema for version: )rrr=z Skipping z2 schema validation. Jsonschema dependency missing.rxr|rbrc)$rr2rTrIrMr_rr`rarrr1loadyaml YAMLErrorrgetattrr"r-rr?rGr6rpr3rqrr RuntimeErrorrrr;rJrrrrn)r]rr\rrdecoded_contentdecoded_configrarrMr:rr"r-markrFnetwork_versionrAs r;validate_cloudconfig_filer sL,%[1O    + / z00226    @ *< ##,$$G 6w ?F" !)!9!9'!B K"--0KE2 k4 ($$%Q{m3GH j///y+6 N O0= a .*4( a  *;78:  E* te  K--./22  < a >>"v 1n %'!^*D1n-D Q 'GA~,F1n-D 99q=D[[1_F '..Df.E188c!fM  -V4  *<3M3M  !/"t !E <<> aoo %F  *"(()(=(=   " "-%%;G 'N 'f=1 D  -Es2 2F(JI?C&I::I? L BLLc|dk(ry|dk(ryy)zProvide a sorting weight for documentation of property types. Weight values ensure 'array' sorted after 'object' which is sorted after anything else which remains unsorted. arrayr?objectrarr9rSs r;_sort_property_orderrs   (  r:c#K|D]@}t|tr*t|ttfst |Ed{=|By7 wrR)rrr6r_flatten)xsxs r;rrsA  a ":a#u+F{ " "G  "s:A A  A  property_dict multi_keyc g}|j|iD]}|jtr|jdrH|j|jdgDcgc]}dtj||dc}r|jds|j |dt t |Scc}w)Nr``r)rrr _YAML_MAPrrxr)rrproperty_typesr enum_values r;_collect_subschema_typesrsN"&&y"5 5 == (  ==  ! !'0mmFB&?"z:>?rB  ]]6 "  ! !)F"3 4 5 ( ))s!C defsct|||jdg}t|ts|g}|jdr+|dDcgc]}dtj||d}}nY|jdr|j t |dn,|jdr|j t |dt|dk(r|d}n'|jtd j|}|jd i}|jdg}t|ts|g}t|}t|jdi|jdiD]'}t||} |r| d k(r|j| )|rJt|dk(r |d |dS|jtd d j|d} |d | S|xsd Scc}w)zNReturn a string representing a property type from a given jsonschema. rrrrrrarrB/items UNDEFINEDz of ())_flatten_schema_refsrrrxrrrrsortrrkrr _get_property_typer) rrrk property_typersub_property_typesprune_undefinedsub_itemsub_typesub_property_docs r;rrs-"&&vr2N nd +() 2?2G -.bq!$%R (     7 #6}gNO   7 #6}gNO >a&q)  450   gr *E62. ($ /01-.O%))GR0%))GR2HI,%h5 x;6 !!(+ , ! "a '#_D);A)>(?@ @$89sxx(:;%5$677  'K'? s !G,c|}tjdd|}tjddj||}tjddj||}|S)aParse description from the meta in a format that we can better display in our docs. This parser does three things: - Guarantee that a paragraph will be in a single line - Guarantee that each new paragraph will be aligned with the first paragraph - Proper align lists of items @param description: The original description in the meta. @param prefix: The number of spaces used to align the current description z (\S)\n(\S)z\1 \2z\n\nz\n\n{}z\n( +)-z\n{}-)rDsubrG)r.rdlist_paragraphs r;_parse_descriptionrs^N&&+>K&&)"2"26":KHK&&HOON3[K r:src_cfgcd|vr5|jdjdd}|j||d|vrd|dvr;|djdjdd}|dj||d|dvrG|ddD]<}d|vs|jdjdd}|j||>t|j dg|j dg|j dgD]<}d|vs|jdjdd}|j||>y) zEFlatten schema: replace $refs in src_cfg with definitions from $defs.rz#/$defs/r$rrrallOfN)poprupdater r)rr reference sub_schemas r;rrsU KK'// B? tI'' WW% %(,,V4< >z2 NI%%d9o6 7 GR  GR  GR / Z "v.66z2FI   d9o ./r:c^|jdd}|sy|D]}|j|y)zFlatten schema: Merge allOf. If a schema as allOf, then all of the sub-schemas must hold. Therefore it is safe to merge them. rN)rr)r sub_schemasrs r;_flatten_schema_all_ofrs5 ++gt,K !# z"#r: prop_configcdtdtdtfd}|jdi}|jdi}g}g}||||t||D] }||||dj t||}|rd|}|S) aGReturn accumulated property description. Account for the following keys: - top-level description key - any description key present in each subitem under anyOf or allOf Order and deprecated property description after active descriptions. Add a trailing stop "." to any description not ending with ":". r descriptionsdeprecated_descriptionsctt|jdr|jt |y|jdr|jt |yy)N)deprecated_versionchanged_version new_versionr.)anyrlrrr)rrrs r;assign_descriptionsz6_get_property_description..assign_descriptions-s]   H  $ * *26: ZZ &    B6 J K'r:rrrr)rrxrr rk)rrrrrrrr.s r;_get_property_descriptionr"s L L$( LCG L OOGR (E OOGR (EL$& \3JK%'MHl4KLM))E,0GHIK+' r:c |dz}g}|jddurydDcgc]}d|vs||dvr|}}|Dcgc]}|j|i}}|D]}|jD]\} } t| |t| | jddur2t | } | jd| } |j t j|| t| |dzt| || jd} | rt| || jd s| jd rC|j tj|| |j t| || | jd gD]h}|jd s|jd s&|j tj|| |j t||| jd | vsd | vs|j t| || dj|Scc}wcc}w)zDReturn restructured text describing the supported schema properties. hiddenTr$)rpatternPropertiesr)rd prop_namer. prop_typerrr)rdrrrdrru) rrrrrrSCHEMA_PROPERTY_TMPLrGrrSCHEMA_LIST_ITEM_TMPL_get_property_docrk)rrrd new_prefixrr property_keysproperty_schemas prop_schemaprop_keyrr.rr alt_schemas r;rrLsh$JJ zz(t#7  6 !Sx0@%@ M 8EE 3+EE'5 %0%6%6%84  !Hk d 3 "; /x(D03K@K OOGX6E   $++!# 2; N0dC ,  OOG,E$UD199\*eii8K.L%%-44#-5 %%)%d:N#())GR"8 J!~~l3z~~+8#))188'1U9 #))- *j  +&+5!!%#$za4 5l ;;z ""{ Fs H8H=metac|jd}|syt}t|dD]W\}}|tj |z }t j |djd}|dj|z }Y|S)zAReturn restructured text describing the meta examples if present.r0r$ra) example_count r&) rSCHEMA_EXAMPLES_HEADERrSCHEMA_EXAMPLES_SPACER_TEMPLATErGtextwrapindentrvrk)rr0 rst_contentcountexampleindented_liness r; _get_examplesrsxx #H (K#Ha01w6==>  "%8>>tDtyy00 1 r:ch|jdsydjd|dD}d|dS)Nr2r$rbc3(K|] }d|d yw)rNr9)rrs r;rz3_get_activate_by_schema_keys_doc..s"QCr sz**Activate only on keys:** ru)rrk)r schema_keyss r; _get_activate_by_schema_keys_docrsD 88- .)) !:;K) T ::r:c| t}|r|s tdt|j}hd}dh}d}||z rdj ||z }n||z |z rdj ||z }|r t |t t|}d|d<d|d <d |d <tjtt|d d|d <|jd i}|j|dr%|j|di}tt |}t|djr t||d|d<|jddsd|d<tjt'|d|d<|dsd|d<dj)|d|d<t+j,dd|d|d<t/||d<t1jdi|}|S#t $rt"j%dd|d<YwxYw)zReturn reStructured text rendering the provided metadata. @param meta: Dict of metadata to render. @param schema: Optional module schema, if absent, read global schema. @raise KeyError: If metadata lacks an expected key. z"Expected non-empty meta and schema>r,r+r-r/r0r1r.r2r$z(Missing required keys in module meta: {}z3Additional unexpected keys found in module meta: {}property_headerz prefix6rprefix3r.z$defsr,rr property_docz3Unable to render property_doc due to invalid schemaz+ No schema definitions for this moduler0z$ No examples for this modulerbr/r-r+title_underbarr9)rC ValueErrorrykeysrGKeyErrorrrrrrr6rrvaluesrAttributeErrorrrrrkrDrrSCHEMA_DOC_TMPL) rrr required_keys optional_keys error_message meta_copyrtemplates r; get_meta_docr s?~ v=>> tyy{ DM//MMtBII D     - A H H}$   }%%Xd^$I#%I #Ii Ii' S)M*+X Im ::gr "D xxT $t*b)dF# 6,  & & () +(9T()In % == , :   %OOM$,?JIj Z F *99T)_5Ii"$&&sDL"AI+K ,I'(%%2 2H O# + KKM N(*In % +s6G###H H ctjjtjjt}t |SrR)r*r@dirnameabspath__file__r) configs_dirs r; get_modulesrs,''//"''//("; 1CSC 12a7 I  DKK #$)9)9  *  }} I #} 2s B0B0c jdtdtdtdtfd} td}|jr |j}n:tjd k7r|jd }n|jd }g}|jr|j rt#|j }nt"j$}|t"j&k(rt(j&}nt(j*}|j-t/|||jnRtjd k7r t1dd||dd}|j-t/t(j*t"j$|t/t(j2t"j$||ddt/t(j4t"j$||ddt/t(j&t"j&|j7dxsdg} | D]J} | j8stj:j=| j8s:|j-| Ltj:j=|d j8st1d|d j8ddd||fS#ttf$r?}|j t k(r tjdt}nYd }~d }~wt$r#t}tjd YwxYw)aReturn appropriate instance-data.json and instance data parts Based on commandline args, and user permissions, determine the appropriate instance-data.json to source for jinja templates and a list of applicable InstanceDataParts such as user-data, vendor-data and network-config for which to validate schema. Avoid returning any InstanceDataParts when the expected config_path does not exist. :return: A tuple of the instance-data.json path and a list of viable InstanceDataParts present on the system. pathsprimary_path_keyraw_fallback_path_keyrBc6|j|xsd}tt5tj|j s?|j|xsd}tj|j r |cdddSddd|S#1swY|SxYw)akGet processed data path when non-empty of fallback to raw data path. - When primary path and raw path exist and are empty, prefer primary path. - When primary path is empty but the raw fallback path is non-empty, this indicates an invalid and ignored raw user-data was provided and cloud-init emitted a warning and did not process unknown raw user-data. In the case of invalid raw user-data header, prefer raw_fallback_path_key so actionable sensible warnings can be reported to the user about the raw unparsable user-data. r$N) get_ipathrFileNotFoundErrorr*statst_size)rDrErFprimary_datapathraw_paths r;get_processed_or_fallback_pathzBget_config_paths_from_args..get_processed_or_fallback_paths"!??+;<B ' ( $77+,44 ??+@AGR778$,,#  $ $ $    $  s ABBtrust)fetch_existing_datasourcez=Using default instance-data/user-data paths for non-root userNzEdatasource not detected, using default instance-data/user-data paths.rr0instance_data_sensitivezNUnable to read system userdata or vendordata as non-root user. Try using sudo.Tr cloud_config userdata_rawvendor_cloud_configvendordata_rawvendor2_cloud_configvendordata2_rawrr$z Config file z does not existz Error: {}fmtr)rr6rr'r(errnorrr)rrr0r*getuidr9r=r\rIrLrMrPrVrrZrrWrXrHr]r@r.) r?rNrDrr config_filesr\instancedata_type userdata_filesupplemental_config_files data_parts r;get_config_paths_from_argsras    #   2 A !//  "..?"../HI+-L    $T%5%56K$11K *33 3 0 ? ?  0 9 9  . T=M=M N  99;!  )  7 >>    ))''    ++''.02B   ,,''.13D   //)) 017R = !*3 /I$$ 8M8M)N##I. / 77>>,q/55 6 <?667 G | ++a W  77f  IIO #$E   '    .  s J::L2 4L+L21L2c t|t}|jrtt |jyt |\}}d}t t|dkD}|r&tddjd|Dzd}g}t|dD]\}} d} |r)td |d | jd | jd | jtjk(rt| j} n|} t| j| | j|j |} | s|j"r | j} n | j} t|d | |r%t'djd|Dddyy#t$$rr} |j s@t|d| jd| jt't)| |dz|j+| jYd} ~ nd} ~ wt,$rY} t|d| jt't)| |dz|j+| jYd} ~ d} ~ wwxYw)z@Handle provided schema args and perform the appropriate actions.Nr$raz!Found cloud-config data types: %srbc3FK|]}t|jywrR)r6r[)rcfg_parts r;rz%handle_schema_args..sOhH001Os!rFr&rz at :z Valid schema r$rz Error: {} )rYc32K|]}t|ywrR)r6)rrs r;rz%handle_schema_args..?sD*c*oDrzError: Invalid schema: {} TrX)rBrCrr2rrarrrkrr[r]r\rIrMrrr=rprr6rr)r+r?r*rr\nested_output_prefixmulti_config_output error_typesidxrdperformed_schema_validation cfg_schemacfgrs r;handle_schema_argsrnsj4 ,K yy htyy!"'A$'G$ s<0145 /iiO,OO P  $K"<3'E X&+#  SEH001h6J6J5K1M    :#<#< <#H$8$89J$J E*C$$$$ " + '.+##"..C"..C-.mC7CDO'EP IID D D- -% 5==+,- ,,-Qx/C/C.DFF,}<   x33 4 4 5 )*(83G3G2JK L #a&2]B C   x33 4 4 5s&-F I1A'H  I1AI,,I1cLt}td|jy)zDTool to validate schema of a cloud-config file or print schema docs.r,r)r;rn parse_argsr:s r;mainrqEs \F+V->->-@A r:__main__)FN)T)FFTrR)r)rKr6r%loggingr*rDr/sysr collectionsrcollections.abcr contextlibrcopyrrrrZr functoolsr itertoolsr r8r r r rrrrrrr cloudinitrrcloudinit.cmd.develrcloudinit.handlersrrcloudinit.helpersrcloudinit.sourcesrcloudinit.temp_utilsrcloudinit.utilrrrrrr _ValidationErrorr Exception getLoggerr3rVERSIONED_USERDATA_SCHEMA_FILEUSERDATA_SCHEMA_FILENETWORK_CONFIG_V1_SCHEMA_FILErrSCHEMA_PROPERTY_HEADERrrrrrDEPRECATED_PREFIXrwrrtyping_extensionsr'r(r*rr=r?rrIrLrMr$rPrZr_r6rnrrprrrrrrrrrrr rrZrr;rJrLrr3rrrrrrrrrrrrrrr rrxrr"rCr;rBrarnrqexit)ts0r;rsdL  #$    (.I#9( >&O g!"E 5 ?' 8 <N"M" (#((*:1adckQ: 88Y8J _ .J.m$ & &&/   t z J! #  SM    &(J&(RI)>I (.2 =  = =FD4IN#9      Y ( |DZI>#9 @ Y @ P#9 '$ Y '$TI/X  t  F)4)HSM) [[ [[ [  [@"(55#"m m TNmm  m  m  mm m`r,r,t/348  N+  ".1  3:0  -B#BBBB BBBB# BBP)55" CC CC C  C  CL  *D*S*T#Y*")(d)($)(3)(Xs,/$/d/4 #D #'4'C'TC#dC#$C#C#L  s ;:;#;GzG8D>GSGT-T- 6OO*4)@)@JT*AH (z, 3%& &'z,z@ F  z CHHTVu8 O @;s"M4- N;N4M?>M?