OXIESEC PANEL
- Current Dir:
/
/
opt
/
gsutil
/
gslib
/
commands
/
__pycache__
Server IP: 2a02:4780:11:1594:0:ef5:22d7:a
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/11/2025 08:19:49 AM
rwxr-xr-x
📄
__init__.cpython-39.pyc
323 bytes
02/11/2025 08:19:49 AM
rw-r--r--
📄
acl.cpython-39.pyc
18.76 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
autoclass.cpython-39.pyc
6.01 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
bucketpolicyonly.cpython-39.pyc
6.75 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
cat.cpython-39.pyc
4.17 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
compose.cpython-39.pyc
4.57 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
config.cpython-39.pyc
40.97 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
cors.cpython-39.pyc
6.56 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
cp.cpython-39.pyc
42.21 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
defacl.cpython-39.pyc
11.25 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
defstorageclass.cpython-39.pyc
5.78 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
du.cpython-39.pyc
8.47 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
hash.cpython-39.pyc
7.87 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
help.cpython-39.pyc
6.41 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
hmac.cpython-39.pyc
12.39 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
iam.cpython-39.pyc
24.6 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
kms.cpython-39.pyc
14.88 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
label.cpython-39.pyc
10.46 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
lifecycle.cpython-39.pyc
6.37 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
logging.cpython-39.pyc
9.04 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
ls.cpython-39.pyc
18.81 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
mb.cpython-39.pyc
12.23 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
mv.cpython-39.pyc
5.06 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
notification.cpython-39.pyc
25.47 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
pap.cpython-39.pyc
6.53 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
perfdiag.cpython-39.pyc
62.18 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
rb.cpython-39.pyc
3.78 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
requesterpays.cpython-39.pyc
5.53 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
retention.cpython-39.pyc
20.02 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
rewrite.cpython-39.pyc
16.12 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
rm.cpython-39.pyc
10.86 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
rpo.cpython-39.pyc
5.96 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
rsync.cpython-39.pyc
53.86 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
setmeta.cpython-39.pyc
11.25 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
signurl.cpython-39.pyc
20.99 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
stat.cpython-39.pyc
5.04 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
test.cpython-39.pyc
17.73 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
ubla.cpython-39.pyc
6.96 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
update.cpython-39.pyc
12.26 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
version.cpython-39.pyc
5.25 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
versioning.cpython-39.pyc
5.51 KB
02/11/2025 08:19:49 AM
rw-r--r--
📄
web.cpython-39.pyc
7.63 KB
02/11/2025 08:19:49 AM
rw-r--r--
Editing: notification.cpython-39.pyc
Close
a +(WgŇ � @ s d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlZddlZddl Z ddl m Z ddlmZ dd l mZ dd l mZ ddl mZ ddlmZ dd lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z% ddl$m&Z& ddl'm(Z( ddl'm)Z) dZ*dZ+dZ,dZ-dZ.e,e+�/d� e*�/d� e- e.�/d� d Z0d Z1d!Z2d"Z3d#Z4d$Z5d%e3 e1 e2 d& e4 e5 d'j6e%j7d(� Z8d)Z9ee0e8�Z:ee,e3�Z;ee*e1�Z<ee+e2�Z=ee-e4�Z>ee.e5�Z?d*d+d,�Z@G d-d.� d.e�ZAdS )/z8This module provides the notification command to gsutil.� )�absolute_import)�print_function)�division)�unicode_literalsN)�datetime)�metrics)�AccessDeniedException)�NotFoundException)� PublishPermissionDeniedException)�Command)�NO_MAX)�CommandArgument)�ApiSelector)�CommandException)�CreateHelpText)�PopulateProjectId)� PubsubApi)�StorageUrlFromString)�Binding)�copy_helper)� shim_util)�GcloudStorageFlag)�GcloudStorageMapz2 gsutil notification list gs://<bucket_name>... zO gsutil notification delete (<notificationConfigName>|gs://<bucket_name>)... z� gsutil notification create -f (json|none) [-p <prefix>] [-t <topic>] \ [-m <key>:<value>]... [-e <eventType>]... gs://<bucket_name> zW gsutil notification watchbucket [-i <id>] [-t <token>] <app_url> gs://<bucket_name> z> gsutil notification stopchannel <channel_id> <resource_id> � a� <B>LIST</B> The list sub-command provides a list of notification configs belonging to a given bucket. The listed name of each notification config can be used with the delete sub-command to delete that specific notification config. For listing Object Change Notifications instead of Cloud Pub/Sub notification subscription configs, add a -o flag. <B>LIST EXAMPLES</B> Fetch the list of notification configs for the bucket example-bucket: gsutil notification list gs://example-bucket The same as above, but for Object Change Notifications instead of Cloud Pub/Sub notification subscription configs: gsutil notification list -o gs://example-bucket Fetch the notification configs in all buckets matching a wildcard: gsutil notification list gs://example-* Fetch all of the notification configs for buckets in the default project: gsutil notification list gs://* a� <B>DELETE</B> The delete sub-command deletes notification configs from a bucket. If a notification config name is passed as a parameter, that notification config alone is deleted. If a bucket name is passed, all notification configs associated with that bucket are deleted. Cloud Pub/Sub topics associated with this notification config are not deleted by this command. Those must be deleted separately, for example with the gcloud command `gcloud beta pubsub topics delete`. Object Change Notification subscriptions cannot be deleted with this command. For that, see the command `gsutil notification stopchannel`. <B>DELETE EXAMPLES</B> Delete a single notification config (with ID 3) in the bucket example-bucket: gsutil notification delete projects/_/buckets/example-bucket/notificationConfigs/3 Delete all notification configs in the bucket example-bucket: gsutil notification delete gs://example-bucket a� <B>CREATE</B> The create sub-command creates a notification config on a bucket, establishing a flow of event notifications from Cloud Storage to a Cloud Pub/Sub topic. As part of creating this flow, the create command also verifies that the destination Cloud Pub/Sub topic exists, creating it if necessary, and verifies that the Cloud Storage bucket has permission to publish events to that topic, granting the permission if necessary. If a destination Cloud Pub/Sub topic is not specified with the -t flag, Cloud Storage chooses a topic name in the default project whose ID is the same as the bucket name. For example, if the default project ID specified is 'default-project' and the bucket being configured is gs://example-bucket, the create command uses the Cloud Pub/Sub topic "projects/default-project/topics/example-bucket". In order to enable notifications, your project's `Cloud Storage service agent <https://cloud.google.com/storage/docs/projects#service-accounts>`_ must have the IAM permission "pubsub.topics.publish". This command checks to see if the destination Cloud Pub/Sub topic grants the service agent this permission. If not, the create command attempts to grant it. A bucket can have up to 100 total notification configurations and up to 10 notification configurations set to trigger for a specific event. <B>CREATE EXAMPLES</B> Begin sending notifications of all changes to the bucket example-bucket to the Cloud Pub/Sub topic projects/default-project/topics/example-bucket: gsutil notification create -f json gs://example-bucket The same as above, but specifies the destination topic ID 'files-to-process' in the default project: gsutil notification create -f json \ -t files-to-process gs://example-bucket The same as above, but specifies a Cloud Pub/Sub topic belonging to the specific cloud project 'example-project': gsutil notification create -f json \ -t projects/example-project/topics/files-to-process gs://example-bucket Create a notification config that only sends an event when a new object has been created: gsutil notification create -f json -e OBJECT_FINALIZE gs://example-bucket Create a topic and notification config that only sends an event when an object beginning with "photos/" is affected: gsutil notification create -p photos/ gs://example-bucket List all of the notificationConfigs in bucket example-bucket: gsutil notification list gs://example-bucket Delete all notitificationConfigs for bucket example-bucket: gsutil notification delete gs://example-bucket Delete one specific notificationConfig for bucket example-bucket: gsutil notification delete \ projects/_/buckets/example-bucket/notificationConfigs/1 <B>OPTIONS</B> The create sub-command has the following options -e Specify an event type filter for this notification config. Cloud Storage only sends notifications of this type. You may specify this parameter multiple times to allow multiple event types. If not specified, Cloud Storage sends notifications for all event types. The valid types are: OBJECT_FINALIZE - An object has been created. OBJECT_METADATA_UPDATE - The metadata of an object has changed. OBJECT_DELETE - An object has been permanently deleted. OBJECT_ARCHIVE - A live version of an object has become a noncurrent version. -f Specifies the payload format of notification messages. Must be either "json" for a payload matches the object metadata for the JSON API, or "none" to specify no payload at all. In either case, notification details are available in the message attributes. -m Specifies a key:value attribute that is appended to the set of attributes sent to Cloud Pub/Sub for all events associated with this notification config. You may specify this parameter multiple times to set multiple attributes. -p Specifies a prefix path filter for this notification config. Cloud Storage only sends notifications for objects in this bucket whose names begin with the specified prefix. -s Skips creation and permission assignment of the Cloud Pub/Sub topic. This is useful if the caller does not have permission to access the topic in question, or if the topic already exists and has the appropriate publish permission assigned. -t The Cloud Pub/Sub topic to which notifications should be sent. If not specified, this command chooses a topic whose project is your default project and whose ID is the same as the Cloud Storage bucket name. <B>NEXT STEPS</B> Once the create command has succeeded, Cloud Storage publishes a message to the specified Cloud Pub/Sub topic when eligible changes occur. In order to receive these messages, you must create a Pub/Sub subscription for your Pub/Sub topic. To learn more about creating Pub/Sub subscriptions, see `the Pub/Sub Subscriber Overview <https://cloud.google.com/pubsub/docs/subscriber>`_. You can create a simple Pub/Sub subscription using the ``gcloud`` command-line tool. For example, to create a new subscription on the topic "myNewTopic" and attempt to pull messages from it, you could run: gcloud beta pubsub subscriptions create --topic myNewTopic testSubscription gcloud beta pubsub subscriptions pull --auto-ack testSubscription a� <B>WATCHBUCKET</B> The watchbucket sub-command can be used to watch a bucket for object changes. A service account must be used when running this command. The app_url parameter must be an HTTPS URL to an application that will be notified of changes to any object in the bucket. The optional id parameter can be used to assign a unique identifier to the created notification channel. If not provided, a random UUID string is generated. The optional token parameter can be used to validate notifications events. To do this, set this custom token and store it to later verify that notification events contain the client token you expect. <B>WATCHBUCKET EXAMPLES</B> Watch the bucket example-bucket for changes and send notifications to an application server running at example.com: gsutil notification watchbucket https://example.com/notify \ gs://example-bucket Assign identifier my-channel-id to the created notification channel: gsutil notification watchbucket -i my-channel-id \ https://example.com/notify gs://example-bucket Set a custom client token that is included with each notification event: gsutil notification watchbucket -t my-client-token \ https://example.com/notify gs://example-bucket a� <B>STOPCHANNEL</B> The stopchannel sub-command can be used to stop sending change events to a notification channel. The channel_id and resource_id parameters should match the values from the response of a bucket watch request. <B>STOPCHANNEL EXAMPLES</B> Stop the notification event channel with channel identifier channel1 and resource identifier SoGqan08XDIFWr1Fv_nGpRJBHh8: gsutil notification stopchannel channel1 SoGqan08XDIFWr1Fv_nGpRJBHh8 a� You can use the ``notification`` command to configure `Pub/Sub notifications for Cloud Storage <https://cloud.google.com/storage/docs/pubsub-notifications>`_ and `Object change notification <https://cloud.google.com/storage/docs/object-change-notification>`_ channels. <B>CLOUD PUB/SUB</B> The "create", "list", and "delete" sub-commands deal with configuring Cloud Storage integration with Google Cloud Pub/Sub. aP <B>OBJECT CHANGE NOTIFICATIONS</B> Object change notification is a separate, older feature within Cloud Storage for generating notifications. This feature sends HTTPS messages to a client application that you've set up separately. This feature is generally not recommended, because Pub/Sub notifications are cheaper, easier to use, and more flexible. For more information, see `Object change notification <https://cloud.google.com/storage/docs/object-change-notification>`_. The "watchbucket" and "stopchannel" sub-commands enable and disable Object change notifications. aY <B>NOTIFICATIONS AND PARALLEL COMPOSITE UPLOADS</B> gsutil supports `parallel composite uploads <https://cloud.google.com/storage/docs/uploads-downloads#parallel-composite-uploads>`_. If enabled, an upload can result in multiple temporary component objects being uploaded before the actual intended object is created. Any subscriber to notifications for this bucket then sees a notification for each of these components being created and deleted. If this is a concern for you, note that parallel composite uploads can be disabled by setting "parallel_composite_upload_threshold = 0" in your .boto config file. Alternately, your subscriber code can filter out gsutil's parallel composite uploads by ignoring any notification about objects whose names contain (but do not start with) the following string: "{composite_namespace}". )Zcomposite_namespacea_ Watch bucket attempt failed: {watch_error} You attempted to watch a bucket with an application URL of: {watch_url} which is not authorized for your project. Please ensure that you are using Service Account authentication and that the Service Account's project is authorized for the application URL. Notification endpoint URLs must also be whitelisted in your Cloud Console project. To do that, the domain must also be verified using Google Webmaster Tools. For instructions, please see `Notification Authorization <https://cloud.google.com/storage/docs/object-change-notification#_Authorization>`_. �NONE�JSON_API_V1)�none�jsonc @ s� e Zd ZdZdd� ZdZejdg d�ede dd d d e jge je� � e�� gg e�� ge�� ge� � e�d �gd�d�Zejdg d �ddeeeeeed�d�Zeeg d�edejjd�edejjd�ed�ed�ed�ed�d�d�eg d�i d�eg d�i dd�d �i d�Z d!d"� Z!d#d$� Z"d%d&� Z#d'd(� Z$d)d*� Z%d9d+d,�Z&d-d.� Z'd/d0� Z(d1d2� Z)d3d4� Z*d5d6� Z+e$e'e)e!e"d�Z,d7d8� Z-dS ):�NotificationCommandz.Implementation of gsutil notification command.c C s t jst�d�t _t jS )Nz]/?(projects/[^/]+/)?b(uckets)?/(?P<bucket>[^/]+)/notificationConfigs/(?P<notification>[0-9]+))r �_notification_path_regex�re�compile��self� r$ �*/opt/gsutil/gslib/commands/notification.py�_GetNotificationPathRegex� s �z-NotificationCommand._GetNotificationPathRegexN�notification)�notify�notifyconfig� notificationsZnotif� zi:t:m:t:of:e:p:sF� )�watchbucket�stopchannel�list�delete�create)�command_name_aliases�usage_synopsis�min_args�max_args�supported_sub_args�file_url_ok�provider_url_ok�urls_start_arg�gs_api_support�gs_default_api�argparse_arguments)r- r. r) �command_helpz$Configure object change notification)r1 r/ r0 r- r. )� help_name�help_name_aliases� help_type�help_one_line_summary� help_text�subcommand_help_text)�storage�bucketsr* r1 z--custom-attributes)�repeat_typez --event-typesz--object-prefixz--payload-formatz--skip-topic-setupz--topic)�-m�-e�-p�-f�-s�-t)�gcloud_command�flag_map)rD rE r* r0 )rD rE r* r/ z--human-readableT)rM rN �supports_output_translation)r1 r0 r/ c C st | � � d}d}| jr>| jD ] \}}|dkr0|}|dkr|}q|pLtt�� �}| jd }| jd }|�� �d�sxtd��t |�}|� � r�|jdks�td | j ��|� � s�td | j ��| j �d||� z| jj|j||||jd�}W nB t�y& } z(| j �tjt| �|d �� � W Y d} ~ n d} ~ 0 0 |j} |j}|j}| j �d� | j �d| � | j �d|� | j �d|� dS )z/Creates a watch on a bucket given in self.args.Nz-irL r ���zhttps://z,The application URL must be an https:// URL.�gs�7The %s command can only be used with gs:// bucket URLs.�*URL must name a bucket for the %s command.z.Watching bucket %s with application URL %s ...)�token�provider)Zwatch_error� watch_urlz0Successfully created watch notification channel.zWatch channel identifier: %sz%Canonicalized resource identifier: %szClient state token: %s)�CheckArguments�sub_opts�str�uuid�uuid4�args�lower� startswithr r �IsBucket�scheme�command_name�logger�info� gsutil_api�WatchBucket�bucket_namer �warn�)NOTIFICATION_AUTHORIZATION_FAILED_MESSAGE�format�id� resourceIdrT )r# � identifierZclient_token�o�arV � bucket_arg� bucket_url�channel�e� channel_id�resource_idr$ r$ r% �_WatchBucket� sd ���� � ��z NotificationCommand._WatchBucketc C sF | j d }| j d }| j�d||� | jj||dd� | j�d� dS )Nr r, z3Removing channel %s with resource identifier %s ...rQ �rU zSuccesfully removed channel.)r\ rb rc rd �StopChannel)r# rs rt r$ r$ r% �_StopChannel( s �z NotificationCommand._StopChannelc C s� t |�}|�� r|jdks(td| j ��|�� s>td| j ��| jj|jdd�j}| j � d|j� t|�D ]x\}}| j � d|d � | j � d|j� | j � d |j � | j � d |j� | j � d|j� | j � dtt�|jd ��� qjdS )z<Lists active channel watches on a bucket given in self.args.rQ rR rS rv z?Bucket %s has the following active Object Change Notifications:z Notification channel %d:r, z Channel identifier: %sz Resource identifier: %sz Application URL: %sz Created by: %sz Creation time: %si� r )r r_ r` r ra rd �ListChannelsrf �itemsrb rc � enumeraters rt �push_url�subscriber_emailrY r � fromtimestamp�creation_time_ms)r# ro rp �channels�idxrq r$ r$ r% � _ListChannels3 s: ��� ���z!NotificationCommand._ListChannelsc C sl | � � d }d }i }g }d }d}| jr�| jD ]�\}}|dkrH|�|� q,|dkrV|}q,|dkr�d|vrntd��|�dd�\} } | || <