
    >                     r   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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.    )absolute_import)division)unicode_literals)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)#InvalidExperimentConfigurationError2   z<Error if a Experiment configuration is improperly specified.r   Nr   r   r   r   r&   r&   2   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=   6   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   r0   r1   8FaultinjectiontestingProjectsLocationsFaultsPatchRequestr   r3   r4   r   r5   r6   )r*   r7   r8   r9   r:   r;   r<   s          r   ParseUpdateFaultFromYamlrA   Z   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   r0   r1   >FaultinjectiontestingProjectsLocationsExperimentsCreateRequestr   r3   r4   r&   r5   r6   )rD   experiment_configr,   r8   reqr:   r;   r<   s           r   ParseCreateExperimentFromYamlrK   }   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)   )rD   r?   rF   rG   r/   )r   r   r0   r1   =FaultinjectiontestingProjectsLocationsExperimentsPatchRequestr   r3   r4   r&   r5   r6   )rD   rI   r8   r9   r:   r;   r<   s          r   ParseUpdateExperimentFromYamlrN      s     T->->-D-DE(LL 
	%33(=w 88NOPO /O
-dii.H
II	 
 
-	 rB   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   UnrecognizedFieldIterr6   appendformatsorted)messageerrorsr;   edges_to_messagefield_namesmessage_field_path
field_names          r   r5   r5      so    ))'2&'-#!M<L!MM!
%%
..+
8 " (. 
(	))r   )r#   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   googlecloudsdk.corer	   rR   r0   r1   r   r   r   r   Errorr   r&   r=   rA   rK   rN   r5   r   r   r   <module>rh      s    * &  ' % , ( * 
 	Z $	 %)$5$5$;$; 8
 %)$5$5$;$; 8
@Z%5%5 @E**:*: E! H  F& R" J
*r   