Ejemplo n.º 1
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))
Ejemplo 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:
      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()