
    ,                       % S r SSKJr  SSKJr  SSK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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r$\%\&-  \'-  \(-  r) " S S\
5      r* " S S\*SS9r+\RX                  " SSS9 " S S5      5       r-\#R\                  R^                  R`                  \-" SSS9\#R\                  R^                  Rb                  \-" SSS9\#R\                  R^                  Rd                  \-" SSS9\#R\                  R^                  Rf                  \-" SS S90r4S!\5S"'    " S# S$\Rl                  5      r7      S,S% jr8SS&.       S-S' jjr9S.S( jr:S/S) jr;\Rx                  \Rz                  " \R|                  R~                  5      \R                   " S* S+\R                  5      5       5       5       rBg)0aL  Command to create a local manifest file from the SaaS Flags API.

This command is used to create a local manifest file from the SaaS Flags API.
The manifest file will contain all flags for the specified UnitKind. By
default, the output file cannot already exist. Use `--overwrite-output-file`
to allow overwriting an existing file.
    )annotations)IterableN)Any	TypedDict)
exceptions)
list_pager)base)flags)log)
properties)files)saasservicemgmt_v1beta1_client) saasservicemgmt_v1beta1_messagesz9https://openfeature.dev/schemas/v1.0.0/flag-manifest.jsonc                  .    \ rS rSr% SrS\S'   S\S'   Srg)	_FlagDefinitionBase3   zA set of flag properties in JSON manifest schema format.

Attributes:
  flagType: The type of the flag (e.g., 'boolean', 'string').
  defaultValue: The default value of the flag.
strflagType
_FlagValuedefaultValue N__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r       &lib/surface/saas_runtime/flags/pull.pyr   r   3   s     -r    r   c                  $    \ rS rSr% SrS\S'   Srg)_FlagDefinition>   zA set of flag properties in JSON manifest schema format.

Attributes:
  flagType: The type of the flag (e.g., 'boolean', 'string').
  defaultValue: The default value of the flag.
  description: A human-readable description of the flag.
r   descriptionr   Nr   r   r    r!   r#   r#   >   s     r    r#   F)totalT)frozenslotsc                  .    \ rS rSr% SrS\S'   S\S'   Srg)	_FlagTypeInfoJ   zA set of type-specific properties for a flag.

Attributes:
  openfeature_type: The OpenFeature type name for the flag.
  default_value: The default value for this flag type.
r   openfeature_typer   default_valuer   Nr   r   r    r!   r*   r*   J   s     r    r*   boolean)r,   r-   integerdoubleg        string z=dict[ezmessages.Flag.ValueTypeValueValuesEnum, _FlagTypeInfo]_FLAG_TYPE_INFO_BY_VALUE_TYPEc                      \ rS rSrSrSrg)InvalidFlagDataErrors   z.Invalid or unsupported flag data from the API.r   N)r   r   r   r   r   r   r   r    r!   r5   r5   s   s    6r    r5   c                N    U [         ;  a  [        SU< SU  S35      e[         U    $ )a  Gets the type info or raises an error.

Args:
  flag_type: The type enum from the API flag message.
  flag_key: The key of the flag (for error messages).

Returns:
  The corresponding _FlagTypeInfo.

Raises:
  InvalidFlagDataError: If the flag type is not supported.
Flag z
 invalid. z is not a supported flag type.)r3   r5   )	flag_typeflag_keys     r!   _GetFlagTypeInfor;   x   s>     33

|:i[ 1 	  
'y	11r    flag_setc             #    ^#     [         R                  " U [        R                  " US9SSS9nU4S jU 5        Sh  vN   g N! [         a    e [
        R                   a!  n[        R                  " SU< S35      UeSnAff = f7f)	a/  Lists all flags for the given parent using automatic pagination.

Args:
  flags_service: The SaaS Flags service client.
  parent: The parent resource name to list flags from.
  flag_set: The flag set ID to filter flags by.

Yields:
  Flags from the API.

Raises:
  ToolException: If the API call fails.
)parentr
   pageSize)servicerequestfieldbatch_size_attributec              3  R   >#    U  H  nTb  UR                   T:X  d  M  Uv   M     g 7f)N)flagSet).0fr=   s     r!   	<genexpr>!_ListFlagsIter.<locals>.<genexpr>   s*      !a		X 5 	
