
                         N   S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	r	\R                  R                  S0rSr\R                  R                  4S	 jr\R                  R                  4S
 jr " S S\R                   5      r " S S\R                   5      rS rS rS rS rS rg)z#Util for Fault Injection Cloud SDK.    )encoding)apis)base)
exceptionsNv1alpha1faultinjectiontestingc                 b    [         R                  U 5      n[        R                  " [        U5      $ N)VERSION_MAPgetr   GetMessagesModule	_API_NAMErelease_trackapi_versions     3lib/googlecloudsdk/api_lib/fault_injection/utils.pyr   r   !   #    .+				;	77    c                 b    [         R                  U 5      n[        R                  " [        U5      $ r
   )r   r   r   GetClientInstancer   r   s     r   r   r   &   r   r   c                       \ rS rSrSrSrg)InvalidFaultConfigurationError+   z7Error if a fault configuration is improperly specified. N__name__
__module____qualname____firstlineno____doc____static_attributes__r   r   r   r   r   +   s    ?r   r   c                       \ rS rSrSrSrg)#InvalidExperimentConfigurationError/   z<Error if a Experiment configuration is improperly specified.r   Nr   r   r   r   r#   r#   /   s    Dr   r#   c                 .   [        [        R                  R                  S9nUR                  n [
        R                  " XUS.U5      n[        U5      nU(       a!  S/nXv-  n[        SR                  U5      5      eU$ ! [         a    [        S5      ef = f)aa  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parentSAn error occurred while parsing the serialized fault. Please check your input file.<Invalid fault config, the following fields are unrecognized:
)r   r   ReleaseTrackALPHA9FaultinjectiontestingProjectsLocationsFaultsCreateRequestr   DictToMessageAttributeErrorr   _GetUnrecognizedFieldPathsjoin)r'   fault_configr)   messagesrequestimport_request_messageunrecognized_field_pathserror_msg_liness           r   ParseCreateFaultFromYamlr:   3   s     T->->-D-DE(NN'	%33FCW 88NOKO /O
(?)C
DD	 
 
(	 s   A> >Bc                 ,   [        [        R                  R                  S9nUR                  n [
        R                  " XS.U5      n[        U5      nU(       a!  S/nXe-  n[        SR                  U5      5      eU$ ! [         a    [        S5      ef = f)a<  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   r0   r1   r   r2   r3   )r'   r4   r5   r6   r7   r8   r9   s          r   ParseUpdateFaultFromYamlr>   W   s     T->->-D-DE(MM'	%33. 88NOKO /O
(?)C
DD	 
 
(	    A= =Bc                 0   [        [        R                  R                  S9nUR                  n [
        R                  " UU US.U5      n[        U5      nU(       a!  S/nXv-  n[        SR                  U5      5      eU$ ! [         a    [        S5      ef = f)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   r0   r1   r#   r2   r3   )rA   experiment_configr)   r5   reqr7   r8   r9   s           r   ParseCreateExperimentFromYamlrH   z   s     T->->-D-DE(OO#%33+&	

 	 88NOPO /O
-dii.H
II	 
 
-	 s   A? ?Bc                 ,   [        [        R                  R                  S9nUR                  n [
        R                  " XS.U5      n[        U5      nU(       a!  S/nXe-  n[        SR                  U5      5      eU$ ! [         a    [        S5      ef = f)a_  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   r0   r1   r#   r2   r3   )rA   rF   r5   r6   r7   r8   r9   s          r   ParseUpdateExperimentFromYamlrK      s     T->->-D-DE(LL 
	%33(=w 88NOPO /O
-dii.H
II	 
 
-	 r?   c                     [         R                  " U 5      n/ nU HF  u  p4SR                  S U 5       5      nU H#  nUR                  SR	                  XV5      5        M%     MH     [        U5      $ )z?Returns the field paths for unrecognized fields in the message..c              3   N   #    U  H  n[         R                  " U5      v   M     g 7fr
   )six	text_type).0es     r   	<genexpr>-_GetUnrecognizedFieldPaths.<locals>.<genexpr>   s     !M<Lq#--"2"2<Ls   #%z{}.{})r   UnrecognizedFieldIterr3   appendformatsorted)messageerrorsr8   edges_to_messagefield_namesmessage_field_path
field_names          r   r2   r2      so    ))'2&'-#!M<L!MM!
%%
..+
8 " (. 
(	))r   )r    apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   googlecloudsdk.corer   rO   r-   r.   r   r   r   r   Errorr   r#   r:   r>   rH   rK   r2   r   r   r   <module>rd      s    * & , ( * 
 	Z $	 %)$5$5$;$; 8
 %)$5$5$;$; 8
@Z%5%5 @E**:*: E! H  F& R" J
*r   