
    Q                     l   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 dd	lmZ dd	lmZ dd
lmZ e
j"                   e
j$                  e
j&                  j(                  e
j&                  j*                         G d de
j,                  e
j.                                      Zddie_        y)zDCommand for getting effective security policies of backend services.    )absolute_import)division)unicode_literals)base_classes)firewalls_utils)lister)base)flags)logc                   2    e Zd ZdZed        Zd Zd Zd Zy)GetEffectiveSecurityPoliciesa  Get the effective security policies of a Compute Engine backend service.

  *{command}* is used to get the effective security policies applied to the
  backend service.

  ## EXAMPLES

  To get the effective security policies for a backend service, run:

    $ {command} example-backend-service

  gets the effective security policies applied on the backend service
  'example-backend-service'.
  c                     t         j                  j                  | d       | j                  j	                  t
        j                         t        j                  |        y )Nzget effective security policies)operation_type)	r
   GLOBAL_BACKEND_SERVICE_ARGAddArgumentdisplay_info	AddFormatr   %EFFECTIVE_SECURITY_POLICY_LIST_FORMATr   AddBaseListerArgs)parsers    Glib/surface/compute/backend_services/get_effective_security_policies.pyArgsz!GetEffectiveSecurityPolicies.Args0   sP    	$$00@ 1  !!== V$    c                 .    |j                  d      }|d   S )N/)split)selfsp_refsp_ref_lists      r   _GetSecurityPolicyNamez3GetEffectiveSecurityPolicies._GetSecurityPolicyName:   s    ,,s#Kr?r   c                    t        j                  | j                               }|j                  }t        j
                  j                  ||j                  t        j                  |            } |j                  j                  di |j                         }|j                  |j                  j                  d|fg      d   }d}d} |j                  j                   di |j                         }	|j                  j                  d|	fg}
t#        |d      rv|j$                  rj|j                  j'                  |j(                  | j+                  |j$                              }|
j-                  |j                  j.                  d|f       d}t#        |d	      rv|j0                  rj|j                  j'                  |j(                  | j+                  |j0                              }|
j-                  |j                  j.                  d|f       d}|j                  |
      }|d   }g }d }d }g }t#        |d
      r|j3                  |j.                         |r|d   }|r|d   }n|r|d   }|j3                  |       |r|j-                  |       |r|j-                  |       |j5                  d      r+|j6                  dk(  r|j                  j9                  |      S g }|D ]&  }|j3                  t;        j<                  |             ( |r$|j3                  t;        j>                  |             |r$|j3                  t;        j>                  |             |S )N)scope_listerGetr   Fr   edgeSecurityPolicy)projectsecurityPolicyTr'   securityPolicies      formatjson)r(    ) r   ComputeApiHolderReleaseTrackclientr
   r   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListermessages ComputeBackendServicesGetRequestAsDictMakeRequestsapitools_clientbackendServices9ComputeBackendServicesGetEffectiveSecurityPoliciesRequesthasattrr%   !ComputeSecurityPoliciesGetRequestr&   r!   appendr(   r'   extendIsSpecifiedr+   3BackendServicesGetEffectiveSecurityPoliciesResponser   /ConvertOrgSecurityPolicyRulesToEffectiveSpRules,ConvertSecurityPolicyRulesToEffectiveSpRules)r   argsholderr0   backend_service_refget_requestget_responsehas_edge_sphas_spget_effective_sp_requestrequestsget_edge_sp_requestget_sp_request	responsesget_effective_sp_responseorg_policiesedge_policybackend_policyall_policiesresultsps                        r   Runz GetEffectiveSecurityPolicies.Run>   s_   **4+<+<+>?F]]F::LL"88@ M 
 C&//BB 

$
$
&K &&				/	/D( 
L KFhvhh  

$
$
&  	..&  H 	23++"OOMM%--44-- N  oo

 
 
1
1

 	
 k|-.<3N3NHH%--44)) I n oo

 
 
1
1

 	
 f##H-I )!LKNL(*<=3DDEaLk	"1	 |n%+&.)!dkkV&;
//
M
M+ N  Fmm

I
I"
M  mm

F
F
 mm

F
F
 Mr   c                 f    ~t         j                  j                  dt        j                  z          y )N
)r   statusPrintr   LIST_NOTICE_SECURITY_POLICY)r   resources_were_displayeds     r   Epilogz#GetEffectiveSecurityPolicies.Epilog   s"     JJTOGGGHr   N)	__name__
__module____qualname____doc__staticmethodr   r!   rW   r^   r-   r   r   r   r      s-     % %fPIr   r   EXAMPLESaX      To get the effective security policies of backend_service with name
    example-backend_service, run:

      $ {command} example-backend_service

    To show all fields of the security policy, please show in JSON format with
    option --format=json

    To list more the fields of the effective security policy rules in table
    format, run:

      $ {command} example-backend_service --format="table(
        type,
        security_policy_name,
        priority,
        description,
        action,
        preview,
        expression,
        src_ip_ranges.list():label=SRC_RANGES)"
        N)rb   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   googlecloudsdk.callioper	   "googlecloudsdk.command_lib.computer
   r3   3googlecloudsdk.command_lib.compute.backend_servicesgooglecloudsdk.corer   UniverseCompatibleReleaseTracksr/   ALPHABETADescribeCommandListCommandr   detailed_helpr-   r   r   <module>rr      s    K &  ' 7 : 1 ( E E # D%%++T->->-C-CDHI4#7#79I9I HI E HIX  .  *r   