vincbeck commented on code in PR #22737:
URL: https://github.com/apache/airflow/pull/22737#discussion_r846412698
##########
airflow/providers/amazon/aws/sensors/s3.py:
##########
@@ -166,13 +173,13 @@ def poke(self, context: 'Context'):
def get_files(self, s3_hook: S3Hook, delimiter: Optional[str] = '/') ->
List:
"""Gets a list of files in the bucket"""
- prefix = self.bucket_key
+ prefix = self.bucket_key[0]
Review Comment:
I actually decided to deprecate `S3KeySizeSensor`
##########
airflow/providers/amazon/aws/sensors/s3.py:
##########
@@ -78,27 +80,32 @@ def __init__(
):
super().__init__(**kwargs)
self.bucket_name = bucket_name
- self.bucket_key = bucket_key
+ self.bucket_key = [bucket_key] if isinstance(bucket_key, str) else
bucket_key
self.wildcard_match = wildcard_match
self.aws_conn_id = aws_conn_id
self.verify = verify
self.hook: Optional[S3Hook] = None
- def _resolve_bucket_and_key(self):
+ def _resolve_bucket_and_key(self, key):
"""If key is URI, parse bucket"""
if self.bucket_name is None:
- self.bucket_name, self.bucket_key =
S3Hook.parse_s3_url(self.bucket_key)
+ return S3Hook.parse_s3_url(key)
else:
- parsed_url = urlparse(self.bucket_key)
+ parsed_url = urlparse(key)
if parsed_url.scheme != '' or parsed_url.netloc != '':
raise AirflowException('If bucket_name provided, bucket_key
must be relative path, not URI.')
+ return self.bucket_name, key
- def poke(self, context: 'Context'):
- self._resolve_bucket_and_key()
- self.log.info('Poking for key : s3://%s/%s', self.bucket_name,
self.bucket_key)
+ def _key_exists(self, key):
+ bucket_name, key = self._resolve_bucket_and_key(key)
+ self.log.info('Poking for key : s3://%s/%s', bucket_name, key)
if self.wildcard_match:
- return self.get_hook().check_for_wildcard_key(self.bucket_key,
self.bucket_name)
- return self.get_hook().check_for_key(self.bucket_key, self.bucket_name)
+ return self.get_hook().check_for_wildcard_key(key, bucket_name)
+
+ return self.get_hook().check_for_key(key, bucket_name)
+
+ def poke(self, context: 'Context'):
+ return all(self._key_exists(key) for key in self.bucket_key)
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]