
    3                       % S r SSKJr  SSKrSSKrSSKJrJr  SSKJ	r
  SSKJr  SSKJr  SSKJs  Js  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Jr  SSKJ r!  SSKJ"r#  SSSSS.r$S\%S'   S\&4S\'4S\(4S\)4S.r*S\%S'   S(S jr+        S)S jr,      S*S jr-      S+S  jr.        S,S! jr/S-S" jr0        S.S# jr1 S/         S0S$ jjr2 S1       S2S% jjr3\Rh                  \Rj                  " \Rl                  Rn                  5      \Rp                   " S& S'\Rr                  5      5       5       5       r:g)3z:Command to create SaaS Runtime Flags from a manifest file.    )annotationsN)AnyCallable)messages)encoding)
exceptions)arg_parsers)base)flags)log)
properties)saasservicemgmt_v1beta1_client) saasservicemgmt_v1beta1_messagesFLAG_VALUE_TYPE_BOOLFLAG_VALUE_TYPE_INTFLAG_VALUE_TYPE_DOUBLEFLAG_VALUE_TYPE_STRING)booleanintegerdoublestringzdict[str, str]FLAG_TYPE_MAP	boolValueintValuedoubleValuestringValue)r   r   r   r   z dict[str, tuple[str, type[Any]]]VALUE_TYPE_HANDLERSc                *    U SL=(       a	    U [         ;   $ )z'Returns True if the flag type is valid.N)r   )	flag_types    &lib/surface/saas_runtime/flags/push.py_ValidFlagTyper!   4   s    	$		=9#==    c                   [         R                  " S[        R                  " U5       S35        UR	                  S5      n[        U5      (       d  [        R                  " SU  SU S35      e[        R	                  U5      nUR	                  S5      nUc  [        R                  " SU  S35      eU U[        XT5      US	.nUR	                  S
5      (       a  US
   US
'   U$ )z@Parses a flag definition and returns a dict of fields to be set.zFlag definition:

flagTypezFlag "z" invalid. "z" is not a supported flag type.defaultValuez%" invalid. "defaultValue" is not set.)key	valueTypeevaluationSpecunitKinddescription)
r   debugpprintpformatgetr!   r   InvalidDataErrorr   _GetDefaultEvaluationSpecDict)flag_keyunit_kind_nameflag_definitionr   
value_typedefault_value	flag_dicts          r    _ParseFlagDatar8   9   s     )) !@ ADE!!*-)			"	"

%
%

,yk 2 	 
   +*!%%n5-

%
%

?@ 
 5
 !) ''.}=Im	r"   c                &   U[         ;  a  [        R                  " SU 35      e[         U   u  p#[        X5      (       d@  [        R                  " SU  SU SUR                   S[        U 5      R                   S3	5      eSS0nU" U 5      XB'   SU/S	.$ )
z=Returns the default evaluation spec for the given value type.zUnsupported value type: zInvalid default value "z" for type z. Expected type z	 but got .namedefault)defaultTargetvariants)r   r   r0   
isinstance__name__type)r6   r5   variant_typeexpected_typevariant_dicts        r    r1   r1   ^   s    
 **

