1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

bitbucket_pipeline_variable: Change pagination logic (#1498) (#1502)

Bitbucket's pagination for pipeline variables is flawed.
Refactor bitbucket_pipeline_variable code to correct this logic.

Fixes: #1425

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit 4c14df6d88)

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
patchback[bot] 2020-12-17 11:12:39 +01:00 committed by GitHub
parent a04912dec0
commit 0bfed46136
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- bitbucket_pipeline_variable - change pagination logic for pipeline variable get API (https://github.com/ansible-collections/community.general/issues/1425).

View file

@ -72,7 +72,7 @@ EXAMPLES = r'''
secured: '{{ item.secured }}'
state: present
with_items:
- { name: AWS_ACCESS_KEY, value: ABCD1234 }
- { name: AWS_ACCESS_KEY, value: ABCD1234, secured: False }
- { name: AWS_SECRET, value: qwe789poi123vbn0, secured: True }
- name: Remove pipeline variable
@ -119,17 +119,16 @@ def get_existing_pipeline_variable(module, bitbucket):
The `value` key in dict is absent in case of secured variable.
"""
content = {
'next': BITBUCKET_API_ENDPOINTS['pipeline-variable-list'].format(
username=module.params['username'],
repo_slug=module.params['repository'],
)
}
variables_base_url = BITBUCKET_API_ENDPOINTS['pipeline-variable-list'].format(
username=module.params['username'],
repo_slug=module.params['repository'],
)
# Look through the all response pages in search of variable we need
while 'next' in content:
page = 1
while True:
next_url = "%s?page=%s" % (variables_base_url, page)
info, content = bitbucket.request(
api_url=content['next'],
api_url=next_url,
method='GET',
)
@ -139,6 +138,11 @@ def get_existing_pipeline_variable(module, bitbucket):
if info['status'] != 200:
module.fail_json(msg='Failed to retrieve the list of pipeline variables: {0}'.format(info))
# We are at the end of list
if 'pagelen' in content and content['pagelen'] == 0:
return None
page += 1
var = next(filter(lambda v: v['key'] == module.params['name'], content['values']), None)
if var is not None: