def AddSchemaSettingsFlags(parser):
    """Adds the flags for filling the SchemaSettings message.

  Args:
    parser: The argparse parser.
  """
    current_group = parser
    set_schema_settings_group = current_group.add_argument_group(
        help=
        """Schema settings. The schema that messages published to this topic must conform to and the expected message encoding."""
    )

    schema_help_text = (
        'that messages published to this topic must conform to.')
    schema = resource_args.CreateSchemaResourceArg(schema_help_text,
                                                   positional=False,
                                                   plural=False,
                                                   required=True)
    resource_args.AddResourceArgs(set_schema_settings_group, [schema])

    set_schema_settings_group.add_argument(
        '--message-encoding',
        type=arg_parsers.ArgList(element_type=lambda x: str(x).lower(),
                                 min_length=1,
                                 max_length=1,
                                 choices=['json', 'binary']),
        metavar='ENCODING',
        help="""The encoding of messages validated against the schema.""",
        required=True)
Пример #2
0
    def Args(cls, parser):

        # Create KMS key presentation spec.
        kms_flag_overrides = {
            'kms-key': '--topic-encryption-key',
            'kms-keyring': '--topic-encryption-key-keyring',
            'kms-location': '--topic-encryption-key-location',
            'kms-project': '--topic-encryption-key-project'
        }

        permission_info = """
    The specified CloudKMS key should have purpose set to "ENCRYPT_DECRYPT".
    The service account,
    "service-${CONSUMER_PROJECT_NUMBER}@gcp-sa-pubsub.iam.gserviceaccount.com"

    requires the IAM cryptoKeyEncrypterDecrypter role for the given CloudKMS key.
    CONSUMER_PROJECT_NUMBER is the project number of the project that is the parent of the
    topic being created"""

        kms_key_presentation_spec = kms_resource_args.GetKmsKeyPresentationSpec(
            'topic',
            flag_overrides=kms_flag_overrides,
            permission_info=permission_info)

        # Create Topic presentation spec.
        topic_presentation_spec = resource_args.CreateTopicResourceArg(
            'to create.', positional=True, plural=True)
        resource_args.AddResourceArgs(
            parser, [kms_key_presentation_spec, topic_presentation_spec])
        labels_util.AddCreateLabelsFlags(parser)
Пример #3
0
    def Args(parser):
        """Registers flags for this command."""
        resource_args.AddTopicResourceArg(parser, 'to update.')
        labels_util.AddUpdateLabelsFlags(parser)
        resource_args.AddResourceArgs(parser, [
            kms_resource_args.GetKmsKeyPresentationSpec(
                'topic',
                flag_overrides=_KMS_FLAG_OVERRIDES,
                permission_info=_KMS_PERMISSION_INFO)
        ])
        flags.AddTopicMessageRetentionFlags(parser, is_update=True)

        msp_group = parser.add_group(mutex=True,
                                     help='Message storage policy options.')
        msp_group.add_argument(
            '--recompute-message-storage-policy',
            action='store_true',
            help=
            'If given, Cloud Pub/Sub will recompute the regions where messages'
            ' can be stored at rest, based on your organization\'s "Resource '
            ' Location Restriction" policy.')
        msp_group.add_argument(
            '--message-storage-policy-allowed-regions',
            metavar='REGION',
            type=arg_parsers.ArgList(),
            help=
            'A list of one or more Cloud regions where messages are allowed to'
            ' be stored at rest.')
Пример #4
0
 def Args(cls, parser):
     topic_help_text = (
         'from which this subscription is receiving messages. '
         'Each subscription is attached to a single topic.')
     topic = resource_args.CreateTopicResourceArg(topic_help_text,
                                                  positional=False)
     subscription = resource_args.CreateSubscriptionResourceArg(
         'to create.', plural=True)
     resource_args.AddResourceArgs(parser, [topic, subscription])
     flags.AddSubscriptionSettingsFlags(parser, cls.ReleaseTrack())
Пример #5
0
 def Args(cls, parser):
   topic_help_text = ('from which this subscription is receiving messages. '
                      'Each subscription is attached to a single topic.')
   topic = resource_args.CreateTopicResourceArg(
       topic_help_text, positional=False)
   subscription = resource_args.CreateSubscriptionResourceArg(
       'to create.', plural=True)
   resource_args.AddResourceArgs(parser, [topic, subscription])
   flags.AddSubscriptionSettingsFlags(parser, support_message_ordering=True)
   labels_util.AddCreateLabelsFlags(parser)
