Skip to content

Commit 0c69948

Browse files
authored
Merge pull request #402 from MagicRB/github-app-secret-provider-translate-from-repo-name
Support translating from "repo_name" in GitHub secret provider
2 parents dd2d478 + 90ac98b commit 0c69948

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

buildbot_nix/buildbot_nix/github_projects.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,11 @@ def get_repo_token(self, repo_full_name: str) -> RepoToken:
418418
return self.installation_tokens[installation_id]
419419

420420
def create_secret_providers(self) -> list[SecretProviderBase]:
421-
return [GitHubAppSecretService(self.installation_tokens, self.jwt_token)]
421+
return [
422+
GitHubAppSecretService(
423+
self.project_id_map, self.installation_tokens, self.jwt_token
424+
)
425+
]
422426

423427
def create_reporter(self) -> ReporterBase:
424428
def get_github_token(props: Properties) -> str:
@@ -465,12 +469,17 @@ def create_reload_builder_steps(
465469

466470
class GitHubAppSecretService(SecretProviderBase):
467471
name: str | None = "GitHubAppSecretService" # type: ignore[assignment]
472+
project_id_map: dict[str, int]
468473
installation_tokens: dict[int, InstallationToken]
469474
jwt_token: JWTToken
470475

471476
def reconfigService( # type: ignore[override]
472-
self, installation_tokens: dict[int, InstallationToken], jwt_token: JWTToken
477+
self,
478+
project_id_map: dict[str, int],
479+
installation_tokens: dict[int, InstallationToken],
480+
jwt_token: JWTToken,
473481
) -> None:
482+
self.project_id_map = project_id_map
474483
self.installation_tokens = installation_tokens
475484
self.jwt_token = jwt_token
476485

@@ -479,9 +488,14 @@ def get(self, entry: str) -> str | None:
479488
get the value from the file identified by 'entry'
480489
"""
481490
if entry.startswith("github-token-"):
482-
return self.installation_tokens[
483-
int(entry.removeprefix("github-token-"))
484-
].get()
491+
try:
492+
return self.installation_tokens[
493+
int(entry.removeprefix("github-token-"))
494+
].get()
495+
except ValueError:
496+
return self.installation_tokens[
497+
self.project_id_map[entry.removeprefix("github-token-")]
498+
].get()
485499
if entry == "github-jwt-token":
486500
return self.jwt_token.get()
487501
return None

0 commit comments

Comments
 (0)