Skip to content

Commit

Permalink
feat(fal): support basic fal profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Jan 13, 2025
1 parent 1d1bddd commit 3b5c647
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
9 changes: 6 additions & 3 deletions projects/fal/src/fal/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import click

from fal.auth import auth0, local
from fal.config import Config
from fal.console import console
from fal.console.icons import CHECK_ICON
from fal.exceptions.auth import UnauthenticatedException
Expand All @@ -16,9 +17,11 @@ def key_credentials() -> tuple[str, str] | None:
if os.environ.get("FAL_FORCE_AUTH_BY_USER") == "1":
return None

if "FAL_KEY" in os.environ:
key = os.environ["FAL_KEY"]
key_id, key_secret = key.split(":", 1)
config = Config()

fal_key = os.environ.get("FAL_KEY") or config.get("key")
if fal_key:
key_id, key_secret = fal_key.split(":", 1)
return (key_id, key_secret)
elif "FAL_KEY_ID" in os.environ and "FAL_KEY_SECRET" in os.environ:
return (os.environ["FAL_KEY_ID"], os.environ["FAL_KEY_SECRET"])
Expand Down
23 changes: 23 additions & 0 deletions projects/fal/src/fal/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os

import tomli


class Config:
DEFAULT_CONFIG_PATH = "~/.fal/config.toml"
DEFAULT_PROFILE = "default"

def __init__(self):
self.config_path = os.path.expanduser(
os.getenv("FAL_CONFIG_PATH", self.DEFAULT_CONFIG_PATH)
)
self.profile = os.getenv("FAL_PROFILE", self.DEFAULT_PROFILE)

try:
with open(self.config_path, "rb") as file:
self.config = tomli.load(file)
except FileNotFoundError:
self.config = {}

def get(self, key):
return self.config.get(self.profile, {}).get(key)

0 comments on commit 3b5c647

Please sign in to comment.