%
%(@&M
NN 3!, 
M	1	1

%
%
!-J< H'001 2(()	,  i,  -];, !.
 r"   c                8   SU ;  a  [         R                  " S5      eU S   n[        U[        5      (       d  [         R                  " S5      eSn/ nUR	                  5        HG  u  pV [        XQU5      n[        R                  " U[        R                  SS9nUR                  U5        MI     U(       a  [         R                  " S
5      eU$ ! [        R                  [         R                  4 a*  n	[        R                  " SU SU	< 35        Sn S	n	A	M  S	n	A	ff = f)z8Parses a JSON manifest file and returns a list of flags.r   z+Manifest must have a top-level "flags" key.z"flags" property is invalid.F)throw_on_unexpected_fieldsz*Failed to parse flag definition for flag "z": TNz+Failed to parse some flags in the manifest.)r   r0   r?   dictitemsr8   	msg_utilsDictToMessageWithErrorCheck
ezmessagesFlagappendrpclite_messagesValidationErrorr   error)
manifest_jsonr3   
flags_data	has_errorr   r2   r4   r7   flag_msges
             r    _GetFlagMessagesFromManifestrV   {   s   
 M!

%
%5  W%*	J	%	%

%
%&D
EE)
%#-#3#3#5h ?Ki66
Z__h ll8 $6 

%
%5  
, 	((##  
ii<XJc!OPis   'AC$D/DDc                   / nSnU  H   n [        XUSS9  UR                  U5        M"     U(       a  [        R                  " S	5      eU$ ! [        R                   a1    [        R
                  R                  SUR                   S35         M  [        R                   a2  n[        XeR                  [        R                  S5        Sn SnAM  SnAf[        R                   a&  n[        R                  " SU 35        Sn SnAM  SnAff = f)
z1Returns a list of flags that are valid to create.FTvalidate_onlyFlag z already exists. Ignoring.zFlag creation would failNzFlag creation would fail: z$Manifest file contains invalid flags)_CreateFlagrM   r   HttpConflictErrorr   statusPrintr'   	HttpError_LogHttpErrorrP   r0   )r   flags_serviceparentvalid_flagsvalidation_failedrT   rU   s          r    _GetValidFlagsre      s     +h#-F "  

%
%&L
MM	 '' I	jjx||n,FGH A||SYY0JK&& 	ii,QC01s*   A

ADD!'CD%DDc                (   [        U [        R                  5      (       d  gU R                  S:w  a  g [        R
                  " U R                  5      nUR                  S0 5      R                  SS5      nSU;   $ ! [        R                   a     gf = f)z<Returns True if the error is due to a flag already existing.Fi  rP   message zalready exists)	r?   r   r_   status_codejsonloadscontentr/   JSONDecodeError)rU   error_contenterror_messages      r    _IsFlagAlreadyExistsErrorrp      s    	Az++	,	,]]cJJqyy)M!%%gr266y"EM},,			 s   AA: :BBc                     [         R                  " U SU 3S9nU R                  U5      $ ! [        R                   a%  n[        XB[        R                  S5         SnAgSnAff = f)zGets a flag by its key.z/flags/)r;   zFailed to get existing flagN)rK   /SaasservicemgmtProjectsLocationsFlagsGetRequestGetr   r_   r`   r   rP   )ra   rb   r2   get_requestrU   s        r    _GetExistingFlagru      sb    LLxwxj)K [))			 !syy*GHs   ), A% A  A%c                ,   [         R                  " UUR                  UUS9n[        R                  " U5      nU(       d6  [
        R                  R                  S[        R                  " U5       35         U R                  U5      nU(       dK  [
        R                  R                  S[        R                  " [        R                  " U5      5       35        gg! [        R                   Ga$  n[        U5      (       Ga  [        XUR                  5      nUc  e [
        R                  " SUR                   S[        R                  " [        R                  " U5      5       35        UR                   UR                   :w  a>  [        R"                  " SUR                   SUR                    S	UR                    35      Ue[        R$                  " UR&                  UR(                  UR*                  UR,                  UR.                  5      eUeSnAff = f)
z'Creates a flag in the SaaS Runtime API.)rb   flagIdvalidateOnlyflagz
Attempting to create flag:
z
Created flag:
Nz
Flag z  already exists. Existing flag:
rZ   z	 of type z* already exists with different value type )rK   2SaasservicemgmtProjectsLocationsFlagsCreateRequestr'   r   MessageToDictr   r]   r^   r-   r.   Creater   r_   rp   ru   r,   r(   r0   r\   responserl   urlmethod_configrequest)	ra   rb   rT   rY   flags_create_reqflags_create_req_dict	flag_resprU   existing_flags	            r    r[   r[      s    CC$	  #001AB	JJ
(8M)N(OP$$%56I	jj
^^H229=>?A  
		  ##&}hllKm			iiHLL> "^^H$:$:=$IJKM
 
	 	 H$6$6	6))HLL>8+=+=*> ?**7*A*A)BD
 	
 **JJ		155!//199
 	
 g+s   6A"C H/DHHc           	     \    [         R                  " U R                  5      nUR                  S0 5      R                  SS5      nUR                  S0 5      R                  SS5      nU" U SU SU SU 35        g! [         R                   a    U" U SU SU R                   35         gf = f)	zLogs an HTTP error.rP   rg   zUnknown errorcode z: z : N)rj   rk   rl   r/   rm   )rU   r2   log_func
msg_prefixrn   ro   
error_codes          r    r`   r`     s    6JJqyy)M!%%gr266?M ""7B/33FOLJ
|1XJbCGH			 6
|1XJb456s   A7A: :.B+*B+c                  :    \ rS rSrSrSSSS.r\S 5       rS rS	r	g
)Pushi&  z4Create SaaS Runtime Flags from a JSON manifest file.z'Create Flags from a JSON manifest file.a            Creates Flags based on the contents of a provided JSON manifest file. Flags defined in the file
          will be created. If a Flag already exists with the same type, it will be ignored. Otherwise,
          the command will exit with an error.
      z          To create flags from a manifest file named `my_flags.json`:

              $ {command} --file=my_flags.json --unit-kind=my-unit-kind
          )briefDESCRIPTIONEXAMPLESc                z    U R                  S[        R                  " 5       SSS9  [        R                  " U SSS9  g)zGRegister flags for gcloud saas-runtime flags push: --file, --unit-kind.z--fileTzPath to the JSON manifest file containing the flag definitions. The manifest file must conform to the OpenFeature CLI flag manifest schema.)rA   requiredhelpz7UnitKind to push all the flags in the manifest file to.)r   	help_textN)add_argumentr	   FileContents	arg_utilsAddUnitKindArgToParser)parsers    r    Args	Push.Args:  sG     %%'   	 $$Kr"   c                   [         R                  R                  R                  R	                  5       nUR
                  R                  R                  5       nUR                  5       R                  5       n[        R                  " SU 35        [        R                  " SUR                   35        [        R                  " SUR                   35        [        R                  " SUR                  5        35        [        R                  " SU 35        [        R                  " SUR                  5        35        [        R                  " SUR                  5        35        [        R                  " 5       nUR                   n ["        R$                  " UR&                  5      n [/        XsR                  5       5      n	[        R4                  R7                  S[9        U	5       S35         [;        XU5      n
U
(       d   [        R4                  R7                  S5        g	[        R4                  R7                  S[9        U
5       S35        U
 H  n [=        XdUSS9  M     [        R4                  R7                  [9        U
5       S35        g	! ["        R(                   a  n[*        R,                  " SU 35      UeS	nAff = f! [0        R2                   a  n[*        R,                  " S
U 35      UeS	nAff = f! [0        R2                   a  n[*        R,                  " SU 35      UeS	nAff = f! [0        R>                   aD  n[A        XRB                  [        RD                  S5        [*        R,                  " SU 35      UeS	nAff = f)z3Execute the gcloud saas-runtime flags push command.z
--project=z--location=z--unit-kind=zParent reference: zParent relative name: zUnitKind Name: zUnitKind RelativeName: zFailed to parse JSON: NzFailed to parse flags: zFound z! flags in manifest. Validating...zNo flags were created: z0No valid flags to create. No flags were created.z+All flags validated successfully. Creating z	 flags...FrX   zFailed to create flagz0Halting execution due to post-validation error: z flags created successfully.)#r   VALUEScoreprojectrs   CONCEPTS	unit_kindParseParentRelativeNamer   r,   locationNamesaasservicemgmt_utilGetV1Beta1ClientInstanceprojects_locations_flagsrj   rk   filerm   calliope_exceptionsToolExceptionrV   r   r0   r]   r^   lenre   r[   r_   r`   r'   rP   )selfargsr   unit_kind_refrb   clientra   manifestrU   r   rc   rT   s               r    RunPush.RunO  s    $$,,002GMM++113M!!#002FII
7)$%IIDMM?+,IIT^^,-.II"=#7#7#9":;<II&vh/0II 2 2 4567II'(B(B(D'EFG!::<F33MDII&h*
..0e JJvc%j\)JKL"5@k 	jjIJJJ	Y	(
  M85I   JJK())EFGW  --"1#
& && --#A3
' && --#A3
'$ !! asyy2IJ!//>qcB
	s`    J %K +K7 L-J>J99J>K4K//K47L*L%%L*-N?N  N N)
r@   
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr   r   __static_attributes__r   r"   r    r   r   &  s8     = 9

-  (@Hr"   r   )r   z
str | Nonereturnbool)r2   strr3   r   r4   dict[str, Any]r   r   )r6   r   r5   r   r   r   )rQ   r   r3   r   r   list[ezmessages.Flag])r   r   ra   =ezclient.SaasservicemgmtV1beta1.ProjectsLocationsFlagsServicerb   r   r   r   )rU   exceptions.HttpErrorr   r   )ra   r   rb   r   r2   r   r   zezmessages.Flag | None)F)
ra   r   rb   r   rT   zezmessages.FlagrY   r   r   None)rh   )rU   r   r2   r   r   zCallable[[str], None]r   r   );r   
__future__r   rj   r-   typingr   r   apitools.base.protorpcliter   rN   apitools.base.pyr   r   +googlecloudsdk.api_lib.saasservicemgmt.utilapi_libsaasservicemgmtutilr   googlecloudsdk.api_lib.utilrI   googlecloudsdk.callioper	   r
   r   'googlecloudsdk.command_lib.saas_runtimer   r   googlecloudsdk.corer   r   =googlecloudsdk.generated_clients.apis.saasservicemgmt.v1beta1r   ezclientr   rK   r   __annotations__r   intfloatr   r   r!   r8   r1   rV   re   rp   ru   r[   r`   DefaultUniverseOnlyReleaseTracksReleaseTrackALPHAHiddenCommandr   r   r"   r    <module>r      s   A "     C % ' J J = / ( E F # * t x &$&&	!~  )$/&,,e4,c2	9 5 >
""" $" 	"J$':#!#36##L P  	8 P  	(  	4P44 4 	4
 
4v 	666 $6 	6$ D%%++,fH4<< fH  - fHr"   