def main():
    parser = get_parser()
    args = parser.parse_args()
    bucket_name = args.bucket_name
    topic = args.topic
    project_id = args.project_id

    storage_client = storage.Client()
    bucket = storage_client.get_bucket(bucket_name)

    bn = BucketNotification(bucket=bucket,
                            topic_name=topic,
                            topic_project=project_id,
                            event_types=["OBJECT_FINALIZE"],
                            payload_format="JSON_API_V1")
    bn.create()
Beispiel #2
0
def _item_to_notification(iterator, item):
    """Convert a JSON blob to the native object.

    .. note::

        This assumes that the ``bucket`` attribute has been
        added to the iterator after being created.

    :type iterator: :class:`~google.api_core.page_iterator.Iterator`
    :param iterator: The iterator that has retrieved the item.

    :type item: dict
    :param item: An item to be converted to a blob.

    :rtype: :class:`.BucketNotification`
    :returns: The next notification being iterated.
    """
    return BucketNotification.from_api_repr(item, bucket=iterator.bucket)
Beispiel #3
0
def _item_to_notification(iterator, item):
    """Convert a JSON blob to the native object.

    .. note::

        This assumes that the ``bucket`` attribute has been
        added to the iterator after being created.

    :type iterator: :class:`~google.api_core.page_iterator.Iterator`
    :param iterator: The iterator that has retrieved the item.

    :type item: dict
    :param item: An item to be converted to a blob.

    :rtype: :class:`.BucketNotification`
    :returns: The next notification being iterated.
    """
    return BucketNotification.from_api_repr(item, bucket=iterator.bucket)
    def notification(self, topic_name,
                     topic_project=None,
                     custom_attributes=None,
                     event_types=None,
                     blob_name_prefix=None,
                     payload_format=NONE_PAYLOAD_FORMAT):
        """Factory:  create a notification resource for the bucket.

        See: :class:`.BucketNotification` for parameters.

        :rtype: :class:`.BucketNotification`
        """
        return BucketNotification(
            self, topic_name,
            topic_project=topic_project,
            custom_attributes=custom_attributes,
            event_types=event_types,
            blob_name_prefix=blob_name_prefix,
            payload_format=payload_format,
        )