
                             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 d Zd Zd Zy)z"Helpers for update commands in GA.    )absolute_import)division)unicode_literals)base)
exceptions)flags)	pem_utils)labels_util)filesc                     	 t        j                  |       }t        j                  |      S # t         j                  t
        t        f$ r& t        j                  ddj                  |             w xY w)zParses a pem chain from a file.

  Args:
    pem_chain_file: file containing the pem_chain.

  Returns:
    The string list of certs in the chain.
  z	pem-chainz,Could not read provided PEM chain file '{}'.)
r   ReadFileContentsr	   ValidateAndParsePemChainErrorOSErrorIOErrorr   InvalidArgumentExceptionformat)pem_chain_filepem_chain_inputs     8lib/googlecloudsdk/command_lib/privateca/update_utils.py_ParsePemChainFromFiler      sf    ,,^<O--o>>
++w	( 

-
-6==nM s
   ), AA0c                 &   t        j                  d      }|j                         }g }| j                  d      rK|j	                  |j                  t        | j                                    |_        |j                  d       t        j                  j                  |       }|j                  |j                  j                  |      }|j                  r"|j                   |_        |j                  d       |st#        j$                  d      ||fS )	a  Creates a CA object and update mask from CA update flags.

  Requires that args has 'pem-chain' and update labels flags registered.

  Args:
    args: The parser that contains the flag values.
    current_labels: The current set of labels for the CA.

  Returns:
    A tuple with the CA object to update with and the list of strings
    representing the update mask, respectively.
  v1)api_version	pem_chain)pemCertificates)pemIssuerChainsubordinate_configlabelsz&No updates found for the requested CA.)privateca_baseGetMessagesModuleCertificateAuthorityIsKnownAndSpecifiedSubordinateConfigSubordinateConfigChainr   r   subordinateConfigappendr
   DiffFromUpdateArgsApplyLabelsValueneeds_updater   privateca_exceptionsNoUpdateExceptions)argscurrent_labelsmessagesca_to_updateupdate_masklabels_difflabels_updates          r   UpdateCAFromArgsr6   2   s    --$?(..0,+	k*%-%?%?6624>>B 7 
 &@ &L"
 +,  //5+####//- '..Lx 	

1
10  
{	""    c                    t        j                  d      }|j                         }g }| j                  d      s"| j                  d      s| j                  d      r|j	                         |_        | j                  d      r,| j                  |j
                  _        |j                  d       | j                  d      r,| j                  |j
                  _
        |j                  d       | j                  d      r5t        j                  |       |j
                  _        |j                  d       t        j                  j!                  |       }|j#                  |j                  j$                  |      }|j&                  r"|j(                  |_        |j                  d       | j                  d	      r+t        j*                  |       |_        |j                  d	       |st/        j0                  d
      ||fS )a  Creates a CA pool object and update mask from CA pool update flags.

  Requires that args has 'publish-crl', 'publish-ca-cert', and
  update labels flags registered.

  Args:
    args: The parser that contains the flag values.
    current_labels: The current set of labels for the CA pool.

  Returns:
    A tuple with the CA pool object to update with and the list of strings
    representing the update mask, respectively.
  r   publish_crlpublish_ca_certpublishing_encoding_formatzpublishing_options.publish_crlz"publishing_options.publish_ca_certz"publishing_options.encoding_formatr   issuance_policyz+No updates found for the requested CA pool.)r    r!   CaPoolIsSpecifiedPublishingOptionspublishingOptionsr9   
publishCrlr'   r:   publishCaCertr   ParseEncodingFormatFlagencodingFormatr
   r(   r)   r*   r+   r,   r   ParseIssuancePolicyissuancePolicyr-   r.   )r/   r0   r1   pool_to_updater3   r4   r5   s          r   UpdateCaPoolFromArgsrH   Z   s    --d3(??$.+ }%			+	,			6	7'/'A'A'CN$&484D4Dn&&19:)*7;7K7Kn&&4=>45

'
'
- &&5 =>  //5+##HOO$?$?P-)00Nx 	'($)$=$=d$CN!()	

1
15  
	$$r7   N)__doc__
__future__r   r   r    googlecloudsdk.api_lib.privatecar   r    googlecloudsdk.callioper   $googlecloudsdk.command_lib.privatecar-   r   r	   $googlecloudsdk.command_lib.util.argsr
   googlecloudsdk.core.utilr   r   r6   rH    r7   r   <module>rQ      s8    ) &  ' C . S 6 : < *(%#P3%r7   