Skip to content

Commit

Permalink
Fix gitlab access token crash in check mode for new tokens (#8796)
Browse files Browse the repository at this point in the history
Fix crash in check mode when attempting to create a new gitlab access token
  • Loading branch information
vvirrank authored Aug 26, 2024
1 parent 9c9c4cb commit e9071e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/8796-gitlab-access-token-check-mode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- gitlab_group_access_token - fix crash in check mode caused by attempted access to a newly created access token (https://github.com/ansible-collections/community.general/pull/8796).
- gitlab_project_access_token - fix crash in check mode caused by attempted access to a newly created access token (https://github.com/ansible-collections/community.general/pull/8796).
5 changes: 4 additions & 1 deletion plugins/modules/gitlab_group_access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ def main():
module.exit_json(changed=True, msg="Successfully recreated access token", access_token=gitlab_access_token.access_token_object._attrs)
else:
gitlab_access_token.create_access_token(group, {'name': name, 'scopes': scopes, 'access_level': access_level, 'expires_at': expires_at})
module.exit_json(changed=True, msg="Successfully created access token", access_token=gitlab_access_token.access_token_object._attrs)
if module.check_mode:
module.exit_json(changed=True, msg="Successfully created access token", access_token={})
else:
module.exit_json(changed=True, msg="Successfully created access token", access_token=gitlab_access_token.access_token_object._attrs)


if __name__ == '__main__':
Expand Down
5 changes: 4 additions & 1 deletion plugins/modules/gitlab_project_access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ def main():
module.exit_json(changed=True, msg="Successfully recreated access token", access_token=gitlab_access_token.access_token_object._attrs)
else:
gitlab_access_token.create_access_token(project, {'name': name, 'scopes': scopes, 'access_level': access_level, 'expires_at': expires_at})
module.exit_json(changed=True, msg="Successfully created access token", access_token=gitlab_access_token.access_token_object._attrs)
if module.check_mode:
module.exit_json(changed=True, msg="Successfully created access token", access_token={})
else:
module.exit_json(changed=True, msg="Successfully created access token", access_token=gitlab_access_token.access_token_object._attrs)


if __name__ == '__main__':
Expand Down

0 comments on commit e9071e9

Please sign in to comment.