imbi-plugin-github 2.44.0__tar.gz → 2.46.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.44.0 → imbi_plugin_github-2.46.0}/PKG-INFO +2 -2
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/pyproject.toml +2 -2
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/secret_provider.py +65 -15
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/tests/test_secret_provider.py +66 -1
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/tests/test_secret_provider_live.py +1 -1
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/.gitignore +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/README.md +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/moon.yml +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/README.md +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/__init__.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/_app_auth.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/_hosts.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/_repos.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/commits.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/deployment.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/doctor.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/identity.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/lifecycle.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/plugin.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/public.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/pull_requests.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/py.typed +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/tests/__init__.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/tests/test_app_auth_scopes.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/tests/test_commits.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/tests/test_deployment.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/tests/test_doctor.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/tests/test_hosts.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/tests/test_identity.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/tests/test_lifecycle.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/tests/test_public.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/tests/test_pull_requests.py +0 -0
- {imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.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.46.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.46.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.46.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.46.0",
|
|
22
22
|
"pydantic>=2",
|
|
23
23
|
"pyjwt[crypto]>=2.8",
|
|
24
24
|
]
|
{imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/secret_provider.py
RENAMED
|
@@ -159,7 +159,11 @@ class _Config(pydantic.BaseModel):
|
|
|
159
159
|
|
|
160
160
|
model_config = pydantic.ConfigDict(extra='forbid')
|
|
161
161
|
|
|
162
|
-
host: str =
|
|
162
|
+
host: str = pydantic.Field(
|
|
163
|
+
default='github.com',
|
|
164
|
+
description='github.com, <tenant>.ghe.com, or a GHES host.',
|
|
165
|
+
title='Host',
|
|
166
|
+
)
|
|
163
167
|
|
|
164
168
|
@pydantic.field_validator('host')
|
|
165
169
|
@classmethod
|
|
@@ -170,18 +174,33 @@ class _Config(pydantic.BaseModel):
|
|
|
170
174
|
class _Locator(pydantic.BaseModel):
|
|
171
175
|
model_config = pydantic.ConfigDict(extra='forbid')
|
|
172
176
|
|
|
173
|
-
app_id: str = pydantic.Field(pattern=r'^[0-9]{1,20}$')
|
|
177
|
+
app_id: str = pydantic.Field(pattern=r'^[0-9]{1,20}$', title='App ID')
|
|
174
178
|
#: ``None``: find the installation of each request's repositories.
|
|
175
179
|
installation_id: str | None = pydantic.Field(
|
|
176
|
-
default=None,
|
|
180
|
+
default=None,
|
|
181
|
+
description="Empty: find it from each request's repositories.",
|
|
182
|
+
pattern=r'^[0-9]{1,20}$',
|
|
183
|
+
title='Installation ID',
|
|
177
184
|
)
|
|
178
185
|
#: The ``secret://`` reference of the App private key (PEM, or
|
|
179
186
|
#: base64 PEM), in a binding that is not ``dynamic``.
|
|
180
|
-
private_key: str
|
|
187
|
+
private_key: str = pydantic.Field(
|
|
188
|
+
description='The secret:// reference of the binding with the key.',
|
|
189
|
+
title='Private key',
|
|
190
|
+
)
|
|
181
191
|
#: ``owner/name`` repositories for ``marketplace_fetch``: the
|
|
182
|
-
#: marketplaces and their external plugins
|
|
192
|
+
#: marketplaces and their external plugins; empty allows each
|
|
193
|
+
#: repository of the installation. Other purposes use the
|
|
183
194
|
#: repositories of the task's project.
|
|
184
|
-
repositories: list[str] = pydantic.Field(
|
|
195
|
+
repositories: list[str] = pydantic.Field(
|
|
196
|
+
default_factory=list[str],
|
|
197
|
+
description=(
|
|
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."
|
|
201
|
+
),
|
|
202
|
+
title='Repositories',
|
|
203
|
+
)
|
|
185
204
|
|
|
186
205
|
@pydantic.field_validator('private_key')
|
|
187
206
|
@classmethod
|
|
@@ -277,6 +296,8 @@ class GitHubApp(secrets.SecretProvider):
|
|
|
277
296
|
|
|
278
297
|
type = 'github_app'
|
|
279
298
|
label = 'GitHub App'
|
|
299
|
+
locator_model = _Locator
|
|
300
|
+
config_model = _Config
|
|
280
301
|
capabilities = frozenset[secrets.SecretCapability](
|
|
281
302
|
{'dynamic_issuance', 'lease_revocation', 'health_check'}
|
|
282
303
|
)
|
|
@@ -458,7 +479,12 @@ class GitHubApp(secrets.SecretProvider):
|
|
|
458
479
|
async def health(
|
|
459
480
|
self, config: dict[str, typing.Any], organization_id: str
|
|
460
481
|
) -> secrets.Health:
|
|
461
|
-
"""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
|
+
"""
|
|
462
488
|
try:
|
|
463
489
|
async with httpx.AsyncClient(
|
|
464
490
|
base_url=_api_base(_host(config)),
|
|
@@ -470,7 +496,16 @@ class GitHubApp(secrets.SecretProvider):
|
|
|
470
496
|
return secrets.Health('unhealthy', err.reason)
|
|
471
497
|
except httpx.TransportError:
|
|
472
498
|
return secrets.Health('unhealthy', 'unreachable')
|
|
473
|
-
|
|
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:
|
|
474
509
|
return secrets.Health('unhealthy', 'provider_error')
|
|
475
510
|
return secrets.Health('healthy', identity={'host': _host(config)})
|
|
476
511
|
|
|
@@ -588,9 +623,14 @@ class GitHubApp(secrets.SecretProvider):
|
|
|
588
623
|
"""Mint a token for the task's repositories and the purpose.
|
|
589
624
|
|
|
590
625
|
``marketplace_fetch`` uses the repository that the runner asks
|
|
591
|
-
for
|
|
592
|
-
|
|
593
|
-
|
|
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.
|
|
594
634
|
|
|
595
635
|
Raises:
|
|
596
636
|
BrokerError: The purpose is unknown, the task has no
|
|
@@ -610,7 +650,7 @@ class GitHubApp(secrets.SecretProvider):
|
|
|
610
650
|
if context.purpose == 'marketplace_fetch':
|
|
611
651
|
repositories = list(locator.get('repositories', []))
|
|
612
652
|
if context.repository is not None:
|
|
613
|
-
if context.repository.lower() not in {
|
|
653
|
+
if repositories and context.repository.lower() not in {
|
|
614
654
|
name.lower() for name in repositories
|
|
615
655
|
}:
|
|
616
656
|
raise secrets.BrokerError(
|
|
@@ -618,9 +658,19 @@ class GitHubApp(secrets.SecretProvider):
|
|
|
618
658
|
)
|
|
619
659
|
repositories = [context.repository]
|
|
620
660
|
else:
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
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)
|
|
624
674
|
# An empty list never reaches GitHub: no repositories would give
|
|
625
675
|
# a token for every repository of the installation.
|
|
626
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.44.0 → imbi_plugin_github-2.46.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.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/deployment.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.0}/src/imbi/plugins/github/lifecycle.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{imbi_plugin_github-2.44.0 → imbi_plugin_github-2.46.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
|