Пример #6
0
  def Args(parser):
    resource_args.AddResourceArgs(
        parser, [_GetKmsKeyPresentationSpec(),
                 _GetTopicPresentationSpec()])
    labels_util.AddCreateLabelsFlags(parser)

    parser.add_argument(
        '--message-storage-policy-allowed-regions',
        metavar='REGION',
        type=arg_parsers.ArgList(),
        help='A list of one or more Cloud regions where messages are allowed to'
        ' be stored at rest.')
Пример #7
0
    def Args(cls, parser):

        # Create KMS key presentation spec.
        kms_flag_overrides = {
            'kms-key': '--topic-encryption-key',
            'kms-keyring': '--topic-encryption-key-keyring',
            'kms-location': '--topic-encryption-key-location',
            'kms-project': '--topic-encryption-key-project'
        }

        permission_info = """
    The specified CloudKMS key should have purpose set to "ENCRYPT_DECRYPT".
    The service account,
    "service-${CONSUMER_PROJECT_NUMBER}@gcp-sa-pubsub.iam.gserviceaccount.com"

    requires the IAM cryptoKeyEncrypterDecrypter role for the given CloudKMS key.
    CONSUMER_PROJECT_NUMBER is the project number of the project that is the parent of the
    topic being created"""

        kms_key_presentation_spec = kms_resource_args.GetKmsKeyPresentationSpec(
            'topic',
            flag_overrides=kms_flag_overrides,
            permission_info=permission_info)

        # Create Topic presentation spec.
        topic_presentation_spec = resource_args.CreateTopicResourceArg(
            'to create.', positional=True, plural=True)
        resource_args.AddResourceArgs(
            parser, [kms_key_presentation_spec, topic_presentation_spec])
        labels_util.AddCreateLabelsFlags(parser)
        parser.add_argument(
            '--message-storage-policy-allowed-regions',
            metavar='REGION',
            type=arg_parsers.ArgList(),
            help=
            'A list of one or more Cloud regions where messages are allowed to'
            ' be stored at rest.')
Пример #8
0
def AddSubscriptionSettingsFlags(parser, is_update=False):
    """Adds the flags for creating or updating a subscription.

  Args:
    parser: The argparse parser.
    is_update: Whether or not this is for the update operation (vs. create).
  """
    AddAckDeadlineFlag(parser)
    AddPushConfigFlags(parser)
    AddMessageRetentionFlags(parser, is_update)
    if not is_update:
        parser.add_argument(
            '--enable-message-ordering',
            action='store_true',
            default=None,
            help=
            """Whether to receive messages with the same ordering key in order.
            If set, messages with the same ordering key are sent to subscribers
            in the order that Pub/Sub receives them.""")
    if not is_update:
        parser.add_argument(
            '--message-filter',
            type=str,
            help=
            """Expression to filter messages. If set, Pub/Sub only delivers the
        messages that match the filter. The expression must be a non-empty
        string in the [Pub/Sub filtering
        language](https://cloud.google.com/pubsub/docs/filtering).""")
    current_group = parser
    if is_update:
        mutual_exclusive_group = current_group.add_mutually_exclusive_group()
        mutual_exclusive_group.add_argument(
            '--clear-dead-letter-policy',
            action='store_true',
            default=None,
            help=
            """If set, clear the dead letter policy from the subscription.""")
        current_group = mutual_exclusive_group

    set_dead_letter_policy_group = current_group.add_argument_group(
        help="""Dead Letter Queue Options. The Cloud Pub/Sub service account
           associated with the enclosing subscription's parent project (i.e.,
           service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com)
           must have permission to Publish() to this topic and Acknowledge()
           messages on this subscription.""")
    dead_letter_topic = resource_args.CreateTopicResourceArg(
        'to publish dead letter messages to.',
        flag_name='dead-letter-topic',
        positional=False,
        required=False)
    resource_args.AddResourceArgs(set_dead_letter_policy_group,
                                  [dead_letter_topic])
    set_dead_letter_policy_group.add_argument(
        '--max-delivery-attempts',
        type=arg_parsers.BoundedInt(5, 100),
        default=None,
        help="""Maximum number of delivery attempts for any message. The value
          must be between 5 and 100. Defaults to 5. `--dead-letter-topic`
          must also be specified.""")
    parser.add_argument(
        '--expiration-period',
        type=ParseExpirationPeriodWithNeverSentinel,
        help="""The subscription will expire if it is inactive for the given
          period. Valid values are strings of the form INTEGER[UNIT], where
          UNIT is one of "s", "m", "h", and "d" for seconds, minutes, hours,
          and days, respectively. If the unit is omitted, seconds is
          assumed. This flag additionally accepts the special value "never" to
          indicate that the subscription will never expire.""")

    current_group = parser
    if is_update:
        mutual_exclusive_group = current_group.add_mutually_exclusive_group()
        mutual_exclusive_group.add_argument(
            '--clear-retry-policy',
            action='store_true',
            default=None,
            help="""If set, clear the retry policy from the subscription.""")
        current_group = mutual_exclusive_group

    set_retry_policy_group = current_group.add_argument_group(
        help="""Retry Policy Options. Retry policy specifies how Cloud Pub/Sub
              retries message delivery for this subscription.""")

    set_retry_policy_group.add_argument(
        '--min-retry-delay',
        type=arg_parsers.Duration(lower_bound='0s', upper_bound='600s'),
        help="""The minimum delay between consecutive deliveries of a given
          message. Value should be between 0 and 600 seconds. Defaults to 10
          seconds. Valid values are strings of the form INTEGER[UNIT], where
          UNIT is one of "s", "m", "h", and "d" for seconds, minutes, hours,
          and days, respectively. If the unit is omitted, seconds is
          assumed.""")
    set_retry_policy_group.add_argument(
        '--max-retry-delay',
        type=arg_parsers.Duration(lower_bound='0s', upper_bound='600s'),
        help="""The maximum delay between consecutive deliveries of a given
          message. Value should be between 0 and 600 seconds. Defaults to 10
          seconds. Valid values are strings of the form INTEGER[UNIT], where
          UNIT is one of "s", "m", "h", and "d" for seconds, minutes, hours,
          and days, respectively. If the unit is omitted, seconds is
          assumed.""")
