Skip to content

Commit 4f501bd

Browse files
committed
Reapply "feat(server): allow configuring client ID and installation ID vial env vars" (#1886)"
1 parent 304b96a commit 4f501bd

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

.github/workflows/bindings-server.main.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ workflow(
5252
runsOn = UbuntuLatest,
5353
env = mapOf(
5454
"APP_PRIVATE_KEY" to expr { APP_PRIVATE_KEY },
55+
"APP_INSTALLATION_ID" to "62885502",
56+
"APP_CLIENT_ID" to "Iv23liIZ17VJKUpjacBs",
5557
),
5658
) {
5759
uses(action = Checkout())

.github/workflows/bindings-server.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ jobs:
4949
- 'check_yaml_consistency'
5050
env:
5151
APP_PRIVATE_KEY: '${{ secrets.APP_PRIVATE_KEY }}'
52+
APP_INSTALLATION_ID: '62885502'
53+
APP_CLIENT_ID: 'Iv23liIZ17VJKUpjacBs'
5254
steps:
5355
- id: 'step-0'
5456
uses: 'actions/checkout@v4'

shared-internal/src/main/kotlin/io/github/typesafegithub/workflows/shared/internal/GitHubApp.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,17 @@ private val logger = logger { }
3131
suspend fun getInstallationAccessToken(): String? {
3232
if (cachedAccessToken?.isExpired() == false) return cachedAccessToken!!.token
3333
val jwtToken = generateJWTToken() ?: return null
34+
val appInstallationId = System.getenv("APP_INSTALLATION_ID") ?: return null
3435
cachedAccessToken =
3536
httpClient
36-
.post("https://api.github.com/app/installations/$INSTALLATION_ID/access_tokens") {
37+
.post("https://api.github.com/app/installations/$appInstallationId/access_tokens") {
3738
header("Accept", "application/vnd.github+json")
3839
header("Authorization", "Bearer $jwtToken")
3940
header("X-GitHub-Api-Version", "2022-11-28")
4041
}.body()
4142
return cachedAccessToken!!.token
4243
}
4344

44-
private const val INSTALLATION_ID = "62885502"
45-
4645
private var cachedAccessToken: Token? = null
4746

4847
@Serializable
@@ -77,15 +76,14 @@ private val httpClient =
7776
}
7877
}
7978

80-
private const val GITHUB_CLIENT_ID = "Iv23liIZ17VJKUpjacBs"
81-
8279
private fun generateJWTToken(): String? {
8380
val key = loadRsaKey() ?: return null
81+
val appClientId = System.getenv("APP_CLIENT_ID") ?: return null
8482
val algorithm = Algorithm.RSA256(null, key)
8583
val now = Instant.now()
8684
return JWT
8785
.create()
88-
.withIssuer(GITHUB_CLIENT_ID)
86+
.withIssuer(appClientId)
8987
.withIssuedAt(now.minusMinutes(1))
9088
.withExpiresAt(now.plusMinutes(9))
9189
.sign(algorithm)

0 commit comments

Comments
 (0)