imbi-plugin-github 2.45.0__tar.gz → 2.47.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/PKG-INFO +2 -2
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/pyproject.toml +2 -2
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/secret_provider.py +43 -12
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/tests/test_secret_provider.py +66 -1
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/tests/test_secret_provider_live.py +1 -1
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/.gitignore +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/README.md +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/moon.yml +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/README.md +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/__init__.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/_app_auth.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/_hosts.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/_repos.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/commits.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/deployment.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/doctor.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/identity.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/lifecycle.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/plugin.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/public.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/pull_requests.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/py.typed +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/tests/__init__.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/tests/test_app_auth_scopes.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/tests/test_commits.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/tests/test_deployment.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/tests/test_doctor.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/tests/test_hosts.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/tests/test_identity.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/tests/test_lifecycle.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/tests/test_public.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/tests/test_pull_requests.py +0 -0
- {imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/tests/test_repos.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: imbi-plugin-github
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.47.0
|
|
4
4
|
Summary: GitHub identity plugin for Imbi (github.com / GHEC / GHES)
|
|
5
5
|
Author-email: "Gavin M. Roy" <gavinr@aweber.com>
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.14
|
|
13
13
|
Requires-Python: >=3.14
|
|
14
14
|
Requires-Dist: httpx>=0.27
|
|
15
|
-
Requires-Dist: imbi-common[databases]==2.
|
|
15
|
+
Requires-Dist: imbi-common[databases]==2.47.0
|
|
16
16
|
Requires-Dist: pydantic>=2
|
|
17
17
|
Requires-Dist: pyjwt[crypto]>=2.8
|
|
18
18
|
Description-Content-Type: text/markdown
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "imbi-plugin-github"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.47.0"
|
|
4
4
|
description = "GitHub identity plugin for Imbi (github.com / GHEC / GHES)"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.14"
|
|
@@ -18,7 +18,7 @@ classifiers = [
|
|
|
18
18
|
]
|
|
19
19
|
dependencies = [
|
|
20
20
|
"httpx>=0.27",
|
|
21
|
-
"imbi-common[databases]==2.
|
|
21
|
+
"imbi-common[databases]==2.47.0",
|
|
22
22
|
"pydantic>=2",
|
|
23
23
|
"pyjwt[crypto]>=2.8",
|
|
24
24
|
]
|
{imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/secret_provider.py
RENAMED
|
@@ -189,13 +189,15 @@ class _Locator(pydantic.BaseModel):
|
|
|
189
189
|
title='Private key',
|
|
190
190
|
)
|
|
191
191
|
#: ``owner/name`` repositories for ``marketplace_fetch``: the
|
|
192
|
-
#: marketplaces and their external plugins
|
|
192
|
+
#: marketplaces and their external plugins; empty allows each
|
|
193
|
+
#: repository of the installation. Other purposes use the
|
|
193
194
|
#: repositories of the task's project.
|
|
194
195
|
repositories: list[str] = pydantic.Field(
|
|
195
196
|
default_factory=list[str],
|
|
196
197
|
description=(
|
|
197
|
-
'owner/name, for marketplace_fetch only.
|
|
198
|
-
|
|
198
|
+
'owner/name, for marketplace_fetch only. Empty: each'
|
|
199
|
+
' repository of the installation. Other purposes use the'
|
|
200
|
+
" repositories of the task's project."
|
|
199
201
|
),
|
|
200
202
|
title='Repositories',
|
|
201
203
|
)
|
|
@@ -477,7 +479,12 @@ class GitHubApp(secrets.SecretProvider):
|
|
|
477
479
|
async def health(
|
|
478
480
|
self, config: dict[str, typing.Any], organization_id: str
|
|
479
481
|
) -> secrets.Health:
|
|
480
|
-
"""Check that the GitHub API answers. No credentials are used.
|
|
482
|
+
"""Check that the GitHub API answers. No credentials are used.
|
|
483
|
+
|
|
484
|
+
A GHEC tenant refuses each anonymous call (401 or 404), so each
|
|
485
|
+
answer other than a redirect, a rate limit or 5xx shows that the
|
|
486
|
+
API answers. A redirect is usually a proxy login page.
|
|
487
|
+
"""
|
|
481
488
|
try:
|
|
482
489
|
async with httpx.AsyncClient(
|
|
483
490
|
base_url=_api_base(_host(config)),
|
|
@@ -489,7 +496,16 @@ class GitHubApp(secrets.SecretProvider):
|
|
|
489
496
|
return secrets.Health('unhealthy', err.reason)
|
|
490
497
|
except httpx.TransportError:
|
|
491
498
|
return secrets.Health('unhealthy', 'unreachable')
|
|
492
|
-
|
|
499
|
+
status = response.status_code
|
|
500
|
+
rate_limited = status == 429 or (
|
|
501
|
+
status == 403
|
|
502
|
+
and (
|
|
503
|
+
response.headers.get('x-ratelimit-remaining') == '0'
|
|
504
|
+
or 'retry-after' in response.headers
|
|
505
|
+
or 'secondary rate limit' in response.text.lower()
|
|
506
|
+
)
|
|
507
|
+
)
|
|
508
|
+
if 300 <= status < 400 or rate_limited or status >= 500:
|
|
493
509
|
return secrets.Health('unhealthy', 'provider_error')
|
|
494
510
|
return secrets.Health('healthy', identity={'host': _host(config)})
|
|
495
511
|
|
|
@@ -607,9 +623,14 @@ class GitHubApp(secrets.SecretProvider):
|
|
|
607
623
|
"""Mint a token for the task's repositories and the purpose.
|
|
608
624
|
|
|
609
625
|
``marketplace_fetch`` uses the repository that the runner asks
|
|
610
|
-
for
|
|
611
|
-
|
|
612
|
-
|
|
626
|
+
for. When the binding lists ``repositories``, the repository must
|
|
627
|
+
be one of them; an empty list allows each repository of the
|
|
628
|
+
installation; the token then covers only that one repository. A
|
|
629
|
+
request without a repository gets every listed repository, and
|
|
630
|
+
none with an empty list (the runner always names one).
|
|
631
|
+
The other purposes use the verified repository ids of all the
|
|
632
|
+
task's projects (:meth:`project_repository_ids`). A project with
|
|
633
|
+
no verified repository adds none.
|
|
613
634
|
|
|
614
635
|
Raises:
|
|
615
636
|
BrokerError: The purpose is unknown, the task has no
|
|
@@ -629,7 +650,7 @@ class GitHubApp(secrets.SecretProvider):
|
|
|
629
650
|
if context.purpose == 'marketplace_fetch':
|
|
630
651
|
repositories = list(locator.get('repositories', []))
|
|
631
652
|
if context.repository is not None:
|
|
632
|
-
if context.repository.lower() not in {
|
|
653
|
+
if repositories and context.repository.lower() not in {
|
|
633
654
|
name.lower() for name in repositories
|
|
634
655
|
}:
|
|
635
656
|
raise secrets.BrokerError(
|
|
@@ -637,9 +658,19 @@ class GitHubApp(secrets.SecretProvider):
|
|
|
637
658
|
)
|
|
638
659
|
repositories = [context.repository]
|
|
639
660
|
else:
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
661
|
+
found: set[int] = set()
|
|
662
|
+
for project_id in context.project_ids:
|
|
663
|
+
with contextlib.suppress(secrets.BrokerError):
|
|
664
|
+
found.update(
|
|
665
|
+
await self.project_repository_ids(
|
|
666
|
+
_host(config), project_id
|
|
667
|
+
)
|
|
668
|
+
)
|
|
669
|
+
if context.project_ids and not found:
|
|
670
|
+
raise secrets.BrokerError(
|
|
671
|
+
'secret_access_denied', 'project_repository_unverified'
|
|
672
|
+
)
|
|
673
|
+
repository_ids = sorted(found)
|
|
643
674
|
# An empty list never reaches GitHub: no repositories would give
|
|
644
675
|
# a token for every repository of the installation.
|
|
645
676
|
if not repositories and not repository_ids:
|
|
@@ -5,6 +5,7 @@ path (provider keys, release, fencing) is tested in imbi-api
|
|
|
5
5
|
(``apps/api/tests/test_secret_github_app.py``).
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
+
import dataclasses
|
|
8
9
|
import datetime
|
|
9
10
|
import json
|
|
10
11
|
import os
|
|
@@ -63,7 +64,7 @@ def _context(
|
|
|
63
64
|
return secrets.ResolveContext(
|
|
64
65
|
organization_id='org',
|
|
65
66
|
task_id=uuid.uuid4(),
|
|
66
|
-
|
|
67
|
+
project_ids=('project',),
|
|
67
68
|
purpose=purpose,
|
|
68
69
|
ttl_seconds=300,
|
|
69
70
|
credential_class='dynamic',
|
|
@@ -182,6 +183,31 @@ class GitHubAppTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
182
183
|
with self.assertRaises(ValueError):
|
|
183
184
|
APP.check_key_host('evil.example')
|
|
184
185
|
|
|
186
|
+
@respx.mock
|
|
187
|
+
async def test_token_covers_every_project(self) -> None:
|
|
188
|
+
route = _mock_github()
|
|
189
|
+
unverified = secrets.BrokerError(
|
|
190
|
+
'secret_access_denied', 'project_repository_unverified'
|
|
191
|
+
)
|
|
192
|
+
found = {'p1': [101], 'p3': [101]}
|
|
193
|
+
|
|
194
|
+
async def repository_ids(_host: str, project_id: str) -> list[int]:
|
|
195
|
+
if project_id not in found:
|
|
196
|
+
raise unverified
|
|
197
|
+
return found[project_id]
|
|
198
|
+
|
|
199
|
+
self.project_repository_ids.side_effect = repository_ids
|
|
200
|
+
context = dataclasses.replace(
|
|
201
|
+
_context('github_write'), project_ids=('p1', 'p2', 'p3')
|
|
202
|
+
)
|
|
203
|
+
await APP.resolve(CONFIG, LOCATOR, None, context)
|
|
204
|
+
body = json.loads(route.calls.last.request.content)
|
|
205
|
+
self.assertEqual(body['repository_ids'], [101])
|
|
206
|
+
found.clear()
|
|
207
|
+
with self.assertRaises(secrets.BrokerError) as ctx:
|
|
208
|
+
await APP.resolve(CONFIG, LOCATOR, None, context)
|
|
209
|
+
self.assertEqual(ctx.exception.reason, 'project_repository_unverified')
|
|
210
|
+
|
|
185
211
|
@respx.mock
|
|
186
212
|
async def test_scope_by_purpose(self) -> None:
|
|
187
213
|
route = _mock_github()
|
|
@@ -292,6 +318,18 @@ class GitHubAppTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
292
318
|
)
|
|
293
319
|
self.assertEqual(ctx.exception.reason, 'repository_not_allowed')
|
|
294
320
|
|
|
321
|
+
@respx.mock
|
|
322
|
+
async def test_marketplace_fetch_with_no_list_allows_any_one(self) -> None:
|
|
323
|
+
route = _mock_github()
|
|
324
|
+
await APP.resolve(
|
|
325
|
+
CONFIG,
|
|
326
|
+
LOCATOR | {'repositories': []},
|
|
327
|
+
None,
|
|
328
|
+
_context('marketplace_fetch', repository='octo/lint'),
|
|
329
|
+
)
|
|
330
|
+
body = json.loads(route.calls.last.request.content)
|
|
331
|
+
self.assertEqual(body['repositories'], ['lint'])
|
|
332
|
+
|
|
295
333
|
@respx.mock
|
|
296
334
|
async def test_finds_the_installation_of_the_repositories(self) -> None:
|
|
297
335
|
"""A binding without an installation_id works in each org."""
|
|
@@ -528,6 +566,33 @@ class GitHubAppTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
528
566
|
respx.get(f'{BASE}/meta').mock(return_value=httpx.Response(200))
|
|
529
567
|
health = await APP.health(CONFIG, 'org')
|
|
530
568
|
self.assertEqual(health.status, 'healthy')
|
|
569
|
+
ghec = 'https://api.aweber.ghe.com/meta'
|
|
570
|
+
limited = {'x-ratelimit-remaining': '0'}
|
|
571
|
+
for status, headers, expected in (
|
|
572
|
+
(401, {}, ('healthy', None)),
|
|
573
|
+
(403, {}, ('healthy', None)),
|
|
574
|
+
(404, {}, ('healthy', None)),
|
|
575
|
+
(302, {}, ('unhealthy', 'provider_error')),
|
|
576
|
+
(403, limited, ('unhealthy', 'provider_error')),
|
|
577
|
+
(403, {'retry-after': '60'}, ('unhealthy', 'provider_error')),
|
|
578
|
+
(429, {}, ('unhealthy', 'provider_error')),
|
|
579
|
+
(503, {}, ('unhealthy', 'provider_error')),
|
|
580
|
+
):
|
|
581
|
+
respx.get(ghec).mock(
|
|
582
|
+
return_value=httpx.Response(status, headers=headers)
|
|
583
|
+
)
|
|
584
|
+
health = await APP.health({'host': 'aweber.ghe.com'}, 'org')
|
|
585
|
+
self.assertEqual((health.status, health.reason), expected, status)
|
|
586
|
+
respx.get(ghec).mock(
|
|
587
|
+
return_value=httpx.Response(
|
|
588
|
+
403,
|
|
589
|
+
json={'message': 'You have exceeded a secondary rate limit.'},
|
|
590
|
+
)
|
|
591
|
+
)
|
|
592
|
+
health = await APP.health({'host': 'aweber.ghe.com'}, 'org')
|
|
593
|
+
self.assertEqual(
|
|
594
|
+
(health.status, health.reason), ('unhealthy', 'provider_error')
|
|
595
|
+
)
|
|
531
596
|
health = await APP.health({'host': 'evil.example'}, 'org')
|
|
532
597
|
self.assertEqual(
|
|
533
598
|
(health.status, health.reason), ('unhealthy', 'host_not_allowed')
|
|
@@ -86,7 +86,7 @@ class GitHubAppLiveTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
86
86
|
secrets.ResolveContext(
|
|
87
87
|
organization_id='live',
|
|
88
88
|
task_id=uuid.uuid4(),
|
|
89
|
-
|
|
89
|
+
project_ids=('live',),
|
|
90
90
|
purpose=purpose,
|
|
91
91
|
ttl_seconds=600,
|
|
92
92
|
credential_class='dynamic',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/_app_auth.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/deployment.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/lifecycle.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{imbi_plugin_github-2.45.0 → imbi_plugin_github-2.47.0}/src/imbi/plugins/github/pull_requests.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|