mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
[PR #7761/33180344 backport][stable-8] Add github_app_access_token lookup plugin (#7802)
Add github_app_access_token lookup plugin (#7761)
* Add github_app_access_token lookup plugin
* Fix a typo in short_description
* Remove unused MockOpenUrl
* Fix MockJWT to be used on jwt_instance instead
* Fix a bunch of pep8 and pylint issue
* Remove JWT from requirements, also default jwt_instance and jwk_from_pem so they can be mocked
* Update version added
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update git reference in doc
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update plugins/lookup/github_app_access_token.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Expose token expiry as a configurable option
* Update BOTMETA.yml
* Update documentation
* Update example with var, so it is more readable
Co-authored-by: Felix Fontein <felix@fontein.de>
* Apply suggestions from code review
Co-authored-by: Felix Fontein <felix@fontein.de>
---------
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 3318034403
)
Co-authored-by: weisheng-p <weisheng-p@users.noreply.github.com>
This commit is contained in:
parent
4776e7bed3
commit
42c65f32eb
3 changed files with 210 additions and 0 deletions
52
tests/unit/plugins/lookup/test_github_app_access_token.py
Normal file
52
tests/unit/plugins/lookup/test_github_app_access_token.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2023, Poh Wei Sheng <weisheng-p@hotmail.sg>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
import json
|
||||
|
||||
from ansible_collections.community.general.tests.unit.compat import unittest
|
||||
from ansible_collections.community.general.tests.unit.compat.mock import (
|
||||
patch,
|
||||
MagicMock,
|
||||
mock_open
|
||||
)
|
||||
from ansible.plugins.loader import lookup_loader
|
||||
|
||||
|
||||
class MockJWT(MagicMock):
|
||||
def encode(self, payload, key, alg):
|
||||
return 'Foobar'
|
||||
|
||||
|
||||
class MockResponse(MagicMock):
|
||||
response_token = 'Bar'
|
||||
|
||||
def read(self):
|
||||
return json.dumps({
|
||||
"token": self.response_token,
|
||||
}).encode('utf-8')
|
||||
|
||||
|
||||
class TestLookupModule(unittest.TestCase):
|
||||
|
||||
def test_get_token(self):
|
||||
with patch.multiple("ansible_collections.community.general.plugins.lookup.github_app_access_token",
|
||||
open=mock_open(read_data="foo_bar"),
|
||||
open_url=MagicMock(return_value=MockResponse()),
|
||||
jwk_from_pem=MagicMock(return_value='private_key'),
|
||||
jwt_instance=MockJWT(),
|
||||
HAS_JWT=True):
|
||||
lookup = lookup_loader.get('community.general.github_app_access_token')
|
||||
self.assertListEqual(
|
||||
[MockResponse.response_token],
|
||||
lookup.run(
|
||||
[],
|
||||
key_path="key",
|
||||
app_id="app_id",
|
||||
installation_id="installation_id",
|
||||
token_expiry=600
|
||||
)
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue