
    ?                     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 policies get command.    N)serviceusage)base)common_flags)log)
properties)yaml)fileszprojects/{}z
folders/{}zorganizations/{}z/consumerPolicies/{}z1970-01-01T00:00:00Zc                   &    e Zd ZdZed        Zd Zy)Geta  Get consumer policy for a project, folder or organization.

  Get consumer policy for a project, folder or
  organization.

  ## EXAMPLES

   Get consumer policy for default policy on current project:

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

   Get consumer 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-namezCName of the consumer 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/policies/get.pyArgszGet.Args?   sM    
    ""6*
      c                 l   |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 ]l  \  }}|dk7  r(|r&t$        j6                  j9                  |dz   |z          3|dk(  s9t$        j6                  j9                  |dz          |D ]  }	t=        |	        n 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enableRulesz: :N)IsSpecified_FOLDER_RESOURCEr   r   _ORGANIZATION_RESOURCEr   _PROJECT_RESOURCEr   r   VALUEScorer   r   GetConsumerPolicyV2Beta_CONSUMER_POLICY_DEFAULTpolicy_namer   endswithr   errorjsondumps_ConvertToDictr   dumpr	   WriteFileContentsstatusPrintitems_PrintRules)
selfargsresource_namer   policydataresultkvenable_rules
             r   RunzGet.RunS   s    !&--dkk:m			.	),33D4E4EFm			)	$'..t||<m!!&&..22D2Ag'..w7m110778H8HIIF &



#
#G
,&&w/			

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

3d6F6FF	
 
		(	#mf%f,,.$!Q!
**

1t8a<
(-
**

1s7
#k$  ! r   N)__name__
__module____qualname____doc__staticmethodr   r=    r   r   r   r   &   s     *  &6r   r   c                 j   | j                   g | 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 )zxConvertToDict command.

  Args:
    policy: consumerPolicy to be convert to orderedDict.

  Returns:
    orderedDict.
  )namer   
updateTime
createTimeetagr   servicesrF   rG   )	rE   rF   rG   rH   r   rI   appendlist_INVALID_TIMESTAMP)r7   outputr<   s      r   r-   r-      s     kk%%%%kk& ''k]""J[5I5I0J#KL ( 
		},,|,,|	-r   c                     dg}|D ]f  }|| j                         v st        j                  j                  d|z   dz          | |   D ]$  }t        j                  j                  d|z          & h y )NrI    r   z  - )keysr   r0   r1   )rulerP   keyvalues       r   r3   r3      s_    
$c
diik	jjsSy3'9%

%(  r   )rA   r+   googlecloudsdk.api_lib.servicesr   googlecloudsdk.callioper   #googlecloudsdk.command_lib.servicesr   googlecloudsdk.corer   r   r   googlecloudsdk.core.utilr	   r#   r!   r"   r'   rL   UniverseCompatibleHiddenReleaseTracksReleaseTrackALPHABETACommandr   r-   r3   rC   r   r   <module>r`      s    %  8 ( < # * $ *!  + 1    D%%++T->->-C-CD`$,, ` E  `FB)r   