
                         p    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  G d d	e	      Z
 G d
 de	      Zy)zHA module container a helper class for generating config report requests.    )absolute_import)division)unicode_literals   )services_util)encodingc                   L    e Zd ZdZdZdZdZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)ConfigReporterValuezAA container class to hold config report value fields and methods.z&type.googleapis.com/google.api.Servicez=type.googleapis.com/google.api.servicemanagement.v1.ConfigRefz@type.googleapis.com/google.api.servicemanagement.v1.ConfigSourcec                     t        j                         | _        || _        d | _        d | _        d | _        d | _        d| _        y NT)	r   GetMessagesModulemessagesserviceconfigswagger_pathswagger_contents	config_idconfig_use_active_idselfr   s     7lib/googlecloudsdk/api_lib/endpoints/config_reporter.py__init__zConfigReporterValue.__init__#   s?    !335DMDLDKD DDN $D    c                 J    || _         d | _        d | _        d | _        d| _        y NFr   r   r   r   r   )r   r   s     r   	SetConfigzConfigReporterValue.SetConfig.   s(    DKD DDN %Dr   c                 J    d | _         || _        || _        d | _        d| _        y r   r   )r   pathcontentss      r   
SetSwaggerzConfigReporterValue.SetSwagger5   s(    DKD$DDN %Dr   c                 J    d | _         d | _        d | _        || _        d| _        y r   r   )r   r   s     r   SetConfigIdzConfigReporterValue.SetConfigId<   s(    DKD DDN %Dr   c                 J    d | _         d | _        d | _        d | _        d| _        y r   r   r   s    r   SetConfigUseDefaultIdz)ConfigReporterValue.SetConfigUseDefaultIdC   s(    DKD DDN $Dr   c                     | j                   rt        j                  S | j                  r| j                  rt        j
                  S | j                  s| j                  rt        j                  S y N)	r   r
   SERVICE_CONFIG_TYPE_URLr   r   CONFIG_SOURCE_TYPE_URLr   r   CONFIG_REF_TYPE_URLr%   s    r   
GetTypeUrlzConfigReporterValue.GetTypeUrlJ   sR    {{ 888			t44 777	444 444 5r   c                 z    | j                   d uxs, | j                  d uxs | j                  d uxs | j                  S r(   )r   r   r   r   r%   s    r   IsReadyForReportz$ConfigReporterValue.IsReadyForReportR   sG    KKt# &T)&NN$&& %%'r   c                 |   i }| j                         sy| j                  r|j                  | j                         nJ| j                  r| j                  j                  | j                  | j                  | j                  j
                  j                  j                        }| j                  j                  |g      }|j                  t        j                  |             n| j                  r'dj                  | j                  | j                        }n\t        j                   | j                        }|r dj                  | j                  |d         }ndj                  | j                        }|j                  d|i       |j                  d| j#                         i       t        j$                  ||      S )	a  Make a value to insert into the GenerateConfigReport request.

    Args:
      value_type: The type to encode the message into. Generally, either
        OldConfigValue or NewConfigValue.

    Returns:
      The encoded config value object of type value_type.
    N)filePathfileContentsfileType)fileszservices/{0}/configs/{1}r   zservices/{0}namez@type)r.   r   updater   r   
ConfigFiler   FileTypeValueValuesEnumOPEN_API_YAMLConfigSourcer   MessageToDictr   formatr   r   #GetActiveServiceConfigIdsForServicer,   DictToMessage)r   
value_typeresultconfig_fileconfig_source_messageresourceactive_config_idss          r   ConstructConfigValuez(ConfigReporterValue.ConstructConfigValueX   sb    F  "	mmDKK 			MM,,$$,,MM,,++MM - <k #mm88}8MmmH**+@AB	-44LL$..*
 *MMLL
 /66ll-a02( $**4<<8(mmVX&'
MM7DOO-./!!&*55r   N)__name__
__module____qualname____doc__r)   r+   r*   r   r   r!   r#   r&   r,   r.   rD    r   r   r
   r
      sE    IDEK	%&&&%5'06r   r
   c                   "    e Zd ZdZd Zd Zd Zy)ConfigReporterz;A container class to hold config report fields and methods.c                     t        j                         | _        t        j                         | _        || _        t        |      | _        t        |      | _        y r(   )	r   GetClientInstanceclientr   r   r   r
   
old_config
new_configr   s     r   r   zConfigReporter.__init__   sA    113DK!335DMDL)'2DO)'2DOr   c                     | j                   j                  | j                  j                  j                        }| j
                  j                  | j                  j                  j                        }| j                  j                  ||      S )N)	oldConfig	newConfig)rO   rD   r   GenerateConfigReportRequestOldConfigValuerP   NewConfigValue)r   old_config_valuenew_config_values      r   ConstructRequestMessagez&ConfigReporter.ConstructRequestMessage   sz    ;;11@@B;;11@@B ==44?O?O 5 Q Qr   c                     | j                   j                  j                  | j                               }|sy |j                  sg S |j                  d   S )Nr   )rN   servicesGenerateConfigReportrY   changeReports)r   r?   s     r   	RunReportzConfigReporter.RunReport   sM    [[!!66$$&(Fi""r   N)rE   rF   rG   rH   r   rY   r^   rI   r   r   rK   rK      s    C3Q#r   rK   N)rH   
__future__r   r   r    r   apitools.base.pyr   objectr
   rK   rI   r   r   <module>rc      s5     O &  '  %m6& m6`#V #r   