GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add support for storage->pubsub notifications · Issue #3956 · googleapis/google-cloud-python

Add support for storage->pubsub notifications #3956

New issue
Copy link
New issue
Copy link
Closed
Closed
Add support for storage->pubsub notifications#3956
Copy link
Assignees
tseaver
Labels
api: storageIssues related to the Cloud Storage API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Description

@tseaver
tseaver
opened on Sep 14, 2017
Issue body actions

See the concepts doc and the registering object changes doc.

Pull requests target the 3956-storage-notifications branch

Steps:

  • Add a BucketNotification class, mapping the notification resource. Note that a BucketNotification may point to a topic which belongs to a different project than the one which owns its bucket. (Add 'BucketNotification' class. #3957)
  • Add Bucket.notification factory. returning new BucketNotification. (Add 'Bucket.notification' factory #3958)
  • Add BucketNotification.create method, mapping notifications/insert. Update the bucket's properties from the response (e.g., to get its server-generated ID). Should we barf if the ID is already set? (Add 'BucketNotification.create' API wrapper. #3966)
  • Add BucketNotification.delete method, mapping notifications/delete. Presumably barf if the ID is not set. (Add 'BucketNotification.delete' API wrapper. #3983)
  • Add BucketNotification.exists method, mapping notifications/get onto boolean (False for NotFound). Presumably barf if the ID is not set. (Add 'BucketNotification.exists' API wrapper. #3984)
  • Add BucketNotification.reload method, mapping notifications/get, Presumably barf if the ID is not set. (Add 'BucketNotification.reload' API wrapper. #3986)
  • Add Bucket.list_notifications method, mapping notifications/list. Return an iterator of BucketNotification instances. (Add 'Bucket.list_notifications' API wrapper. #3990)
  • Add a system test which exercises the new API wrapper methods. (Add system tests for bucket notifications. #4021)

Questions:

  • Do we need to support de novo creation of BucketNotfication instances w/ a user-supplied ID? The spec says that the ID is generated during notifications/insert, which suggests not.
  • I assume that access to the new features does not depend on being able to import google.cloud.pubsub. The counter-example would be that BucketNotification.create must verify the existence of its topic, and maybe create a new one. Or does the back-end do that? The docs say that a topic is created if it does not exist.
  • There is no documented support for update / patch of existing notifications. Is that intentional?
  • What are the intended semantics of passing {'payload_format`: 'NONE'}? I don't think subscribers will find message with an empty payload useful, so I must be misunderstanding something. Do the non-payload attributes provide enough information for the subscriber to do something useful?

/cc @lukesneeringer, perhaps to loop in the appropriate GCS back-end contact.

Activity

Next
  1. tseaver
    added
    api: storageIssues related to the Cloud Storage API.
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    on Sep 14, 2017
  2. tseaver
    self-assigned this
    on Sep 14, 2017
  3. tseaver commented on Sep 14, 2017

    @tseaver
    tseaver
    on Sep 14, 2017
    ContributorAuthor
    More actions

    Another question: do we need a "round trip" system test? E.g., one which verifies that notifications arrive at the subscriber? Or can we get away with just doing BucketNotification CRUD in the system tests?

  4. tseaver
    added 4 commits that reference this issue on Sep 15, 2017

    Add 'BucketNotification' class. (#3957)

    71dff99

    Add 'Bucket.notification' factory. (#3958)

    327347e

    Add 'BucketNotification.create' API wrapper. (#3966)

    49b6e7d

    Add 'BucketNotification.delete' API wrapper. (#3983)

    0a2a40f
  5. BrandonY commented on Sep 18, 2017

    @BrandonY
    BrandonY
    on Sep 18, 2017
    Contributor
    More actions

    Hi @tseaver,

    Answers to questions:

    Do we need to support de novo creation of BucketNotfication instances w/ a user-supplied ID? The spec says that the ID is generated during notifications/insert, which suggests not.

    Indeed, GCS will generate IDs for you.

    I assume that access to the new features does not depend on being able to import google.cloud.pubsub. The counter-example would be that BucketNotification.create must verify the existence of its topic, and maybe create a new one. Or does the back-end do that? The docs say that a topic is created if it does not exist.

    GCS will not create a Cloud Pub/Sub topic for you if one does not exist. It will, though, check to see if the topic you specify exists and permissions have been appropriately configured for GCS to be able to publish topics to it, and the call to create a subscription will fail if either of these two requirements are not met. The "gsutil" command-line utility will, on the client side, create a topic if it does not exist.

    I suggest a similar, single "subscribe()" command exist, that fetches the correct robot name, attaches appropriate permissions for it to a Pub/Sub topic (and maybe creates that topic), and then creates the subscription. Otherwise pretty much every user will have to write out that same chain of commands.

    There is no documented support for update / patch of existing notifications. Is that intentional?

    Yes. Subscriptions cannot be modified. They can only be deleted and created.

    What are the intended semantics of passing {'payload_format`: 'NONE'}? I don't think subscribers will find message with an empty payload useful, so I must be misunderstanding something. Do the non-payload attributes provide enough information for the subscriber to do something useful?

    The attributes provide enough information to accomplish most tasks. They tell you the event that happened (an object was created, an object was deleted), and they also tell you which object it happened to and when. The payload may be useful if you want to see, for instance, the object's type or its size, but it's not necessary in many cases.

    Another question: do we need a "round trip" system test? E.g., one which verifies that notifications arrive at the subscriber? Or can we get away with just doing BucketNotification CRUD in the system tests?

    A round trip test would be ideal, but getting back a successful "subscription created" message from GCS is a good sign that you've done things correctly.

  6. tseaver
    added a commit that references this issue on Sep 18, 2017

    Add 'BucketNotification.{reload,exists}' API wrappers. (#3986)

    7190c86
  7. tseaver commented on Sep 18, 2017

    @tseaver
    tseaver
    on Sep 18, 2017
    ContributorAuthor
    More actions

    @lukesneeringer Working on system tests for the feature, and running into permissions errors:

    Traceback (most recent call last):
      File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/storage/tests/system.py", line 609, in test_notification_minimal
        self.assertTrue(notification.exists())
      File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/storage/.nox/sys-3-6/lib/python3.6/site-packages/test_utils/retry.py", line 95, in wrapped_function
        return to_wrap(*args, **kwargs)
      File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/storage/google/cloud/storage/notification.py", line 243, in create
        data=properties,
      File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/storage/.nox/sys-3-6/lib/python3.6/site-packages/google/cloud/_http.py", line 293, in api_request
        raise exceptions.from_http_response(response)
    google.api.core.exceptions.Forbidden: 403 POST https://www.googleapis.com/storage/v1/b/notification-minimal-1505764404665/notificationConfigs: The service account '[email protected]' does not have permission to publish messages to to the Cloud Pub/Sub topic '//pubsub.googleapis.com/projects/precise-truck-742/topics/notification-1505764383884', or that topic does not exist.

    Does the feature require whitelisting? The docs say that the notifications/insert API will create the topic if needed: I changed the test to create it, without changing the error.

  8. BrandonY commented on Sep 18, 2017

    @BrandonY
    BrandonY
    on Sep 18, 2017
    Contributor
    More actions

    You cannot create a notification to publish to a given Cloud Pub/Sub topic until the following conditions are met:
    1.) the topic exists.
    2.) the GCS service account associated with the project that owns this bucket has permission to publish to that topic.

    GCS enforces this constraint, which is what you're seeing. The error message is correct.

  9. tseaver commented on Sep 20, 2017

    @tseaver
    tseaver
    on Sep 20, 2017
    ContributorAuthor
    More actions

    @BrandonY thanks for the followup. Two points:

    • The docs for enabling notification say:

    If you use a [TOPIC_NAME] that doesn't exist in your project, one is created for you.

    I'm guessing that the described behavior is a feature of the gsutil notification create subcommand, rather than the notifications/insert API.

    • I see that error message even when I precreate the topic using the same service account as the one used to create the bucket, and which I'm using to attempt to invoke notifications/insert. I can successfully verify that the account has the 'pubsub.topics.publish` permission on that topic, e.g.:
    (pdb)  pp self.publisher_client.test_iam_permissions(self.topic_path, ['pubsub.topics.publish'])
    permissions: "pubsub.topics.publish"
  10. dhermes commented on Sep 20, 2017

    @dhermes
    dhermes
    on Sep 20, 2017
    Contributor
    More actions

    @tseaver If you're using gsutil to understand the behavior, you can actually log the requests made (as well as the payloads sent and received).

  11. tseaver commented on Sep 20, 2017

    @tseaver
    tseaver
    on Sep 20, 2017
    ContributorAuthor
    More actions

    @dhermes I'm not running gsutil: I'm reading docs.

  12. 4 remaining items

  13. BrandonY commented on Sep 21, 2017

    @BrandonY
    BrandonY
    on Sep 21, 2017
    Contributor
    More actions

    Hi @tseaver,

    GCS will not create a topic for you if one does not exist.

    I believe you're looking at the instructions under the "gsutil" tab. It is true that the gsutil program will create a topic if you do not specify one. If you click the other tab header, JSON API, you should not see that text.

    That is a bit confusing, though. I'll see about changing that bit of doc.

  14. tseaver commented on Sep 21, 2017

    @tseaver
    tseaver
    on Sep 21, 2017
    ContributorAuthor
    More actions

    @BrandonY thanks for the follow-up.

    I had decided already that auto-creation of the topic was not an API feature. The system tests I am working on create the topic before creating the bucket: they then attempts to create the notification, but fail with the 403.

    The Ruby and PHP guys implementing the feature followed up on my query. Maybe their phrasing makes the issue clearer?

  15. tseaver commented on Sep 22, 2017

    @tseaver
    tseaver
    on Sep 22, 2017
    ContributorAuthor
    More actions

    @BrandonY 7d9ee94 adds the binding to the topic's IAM policy, required to enable creating the notifications. Those system tests are now passing.

  16. tseaver commented on Sep 22, 2017

    @tseaver
    tseaver
    on Sep 22, 2017
    ContributorAuthor
    More actions

    @BrandonY re: round-trip tests. The concept docs say:

    When you add a notification configuration, Cloud Storage may take up to 30 seconds to begin sending notifications associated with it.

    That makes writing a non-flaky system test for the round-trip a good deal harder: how can we know when the notification is active?

  17. BrandonY commented on Sep 22, 2017

    @BrandonY
    BrandonY
    on Sep 22, 2017
    Contributor
    More actions

    Yes, the service account for the project must have permission to publish to the topic before the call to create the subscription will succeed.

    Writing a system test that obeys this constraint will require waiting 30 seconds after you create a notification before verifying that changes are being received by Cloud Pub/Sub. In practice, you can probably get away with 10-15 seconds.

  18. tseaver
    added 6 commits that reference this issue on Sep 25, 2017

    Add 'BucketNotification' class. (#3957)

    8df3da8

    Add 'Bucket.notification' factory. (#3958)

    fcdcf20

    Add 'BucketNotification.create' API wrapper. (#3966)

    41b1c26

    Add 'BucketNotification.delete' API wrapper. (#3983)

    6f3c1e0

    Add 'BucketNotification.{reload,exists}' API wrappers. (#3986)

    2293eda

    Add 'Bucket.list_notifications' API wrapper. (#3990)

    352aeed
  19. tseaver
    closed this as completedin #4127on Oct 10, 2017
  20. tseaver
    added a commit that references this issue on Oct 10, 2017

    Add support for bucket notifications (#4127)

    This issue will close once commit ce7afe6 is merged into the 'main' branch.
    ce7afe6
  21. parthea
    added a commit that references this issue on Sep 22, 2023

    chore: move samples from python-docs-sample (#33)

    69c4425
  22. parthea
    added a commit that references this issue on Mar 9, 2026

    Add support for bucket notifications (#4127)

    This issue will close once commit ad893db is merged into the 'main' branch.
    ad893db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @tseaver
    tseaver

Labels

api: storageIssues related to the Cloud Storage API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.