def execute(self, context: 'Context'): self.log.info( 'List Notification Channels: Project id: %s Format: %s Filter: %s Order By: %s Page Size: %s', self.project_id, self.format_, self.filter_, self.order_by, self.page_size, ) if self.hook is None: self.hook = StackdriverHook( gcp_conn_id=self.gcp_conn_id, delegate_to=self.delegate_to, impersonation_chain=self.impersonation_chain, ) channels = self.hook.list_notification_channels( format_=self.format_, project_id=self.project_id, filter_=self.filter_, order_by=self.order_by, page_size=self.page_size, retry=self.retry, timeout=self.timeout, metadata=self.metadata, ) result = [NotificationChannel.to_dict(channel) for channel in channels] return result
def list_notification_channels( self, project_id: str = PROVIDE_PROJECT_ID, format_: Optional[str] = None, filter_: Optional[str] = None, order_by: Optional[str] = None, page_size: Optional[int] = None, retry: Optional[str] = DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Any: """ Fetches all the Notification Channels identified by the filter passed as filter parameter. The desired return type can be specified by the format parameter, the supported formats are "dict", "json" and None which returns python dictionary, stringified JSON and protobuf respectively. :param format_: (Optional) Desired output format of the result. The supported formats are "dict", "json" and None which returns python dictionary, stringified JSON and protobuf respectively. :param filter_: If provided, this field specifies the criteria that must be met by notification channels to be included in the response. For more details, see https://cloud.google.com/monitoring/api/v3/sorting-and-filtering. :param order_by: A comma-separated list of fields by which to sort the result. Supports the same set of field references as the ``filter`` field. Entries can be prefixed with a minus sign to sort by the field in descending order. For more details, see https://cloud.google.com/monitoring/api/v3/sorting-and-filtering. :param page_size: The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page. :param retry: A retry object used to retry requests. If ``None`` is specified, requests will be retried using a default configuration. :param timeout: The amount of time, in seconds, to wait for the request to complete. Note that if ``retry`` is specified, the timeout applies to each individual attempt. :param metadata: Additional metadata that is provided to the method. :param project_id: The project to fetch notification channels from. """ client = self._get_channel_client() channels = client.list_notification_channels( request={ 'name': f'projects/{project_id}', 'filter': filter_, 'order_by': order_by, 'page_size': page_size, }, retry=retry, timeout=timeout, metadata=metadata, ) if format_ == "dict": return [ NotificationChannel.to_dict(channel) for channel in channels ] elif format_ == "json": return [ NotificationChannel.to_json(channel) for channel in channels ] else: return channels