imbi-plugin-github 2.52.0__tar.gz → 2.54.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.
Files changed (33) hide show
  1. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/PKG-INFO +2 -2
  2. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/pyproject.toml +2 -2
  3. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/src/imbi/plugins/github/secret_provider.py +40 -2
  4. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/tests/test_secret_provider.py +58 -0
  5. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/.gitignore +0 -0
  6. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/README.md +0 -0
  7. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/moon.yml +0 -0
  8. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/src/imbi/plugins/github/README.md +0 -0
  9. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/src/imbi/plugins/github/__init__.py +0 -0
  10. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/src/imbi/plugins/github/_app_auth.py +0 -0
  11. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/src/imbi/plugins/github/_hosts.py +0 -0
  12. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/src/imbi/plugins/github/_repos.py +0 -0
  13. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/src/imbi/plugins/github/commits.py +0 -0
  14. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/src/imbi/plugins/github/deployment.py +0 -0
  15. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/src/imbi/plugins/github/doctor.py +0 -0
  16. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/src/imbi/plugins/github/identity.py +0 -0
  17. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/src/imbi/plugins/github/lifecycle.py +0 -0
  18. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/src/imbi/plugins/github/plugin.py +0 -0
  19. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/src/imbi/plugins/github/public.py +0 -0
  20. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/src/imbi/plugins/github/pull_requests.py +0 -0
  21. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/src/imbi/plugins/github/py.typed +0 -0
  22. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/tests/__init__.py +0 -0
  23. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/tests/test_app_auth_scopes.py +0 -0
  24. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/tests/test_commits.py +0 -0
  25. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/tests/test_deployment.py +0 -0
  26. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/tests/test_doctor.py +0 -0
  27. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/tests/test_hosts.py +0 -0
  28. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/tests/test_identity.py +0 -0
  29. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/tests/test_lifecycle.py +0 -0
  30. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/tests/test_public.py +0 -0
  31. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/tests/test_pull_requests.py +0 -0
  32. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/tests/test_repos.py +0 -0
  33. {imbi_plugin_github-2.52.0 → imbi_plugin_github-2.54.0}/tests/test_secret_provider_live.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: imbi-plugin-github
3
- Version: 2.52.0
3
+ Version: 2.54.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.52.0
15
+ Requires-Dist: imbi-common[databases]==2.54.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.52.0"
3
+ version = "2.54.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.52.0",
21
+ "imbi-common[databases]==2.54.0",
22
22
  "pydantic>=2",
23
23
  "pyjwt[crypto]>=2.8",
24
24
  ]
@@ -63,6 +63,12 @@ LOGGER = logging.getLogger(__name__)
63
63
  PURPOSE_PERMISSIONS: dict[str, dict[str, str]] = {
64
64
  'workspace_checkout': {'contents': 'read'},
65
65
  'marketplace_fetch': {'contents': 'read'},
66
+ 'github_read': {
67
+ 'actions': 'read',
68
+ 'contents': 'read',
69
+ 'issues': 'read',
70
+ 'pull_requests': 'read',
71
+ },
66
72
  'github_write': {
67
73
  'contents': 'write',
68
74
  'pull_requests': 'write',
@@ -70,6 +76,18 @@ PURPOSE_PERMISSIONS: dict[str, dict[str, str]] = {
70
76
  },
71
77
  }
72
78
 
79
+ #: CI read permissions that a purpose adds when the installation grants
80
+ #: them, so an agent can wait for and read checks. Asking for one the
81
+ #: installation lacks would make GitHub refuse the whole token (422).
82
+ PURPOSE_OPTIONAL_PERMISSIONS: dict[str, dict[str, str]] = {
83
+ 'github_read': {'checks': 'read', 'statuses': 'read'},
84
+ 'github_write': {
85
+ 'actions': 'read',
86
+ 'checks': 'read',
87
+ 'statuses': 'read',
88
+ },
89
+ }
90
+
73
91
  #: The binding test asks for the smallest permission set.
74
92
  _TEST_PERMISSIONS = {'metadata': 'read'}
75
93
 
@@ -278,6 +296,25 @@ def _options(raw: object) -> dict[str, typing.Any]:
278
296
  return {}
279
297
 
280
298
 
299
+ def _with_granted(
300
+ permissions: dict[str, str],
301
+ optional: dict[str, str],
302
+ installation: dict[str, typing.Any] | None,
303
+ ) -> dict[str, str]:
304
+ """``permissions`` plus each optional one the installation grants."""
305
+ if not optional or installation is None:
306
+ return permissions
307
+ granted = typing.cast(
308
+ dict[str, str], installation.get('permissions') or {}
309
+ )
310
+ extra = {
311
+ name: level
312
+ for name, level in optional.items()
313
+ if name not in permissions and granted.get(name) in (level, 'write')
314
+ }
315
+ return permissions | extra
316
+
317
+
281
318
  def _expiry(value: object) -> datetime.datetime:
282
319
  if isinstance(value, str):
283
320
  try:
@@ -645,6 +682,7 @@ class GitHubApp(secrets.SecretProvider):
645
682
  raise secrets.BrokerError(
646
683
  'secret_access_denied', 'purpose_not_supported'
647
684
  )
685
+ optional = PURPOSE_OPTIONAL_PERMISSIONS.get(context.purpose, {})
648
686
  repositories: list[str] = []
649
687
  repository_ids: list[int] | None = None
650
688
  if context.purpose == 'marketplace_fetch':
@@ -692,7 +730,7 @@ class GitHubApp(secrets.SecretProvider):
692
730
  client, repositories, repository_ids
693
731
  )
