-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathauthenticate.rb
29 lines (24 loc) · 1.2 KB
/
authenticate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'base64'
def authenticate
if ENV['ANALYTICS_DATA_CREDENTIALS']
# If ANALYTICS_DATA_CREDENTIALS is already set, assume it's pointing to a local file
puts "Using local credentials from ANALYTICS_DATA_CREDENTIALS."
else
if ENV['HEROKU_ANALYTICS_DATA_CREDENTIALS']
# Decode the service account JSON from the HEROKU_ANALYTICS_DATA_CREDENTIALS environment variable
service_account_json = Base64.decode64(ENV['HEROKU_ANALYTICS_DATA_CREDENTIALS'])
# Determine the path to key_temp.py in the same directory as the current script
current_directory = File.dirname(__FILE__)
service_account_file_path = File.join(current_directory, 'key_temp.json')
# Write the decoded JSON to key_temp.py, overriding the file if it already exists
File.open(service_account_file_path, 'w') do |file|
file.write(service_account_json)
end
# Set the environment variable to the path of the file
ENV['ANALYTICS_DATA_CREDENTIALS'] = service_account_file_path
puts "Using credentials from HEROKU_ANALYTICS_DATA_CREDENTIALS and writing to key_temp.json."
else
raise "HEROKU_ANALYTICS_DATA_CREDENTIALS environment variable is not set."
end
end
end