
                             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Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy
)z.Anthos Policy Controller status API utilities.    )absolute_import)division)unicode_literals)
exceptions)apis)base)api_util)	constantsNc                 Z    | t         j                  j                  k(  ryt        d| z         )Nv1alphazInvalid release track: )r   ReleaseTrackALPHA
ValueErrorrelease_tracks    Olib/googlecloudsdk/api_lib/container/fleet/policycontroller/status_api_utils.py_GetApiVersionFromReleaseTrackr      s*    d''---,}<==    c                 @    t        j                  dt        |             S )z9Returns the Policy Controller status API messages module.anthospolicycontrollerstatus_pa)r   GetMessagesModuler   r   s    r   r   r   $        			'$]3
5 5r   c                 @    t        j                  dt        |             S )z9Returns the Policy Controller status API client instance.r   )r   GetClientInstancer   r   s    r   r   r   +   r   r   c           	         	 t        j                  ||      }	 |j                  dj                  |||j                              }| j                  j                  |      }|j                  j                  |j                  j                  t        j                  t!        j"                  |j$                  j&                              ||j(                  j*                  xs dg |j$                  j,                  xs i |j$                  j.                  xs i dS # t        j                  $ r% t	        j
                  dj                  |            w xY w# t        j                  $ r& t	        j
                  dj                  ||            w xY w)z*Returns a formatted membership constraint.z+Membership [{}] was not found in the Fleet.z'projects/{}/membershipConstraints/{}/{}namez7Constraint [{}] was not found in Fleet membership [{}].r   )r   templateenforcementAction
membershipviolationCount
violationsmatch
parameters)fleet_api_utilGetMembershipapitools_exceptionsHttpNotFoundErrorr   ErrorformatEAnthospolicycontrollerstatusPaProjectsMembershipConstraintsGetRequestuniqueIdprojects_membershipConstraintsGetconstraintRefr   constraintTemplateNamer
   get_enforcement_action_labelsix	text_typespecr   statusnumViolationskubernetesMatchr$   )	clientmessagesconstraint_name
project_idr    r   membership_objrequestresponses	            r   GetMembershipConstraintr?   2   sf   #11*2?AN.\\6==)@)@B ] CG 4488AH 
 
 
%
%

 
 
7
7

0
0mmHMM;;<>
//
'
'
,1
--
'
'
-2
--
"
"
(b
  
	.	. 


5	
	  
	.	. .


A		,. ..s   D AE 8E9F
c                    	 |j                  dj                  ||            }| j                  j                  |      }|j                  j                  |j                  j                  g |j                  xs dg |j                  xs dd}|j                  dj                  |            }| j                  j                  |      }|j                   D ]h  }	|dj                  |	j"                  j                  |	j"                  j                        k(  sA|d	   j%                  |	j&                  j                         j |S # t        j
                  $ r% t        j                  dj                  |            w xY w)
z%Returns a formatted Fleet constraint.zprojects/{}/fleetConstraints/{}r   z+Constraint [{}] was not found in the fleet.r   )r   r   r"   r!   membershipsmembershipCountzprojects/{})parentz{}/{}rA   )@AnthospolicycontrollerstatusPaProjectsFleetConstraintsGetRequestr*   projects_fleetConstraintsr.   r'   r(   r   r)   refr   r0   r6   numMembershipsFAnthospolicycontrollerstatusPaProjectsMembershipConstraintsListRequestr-   ListmembershipConstraintsr/   appendmembershipRef)
r8   r9   r:   r;   r=   r>   
constraintmembership_constraints_requestmembership_constraints_responsemembership_constraints
             r   GetFleetConstraintrQ   Z   sv   "WW.55) X *G //33G<H ll,,55 ..3!!005A* $,#r#r!!*- $s $/ $*$I$I$N$N$%&!  ?TT'..++BB++002 2 &&

-
-
2
24	  U 
3 
	.	. "