694
732
  installation_id = str(installation['id'])
695
- elif repositories:
733
+ elif repositories or optional:
696
734
  installation = await self._installation(
697
735
  client, installation_id
698
736
  )
@@ -702,7 +740,7 @@ class GitHubApp(secrets.SecretProvider):
702
740
  token, expires_at = await self._mint(
703
741
  client,
704
742
  installation_id,
705
- permissions,
743
+ _with_granted(permissions, optional, installation),
706
744
  names,
707
745
  repository_ids,
708
746
  )
@@ -217,6 +217,15 @@ class GitHubAppTestCase(unittest.IsolatedAsyncioTestCase):
217
217
  {'repository_ids': [101]},
218
218
  {'contents': 'read'},
219
219
  ),
220
+ 'github_read': (
221
+ {'repository_ids': [101]},
222
+ {
223
+ 'actions': 'read',
224
+ 'contents': 'read',
225
+ 'issues': 'read',
226
+ 'pull_requests': 'read',
227
+ },
228
+ ),
220
229
  'github_write': (
221
230
  {'repository_ids': [101]},
222
231
  {
@@ -389,6 +398,55 @@ class GitHubAppTestCase(unittest.IsolatedAsyncioTestCase):
389
398
  )
390
399
  self.assertEqual(ctx.exception.reason, 'installation_not_found')
391
400
 
401
+ @respx.mock
402
+ async def test_ci_read_only_when_the_installation_grants_it(
403
+ self,
404
+ ) -> None:
405
+ """CI permissions the installation lacks are never asked for."""
406
+ respx.get(INSTALLATION_URL).mock(
407
+ return_value=httpx.Response(
408
+ 200,
409
+ json=INSTALLATION
410
+ | {
411
+ 'permissions': {
412
+ 'contents': 'write',
413
+ 'checks': 'write',
414
+ 'statuses': 'read',
415
+ 'metadata': 'read',
416
+ }
417
+ },
418
+ )
419
+ )
420
+ route = respx.post(TOKENS_URL).mock(
421
+ return_value=httpx.Response(
422
+ 201,
423
+ json={'token': TOKEN, 'expires_at': '2099-01-01T00:00:00Z'},
424
+ )
425
+ )
426
+ await APP.resolve(CONFIG, LOCATOR, None, _context('github_write'))
427
+ self.assertEqual(
428
+ json.loads(route.calls.last.request.content)['permissions'],
429
+ {
430
+ 'checks': 'read',
431
+ 'contents': 'write',
432
+ 'issues': 'write',
433
+ 'pull_requests': 'write',
434
+ 'statuses': 'read',
435
+ },
436
+ )
437
+ await APP.resolve(CONFIG, LOCATOR, None, _context('github_read'))
438
+ self.assertEqual(
439
+ json.loads(route.calls.last.request.content)['permissions'],
440
+ {
441
+ 'actions': 'read',
442
+ 'checks': 'read',
443
+ 'contents': 'read',
444
+ 'issues': 'read',
445
+ 'pull_requests': 'read',
446
+ 'statuses': 'read',
447
+ },
448
+ )
449
+
392
450
  @respx.mock
393
451
  async def test_disallowed_host_gets_no_jwt(self) -> None:
394
452
  """A host that left the allowlist after the provider was saved."""