mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-04 15:29:10 -07:00
fix: github_deploy_key check key exists on 422 (#10011)
* fix: github_deploy_key check key exists on 422 If we get a 422 response code as we add a key, check if it's because the key already exists or for another reason. fixes: #6718 * chore: add changelog 10011-github_deploy_key-check-key-present * chore: fix changelog fragment * chore: fix changelog fragment * Update changelog fragment. --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
e0a283bb36
commit
c248073079
2 changed files with 8 additions and 1 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "github_deploy_key - check that key really exists on 422 to avoid masking other errors (https://github.com/ansible-collections/community.general/issues/6718, https://github.com/ansible-collections/community.general/pull/10011)."
|
|
@ -259,9 +259,14 @@ class GithubDeployKey(object):
|
||||||
key_id = response_body["id"]
|
key_id = response_body["id"]
|
||||||
self.module.exit_json(changed=True, msg="Deploy key successfully added", id=key_id)
|
self.module.exit_json(changed=True, msg="Deploy key successfully added", id=key_id)
|
||||||
elif status_code == 422:
|
elif status_code == 422:
|
||||||
|
# there might be multiple reasons for a 422
|
||||||
|
# so we must check if the reason is that the key already exists
|
||||||
|
if self.get_existing_key():
|
||||||
self.module.exit_json(changed=False, msg="Deploy key already exists")
|
self.module.exit_json(changed=False, msg="Deploy key already exists")
|
||||||
else:
|
else:
|
||||||
self.handle_error(method="POST", info=info)
|
self.handle_error(method="POST", info=info)
|
||||||
|
else:
|
||||||
|
self.handle_error(method="POST", info=info)
|
||||||
|
|
||||||
def remove_existing_key(self, key_id):
|
def remove_existing_key(self, key_id):
|
||||||
resp, info = fetch_url(self.module, "{0}/{1}".format(self.url, key_id), headers=self.headers, method="DELETE")
|
resp, info = fetch_url(self.module, "{0}/{1}".format(self.url, key_id), headers=self.headers, method="DELETE")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue