-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[master] S3 Pillar Pagination Fixes #55694
Conversation
9c18b2f
to
08d2055
Compare
Codecov Report
@@ Coverage Diff @@
## master #55694 +/- ##
==========================================
- Coverage 18.8% 18.79% -0.01%
==========================================
Files 818 817 -1
Lines 175220 175144 -76
Branches 37597 37580 -17
==========================================
- Hits 32937 32905 -32
+ Misses 139601 139560 -41
+ Partials 2682 2679 -3
|
@@ -312,6 +324,14 @@ def __get_pillar_environments(files): | |||
if s3_meta: | |||
bucket_files[bucket] = __get_pillar_files_from_s3_meta(s3_meta) | |||
|
|||
# Check if we have a NextContinuationToken and loop until we don't | |||
while True: | |||
continuation_token = __get_continuation_token(s3_meta) |
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.
Could this be rewritten as an iterator?
for continuation_token in __get_continuation_tokens(s3_meta):
...
I think the function would just be:
for item in s3_meta:
if item.get('NextContinuationToken'):
yield item('NextContinuationToken')
Or something to that effect.
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.
Not sure if that approach will work. There is only ever one NextContinuationToken
in s3_meta, but it could be different when s3_meta is updated after subsequent calls to __get_s3_meta
. Once it's not longer in s3_meta then it should exist the loop since there are no more results to pull down.
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.
Oooooh. I see!
What about something like this?
# helper s3 query function
def __get_s3_meta():
params = {'prefix': prefix, 'list-type': 2}
while True:
result = __utils__['s3.query'](
key=creds.key,
keyid=creds.keyid,
kms_keyid=creds.kms_keyid,
bucket=creds.bucket,
service_url=creds.service_url,
verify_ssl=creds.verify_ssl,
location=creds.location,
return_bin=False,
params={'prefix': prefix},
path_style=creds.path_style,
https_enable=creds.https_enable)
yield result
continuation_token = next((item.get('NextContinuationToken')
for item in s3_meta
if item.get('NextContinuationToken')),
None)
if continuation_token is None:
break
else:
params['continuation-token'] = continuation_token
Then it could simply be
for s3_meta in __get_s3_meta():
...
Would that work?
84ebbfc
to
77eb90d
Compare
What does this PR do?
Fixing S3 pillar when the keys in a bucket exceed 1000, ensure we are handling pagination properly
What issues does this PR fix or reference?
#55662
Tests written?
[NOTICE] Bug fixes or features added to Salt require tests.
Please review the test documentation for details on how to implement tests into Salt's test suite.
Not Yet.
Commits signed with GPG?
Yes
Please review Salt's Contributing Guide for best practices.
See GitHub's page on GPG signing for more information about signing commits with GPG.