Skip to content

Commit 8405687

Browse files
committed
Use credentials.json to write token to env var
1 parent 701ea13 commit 8405687

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
from google.oauth2 import service_account
3+
from google.auth.transport.requests import Request
4+
5+
def get_token_from_user_file(user_file_path):
6+
SCOPES = ["https://www.googleapis.com/auth/spreadsheets"]
7+
8+
credentials = service_account.Credentials.from_service_account_file(
9+
user_file_path,
10+
scopes=SCOPES
11+
)
12+
13+
request = Request()
14+
credentials.refresh(request)
15+
return credentials.token
16+
17+
key_file_path = "credentials.json"
18+
token = get_token_from_user_file(key_file_path)
19+
20+
env_file = os.getenv('GITHUB_ENV')
21+
22+
with open(env_file, "a") as myfile:
23+
# Set the token as an env var for some tests
24+
myfile.write(f"TOKEN={token}\n")
25+
# Set the key_file filepath as an env var for other tests
26+
myfile.write(f"KEY_FILE_PATH={key_file_path}")
27+

0 commit comments

Comments
 (0)