File size: 893 Bytes
0068ee8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import os
from pathlib import Path
import sys
import inspect

currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, os.path.dirname(parentdir))

from exec_engine.credentials.credentials_utils import CREDS_FOLDER_PATH, insert_creds

AUTHORIZATION_FOLDER_PATH = os.path.dirname(Path(os.path.realpath(__file__)))

def authorize_service(name: str):
    name = name.lower()
    authorization_file = "{name}_authorization.py".format(name = name)
    authorization_path = os.path.join(AUTHORIZATION_FOLDER_PATH, authorization_file)

    if not os.path.exists(authorization_path):
        return False
    else:
        print(exec(open(authorization_path).read(), globals()))
        insert_creds(name, os.path.join(CREDS_FOLDER_PATH, name), target = CREDS_FOLDER_PATH, cred_type="path")
        return True