ercanburak commited on
Commit
121d002
·
1 Parent(s): 3e36801

get private keys as env var

Browse files
Files changed (2) hide show
  1. evreal_cred.json +13 -0
  2. gdrive.py +5 -1
evreal_cred.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "type": "service_account",
3
+ "project_id": "evreal",
4
+ "private_key_id": "***",
5
+ "private_key": "***",
6
+ "client_email": "[email protected]",
7
+ "client_id": "112071584481993672650",
8
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
9
+ "token_uri": "https://oauth2.googleapis.com/token",
10
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/evreal%40evreal.iam.gserviceaccount.com",
12
+ "universe_domain": "googleapis.com"
13
+ }
gdrive.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
 
3
  from pydrive2.auth import GoogleAuth
4
  from pydrive2.drive import GoogleDrive
@@ -9,7 +10,10 @@ def login_with_service_account():
9
  scope = ["https://www.googleapis.com/auth/drive"]
10
  gauth = GoogleAuth()
11
  gauth.auth_method = 'service'
12
- gauth.credentials = ServiceAccountCredentials.from_json_keyfile_name('evreal-bf06ca1ac056.json', scope)
 
 
 
13
  return gauth
14
 
15
 
 
1
  import os
2
+ import json
3
 
4
  from pydrive2.auth import GoogleAuth
5
  from pydrive2.drive import GoogleDrive
 
10
  scope = ["https://www.googleapis.com/auth/drive"]
11
  gauth = GoogleAuth()
12
  gauth.auth_method = 'service'
13
+ cred_dict = json.load(open('evreal_cred.json', 'r'))
14
+ cred_dict['private_key_id'] = os.environ['PRIVATE_KEY_ID']
15
+ cred_dict['private_key'] = os.environ['PRIVATE_KEY'].replace('\\n', '\n')
16
+ gauth.credentials = ServiceAccountCredentials.from_json_keyfile_dict(cred_dict, scope)
17
  return gauth
18
 
19