
    cel!                        d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 g dZ
 ej                  dd       ej                  d	d
d       ej                  dd       ej                  ddd       ej                  de
d       ej                  ddd       ej                  dg d      gZdgZd Zd Zd Zd Zd Zd Zd  Zed!k(  r ej2                   e              yy)"a(  Configuration Validator

Uses the sample config generator configuration file to retrieve a list of all
the available options in a project, then compares it to what is configured in
the provided file.  If there are any options set that are not defined in the
project then it returns those errors.
    N)cfg)	generator)	z
.*_ur(i|l)z.*connectionpasswordusernamemy_ipzhost(name)?glance_api_serversosapi_volume_listenosapi_compute_listen	namespacezHOption namespace under "oslo.config.opts" in which to query for options.)helpz
input-fileTzConfig file to validate.)requiredr   zopt-datazYPath to a YAML file containing definitions of options, as output by the config generator.zcheck-defaultsFz@Report differences between the sample values and current values.)defaultr   zexclude-optionsz]Exclude options matching these patterns when comparing the current and sample configurations.zfatal-warningsz)Report failure if any warnings are found.zexclude-groupzGroups that should not be validated if they are present in the specified input-file. This may be necessary for dynamically named groups which do not appear in the sample config data.keystone_authtokenc                 .    | j                  t               y)a
  Register the formatter's CLI options with a ConfigOpts instance.

    Note, this must be done before the ConfigOpts instance is called to parse
    the configuration.

    :param conf: a ConfigOpts instance
    :raises: DuplicateOptError, ArgsAlreadyParsedError
    N)register_cli_opts_validator_opts)confs    7/usr/lib/python3/dist-packages/oslo_config/validator.py_register_cli_optsr   O   s     	?+    c                     | |d   vry|d   |    D cg c]  }|d   	 }}||d   |    D cg c]  }|j                  d       c}z  }||v S c c}w c c}w )Ndeprecated_optionsFnamedestgetgroupoptionopt_datao	name_datas        r   _validate_deprecated_optr#   [   sq    H122$,-A$B5$IJq6JIJ2F)G)NOA!%%-OOIY KOs
   AAc           
         d}g }|j                   D ]&  }|j                  t        j                  |             ( |d   j	                         D ]j  \  }}||j
                  v r|| vrt        j                  d|       1|d   D ]1  }t        |d   t              st        |d         g}	n|d   }	t        |d   |j                  d      g      }
|
j                  | |         s`	 | |   |d      }|d   t        fd|D              rt        j                   d	|       t#        |      d
kD  r!t        j                   d|t#        |             |d   s*t        j                  d|dj%                  |             d}t'        |	      j                  |      rt        j                  d||	|       d}4 m |S # t        $ r+ | |   |j                  d         }|j                  d      Y w xY w)a  Compares the current and sample configuration and reports differences

    :param section: ConfigParser instance
    :param opt_data: machine readable data from the generator instance
    :param conf: ConfigOpts instance
    :returns: boolean wether or not warnings were reported
    Foptionsz<Group %s from the sample config is not defined in input-fileoptsr   r   r   c              3   @   K   | ]  }|j                          y wN)	fullmatch).0rexkeynames     r   	<genexpr>z%_validate_defaults.<locals>.<genexpr>   s     Gc3==)Gs   zz%s/%s Ignoring option because it is part of the excluded patterns. This can be changed with the --exclude-options argument   z%s/%s defined %s timesz1%s/%s sample value is empty but input-file has %sz, Tz"%s/%s sample value %s is not in %s)exclude_optionsappendrecompileitemsexclude_grouploggingwarning
isinstanceliststrsetr   intersectionKeyErroranyinfolenjoin	frozenset)sectionsr    r   warningsexclusion_regexespatternr   r&   optdefaults	opt_namesvaluer,   s               @r   _validate_defaultsrJ   c   s    H'' 6  G!456	*002 2 tD&&& OO#% < *	 C
 c)nd3I/0y>
 S[#''&/:;I))(5/:* F4f+
 G5FGG %w0 5zA~,eWc%jJy>G7DIIe$46  x(55e<87He5  U*	 2 f O1  * 8''&/*s   %F>>1G21G2c                     | |d   vry|d   |    d   D cg c]  }|d   	 }}||d   |    d   D cg c]  }|j                  d       c}z  }||v S c c}w c c}w )Nr%   Fr&   r   r   r   r   s        r   _validate_optrL      sx    HY''$,Y$7$>v$FGq6GIG))<U)CF)KLA!%%-LLIY HLs
   AAc                     t        | j                        5 }t        j                  |      cd d d        S # 1 sw Y   y xY wr(   )openr    yaml	safe_load)r   fs     r   load_opt_datarR      s1    	dmm	 !~~a ! ! !s   5>c                    | j                  t               | j                  rIt        j                  t        j
                  | j                              }t        j                  ||       }n#| j                  rt        |       }nt        d      i }t        j                  | j                  |      }|j                          d}d}| j                  rt        |||       }|j!                         D ]  \  }}|| j"                  v r|D ]p  }	t%        ||	|      rt'        j(                  d||	       d}*t+        ||	|      r8|t,        v rt'        j.                  d|	|       Xt'        j0                  d||	       d}r  |s|r| j2                  ryy)	Nz(Neither namespace nor opt-data provided.FzDeprecated opt %s/%s foundTzIgnoring missing option "%s" from group "%s" because the group is known to have incomplete sample config data and thus cannot be validated properly.z&%s/%s is not part of the sample configr.   r   )register_optsr   r   r   _get_groups
_list_opts_generate_machine_readable_datar    rR   RuntimeErrorr   ConfigParser
input_fileparsecheck_defaultsrJ   r3   r4   r#   r5   r6   rL   KNOWN_BAD_GROUPSr>   errorfatal_warnings)
r   groupsr    rB   parserrC   errorssectionr%   r   s
             r   	_validaterd      sj   '~~&&y';';DNN'KL<<VTJ	 & EFFHdoox8F
LLNHF%h$?$NN, d((( 	F'B <gvN"7FH=..LL "A "(	2
 F%v/	$ (t22r   c                     t         j                  j                  d      } t        j                  t        j
                         t        j                         }t        |       	  |t        j                  dd |        t        |      S # t        j                  $ r+ |j                          t        j                  dd st         w xY w)z+The main function of oslo-config-validator.zoslo.config)levelr.   N)version)	importlibmetadatarg   r5   basicConfigINFOr   
ConfigOptsr   sysargvRequiredOptError
print_help
SystemExitrd   )rg   r   s     r   mainrr      s      ((7Ggll+>>DtSXXab\7+ T?  xx|	s   $B
 
>C__main__)__doc__importlib.metadatarh   r5   r1   rm   rO   oslo_configr   r   VALIDATE_DEFAULTS_EXCLUSIONSMultiStrOptStrOptBoolOptListOptr   r]   r   r#   rJ   rL   rR   rd   rr   __name__exit r   r   <module>r      s6      	 
   !   COO CJJ') CJJ/0 CKK
 CKK,67
 CKK8: COOKL7!H )) 	,@F!
%P  zCHHTV r   