
    L                     f   d Z ddl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
ZdZdZdZdZej&                  ej(                   ej*                  ej,                  j.                  ej,                  j0                         G d dej2                                             Zd Zd Zy)z"services mcp policies get command.    N)serviceusage)base)common_flags)log)
properties)yaml)fileszprojects/{}z
folders/{}zorganizations/{}z/mcpPolicies/{}z1970-01-01T00:00:00Zc                   &    e Zd ZdZed        Zd Zy)Geta  Get MCP policy for a project, folder or organization.

  Get MCP policy for a project, folder or
  organization.

  ## EXAMPLES

   Get MCP policy for default policy on current project:

   $ {command}
      OR
   $ {command} --policy-name=default

   Get MCP policy for default policy on current project and save the
   content in an output file:

   $ {command} --output-file=/path/to/the/file.yaml
       OR
   $ {command} --output-file=/path/to/the/file.json
  c                 |    | j                  ddd       t        j                  |        | j                  dd       y )Nz--policy-namez>Name of the MCP policy. Currently only "default" is supported.default)helpr   z--output-filezNPath to the file to write policy contents to. Supported format:.yaml or .json.)r   )add_argumentr   add_resource_args)parsers    (lib/surface/services/mcp/policies/get.pyArgszGet.Args?   sI    
M  
 ""6*
      c                    |j                  d      r t        j                  |j                        }n|j                  d      r t        j                  |j
                        }nz|j                  d      r t        j                  |j                        }nIt        j                  j                  j                  j                  d      }t        j                  |      }t        j                  |t        j                  |j                        z         }|j                  d      r|j                   j#                  d      s1|j                   j#                  d      st%        j&                  d	       y|j                   j#                  d      r!t)        j*                  t-        |      d
      }n t/        j0                  t-        |      d      }t3        j4                  |j                   |       t$        j6                  j9                  d|j                   z         y|j                  d      r|S t-        |      }|j;                         D ]  \  }}|dvr'|r%t$        j6                  j9                  |dz   |z          |dk(  r?t$        j6                  j9                  |dz          |j<                  D ]  }	t?        |	        u|dk(  s{t$        j6                  j9                  |dz          |D ]  }
tA        |
         y)zRun command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Resource name and its parent name.
    folderorganizationprojectT)requiredoutput_filez.jsonz.yamlzGInvalid output-file format. Please provide path to a yaml or json file.F)	sort_keys)
round_tripz%Policy written to the output file %s format)mcpEnableRulescontentSecurityz: r   :r   N)!IsSpecified_FOLDER_RESOURCEr   r   _ORGANIZATION_RESOURCEr   _PROJECT_RESOURCEr   r   VALUEScorer   r   GetMcpPolicy_MCP_POLICY_DEFAULTpolicy_namer   endswithr   errorjsondumps_ConvertToDictr   dumpr	   WriteFileContentsstatusPrintitemscontentSecurityProvidersprint_PrintRules)selfargsresource_namer   policydataresultkvcontent_security_providerenable_rules              r   RunzGet.RunP   sR    !&--dkk:m			.	),33D4E4EFm			)	$'..t||<m!!&&..22D2Ag'..w7m&&+2243C3CDDF &



#
#G
,&&w/			

 $$W-N62eD$>&1dC$ 0 0$7

3d6F6FF	
 
		(	#mf%f,,.$!Q99a
**

1t8a<
(!!
**

1s7
#+,+E+E'+, ,F""
**

1s7
#k$  ! r   N)__name__
__module____qualname____doc__staticmethodr   rA    r   r   r   r   &   s     *   :r   r   c                    | j                   g | j                  | j                  | j                  | j                  d}| j
                  D ]8  }|j                  s|d   j                  dt        |j                        i       : | j
                  s|d= | j                  t        k(  r|d= | j                  t        k(  r|d= |S )zsConvertToDict command.

  Args:
    policy: mcpPolicy to be convert to orderedDict.

  Returns:
    orderedDict.
  )namer   
updateTime
createTimeetagr   r   mcpservicesrJ   rK   )
rI   rJ   rK   rL   r   r   mcpServicesappendlist_INVALID_TIMESTAMP)r:   outputr@   s      r   r.   r.      s     kk%%%%kk//& **k%%${667
8 + 
		 ,,|,,|	-r   c                     dg}|D ]m  }|| j                         v st        j                  j                  d|z   dz          | |   D ]+  }|D ]$  }t        j                  j                  d|z          & - o y )NrN    r    z  - )keysr   r1   r2   )rulerU   keyrM   servicess        r   r6   r6      sj    
$c
diik	jjsSy3'c+#H
**

6H,
- $ # r   )rE   r,   googlecloudsdk.api_lib.servicesr   googlecloudsdk.callioper   #googlecloudsdk.command_lib.servicesr   googlecloudsdk.corer   r   r   googlecloudsdk.core.utilr	   r$   r"   r#   r(   rQ   UniverseCompatibleHiddenReleaseTracksReleaseTrackALPHABETACommandr   r.   r6   rG   r   r   <module>re      s    )  8 ( < # * $ *!  + '    D%%++T->->-C-CDa$,, a E  aH!H.r   