Ë
    €Ï>  ã                   ón  — 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Ze
j                  j                  d
iZdZe
j                  j                  fd„Ze
j                  j                  fd„Z G d„ dej(                  «      Z G d„ dej(                  «      Zd„ Zd„ Zd„ Zd„ Zd„ Zy	)z#Util for Fault Injection Cloud SDK.é    )Úabsolute_import)Údivision)Úunicode_literals)Úencoding)Úapis)Úbase)Ú
exceptionsNÚv1alpha1Úfaultinjectiontestingc                 ó`   — t         j                  | «      }t        j                  t        |«      S ©N)ÚVERSION_MAPÚgetr   ÚGetMessagesModuleÚ	_API_NAME©Úrelease_trackÚapi_versions     ú3lib/googlecloudsdk/api_lib/fault_injection/utils.pyr   r   $   ó#   € Ü—‘ Ó.€+Ü	×	Ñ	¤	¨;Ó	7Ð7ó    c                 ó`   — t         j                  | «      }t        j                  t        |«      S r   )r   r   r   ÚGetClientInstancer   r   s     r   r   r   )   r   r   c                   ó   — e Zd ZdZy)ÚInvalidFaultConfigurationErrorz7Error if a fault configuration is improperly specified.N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   r   r   .   s   „ Ú?r   r   c                   ó   — e Zd ZdZy)Ú#InvalidExperimentConfigurationErrorz<Error if a Experiment configuration is improperly specified.Nr   r!   r   r   r#   r#   2   s   „ ÚDr   r#   c                 ó*  — t        t        j                  j                  ¬«      }|j                  }	 t        j                  || |dœ|«      }t        |«      }|r"dg}||z  }t        dj                  |«      «      ‚|S # t        $ r t        d«      ‚w xY w)as  Converts the given fault dict to the corresponding import request.

  Args:
    fault: faultId, fault name
    fault_config: dict, fault configuation of the create fault request.
    parent: parent for fault resource

  Returns:
    FaultinjectiontestingProjectsLocationsFaultsCreateRequest
  Raises:
    InvalidFaultConfigurationError: If the fault config is invalid.
  ©r   )ÚfaultÚfaultIdÚparentúSAn error occurred while parsing the serialized fault. Please check your input file.ú<Invalid fault config, the following fields are unrecognized:Ú
)r   r   ÚReleaseTrackÚALPHAÚ9FaultinjectiontestingProjectsLocationsFaultsCreateRequestr   ÚDictToMessageÚAttributeErrorr   Ú_GetUnrecognizedFieldPathsÚjoin)r&   Úfault_configr(   ÚmessagesÚrequestÚimport_request_messageÚunrecognized_field_pathsÚerror_msg_liness           r   ÚParseCreateFaultFromYamlr9   6   s¬   € ô ¬T×->Ñ->×-DÑ-DÔE€(Ø×NÑN€'ð	Ü%×3Ñ3Ø¨5¸FÑCÀWóÐô 8Ð8NÓOÐÙàKð€Oð Ð/Ñ/€OÜ
(¨¯©°?Ó)CÓ
DÐDà	Ðøô 
ò Ü
(ð	óð ðúó   ²A= Á=Bc                 ó(  — t        t        j                  j                  ¬«      }|j                  }	 t        j                  || dœ|«      }t        |«      }|r"dg}||z  }t        dj                  |«      «      ‚|S # t        $ r t        d«      ‚w xY w)aL  Converts the given fault dict to the corresponding import request.

  Args:
    fault: faultId, fault name
    fault_config: dict, fault configuation of the create fault request.

  Returns:
    FaultinjectiontestingProjectsLocationsFaultsPatchRequest
  Raises:
    InvalidFaultConfigurationError: If the fault config is invalid.
  r%   )r&   Únamer)   r*   r+   )r   r   r,   r-   Ú8FaultinjectiontestingProjectsLocationsFaultsPatchRequestr   r/   r0   r   r1   r2   )r&   r3   r4   r5   r6   r7   r8   s          r   ÚParseUpdateFaultFromYamlr>   Z   sª   € ô ¬T×->Ñ->×-DÑ-DÔE€(Ø×MÑM€'ð	Ü%×3Ñ3Ø¨Ñ.°óÐô 8Ð8NÓOÐÙàKð€Oð Ð/Ñ/€OÜ
(¨¯©°?Ó)CÓ
DÐDà	Ðøô 
ò Ü
(ð	óð ðúó   ²A< Á<Bc                 ó*  — t        t        j                  j                  ¬«      }|j                  }	 t        j                  || |dœ|«      }t        |«      }|r"dg}||z  }t        dj                  |«      «      ‚|S # t        $ r t        d«      ‚w xY w)aŸ  Converts the given fault dict to the corresponding import request.

  Args:
    experiment: ExperimentId, Experiment name
    experiment_config: dict, experiment config of the create experiment request.
    parent: parent for experiment resource

  Returns:
    FaultinjectiontestingProjectsLocationsExperimentsCreateRequest
  Raises:
    InvalidExperimentConfigurationError: If the experiment config is invalid.
  r%   )Ú