5		 " ""s   =E 8E9c                 X    | j                   }|j                         }t        |||d       S )Nc                     | j                   S N)fleetConstraintsr>   s    r   <lambda>z&ListFleetConstraints.<locals>.<lambda>   s
    H$=$=r   )rE   AAnthospolicycontrollerstatusPaProjectsFleetConstraintsListRequest	_Autopager8   msgr;   	client_fnreqs        r   ListFleetConstraintsr^   }   s1    ..)MMO#	9c:=
? ?r   c                 X    | j                   }|j                         }t        |||d       S )Nc                     | j                   S rT   )rJ   rV   s    r   rW   z+ListMembershipConstraints.<locals>.<lambda>   s
    H$B$Br   )r-   rH   rY   rZ   s        r   ListMembershipConstraintsra      s3    33)RRT#	9c:B
D Dr   c                 X    | j                   }|j                         }t        |||d       S )Nc                     | j                   S rT   )fleetConstraintTemplatesrV   s    r   rW   z.ListFleetConstraintTemplates.<locals>.<lambda>   s
    H$E$Er   )!projects_fleetConstraintTemplatesIAnthospolicycontrollerstatusPaProjectsFleetConstraintTemplatesListRequestrY   rZ   s        r   ListFleetConstraintTemplatesrg      s3    66)UUW#	9c:E
G Gr   c                 X    | j                   }|j                         }t        |||d       S )Nc                     | j                   S rT   )membershipConstraintTemplatesrV   s    r   rW   z3ListMembershipConstraintTemplates.<locals>.<lambda>   s
    H$J$Jr   )&projects_membershipConstraintTemplatesNAnthospolicycontrollerstatusPaProjectsMembershipConstraintTemplatesListRequestrY   rZ   s        r   !ListMembershipConstraintTemplatesrm      s3    ;;)ZZ\#	9c:J
L Lr   c                 X    | j                   }|j                         }t        |||d       S )Nc                     | j                   S rT   )#membershipConstraintAuditViolationsrV   s    r   rW   z ListViolations.<locals>.<lambda>   s
    xCCr   ),projects_membershipConstraintAuditViolationsTAnthospolicycontrollerstatusPaProjectsMembershipConstraintAuditViolationsListRequestrY   rZ   s        r   ListViolationsrs      s4    AA)``b#	jC
E Er   c                 X    | j                   }|j                         }t        |||d       S )Nc                     | j                   S rT   )rA   rV   s    r   rW   z!ListMemberships.<locals>.<lambda>   s
    H$8$8r   )projects_memberships<AnthospolicycontrollerstatusPaProjectsMembershipsListRequestrY   rZ   s        r   ListMembershipsrx      s1    )))HHJ#	9c:8
: :r   c                     g }d}	 d|z   |_         ||_        | j                  |      }| ||      z  }|j                  s	 |S |j                  }I)a  Auto-page through the responses if the next page token is not empty and returns a list of all resources.

  Args:
    client_fn: Function specific to the endpoint
    request: Request object specific to the endpoint
    project_id: Project id that will be used in populating the request object
    resource_collector: Function to be used for retrieving the relevant field
      from the response

  Returns:
    List of all resources specific to the endpoint
   z	projects/)rC   	pageTokenrI   nextPageToken)r\   r=   r;   resource_collector	resourcesnext_page_tokenr>   s          r   rY   rY      sg     )/ :-GN'G~~g&H#H--I!!	 ,,O 	r   )__doc__
__future__r   r   r   apitools.base.pyr   r'   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   *googlecloudsdk.command_lib.container.fleetr	   r%   ;googlecloudsdk.command_lib.container.fleet.policycontrollerr
   googlecloudsdk.corer2   r   r   r   r?   rQ   r^   ra   rg   rm   rs   rx   rY    r   r   <module>r      sj    5 &  ' > , ( Q Q * 
>55%P F?DGLE:r   