def AddSubscriptionSettingsFlags(parser,
                                 is_update=False,
                                 support_enable_exactly_once_delivery=False):
    """Adds the flags for creating or updating a subscription.

  Args:
    parser: The argparse parser.
    is_update: Whether or not this is for the update operation (vs. create).
    support_enable_exactly_once_delivery: Whether or not this should support
      enable_exactly_once_delivery
  """
    AddAckDeadlineFlag(parser)
    AddPushConfigFlags(parser)
    AddBigQueryConfigFlags(parser, is_update)
    AddSubscriptionMessageRetentionFlags(parser, is_update)
    if not is_update:
        parser.add_argument(
            '--enable-message-ordering',
            action='store_true',
            default=None,
            help=
            """Whether to receive messages with the same ordering key in order.
            If set, messages with the same ordering key are sent to subscribers
            in the order that Pub/Sub receives them.""")
    if not is_update:
        parser.add_argument(
            '--message-filter',
            type=str,
            help=
            """Expression to filter messages. If set, Pub/Sub only delivers the
        messages that match the filter. The expression must be a non-empty
        string in the [Pub/Sub filtering
        language](https://cloud.google.com/pubsub/docs/filtering).""")
    current_group = parser
    if is_update:
        mutual_exclusive_group = current_group.add_mutually_exclusive_group()
        mutual_exclusive_group.add_argument(
            '--clear-dead-letter-policy',
            action='store_true',
            default=None,
            help=
            """If set, clear the dead letter policy from the subscription.""")
        current_group = mutual_exclusive_group

    set_dead_letter_policy_group = current_group.add_argument_group(
        help="""Dead Letter Queue Options. The Cloud Pub/Sub service account
           associated with the enclosing subscription's parent project (i.e.,
           service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com)
           must have permission to Publish() to this topic and Acknowledge()
           messages on this subscription.""")
    dead_letter_topic = resource_args.CreateTopicResourceArg(
        'to publish dead letter messages to.',
        flag_name='dead-letter-topic',
        positional=False,
        required=False)
    resource_args.AddResourceArgs(set_dead_letter_policy_group,
                                  [dead_letter_topic])
    set_dead_letter_policy_group.add_argument(
        '--max-delivery-attempts',
        type=arg_parsers.BoundedInt(5, 100),
        default=None,
        help="""Maximum number of delivery attempts for any message. The value
          must be between 5 and 100. Defaults to 5. `--dead-letter-topic`
          must also be specified.""")
    parser.add_argument(
        '--expiration-period',
        type=ParseExpirationPeriodWithNeverSentinel,
        help="""The subscription will expire if it is inactive for the given
          period. {} This flag additionally accepts the special value "never" to
          indicate that the subscription will never expire.""".format(
            DURATION_HELP_STR))

    current_group = parser
    if is_update:
        mutual_exclusive_group = current_group.add_mutually_exclusive_group()
        mutual_exclusive_group.add_argument(
            '--clear-retry-policy',
            action='store_true',
            default=None,
            help="""If set, clear the retry policy from the subscription.""")
        current_group = mutual_exclusive_group

    set_retry_policy_group = current_group.add_argument_group(
        help="""Retry Policy Options. Retry policy specifies how Cloud Pub/Sub
              retries message delivery for this subscription.""")

    set_retry_policy_group.add_argument(
        '--min-retry-delay',
        type=arg_parsers.Duration(lower_bound='0s', upper_bound='600s'),
        help="""The minimum delay between consecutive deliveries of a given
          message. Value should be between 0 and 600 seconds. Defaults to 10
          seconds. {}""".format(DURATION_HELP_STR))
    set_retry_policy_group.add_argument(
        '--max-retry-delay',
        type=arg_parsers.Duration(lower_bound='0s', upper_bound='600s'),
        help="""The maximum delay between consecutive deliveries of a given
          message. Value should be between 0 and 600 seconds. Defaults to 10
          seconds. {}""".format(DURATION_HELP_STR))
    if support_enable_exactly_once_delivery:
        help_text_suffix = ''
        if is_update:
            help_text_suffix = (' To disable exactly-once delivery use '
                                '`--no-enable-exactly-once-delivery`.')
        parser.add_argument('--enable-exactly-once-delivery',
                            action='store_true',
                            default=None,
                            help="""\
            Whether or not to enable exactly-once delivery on the subscription.
            If true, Pub/Sub provides the following guarantees for the delivery
            of a message with a given value of `message_id` on this
            subscription: The message sent to a subscriber is guaranteed not to
            be resent before the message's acknowledgment deadline expires. An
            acknowledged message will not be resent to a subscriber.""" +
                            help_text_suffix)
