@@ -115,6 +115,7 @@ public void setOwner(String owner) {
115115
116116 @ SuppressWarnings ("deprecation" ) // preview features are required for GitHub app integration, GitHub api adds deprecated to all preview methods
117117 static AppInstallationToken generateAppInstallationToken (String appId , String appPrivateKey , String apiUrl , String owner ) {
118+ JenkinsJVM .checkJenkinsJVM ();
118119 // We expect this to be fast but if anything hangs in here we do not want to block indefinitely
119120 try (Timeout timeout = Timeout .limit (30 , TimeUnit .SECONDS )) {
120121 String jwtToken = createJWT (appId , appPrivateKey );
@@ -149,7 +150,8 @@ static AppInstallationToken generateAppInstallationToken(String appId, String ap
149150 .create ();
150151
151152 long expiration = getExpirationSeconds (appInstallationToken );
152- AppInstallationToken token = new AppInstallationToken (appInstallationToken .getToken (),
153+ AppInstallationToken token = new AppInstallationToken (
154+ Secret .fromString (appInstallationToken .getToken ()),
153155 expiration );
154156 LOGGER .log (Level .FINER ,
155157 "Generated App Installation Token for app ID {0}" ,
@@ -185,7 +187,6 @@ private static long getExpirationSeconds(GHAppInstallationToken appInstallationT
185187 @ NonNull
186188 @ Override
187189 public Secret getPassword () {
188- String appInstallationToken ;
189190 synchronized (this ) {
190191 try {
191192 if (cachedToken == null || cachedToken .isStale ()) {
@@ -208,12 +209,11 @@ public Secret getPassword() {
208209 throw e ;
209210 }
210211 }
211- appInstallationToken = cachedToken .getToken ();
212- }
212+ LOGGER .log (Level .FINEST , "Returned GitHub App Installation Token for app ID {0}" , appID );
213213
214- LOGGER .log (Level .FINEST , "Returned GitHub App Installation Token for app ID {0}" , appID );
214+ return cachedToken .getToken ();
215+ }
215216
216- return Secret .fromString (appInstallationToken );
217217 }
218218
219219 /**
@@ -265,7 +265,7 @@ static class AppInstallationToken implements Serializable {
265265 */
266266 static long NOT_STALE_MINIMUM_SECONDS = Duration .ofMinutes (1 ).getSeconds ();
267267
268- private final String token ;
268+ private final Secret token ;
269269 private final long expirationEpochSeconds ;
270270 private final long staleEpochSeconds ;
271271
@@ -281,7 +281,7 @@ static class AppInstallationToken implements Serializable {
281281 * @param token the token string
282282 * @param expirationEpochSeconds the time in epoch seconds that this token will expire
283283 */
284- public AppInstallationToken (String token , long expirationEpochSeconds ) {
284+ public AppInstallationToken (Secret token , long expirationEpochSeconds ) {
285285 long now = Instant .now ().getEpochSecond ();
286286 long minimumAllowedAge = Math .max (1 , NOT_STALE_MINIMUM_SECONDS );
287287 long maximumAllowedAge = Math .max (1 , 1 + STALE_AFTER_SECONDS );
@@ -306,7 +306,7 @@ public AppInstallationToken(String token, long expirationEpochSeconds) {
306306 this .staleEpochSeconds = now + secondsUntilStale ;
307307 }
308308
309- public String getToken () {
309+ public Secret getToken () {
310310 return token ;
311311 }
312312
@@ -405,7 +405,6 @@ public String getUsername() {
405405 public Secret getPassword () {
406406 JenkinsJVM .checkNotJenkinsJVM ();
407407 try {
408- String appInstallationToken ;
409408 synchronized (this ) {
410409 try {
411410 if (cachedToken == null || cachedToken .isStale ()) {
@@ -427,12 +426,11 @@ public Secret getPassword() {
427426 throw e ;
428427 }
429428 }
430- appInstallationToken = cachedToken .getToken ();
431- }
429+ LOGGER .log (Level .FINEST , "Returned GitHub App Installation Token for app ID {0} on agent" , appID );
432430
433- LOGGER .log (Level .FINEST , "Returned GitHub App Installation Token for app ID {0} on agent" , appID );
431+ return cachedToken .getToken ();
432+ }
434433
435- return Secret .fromString (appInstallationToken );
436434 } catch (IOException | InterruptedException x ) {
437435 throw new RuntimeException (x );
438436 }
0 commit comments