>s   '	'NzFailed to retrieve flags for z from the SaaS Flags API.)	r   YieldFromList
ezmessages0SaasservicemgmtProjectsLocationsFlagsListRequestGeneratorExitapitools_exceptions	HttpErrorcalliope_exceptionsToolException)flags_servicer?   r=   flags_iteratores     `  r!   _ListFlagsIterrV      s     &--KK
 'N!   
 
			&	& 

+
+
'z1JKs8   B8A AA BA B#A??BBc                    [        U R                  U R                  5      nUR                  UR                  S.nU R
                  (       a  U R
                  US'   U$ )zConstructs a single flag entry for the manifest.

Args:
  flag: The flag message from the API.

Returns:
  A dictionary representing the flag definition in the manifest.
)r   r   r%   )r;   	valueTypekeyr,   r-   r%   )flagflag_type_infoflag_definitions      r!   _ConstructFlagEntryr]      sT     $DNNDHH=. !11$22&/
 
%)%5%5OM"	r    c                   0 nU  Ho  nUR                   (       d  [        SUR                  < S35      eUR                   U;   a  [        SUR                   < S35      e[        U5      XR                   '   Mq     [        US.$ )a  Constructs a JSON manifest file from an iterable of flags.

Args:
  flags: An iterable of flag messages from the API.

Returns:
  A dictionary representing the entire flag manifest.

Raises:
  InvalidFlagDataError: If any flag data is invalid or duplicate.
z;Flag invalid. "key" is required but missing for flag name: .r8   z< is a duplicate. Cannot create manifest with duplicate keys.)z$schemar
   )rY   r5   namer]   _OPENFEATURE_SCHEMA_URL)r
   manifest_flagsrZ   s      r!   _ConstructManifestrc      s     . d88 ii]! 
 xx>! $(( 8 8   348N88 " )
 r    c                  z    \ rS rSrSrS\R                  " S5      \R                  " S5      S.r\S 5       r	S r
S	rg
)Pull   z?Command to create a JSON manifest file from the SaaS Flags API.zLCreate a JSON manifest file using the SaaS Flags API as the source of truth.a            Creates a Flags manifest file under the specified location. The manifest file will contain all
          flags for the specified UnitKind. By default, the output file cannot already exist. Use
          `--overwrite-output-file` to allow overwriting an existing file.
      z          To create a manifest file named `my_flags.json` in a home directory:

              $ {command} --output-file=~/my_flags.json --unit-kind=my-unit-kind
          )briefDESCRIPTIONEXAMPLESc                    U R                  S[        SSS9  U R                  SSSSS	9  U R                  S
[        SSS9  [        R                  " U SSS9  g)zvRegisters flags for gcloud saas-runtime flags pull: --output-file, --unit-kind.

Args:
  parser: The argparse parser.
z--output-fileTzPath to the JSON manifest file that will be created containing the flag definitions. The manifest file will conform to the OpenFeature CLI flag manifest schema.)typerequiredhelpz--overwrite-output-file
store_trueFzAOverwrite the output file if it already exists. Default is False.)actiondefaultrm   z
--flag-setzFlag set ID to filter flags by.z$UnitKind to pull all the flags from.)rl   	help_textN)add_argumentr   	arg_utilsAddUnitKindArgToParser)parsers    r!   Args	Pull.Args  s     5  	 !O   .	   $$8r    c           	        [         R                  R                  R                  R	                  SS9nUR
                  R                  R                  5       nUR                  5       R                  5       n[        R                  " SU5        [        R                  " SUR                  5        [        R                  " SUR                  5        [        R                  " SUR                  5       5        [        R                  " SU5        [        R                  " SUR                  5       5        [        R                  " S	UR                  5       5        [        R                  " 5       nUR                   n[        R"                  R%                  S
U< S35        ['        XdUR(                  S9n[+        U5      nUR-                  S5      (       d%  [        R"                  R%                  SU< S35        g[        R"                  R%                  S5        [.        R0                  " USSSS9n	[        R                  " S[3        UR-                  S/ 5      5      5         [4        R6                  " UR8                  U	UR:                  S9  [        R"                  R%                  SUR8                  < 35        g! [4        R<                   a*  n
[>        R@                  " SUR8                  < 35      U
eSn
A
ff = f)zExecutes the gcloud saas-runtime flags pull command.

Args:
  args: An argparse namespace. All the arguments the command is called with.

Raises:
  ToolException: If file writing fails or API call fails.
T)rl   z--project=%sz--location=%sz--unit-kind=%szParent reference: %szParent relative name: %szUnitKind Name: %szUnitKind RelativeName: %szFetching flags from z...r<   r
   z No flags found or processed for z. No manifest file was created.NzEGenerating manifest. Using zero values as defaultValue for all flags.   F)indent	sort_keysensure_asciiz!Manifest generated with %d flags.)pathcontents	overwritez&Successfully created manifest file at zCould not write to output file )!r   VALUEScoreprojectGetCONCEPTS	unit_kindParseParentRelativeNamer   debuglocationNamesaasservicemgmt_utilGetV1Beta1ClientInstanceprojects_locations_flagsstatusPrintrV   r=   rc   getjsondumpslenr   WriteFileContentsoutput_fileoverwrite_output_fileErrorrQ   rR   )selfargsr   unit_kind_refr?   clientrS   rT   manifest_datamanifest_contentrU   s              r!   RunPull.Run6  sM    $$,,00$0?GMM++113M!!#002FIIng&IIot}}-II/II$m&:&:&<=II(&1II!=#5#5#78II)=+E+E+GH!::<F33MJJ+F:S9:#N '~6MW%%	jj,VJ 7  JJO zza4e II+S1B1B7B1O-P#..
 
jj243C3C2F
G ;; --+D,<,<+?
@s   AJ1 1K/%K**K/r   N)r   r   r   r   r   textwrapdedentdetailed_helpstaticmethodrv   r   r   r   r    r!   re   re      sT     H __ &
 
 // # -" & &P;r    re   )r9   z/ezmessages.Flag.ValueTypeValueValuesEnum | Noner:   r   returnr*   )rS   z=ezclient.SaasservicemgmtV1beta1.ProjectsLocationsFlagsServicer?   r   r=   z
str | Noner   Iterable[ezmessages.Flag])rZ   zezmessages.Flagr   r#   )r
   r   r   zdict[str, Any])Cr   
__future__r   collections.abcr   dataclassesr   r   typingr   r   apitools.base.pyr   rO   r   +googlecloudsdk.api_lib.saasservicemgmt.utilapi_libsaasservicemgmtutilr   googlecloudsdk.callioper	   rQ   'googlecloudsdk.command_lib.saas_runtimer
   rs   googlecloudsdk.corer   r   googlecloudsdk.core.utilr   =googlecloudsdk.generated_clients.apis.saasservicemgmt.v1beta1r   ezclientr   rL   ra   boolintfloatr   r   r   r#   	dataclassr*   FlagValueTypeValueValuesEnumFLAG_VALUE_TYPE_BOOLFLAG_VALUE_TYPE_INTFLAG_VALUE_TYPE_DOUBLEFLAG_VALUE_TYPE_STRINGr3   r   rR   r5   r;   rV   r]   rc   DefaultUniverseOnlyReleaseTracksReleaseTrackALPHAHiddenCommandre   r   r    r!   <module>r      s    # $    ! > ' J J ( E F # * * t x @  CZ%#%
) 	) 	 d$/	 	 0	 OO,,AA&	

 OO,,@@-"C OO,,CC%	

 OO,,CC%	
%    8.<< 
2>2JM226  	(P(( 	(
 (V,#L D%%++,x4<< x  - xr    