-
Notifications
You must be signed in to change notification settings - Fork 16.4k
S3KeySensor to use S3Hook url parser #21500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
25a9855
S3KeySensor should parse bucket and key outside of poke
dstandish ba4f318
must resolve only after template rendering
dstandish ce061ac
fixup! must resolve only after template rendering
dstandish 1e40c03
economize
dstandish 923ed05
fixup! economize
dstandish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -77,31 +77,24 @@ def __init__( | |||||
| **kwargs, | ||||||
| ): | ||||||
| super().__init__(**kwargs) | ||||||
|
|
||||||
| self.bucket_name = bucket_name | ||||||
| self.bucket_key = bucket_key | ||||||
| self.wildcard_match = wildcard_match | ||||||
| self.aws_conn_id = aws_conn_id | ||||||
| self.verify = verify | ||||||
| self.hook: Optional[S3Hook] = None | ||||||
|
|
||||||
| def poke(self, context: 'Context'): | ||||||
|
|
||||||
| def _resolve_bucket_and_key(self): | ||||||
| """If key is URI, parse bucket""" | ||||||
| if self.bucket_name is None: | ||||||
| parsed_url = urlparse(self.bucket_key) | ||||||
| if parsed_url.netloc == '': | ||||||
| raise AirflowException('If key is a relative path from root, please provide a bucket_name') | ||||||
| self.bucket_name = parsed_url.netloc | ||||||
| self.bucket_key = parsed_url.path.lstrip('/') | ||||||
| self.bucket_name, self.bucket_key = S3Hook.parse_s3_url(self.bucket_key) | ||||||
| else: | ||||||
| parsed_url = urlparse(self.bucket_key) | ||||||
| if parsed_url.scheme != '' or parsed_url.netloc != '': | ||||||
| raise AirflowException( | ||||||
| 'If bucket_name is provided, bucket_key' | ||||||
| ' should be relative path from root' | ||||||
| ' level, rather than a full s3:// url' | ||||||
| ) | ||||||
| raise AirflowException('If bucket_name provided, bucket_key must be relative path, not URI.') | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i was trying to keep it on one line :) lemme see if that works |
||||||
|
|
||||||
| 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) | ||||||
| if self.wildcard_match: | ||||||
| return self.get_hook().check_for_wildcard_key(self.bucket_key, self.bucket_name) | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't have to happen in this PR but I wonder if
S3Hook.parse_s3_url()could be augmented with some sort of configurable check between validating a URI vs. a relative path? Centralize some of this logic there without haveurlparse()is different places. Anyway, just a thought.