Beispiel #1
0
def UpdateCAFromArgs(args, current_labels):
  """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.
  """
  messages = privateca_base.GetMessagesModule(api_version='v1')
  ca_to_update = messages.CertificateAuthority()
  update_mask = []

  if args.IsKnownAndSpecified('pem_chain'):
    ca_to_update.subordinateConfig = messages.SubordinateConfig(
        pemIssuerChain=messages.SubordinateConfigChain(
            pemCertificates=_ParsePemChainFromFile(args.pem_chain)))
    update_mask.append('subordinate_config')
  labels_diff = labels_util.Diff.FromUpdateArgs(args)
  labels_update = labels_diff.Apply(messages.CertificateAuthority.LabelsValue,
                                    current_labels)
  if labels_update.needs_update:
    ca_to_update.labels = labels_update.labels
    update_mask.append('labels')

  if not update_mask:
    raise privateca_exceptions.NoUpdateExceptions(
        'No updates found for the requested CA.')

  return ca_to_update, update_mask
Beispiel #2
0
def UpdateCAFromArgs(args, current_labels):
    """Creates a CA object and update mask from CA update flags.

  Requires that args has 'pem-chain', '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.

  Returns:
    A tuple with the CA object to update with and the list of strings
    representing the update mask, respectively.
  """
    messages = privateca_base.GetMessagesModule()
    ca_to_update = messages.CertificateAuthority()
    update_mask = []

    if 'pem_chain' in vars(args) and args.IsSpecified('pem_chain'):
        ca_to_update.subordinateConfig = messages.SubordinateConfig(
            pemIssuerChain=messages.SubordinateConfigChain(
                pemCertificates=_ParsePemChainFromFile(args.pem_chain)))
        update_mask.append('subordinate_config')

    if args.IsSpecified('publish_crl') or args.IsSpecified('publish_ca_cert'):
        ca_to_update.issuingOptions = messages.IssuingOptions()
        if args.IsSpecified('publish_crl'):
            ca_to_update.issuingOptions.includeCrlAccessUrl = args.publish_crl
            update_mask.append('issuing_options.include_crl_access_url')
        if args.IsSpecified('publish_ca_cert'):
            ca_to_update.issuingOptions.includeCaCertUrl = args.publish_ca_cert
            update_mask.append('issuing_options.include_ca_cert_url')

    labels_diff = labels_util.Diff.FromUpdateArgs(args)
    labels_update = labels_diff.Apply(
        messages.CertificateAuthority.LabelsValue, current_labels)
    if labels_update.needs_update:
        ca_to_update.labels = labels_update.labels
        update_mask.append('labels')

    if args.IsSpecified('issuance_policy'):
        ca_to_update.certificatePolicy = flags.ParseIssuancePolicy(args)
        update_mask.append('certificate_policy')

    if not update_mask:
        raise privateca_exceptions.NoUpdateExceptions(
            'No updates found for the requested CA.')

    return ca_to_update, update_mask
Beispiel #3
0
def UpdateCaPoolFromArgs(args, current_labels):
  """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.
  """
  messages = privateca_base.GetMessagesModule('v1')
  pool_to_update = messages.CaPool()
  update_mask = []

  if args.IsSpecified('publish_crl') or args.IsSpecified('publish_ca_cert'):
    pool_to_update.publishingOptions = messages.PublishingOptions()
    if args.IsSpecified('publish_crl'):
      pool_to_update.publishingOptions.publishCrl = args.publish_crl
      update_mask.append('publishing_options.publish_crl')
    if args.IsSpecified('publish_ca_cert'):
      pool_to_update.publishingOptions.publishCaCert = args.publish_ca_cert
      update_mask.append('publishing_options.publish_ca_cert')

  labels_diff = labels_util.Diff.FromUpdateArgs(args)
  labels_update = labels_diff.Apply(messages.CaPool.LabelsValue,
                                    current_labels)
  if labels_update.needs_update:
    pool_to_update.labels = labels_update.labels
    update_mask.append('labels')

  if args.IsSpecified('issuance_policy'):
    pool_to_update.issuancePolicy = flags_v1.ParseIssuancePolicy(args)
    update_mask.append('issuance_policy')

  if not update_mask:
    raise privateca_exceptions.NoUpdateExceptions(
        'No updates found for the requested CA pool.')

  return pool_to_update, update_mask