experimentÚexperimentIdr(   úXAn error occurred while parsing the serialized experiment. Please check your input file.úAInvalid experiment config, the following fields are unrecognized:r+   )r   r   r,   r-   Ú>FaultinjectiontestingProjectsLocationsExperimentsCreateRequestr   r/   r0   r#   r1   r2   )rA   Úexperiment_configr(   r4   Úreqr6   r7   r8   s           r   ÚParseCreateExperimentFromYamlrH   }   s³   € ô ¬T×->Ñ->×-DÑ-DÔE€(Ø×OÑO€#ðÜ%×3Ñ3à+Ø&Øñ	
ð
 	óÐô 8Ð8NÓOÐÙàPð€Oð Ð/Ñ/€OÜ
-¨d¯i©i¸Ó.HÓ
IÐIà	Ðøô 
ò Ü
-ð	óð ðúr:   c                 ó(  — t        t        j                  j                  ¬«      }|j                  }	 t        j                  || dœ|«      }t        |«      }|r"dg}||z  }t        dj                  |«      «      ‚|S # t        $ r t        d«      ‚w xY w)ao  Converts the given fault dict to the corresponding import request.

  Args:
    experiment: experimentId, experiment name
    experiment_config: dict, fault configuation of the create fault request.

  Returns:
    FaultinjectiontestingProjectsLocationsExperimentsPatchRequest
  Raises:
    InvalidExperimentConfigurationError: If the experiment config is invalid.
  r%   )rA   r<   rC   rD   r+   )r   r   r,   r-   Ú=FaultinjectiontestingProjectsLocationsExperimentsPatchRequestr   r/   r0   r#   r1   r2   )rA   rF   r4   r5   r6   r7   r8   s          r   ÚParseUpdateExperimentFromYamlrK   ¦   s­   € ô ¬T×->Ñ->×-DÑ-DÔE€(à×LÑLð 
ð	Ü%×3Ñ3Ø(°*Ñ=¸wóÐô 8Ð8NÓOÐÙàPð€Oð Ð/Ñ/€OÜ
-¨d¯i©i¸Ó.HÓ
IÐIà	Ðøô 
ò Ü
-ð	óð ðúr?   c                 óÚ   — t        j                  | «      }g }|D ]E  \  }}dj                  d„ |D «       «      }|D ]#  }|j                  dj	                  ||«      «       Œ% ŒG t        |«      S )z?Returns the field paths for unrecognized fields in the message.Ú.c              3   óF   K  — | ]  }t        j                  |«      –— Œ y ­wr   )ÚsixÚ	text_type)Ú.0Úes     r   Ú	<genexpr>z-_GetUnrecognizedFieldPaths.<locals>.<genexpr>Ð   s   è ø€ Ð!MÑ<L°q¤#§-¡-°×"2Ñ<Lùs   ‚!z{}.{})r   ÚUnrecognizedFieldIterr2   ÚappendÚformatÚsorted)ÚmessageÚerrorsr7   Úedges_to_messageÚfield_namesÚmessage_field_pathÚ
field_names          r   r1   r1   Ë   ss   € ä×)Ñ)¨'Ó2€&ØÐÛ'-Ñ#Ð˜ØŸ™Ñ!MÑ<LÓ!MÓMÐÛ!ˆ
Ø×%Ñ%Ø
.‰.Ð+¨ZÓ
8õñ "ð (.ô 
Ð(Ó	)Ð)r   )r    Ú
__future__r   r   r   Úapitools.base.pyr   Úgooglecloudsdk.api_lib.utilr   Úgooglecloudsdk.callioper   Úgooglecloudsdk.corer	   rO   r,   r-   r   r   r   r   ÚErrorr   r#   r9   r>   rH   rK   r1   r!   r   r   Ú<module>rd      s´   ðñ *å &Ý Ý 'å %Ý ,Ý (Ý *Û 
ð 	×Ñ×Ñ˜Zð€ð $€	ð %)×$5Ñ$5×$;Ñ$;ó 8ð
 %)×$5Ñ$5×$;Ñ$;ó 8ô
@ Z×%5Ñ%5ô @ôE¨*×*:Ñ*:ô Eò! òH  òF& òR" óJ
*r   