Пример #10
0
 def Args(cls, parser):
     resource_args.AddResourceArgs(
         parser,
         [_GetKmsKeyPresentationSpec(),
          _GetTopicPresentationSpec()])
     labels_util.AddCreateLabelsFlags(parser)
Пример #11
0
def AddSubscriptionSettingsFlags(parser,
                                 is_update=False,
                                 support_message_ordering=False,
                                 support_filtering=False):
  """Adds the flags for creating or updating a subscription.

  Args:
    parser: The argparse parser.
    is_update: Whether or not this is for the update operation (vs. create).
    support_message_ordering: Whether or not flags for ordering should be added.
    support_filtering: Whether or not flags for filtering should be added.
  """
  AddAckDeadlineFlag(parser)
  AddPushConfigFlags(parser)
  AddMessageRetentionFlags(parser, is_update)
  if support_message_ordering and not is_update:
    parser.add_argument(
        '--enable-message-ordering',
        action='store_true',
        default=None,
        help="""Whether or not to receive messages with the same ordering key in
            order. If true, messages with the same ordering key will by sent to
            subscribers in the order in which they were received by Cloud
            Pub/Sub.""")
  if support_filtering and not is_update:
    parser.add_argument(
        '--filter',
        type=str,
        help="""A non-empty string written in the Cloud Pub/Sub filter
            language. This feature is part of an invitation-only alpha
            release.""")
  current_group = parser
  if is_update:
    mutual_exclusive_group = current_group.add_mutually_exclusive_group()
    mutual_exclusive_group.add_argument(
        '--clear-dead-letter-policy',
        action='store_true',
        default=None,
        help="""If set, clear the dead letter policy from the subscription.""")
    current_group = mutual_exclusive_group

  set_dead_letter_policy_group = current_group.add_argument_group(
      help="""Dead Letter Queue Options. The Cloud Pub/Sub service account
           associated with the enclosing subscription's parent project (i.e.,
           service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com)
           must have permission to Publish() to this topic and Acknowledge()
           messages on this subscription.""")
  dead_letter_topic = resource_args.CreateTopicResourceArg(
      'to publish dead letter messages to.',
      flag_name='dead-letter-topic',
      positional=False,
      required=False)
  resource_args.AddResourceArgs(set_dead_letter_policy_group,
                                [dead_letter_topic])
  set_dead_letter_policy_group.add_argument(
      '--max-delivery-attempts',
      type=arg_parsers.BoundedInt(5, 100),
      default=None,
      help="""Maximum number of delivery attempts for any message. The value
          must be between 5 and 100. Defaults to 5. `--dead-letter-topic`
          must also be specified.""")
  parser.add_argument(
      '--expiration-period',
      type=ParseExpirationPeriodWithNeverSentinel,
      help="""The subscription will expire if it is inactive for the given
          period. Valid values are strings of the form INTEGER[UNIT], where
          UNIT is one of "s", "m", "h", and "d" for seconds, minutes, hours,
          and days, respectively. If the unit is omitted, seconds is
          assumed. This flag additionally accepts the special value "never" to
          indicate that the subscription will never expire.""")