tinker-agent 1.0.17 → 1.0.18
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.
- package/package.json +1 -1
- package/setup-agent.rb +14 -7
package/package.json
CHANGED
package/setup-agent.rb
CHANGED
|
@@ -285,24 +285,31 @@ def setup_github_auth!
|
|
|
285
285
|
{ token: data['token'], expires_at: Time.parse(data['expires_at']) }
|
|
286
286
|
end
|
|
287
287
|
|
|
288
|
-
def
|
|
288
|
+
def find_or_create_cached_token(app_id, installation_id, key_path)
|
|
289
289
|
cache_file = '/tmp/github-app-token-cache'
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
return cache['token'] if expires_at > Time.now + 300
|
|
294
|
-
end
|
|
290
|
+
cached_token = read_cached_token(cache_file)
|
|
291
|
+
return cached_token if cached_token
|
|
292
|
+
|
|
295
293
|
jwt = generate_jwt(app_id, key_path)
|
|
296
294
|
token_data = get_installation_token(jwt, installation_id)
|
|
297
295
|
File.write(cache_file, token_data.to_json)
|
|
298
296
|
token_data[:token]
|
|
299
297
|
end
|
|
300
298
|
|
|
299
|
+
def read_cached_token(cache_file)
|
|
300
|
+
return nil unless File.exist?(cache_file)
|
|
301
|
+
cache = JSON.parse(File.read(cache_file))
|
|
302
|
+
expires_at = Time.parse(cache['expires_at'])
|
|
303
|
+
return cache['token'] if expires_at > Time.now + 300
|
|
304
|
+
nil
|
|
305
|
+
rescue
|
|
306
|
+
end
|
|
307
|
+
|
|
301
308
|
app_id = ENV['GITHUB_APP_CLIENT_ID'] || ENV['GITHUB_APP_ID']
|
|
302
309
|
installation_id = ENV['GITHUB_APP_INSTALLATION_ID']
|
|
303
310
|
key_path = ENV['GITHUB_APP_PRIVATE_KEY_PATH']
|
|
304
311
|
|
|
305
|
-
puts
|
|
312
|
+
puts find_or_create_cached_token(app_id, installation_id, key_path)
|
|
306
313
|
RUBY
|
|
307
314
|
|
|
308
315
|
# Install helper via sudo to /usr/local/bin
|