
    '                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	l
mZ dd
lZ G d dej                        Zd Z G d dej"                        Zy
)z=A module for diagnosing common problems caused by properties.    )absolute_import)division)unicode_literals)config)
properties)named_configs)
check_base)diagnostic_baseNc                   "     e Zd ZdZ fdZ xZS )PropertyDiagnosticz2Diagnoses issues that may be caused by properties.c                 J    d}t         t        |   |dt        |      g       y )NzDProperty diagnostic detects issues that may be caused by properties.zProperty diagnostic)introtitle	checklist)superr   __init__HiddenPropertiesChecker)self ignore_hidden_property_allowlistr   	__class__s      ;lib/googlecloudsdk/core/diagnostics/property_diagnostics.pyr   zPropertyDiagnostic.__init__!   s2    E	
d,0*+KLM - O    )__name__
__module____qualname____doc__r   __classcell__)r   s   @r   r   r      s    :O Or   r   c               #   L   K   t         j                  D ]  } | D ]  }|   y w)N)r   VALUES)sectionprops     r   _AllPropertiesr"   )   s%     ""gj  #s   "$c                   >    e Zd ZdZdZd Zed        Zd	dZd Z	d Z
y)
r   z3Checks whether any hidden properties have been set.)zmetrics/environmentzcore/universe_domainc                     || _         t        t        j                  j                  j
                  j                         xs dj                  d            | _        t        j                  j                         | _        y )N ,)r   setr   r   diagnosticshidden_property_allowlistGetsplit	allowlistr   ActivePropertiesFileLoad_properties_file)r   r   s     r   r   z HiddenPropertiesChecker.__init__7   s[    ,LD)				&	&	@	@	D	D	F	L"	sDN *>>CCEDr   c                      y)Nzhidden properties )r   s    r   issuezHiddenPropertiesChecker.issue?   s    r   c                 b   g }t               D ]A  }|j                  r|j                  s| j                  |      }|s1|j	                  |       C |r.| j                  ||      }t        j                  d||      }|dfS dj                  |rdnd      }t        j                  d|      }|dfS )	aA  Run hidden property check.

    Args:
      first_run: bool, True if first time this has been run this invocation.

    Returns:
      A tuple of (check_base.Result, fixer) where fixer is a function that can
        be used to fix a failed check, or None if the check passed or failed
        with no applicable fix.
    F)passedmessagefailuresNzHidden Property Check {0}.r4   z
now passesT)r4   r5   )	r"   is_internal	is_hidden_CheckHiddenPropertyappend_ConstructMessageFromFailuresr	   Resultformat)r   	first_runr6   r!   failfail_messageresultpass_messages           r   CheckzHiddenPropertiesChecker.CheckC   s     H 				((.
//$
 ! 77)Ll  |*24fT\/66<1LdLAF4<r   c                 6   t        j                  |      | j                  v ry | j                  s"t        j                  |      | j                  v ry t        j                  || j                        }|'dj                  |      }t        j                  |      S y )Nz[{0}])r5   )six	text_type
_ALLOWLISTr   r,   r   _GetPropertyWithoutCallbackr/   r=   r	   Failure)r   r!   valuemsgs       r   r9   z,HiddenPropertiesChecker._CheckHiddenPropertya   s    
}}Tdoo-11dt~~- 2249N9NOENN4 c,, r   c                 :   dj                  |rdnd      }|r|dz  }|D ]   }|dj                  |j                        z  }" |rW|dj                  t        j                  j	                         j
                  t        j                         j                        z  }|S )NzHidden Property Check {0}.
failedzstill does not passz/The following hidden properties have been set:
z    {0}
z5Properties files
    User: {0}
    Installation: {1}
)	r=   r5   r   ConfigurationStoreActiveConfig	file_pathr   Pathsinstallation_properties_path)r   r6   r>   r5   failures        r   r;   z5HiddenPropertiesChecker._ConstructMessageFromFailuresn   s    ,33	H4IKGCCg##GOO44g  ,,2F#66CCEOOllnAA-Cg Nr   N)T)r   r   r   r   rG   r   propertyr2   rC   r9   r;   r1   r   r   r   r   /   s5    ;*
F  <-r   r   )r   
__future__r   r   r   googlecloudsdk.corer   r   "googlecloudsdk.core.configurationsr   googlecloudsdk.core.diagnosticsr	   r
   rE   
Diagnosticr   r"   Checkerr   r1   r   r   <module>r[      sS     D &  ' & * < 6 ; 
O33 OMj00 Mr   