Esempio n. 1
0
    def Run(self, args):
        client = certificate_maps.CertificateMapClient()
        map_ref = args.CONCEPTS.map.Parse()

        new_description = None
        if args.IsSpecified('description'):
            new_description = args.description

        labels_update = None
        labels_diff = labels_util.Diff.FromUpdateArgs(args)
        if labels_diff.MayHaveUpdates():
            orig_resource = client.Get(map_ref)
            labels_update = labels_diff.Apply(
                client.messages.CertificateMap.LabelsValue,
                orig_resource.labels).GetOrNone()

        if new_description is None and labels_update is None:
            raise exceptions.Error('Nothing to update.')
        response = client.Patch(map_ref,
                                labels=labels_update,
                                description=new_description)
        response = util.WaitForOperation(response, is_async=args.async_)
        log.UpdatedResource(map_ref.Name(),
                            'certificate map',
                            is_async=args.async_)
        return response
  def Run(self, args):
    client = certificate_maps.CertificateMapClient()
    map_ref = args.CONCEPTS.map.Parse()

    console_io.PromptContinue(
        'You are about to delete certificate map \'{}\''.format(
            map_ref.certificateMapsId),
        throw_if_unattended=True,
        cancel_on_no=True)

    response = client.Delete(map_ref)

    response = util.WaitForOperation(response, is_async=args.async_)
    log.DeletedResource(map_ref.Name(), 'map', is_async=args.async_)
    return response
Esempio n. 3
0
    def Run(self, args):
        client = certificate_maps.CertificateMapClient()
        map_ref = args.CONCEPTS.map.Parse()
        location_ref = map_ref.Parent()
        labels = labels_util.ParseCreateArgs(
            args, client.messages.CertificateMap.LabelsValue)

        response = client.Create(location_ref,
                                 map_ref.certificateMapsId,
                                 description=args.description,
                                 labels=labels)
        operation_response = util.WaitForOperation(response,
                                                   is_async=args.async_)
        log.CreatedResource(map_ref.Name(),
                            'certificate map',
                            is_async=args.async_)
        return operation_response
    def Run(self, args):
        client = certificate_map_entries.CertificateMapEntryClient()
        entry_ref = args.CONCEPTS.entry.Parse()
        map_ref = entry_ref.Parent()
        cert_refs = args.CONCEPTS.certificates.Parse()
        labels = labels_util.ParseCreateArgs(
            args, client.messages.CertificateMapEntry.LabelsValue)

        response = client.Create(map_ref,
                                 entry_ref.certificateMapEntriesId,
                                 hostname=args.hostname,
                                 cert_refs=cert_refs,
                                 description=args.description,
                                 labels=labels)
        operation_response = util.WaitForOperation(response,
                                                   is_async=args.async_)
        log.CreatedResource(entry_ref.Name(),
                            'certificate map entry',
                            is_async=args.async_)
        return operation_response
Esempio n. 5
0
    def Run(self, args):
        client = certificates.CertificateClient()
        cert_ref = args.CONCEPTS.certificate.Parse()

        new_self_managed_cert_data = None
        # Certificate and private key files are marked as required flags in the
        # group, so no need to manually check situations when only one of them is
        # provided, gcloud should take care of it.
        if args.IsSpecified('certificate_file') and args.IsSpecified(
                'private_key_file'):
            new_self_managed_cert_data = client.messages.SelfManagedCertData(
                certificatePem=args.certificate_file.encode('utf-8'),
                privateKeyPem=args.private_key_file.encode('utf-8'),
            )

        new_description = None
        if args.IsSpecified('description'):
            new_description = args.description

        labels_update = None
        labels_diff = labels_util.Diff.FromUpdateArgs(args)
        if labels_diff.MayHaveUpdates():
            orig_resource = client.Get(cert_ref)
            labels_update = labels_diff.Apply(
                client.messages.Certificate.LabelsValue,
                orig_resource.labels).GetOrNone()

        if new_description is None and labels_update is None and new_self_managed_cert_data is None:
            raise exceptions.Error('Nothing to update.')
        response = client.Patch(
            cert_ref,
            self_managed_cert_data=new_self_managed_cert_data,
            labels=labels_update,
            description=new_description)
        response = util.WaitForOperation(response, is_async=args.async_)
        log.UpdatedResource(cert_ref.Name(),
                            'certificate',
                            is_async=args.async_)
        return response
Esempio n. 6
0
    def Run(self, args):
        client = certificates.CertificateClient()
        cert_ref = args.CONCEPTS.certificate.Parse()
        location_ref = cert_ref.Parent()
        labels = labels_util.ParseCreateArgs(
            args, client.messages.Certificate.LabelsValue)

        response = client.Create(
            location_ref,
            cert_ref.certificatesId,
            self_managed_cert_data=client.messages.SelfManagedCertData(
                certificatePem=args.certificate_file.encode('utf-8'),
                privateKeyPem=args.private_key_file.encode('utf-8'),
            ),
            description=args.description,
            labels=labels)
        operation_response = util.WaitForOperation(response,
                                                   is_async=args.async_)
        log.CreatedResource(cert_ref.Name(),
                            'certificate',
                            is_async=args.async_)
        return operation_response
Esempio n. 7
0
  def Run(self, args):
    client = certificate_map_entries.CertificateMapEntryClient()
    entry_ref = args.CONCEPTS.entry.Parse()

    new_description = None
    if args.IsSpecified('description'):
      new_description = args.description

    new_certs = None
    if args.IsSpecified('certificates'):
      new_certs = args.CONCEPTS.certificates.Parse()
      console_io.PromptContinue(
          'You are about to overwrite certificates from map entry \'{}\''
          .format(entry_ref.certificateMapEntriesId),
          throw_if_unattended=True,
          cancel_on_no=True)

    labels_update = None
    labels_diff = labels_util.Diff.FromUpdateArgs(args)
    if labels_diff.MayHaveUpdates():
      orig_resource = client.Get(entry_ref)
      labels_update = labels_diff.Apply(
          client.messages.CertificateMapEntry.LabelsValue,
          orig_resource.labels).GetOrNone()

    if new_description is None and labels_update is None and new_certs is None:
      raise exceptions.Error('Nothing to update.')
    response = client.Patch(
        entry_ref,
        labels=labels_update,
        description=new_description,
        cert_refs=new_certs)
    response = util.WaitForOperation(response, is_async=args.async_)
    log.UpdatedResource(
        entry_ref.Name(), 'certificate map entry', is_async=args.async_)
    return response