|
| 1 | +// Copyright 2020 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +'use strict'; |
| 16 | + |
| 17 | +/** |
| 18 | + * This application demonstrates how to perform basic operations on files with |
| 19 | + * the Google Cloud Storage API. |
| 20 | + * |
| 21 | + * For more information, see the README.md under /storage and the documentation |
| 22 | + * at https://cloud.google.com/storage/docs. |
| 23 | + */ |
| 24 | + |
| 25 | +function main(bucketName = 'my-bucket', notificationId = '1') { |
| 26 | + // [START storage_print_pubsub_bucket_notification] |
| 27 | + /** |
| 28 | + * TODO(developer): Uncomment the following lines before running the sample. |
| 29 | + */ |
| 30 | + // The ID of your GCS bucket |
| 31 | + // const bucketName = 'your-unique-bucket-name'; |
| 32 | + |
| 33 | + // The ID of the notification |
| 34 | + // const notificationId = '1'; |
| 35 | + |
| 36 | + // Imports the Google Cloud client library |
| 37 | + const {Storage} = require('@google-cloud/storage'); |
| 38 | + |
| 39 | + // Creates a client |
| 40 | + const storage = new Storage(); |
| 41 | + |
| 42 | + async function getMetadata() { |
| 43 | + try { |
| 44 | + // Get the notification metadata |
| 45 | + const [metadata] = await storage |
| 46 | + .bucket(bucketName) |
| 47 | + .notification(notificationId) |
| 48 | + .getMetadata(); |
| 49 | + |
| 50 | + console.log(`ID: ${metadata.id}`); |
| 51 | + console.log(`Topic: ${metadata.topic}`); |
| 52 | + console.log(`Event Types: ${metadata.event_types}`); |
| 53 | + console.log(`Custom Attributes: ${metadata.custom_attributes}`); |
| 54 | + console.log(`Payload Format: ${metadata.payload_format}`); |
| 55 | + console.log(`Object Name Prefix: ${metadata.object_name_prefix}`); |
| 56 | + console.log(`Etag: ${metadata.etag}`); |
| 57 | + console.log(`Self Link: ${metadata.selfLink}`); |
| 58 | + console.log(`Kind: ${metadata.kind}`); |
| 59 | + } catch (error) { |
| 60 | + console.error('Error executing get metadata:', error.message || error); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + getMetadata(); |
| 65 | + // [END storage_print_pubsub_bucket_notification] |
| 66 | +} |
| 67 | +main(...process.argv.slice(2)); |
0 commit comments