
                             S 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S rS rS rS rS rS rS rS rS rSS jrg)z;Declarative Response Hooks for Cloud SCC's Asset responses.    )absolute_import)division)print_function)unicode_literals)_JsonValueToPythonValue)securitycenter_client)InvalidSCCInputErrorc                     A[        U 5      n[        U5      S:  a  [        S5      eU H  nUR                  R                  s  $    g)z+Returns security marks from asset response.   zPListAssetResponse must only return one asset since it is filtered by Asset Name.N)listlenr	   assetsecurityMarks)responseargslist_asset_responseasset_results       ;lib/googlecloudsdk/command_lib/scc/assets/response_hooks.py ExtractSecurityMarksFromResponser      sM    
X	!
	  *l+++ *    c                 .   A[        U 5      nU(       d  [        S5      e[        U5      S:  a  [        S5      eU HW  n[        UR                  R
                  R                  S5      S   5      UR                  R                  R                  S.nUs  $    g)zDReturns asset that matches the user provided asset or resource-name.z!Asset or resource does not exist.r   zaListAssetResponse must only return one asset since it is filtered by Asset Name or Resource Name./   )r   resourceNameN)	r   r	   r   intr   namesplitsecurityCenterPropertiesr   )r   r   r   r   result_dictionarys        r   (ExtractMatchingAssetFromDescribeResponser    '   s    
X	
B
CC	!
	*+ + *l\'',,2237:;$**CCPP  *r   c                     A[        U 5      n[        U5      n[        U5      n[        U5      n[	        XE5      n[        U5      nSU0nU$ )z<Returns Parent for the user provided asset or resource-name.parent)_ValidateAndGetAssetResult_GetAssetResourceParent_ExtractOrganization_FilterOnResourceName	_GetAsset
_GetParent)	r   r   r   asset_parentorganizationresource_name_filterr   r"   r   s	            r   )ExtractMatchingAssetFromGetParentResponser,   9   sS    
+H5,(6,%l3,.|<
L
7%e&(	r   c                     A[        U 5      n[        U5      n[        U5      n[        U5      n[	        XE5      n[        U5      nSU0nU$ )z?Returns ProjectId for the user provided asset or resource-name.	projectId)r#   _GetAssetProjectr%   r&   r'   _GetProjectId)	r   r   r   asset_projectr*   r+   r   
project_idr   s	            r   *ExtractMatchingAssetFromGetProjectResponser3   G   sS    
+H5,"<0-%l3,.}=
L
7%U#*"J/	r   c                 z    [        U 5      nU(       d  [        S5      e[        U5      S:  a  [        S5      eUS   $ )NzAsset or resource does not exist for the provided Organization. Please verify that both the OrganizationId and AssetId/ResourceName are correct.r   z>An asset can not have multiple projects. Something went wrong.r   )r   r	   r   )r   r   s     r   r#   r#   U   sN    X	
	  		!
HJ J	Q	r   c                 b    U R                   R                  R                  nUc  [        S5      eU$ )NzAsset does not have a parent.)r   r   resourceParentr	   )r   r)   s     r   r$   r$   b   s1    ##<<KK,
>
??	r   c                 b    U R                   R                  R                  nUc  [        S5      eU$ )Nz/Organization assets do not belong to a Project.)r   r   resourceProjectr	   )r   r1   s     r   r/   r/   i   s5    $$==MM-
9; ;	r   c                     SU -   S-   $ )Nz'securityCenterProperties.resourceName="" )asset_propertys    r   r&   r&   q   s    	3n	Dt	KKr   c                     U R                   R                   Vs/ s H!  nUR                  S:X  d  M  UR                  PM#     nnU(       d  [	        S5      e[        US   5      $ s  snf )Nr.   z#No projectId exists for this asset.r   resourcePropertiesadditionalPropertieskeyvaluer	   r   )r   xr2   s      r   r0   r0   u   sg     ''<<<!	
+	 agg<  
 

D
EE	 A	//
   A#A#c                     U R                   R                   Vs/ s H!  nUR                  S:X  d  M  UR                  PM#     nnU(       d  [	        S5      e[        US   5      $ s  snf )Nr   z No parent exists for this asset.r   r>   )r   rC   r"   s      r   r(   r(      sf     ''<<<!	
& agg< 	 
 

A
BB	 	++rD   c                     U R                   R                  R                  S5      S   S-   U R                   R                  R                  S5      S   -   $ )Nr   r   r   )r   r   r   )r   s    r   r%   r%      sO    



!
!
'
'
,Q
/#
5



!
!
'
'
,Q
/0 1r   Nc                     [         R                  " 5       nUR                  XS9nUR                  n[	        U5      S:w  a  [        S5      eUS   R                  $ )N)r"   request_filterr   zCSomething went wrong while retrieving the ProjectId for this Asset.r   )	sc_clientAssetsClientListlistAssetsResultsr   r	   r   )r"   rH   asset_service_clientlist_asset_response_for_projectlist_asset_resultss        r   r'   r'      sg    "//1$8$=$= %> %4!6HH	!
MO O	A		$	$$r   )N)__doc__
__future__r   r   r   r   apitools.base.py.extra_typesr   googlecloudsdk.api_lib.sccr   rI   %googlecloudsdk.command_lib.scc.errorsr	   r   r    r,   r3   r#   r$   r/   r&   r0   r(   r%   r'   r;   r   r   <module>rU      s]    B &  % ' @ I F	,$
 L0,1
%r   