def Run(self, args):
        """This is what gets called when the user runs this command.

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

    Yields:
      Subscription paths that match the regular expression in args.name_filter.

    Raises:
      sdk_ex.HttpException if there is an error with the regular
      expression syntax.
    """
        msgs = self.context['pubsub_msgs']
        pubsub = self.context['pubsub']

        page_token = None
        subscriptions_listed = 0
        should_truncate_res = args.max_results and not args.name_filter

        try:
            while True:
                list_subscriptions_req = msgs.PubsubProjectsSubscriptionsListRequest(
                    project=util.ProjectFormat(), pageToken=page_token)

                if should_truncate_res:
                    list_subscriptions_req.pageSize = min(
                        args.max_results, util.MAX_LIST_RESULTS)

                list_subscriptions_response = pubsub.projects_subscriptions.List(
                    list_subscriptions_req)

                for subscription in list_subscriptions_response.subscriptions:
                    if not util.SubscriptionMatches(subscription.name,
                                                    args.name_filter):
                        continue

                    # If max_results > 0 and we have already sent that
                    # amount of subscriptions, just raise (StopIteration) iff name_filter
                    # is not set, else this limit wouldn't make sense.
                    if should_truncate_res and subscriptions_listed >= args.max_results:
                        raise StopIteration()

                    subscriptions_listed += 1
                    yield subscription

                page_token = list_subscriptions_response.nextPageToken
                if not page_token:
                    break

        except re.error as e:
            raise sdk_ex.HttpException(str(e))
Esempio n. 2
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

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

    Yields:
      Subscription paths that match the regular expression in args.name_filter.

    Raises:
      sdk_ex.HttpException if there is an error with the regular
      expression syntax.
    """
        msgs = self.context['pubsub_msgs']
        pubsub = self.context['pubsub']

        page_token = None
        if args.page_size:
            page_size = min(args.page_size, util.MAX_LIST_RESULTS)
        else:
            page_size = None
        if not args.filter and args.limit:
            page_size = min(args.limit, page_size or util.MAX_LIST_RESULTS)

        try:
            while True:
                list_subscriptions_req = msgs.PubsubProjectsSubscriptionsListRequest(
                    project=util.ProjectFormat(),
                    pageToken=page_token,
                    pageSize=page_size)

                list_subscriptions_response = pubsub.projects_subscriptions.List(
                    list_subscriptions_req)

                for subscription in list_subscriptions_response.subscriptions:
                    yield SubscriptionDict(subscription)

                page_token = list_subscriptions_response.nextPageToken
                if not page_token:
                    break
                yield resource_printer_base.PageMarker()

        except re.error as e:
            raise sdk_ex.HttpException(str(e))
Esempio n. 3
0
  def Run(self, args):
    """This is what gets called when the user runs this command.

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

    Yields:
      Topic paths that match the regular expression in args.name_filter.
    """
    msgs = self.context['pubsub_msgs']
    pubsub = self.context['pubsub']

    page_size = None
    page_token = None

    if args.page_size:
      page_size = min(args.page_size, util.MAX_LIST_RESULTS)

    if not args.filter and args.limit:
      page_size = min(args.limit, page_size or util.MAX_LIST_RESULTS)

    while True:
      list_topics_request = msgs.PubsubProjectsTopicsListRequest(
          project=util.ProjectFormat(),
          pageToken=page_token,
          pageSize=page_size)

      list_topics_response = pubsub.projects_topics.List(
          list_topics_request)

      for topic in list_topics_response.topics:
        yield TopicDict(topic)

      page_token = list_topics_response.nextPageToken
      if not page_token:
        break
      yield resource_printer_base.PageMarker()