-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.py
57 lines (42 loc) · 1.37 KB
/
config.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import configparser
import functools
import os
from fal_client.auth import MissingCredentialsError, FAL_RUN_HOST
@functools.cache
def get_fal_config():
curr_dir = os.path.dirname(os.path.realpath(__file__))
fal_config_path = os.path.join(curr_dir, "fal-config.ini")
config = configparser.ConfigParser()
config.read(fal_config_path)
return config
@functools.cache
def get_fal_endpoint():
config = get_fal_config()
endpoint = os.environ.get("FAL_COMFY_ENDPOINT", config["fal"]["application_name"])
return f"https://{FAL_RUN_HOST}/{endpoint}"
@functools.cache
def get_headers():
api_key = get_fal_api_key()
return {"Authorization": f"Key {api_key}"}
def get_fal_api_key():
from fal_client.auth import fetch_credentials
try:
api_key = fetch_credentials()
except MissingCredentialsError:
api_key = None
try:
if not api_key:
config = get_fal_config()
api_key = config["fal"]["api_key"]
except Exception as e:
print(e)
if not api_key:
raise MissingCredentialsError("No FAL API key found.")
return api_key
def set_fal_credentials():
api_key = get_fal_api_key()
os.environ["FAL_KEY"] = api_key
# Backwards compatibility
key_id, key_secret = api_key.split(":")
os.environ["FAL_KEY_ID"] = key_id
os.environ["FAL_KEY_SECRET"] = key_secret