
    %                        S r SSKJr  SSKJr  SSK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KJr  SSKJr  SrSr\\R;                  S5      -   rSrSr S\ -   \-   r!\" \\!5      r"\" \\5      r#\" \\ 5      r$\RJ                  RL                  r&S\RN                  " 5       -   S-   S-   S-   r( " S S\5      r)g)z/This module provides the pap command to gsutil.    )absolute_import)print_functionN)metrics)Command)CommandArgument)ApiSelector)CommandException)NO_URLS_MATCHED_TARGET)CreateHelpText)storage_v1_messages)NO_MAX)GcloudStorageMap)	shim_utilz=
  gsutil pap set (enforced|inherited) gs://<bucket_name>...
z(
  gsutil pap get gs://<bucket_name>...

a  
<B>SET</B>
  The ``pap set`` command configures public access prevention
  for Cloud Storage buckets. If you set a bucket to be
  ``inherited``, it uses public access prevention only if
  the bucket is subject to the `public access prevention
  <https://cloud.google.com/storage/docs/org-policy-constraints#public-access-prevention>`_
  organization policy constraint.

<B>SET EXAMPLES</B>
  Configure ``redbucket`` and ``bluebucket`` to use public
  access prevention:

    gsutil pap set enforced gs://redbucket gs://bluebucket
a  
<B>GET</B>
  The ``pap get`` command returns public access prevention
  values for the specified Cloud Storage buckets.

<B>GET EXAMPLES</B>
  Check if ``redbucket`` and ``bluebucket`` are using public
  access prevention:

    gsutil pap get gs://redbucket gs://bluebucket
z
  The ``pap`` command is used to retrieve or configure the
  `public access prevention
  <https://cloud.google.com/storage/docs/public-access-prevention>`_ setting of
  Cloud Storage buckets. This command has two sub-commands: ``get`` and ``set``.
z)--format=value[separator=": "](name.sub("z","gs://"),z.iamConfiguration.publicAccessPrevention.yesno(zno="inherited"))c                   x   \ rS rSrSr\R                  " SS/\S\SSSS\	R                  /\	R                  \R                  " S5      /\" S	S
S/S9\R                  " 5       /S.S9r\R                  " SS/SS\\\S.S9r\" \" SSS\S/0 SS9\" \" / SQ0 S9\" / SQ0 S9S.0 S9S.0 S9rS rS rS rS rS  rS!rg")#
PapCommand\   z"Implements the gsutil pap command.pappublicaccessprevention    F   modeenforced	inherited)choicesgetset)command_name_aliasesusage_synopsismin_argsmax_argssupported_sub_argsfile_url_okprovider_url_okurls_start_arggs_api_supportgs_default_apiargparse_argumentscommand_helpz"Configure public access prevention)	help_namehelp_name_aliases	help_typehelp_one_line_summary	help_textsubcommand_help_textstoragebucketslistz--rawT)gcloud_commandflag_mapsupports_output_translation)r2   r3   updatez--public-access-prevention)r5   r6   )r2   r3   r8   z--no-public-access-prevention)r   r   c                 h    UR                   R                  S:w  a  [        SU R                  -  5      eg )Ngsz7The %s command can only be used with gs:// bucket URLs.)storage_urlschemer	   command_name)selfblrs     %platform/gsutil/gslib/commands/pap.py,_ValidateBucketListingRefAndReturnBucketName7PapCommand._ValidateBucketListingRefAndReturnBucketName   s7    
%
C


  &    c                    UR                   nU R                  R                  UR                  S/UR                  S9nUR
                  nUR                  =(       d    Sn[        U5      R                  S5      n[        U< SU< 35        g)z7Gets the public access prevention setting for a bucket.iamConfigurationfieldsproviderr   /z: N)
r;   
gsutil_api	GetBucketbucket_namer<   rE   publicAccessPreventionstrrstripprint)r>   r?   
bucket_urlbucket_metadata
iam_configpublic_access_preventionbuckets          r@   _GetPublicAccessPrevention%PapCommand._GetPublicAccessPrevention   s|    Joo//
0F0F8J7K9C9J9J 0 LO !11J)@@OK_##C(F	f6
78rC   c                    UR                   n[        5       nX$l        [        R                  " US9n[        SU< S[        U5      R                  S5      < 35        U R                  R                  UR                  US/UR                  S9  g)zMSets the Public Access Prevention setting for a bucket enforced or inherited.)rE   z!Setting Public Access Prevention z for rI   rE   rF   r   )r;   IamConfigurationValuerM   apitools_messagesBucketrP   rN   rO   rJ   PatchBucketrL   r<   )r>   r?   setting_argrQ   rS   rR   s         r@   _SetPublicAccessPrevention%PapCommand._SetPublicAccessPrevention   s    J&(J(3%'..
KO	J..s35 6 	OO
 6 6 /(:';)3):):   < rC   c           
         U R                   R                  S5      nUS;  a  [        S5      eSn/ nSnUS:X  a  U R                  nO>US:X  a8  U R                  nU R                   R                  S5      nUR                  U5        U R                  R                  S5      [        R                  :w  a;  [        SR                  [        R                  " S	U R                  -  5      5      5      eS
nU R                   nU(       d  U R                  5         U H  nU R                  U5      nU H  n	U R                  R                  U	R                   R"                  5      [        R                  :w  a;  [        SR                  [        R                  " SU R                  -  5      5      5      eSnU" U	/UQ76   M     M     U(       d  [        [$        ['        U5      -  5      eg)z-Handles pap command on Cloud Storage buckets.r   r   zpap only supports get|setNr   r   r:   r   z=The "%s" command can only be with the Cloud Storage JSON API.Fz2The "%s" command can only be used for GCS Buckets.T)argspopr	   rV   r^   appendrJ   GetApiSelectorr   JSONjointextwrapwrapr=   $RaiseWrongNumberOfArgumentsExceptionGetBucketUrlIterFromArgr;   r<   r
   r4   )
r>   
subcommandsubcommand_funcsubcommand_argsr]   some_matchedurl_argsurl_strbucket_iterbucket_listing_refs
             r@   _PapPapCommand._Pap   s   q!J'899OOKU77o	u	77oIIMM!$k[)%%d+{/?/??TYY
-- %(,(9(9: ;< = =
 LyyH
//1009k +
??))**1136A6F6FG mm (+/+<+<= >"? @ @ *=_= !,  3d8nDEErC   c                     U R                   S   nU R                  SS9  US:X  d  US:X  aD  [        R                  " U R                  S9  [        R                  " U/S9  U R                  5         g	[        SU-  5      e)
z(Command entry point for the pap command.r   T)
check_argsr   r   )sub_opts)subcommandsz-Invalid subcommand "%s", use get|set instead.N)ra   ParseSubOptsr   LogCommandParamsrw   rs   r	   )r>   action_subcommands     r@   
RunCommandPapCommand.RunCommand   sv    		!&E!%6%%?6,=+>?
iikL./ 0 0rC    N)__name__
__module____qualname____firstlineno____doc__r   CreateCommandSpec	_SYNOPSISr   r   re   r   MakeNCloudURLsArgument%MakeZeroOrMoreCloudBucketURLsArgumentcommand_specHelpSpec_DETAILED_HELP_TEXT_get_help_text_set_help_text	help_specr   _GCLOUD_LIST_FORMATgcloud_storage_maprA   rV   r^   rs   r|   __static_attributes__r~   rC   r@   r   r   \   s@   ***45!&&' %%!88;=fz;.GHCCE	,( 12@#
) ( F4G" .2  +.  (* +.  (*", /#H K&P
9$+Z0rC   r   )*r   
__future__r   r   rg   gslibr   gslib.commandr   gslib.command_argumentr   gslib.cs_api_mapr   gslib.exceptionr	   r
   gslib.help_providerr   "gslib.third_party.storage_apitoolsr   rZ   gslib.utils.constantsr   gslib.utils.shim_utilr   gslib.utilsr   _SET_SYNOPSIS_GET_SYNOPSISlstripr   _SET_DESCRIPTION_GET_DESCRIPTION_DESCRIPTIONr   r   r   r[   rY   get_format_flag_caretr   r   r~   rC   r@   <module>r      s   6 & %   ! 2 ( , 2 . W ( 2 ! M0066	  
 
 
 ** %Y= /?@/?@ *00FF G 6689;HIGH ** g0 g0rC   