imbi-plugin-github 2.44.0__py3-none-any.whl → 2.46.0__py3-none-any.whl

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.
@@ -159,7 +159,11 @@ class _Config(pydantic.BaseModel):
159
159
 
160
160
  model_config = pydantic.ConfigDict(extra='forbid')
161
161
 
162
- host: str = 'github.com'
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, pattern=r'^[0-9]{1,20}$'
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. Other purposes use the
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(default_factory=list[str])
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
- if response.status_code != 200:
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, which must be in the ``repositories`` of the binding; with
592
- none, all of them. The other purposes use the verified repository
593
- ids of the task's project (:meth:`project_repository_ids`).
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
- repository_ids = await self.project_repository_ids(
622
- _host(config), context.project_id
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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: imbi-plugin-github
3
- Version: 2.44.0
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.44.0
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
@@ -12,7 +12,7 @@ imbi/plugins/github/plugin.py,sha256=LDFCqj6e2jfF9io3U7cC0eVOUAxw1ENvFS-0AWOMuDc
12
12
  imbi/plugins/github/public.py,sha256=GZnTLbj_Gl5sHWuRqFuajnoO2xPudNQumAt4h_uJpYw,3114
13
13
  imbi/plugins/github/pull_requests.py,sha256=DH9CnJoCpY5Ats5sZ_ktLvy54kBwK9g_-CDMlAIOq7Y,32553
14
14
  imbi/plugins/github/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- imbi/plugins/github/secret_provider.py,sha256=83BQwbG6AuIlyCWAskkN5hrVbRc9X5UqQJl5qt7Pij0,27317
16
- imbi_plugin_github-2.44.0.dist-info/METADATA,sha256=o6mVXl-pbwOEL5FSJnvFz8dQo292FnGptle6Rj57fT0,8977
17
- imbi_plugin_github-2.44.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
18
- imbi_plugin_github-2.44.0.dist-info/RECORD,,
15
+ imbi/plugins/github/secret_provider.py,sha256=6o8-RK22CqoJxeLYFP_sm976anIR_2XR0FAGCfNrnkg,29447
16
+ imbi_plugin_github-2.46.0.dist-info/METADATA,sha256=UbqnZPzDbOwNWSP-P_Yhbu-OM5rbMzxO_6Nzb_eYFrQ,8977
17
+ imbi_plugin_github-2.46.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
18
+ imbi_plugin_github-2.46.0.dist-info/RECORD,,