B ㊇cY@spdZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z ddl mZmZmZdd lmZdd lmZmZmZmZmZmZeeZed Zed Zed Z dZ!eZ"eZ#GdddZ$GdddZ%Gddde Z&Gddde%Z'Gddde%Z(Gddde%Z)GdddZ*GdddeZ+Gdd d Z,Gd!d"d"Z-Gd#d$d$Z.dS)%a| NOTE: All classes and functions in this module are considered private and are subject to abrupt breaking changes. Please do not use them directly. To view the raw JSON that the objects in this module represent, please go to any `endpoint-rule-set.json` file in /botocore/data/// or you can look at the test files in /tests/unit/data/endpoints/valid-rules/ N)Enum) lru_cache) Formatter) NamedTuple) xform_name)IPV4_REquoteurlparse)EndpointResolutionError) ArnParserInvalidArnExceptionis_valid_ipv4_endpoint_urlis_valid_ipv6_endpoint_urlnormalize_url_pathpercent_encodez\{[a-zA-Z#]+\}z(\w+)\[(\d+)\]z^(?!-)[a-zA-Z\d-]{1,63}(?sz7RuleSetStandardLibary.call_function..argvrassignz Assignment z= already exists in scoped variables and cannot be overwritten)msg)r6getattrr )rfunc_signaturer)Z func_args func_namefuncr*r;r)r)rrr0s   z#RuleSetStandardLibary.call_functioncCs|dk S)zYEvaluates whether a value is set. :type value: Any :rytpe: bool Nr)rr(rrris_setszRuleSetStandardLibary.is_setcCspxj|dD]\}t|}|dk r`|\}}t|}||}|dksT|t|krXdS||S||}q W|S)apFind an attribute within a value given a path string. The path can contain the name of the attribute and an index in brackets. A period separating attribute names indicates the one to the right is nested. The index will always occur at the end of the path. :type value: dict or list :type path: str :rtype: Any r4N)r' GET_ATTR_REr!groupsintr1len)rr(pathpartmatchnameindexrrrget_attrs     zRuleSetStandardLibary.get_attrcCs|d}|d|d<|S)NoutputsidrIr)r partitionoutputrrrformat_partition_outputs z-RuleSetStandardLibary.format_partition_outputcCs$t|d|dk }||dkp"|S)NZ regionRegexZregions)rerH)rregionrNZ matches_regexrrris_partition_matchsz(RuleSetStandardLibary.is_partition_matchcCsH|jd}|dk r6x"|D]}|||r||SqW|d}||S)zbMatch a region string to an AWS partition. :type value: str :rtype: dict partitionsNr)rrSrP)rr(rTrN aws_partitionrrrrUs   z#RuleSetStandardLibary.aws_partitioncCs|dks|dsdSyt|}Wntk r8dSXt|d|d|dfsXdS|d|d<|d}d|kr|dnd }|||d <|S) zeParse and validate string for ARN components. :type value: str :rtype: dict Nzarn:rNserviceresourceaccountZ accountId:/Z resourceId) startswith ARN_PARSERZ parse_arnr allpopr')rr(Zarn_dictrW delimiterrrr aws_parse_arns z#RuleSetStandardLibary.aws_parse_arncsT|dks|dkr"|ddkr"dS|dkrFtfdd|dDSt|dk S)zEvaluates whether a value is a valid host label per RFC 1123. If allow_subdomains is True, split on `.` and validate each component separately. :type value: str :type allow_subdomains: bool :rtype: bool NFr4rTc3s|]}|dVqdS)FN)is_valid_host_label)r7label)rrr sz.)countr]r'VALID_HOST_LABEL_RErH)rr(allow_subdomainsr)rrras  z)RuleSetStandardLibary.is_valid_host_labelcCsBtdd||fDs:dt|dt|d}t|d||kS)z|Evaluates two string values for equality. :type value1: str :type value2: str :rtype: bool css|]}t|tVqdS)N)rr)r7valrrrrcsz6RuleSetStandardLibary.string_equals..z!Both values must be strings, not z and r4)r<)r]typer )rvalue1value2r<rrr string_equalss z#RuleSetStandardLibary.string_equalscCs|dkr dSt|S)zcPerform percent-encoding on an input string. :type value: str :rytpe: str N)r)rr(rrr uri_encodesz RuleSetStandardLibary.uri_encodecCs|dkr dSt|}y |jWntk r2dSX|j}|j}|dksTt|dkrXdS|j}tt|}| ds~|d}||j ||t |pt |dS)z[Parse a URL string into components. :type value: str :rtype: dict N)httpshttprrZ)scheme authorityrFZnormalizedPathZisIp) r port ValueErrorroqueryrErFrrendswithnetlocr r)rr(Zurl_componentsrorsrFZnormalized_pathrrr parse_urls*    zRuleSetStandardLibary.parse_urlcCsBtdd||fDs:dt|dt|d}t|d||kS)zEvaluates two boolean values for equality. :type value1: bool :type value2: bool :rtype: bool css|]}t|tVqdS)N)rbool)r7rgrrrrcKsz7RuleSetStandardLibary.boolean_equals..z"Both arguments must be bools, not z and r4)r<)r]rhr )rrirjr<rrrboolean_equalsDs z$RuleSetStandardLibary.boolean_equalscCs(y|ddStk r"dSXdS)zmEvaluates if a string only contains ASCII characters. :type value: str :rtype: bool asciiTFN)encodeUnicodeEncodeError)rr(rrris_asciiPs  zRuleSetStandardLibary.is_asciicCs~t|ts$dt|d}t|d||ksBt||ksB||sFdS|dkrrt||}t||}|||S|||S)aComputes a substring given the start index and end index. If `reverse` is True, slice the string from the end instead. :type value: str :type start: int :type end: int :type reverse: bool :rtype: str zInput must be a string, not r4)r<NT)rrrhr rEr|)rr(startstopreverser<Zr_startZr_stoprrr substring\s     zRuleSetStandardLibary.substringcCs| S)zpA function implementation of the logical operator `not`. :type value: Any :rtype: bool r)rr(rrr_notsszRuleSetStandardLibary._notcsd|dks.t|dks.||ks.t|dk r2dS|dkrVtfdd|dDSj|ddS) aEvaluates whether a value is a valid bucket name for virtual host style bucket URLs. To pass, the value must meet the following criteria: 1. is_valid_host_label(value) is True 2. length between 3 and 63 characters (inclusive) 3. does not contain uppercase characters 4. is not formatted as an IP address If allow_subdomains is True, split on `.` and validate each component separately. :type value: str :type allow_subdomains: bool :rtype: bool NFTc3s|]}|dVqdS)FN)!aws_is_virtual_hostable_s3_bucket)r7rb)rrrrcszJRuleSetStandardLibary.aws_is_virtual_hostable_s3_bucket..r4)rf)rElowerrrHr]r'ra)rr(rfr)rrr{s   z7RuleSetStandardLibary.aws_is_virtual_hostable_s3_bucketN)__name__ __module__ __qualname____doc__rrrr"r/r2r6r0rArKrPrSrUr`rarkrlrvrxr|rrrrrrrr7s0    %  rc@s*eZdZdZd ddZddZddZdS) BaseRulez-Base interface for individual endpoint rules.NcCs||_||_dS)N) conditions documentation)rrrrrrrszBaseRule.__init__cCs tdS)N)NotImplementedError)rr)rule_librrrevaluateszBaseRule.evaluatecCs4x.|jD]$}|||}|dks(|dkrdSqWdS)zDetermine if all conditions in a rule are met. :type scope_vars: dict :type rule_lib: RuleSetStandardLibrary :rtype: bool FNT)rr0)rr)rr>r*rrrevaluate_conditionss   zBaseRule.evaluate_conditions)N)rrrrrrrrrrrrs rc@s*eZdZUdZeed<eed<eed<dS)RuleSetEndpointz.A resolved endpoint object returned by a rule.url propertiesheadersN)rrrrr__annotations__rrrrrrs rcs4eZdZfddZddZddZddZZS) EndpointRulec stjf|||_dS)N)superrendpoint)rrkwargs) __class__rrrszEndpointRule.__init__cCsT|||rP||jd|}||jdi||}|||}t|||dSdS)zDetermine if conditions are met to provide a valid endpoint. :type scope_vars: dict :rtype: RuleSetEndpoint rr)rrrN)rr2rresolve_propertiesr1resolve_headersr)rr)rrrrrrrrs    zEndpointRule.evaluatecs^t|tr fdd|DSt|trDfdd|DS|rZ|S|S)zTraverse `properties` attribute, resolving any template strings. :type properties: dict/list/str :type scope_vars: dict :type rule_lib: RuleSetStandardLibrary :rtype: dict csg|]}|qSr)r)r7prop)rr)rrrr9sz3EndpointRule.resolve_properties..cs i|]\}}||qSr)r)r7keyr()rr)rrr sz3EndpointRule.resolve_properties..)rlistritemsr"r/)rrr)rr)rr)rrrs     zEndpointRule.resolve_propertiescsDi}|jdi}x,|D] \}}fdd|D||<qW|S)zIterate through headers attribute resolving all values. :type scope_vars: dict :type rule_lib: RuleSetStandardLibrary :rtype: dict rcsg|]}|qSr)r2)r7item)rr)rrr9sz0EndpointRule.resolve_headers..)rr1r)rr)rZresolved_headersrheadervaluesr)rr)rrs zEndpointRule.resolve_headers)rrrrrrr __classcell__rr)rrrs rcs$eZdZfddZddZZS) ErrorRulec stjf|||_dS)N)rrerror)rrr)rrrrszErrorRule.__init__cCs(|||r$||j|}t|ddS)zIf an error rule's conditions are met, raise an error rule. :type scope_vars: dict :type rule_lib: RuleSetStandardLibrary :rtype: EndpointResolutionError )r<N)rr2rr )rr)rrrrrrs  zErrorRule.evaluate)rrrrrrrr)rrrs rcs(eZdZdZfddZddZZS)TreeRulezA tree rule is non-terminal meaning it will never be returned to a provider. Additionally this means it has no attributes that need to be resolved. c s"tjf|dd|D|_dS)NcSsg|]}tjf|qSr) RuleCreatorcreate)r7rulerrrr9sz%TreeRule.__init__..)rrrules)rrr)rrrrszTreeRule.__init__cCs8|||r4x&|jD]}|||}|r|SqWdS)zIf a tree rule's conditions are met, iterate its sub-rules and return first result found. :type scope_vars: dict :type rule_lib: RuleSetStandardLibrary :rtype: RuleSetEndpoint/EndpointResolutionError N)rrrcopy)rr)rrZ rule_resultrrrrs   zTreeRule.evaluate)rrrrrrrrr)rrrs rc@s$eZdZeZeZeZe ddZ dS)rcKsN|d}yt||}Wn&tk r>td|ddYn X|f|SdS)z_Create a rule instance from metadata. :rtype: TreeRule/EndpointRule/ErrorRule rhzUnknown rule type: z1. A rule must be of type tree, endpoint or error.)r<N)r^r=AttributeErrorr )clsrZ rule_typeZ rule_classrrrr.s zRuleCreator.createN) rrrrrrrrtree classmethodrrrrrr(src@seZdZdZeZeZdS) ParameterTypez8Translation from `type` attribute to native Python type.N)rrrrrstringrwbooleanrrrrr@src@s*eZdZdZd ddZddZddZdS) ParameterDefinitionz9The spec of an individual parameter defined in a RuleSet.NcCsf||_ytt|j|_Wn&tk rBtd|ddYnX||_||_ ||_ ||_ ||_ dS)NzUnknown parameter type: z0. A parameter must be of type string or boolean.)r<) rIr=rrr(parameter_typerr rbuiltindefaultrequired deprecated)rrIrrbuiltInrrrrrrrJs zParameterDefinition.__init__cCst||js(td|jd|jdd|jdk r|jd}|jd}|jd}|rh|d |7}|r||d |d7}t|dS) zwPerform base validation on parameter input. :type value: Any :raises: EndpointParametersError zValue (z) is the wrong type. Must be r4)r<Nz has been deprecated.messagesince z Deprecated since )rrr rIrr1loggerinfo)rr(Zdepr_strr<rrrrvalidate_inputds      z"ParameterDefinition.validate_inputcCs>|dkr0|jdk r|jS|jr:td|jn |||S)z>Process input against spec, applying default if value is None.Nz)Cannot find value for required parameter )rrr rIr)rr(rrr process_input|s  z!ParameterDefinition.process_input)NNNNN)rrrrrrrrrrrrGs rc@s2eZdZdZd ddZddZddZd d ZdS) RuleSetz:Collection of rules to derive a routable service endpoint.NcCs6||_|||_dd|D|_t||_||_dS)NcSsg|]}tjf|qSr)rr)r7rrrrr9sz$RuleSet.__init__..)version_ingest_parameter_spec parametersrrrr)rrrrrTrrrrrs   zRuleSet.__init__cCsdd|DS)Nc SsHi|]@\}}t||d|d|d|d|d|d|qS)rhrrrrr)rr1)r7rIspecrrrrs z2RuleSet._ingest_parameter_spec..)r)rrrrrrs zRuleSet._ingest_parameter_speccCs<x6|jD](\}}|||}|dk r |||<q WdS)zYProcess each input parameter against its spec. :type input_params: dict N)rrrr1)rZ input_paramsrIrr(rrrprocess_input_parameterss  z RuleSet.process_input_parameterscCs<||x,|jD]"}|||j}|dk r|SqWdS)zmEvaluate input parameters against rules returning first match. :type input_parameters: dict N)rrrrr)rinput_parametersrZ evaluationrrrrs   zRuleSet.evaluate)N)rrrrrrrrrrrrrs   rc@s*eZdZdZddZeedddZdS)EndpointProviderz.z"No endpoint found for parameters: )r<)rrrjoinrr )rrZparams_for_errorrZ param_stringrrrresolve_endpoints z!EndpointProvider.resolve_endpointN)rrrrrr CACHE_SIZErrrrrrsr)/rloggingrQenumr functoolsrrrtypingrZbotocorerZbotocore.compatrrr Zbotocore.exceptionsr Zbotocore.utilsr r r rrr getLoggerrrcompiler rBrerr\r%rrrrrrrrrrrrrrrs>         fAD2