Skip to content

Commit

Permalink
[cfi] bug fix + update client to use utils.CFEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
yashbonde committed Oct 16, 2023
1 parent 70679ae commit 0e175d1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cf_internal
12 changes: 7 additions & 5 deletions chainfury/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
from functools import lru_cache
from typing import Dict, Any, Tuple

from chainfury.utils import logger
from chainfury.utils import logger, CFEnv


class Subway:
"""
Simple code that allows writing APIs by `.attr.ing` them. This is inspired from gRPC style functional calls which
hides the complexity of underlying networking. This is useful when you are trying to debug live server directly.
**If you want to setup a client, use the ``get_client`` function, this is not what you are looking for.**
Note:
User is solely responsible for checking if the certain API endpoint exists or not. This simply wraps the API
calls and does not do any validation.
Expand Down Expand Up @@ -140,8 +142,8 @@ def get_client(prefix: str = "/api/", url="", token: str = "", trailing: str = "
Example:
>>> from chainfury import get_client
>>> client = get_client()
>>> cf_actions = client.api.v1.fury.actions.list()
>>> cf_actions
>>> chains = client.api.chains() # GET /api/chains
>>> chains
Note:
The `get_client` function is a convenience function that can be used to get a client object. It is not required
Expand All @@ -158,10 +160,10 @@ def get_client(prefix: str = "/api/", url="", token: str = "", trailing: str = "
Returns:
Subway: A Subway object that can be used to interact with the API.
"""
url = url or os.environ.get("CF_URL", "")
url = url or CFEnv.CF_URL()
if not url:
raise ValueError("No url provided, please set CF_URL environment variable or pass url as argument")
token = token or os.environ.get("CF_TOKEN", "")
token = token or CFEnv.CF_TOKEN()
if not token:
raise ValueError("No token provided, please set CF_TOKEN environment variable or pass token as argument")

Expand Down
4 changes: 4 additions & 0 deletions chainfury/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class CFEnv:
* CF_BLOB_BUCKET: blob storage bucket name (only used for `s3` engine)
* CF_BLOB_PREFIX: blob storage prefix (only used for `s3` engine)
* CF_BLOB_AWS_CLOUD_FRONT: blob storage cloud front url, if not provided defaults to primary S3 URL (only used for `s3` engine)
* CF_URL: the URL of the chainfury server
* CF_TOKEN: the token to use to authenticate with the chainfury server
"""

CF_LOG_LEVEL = lambda: os.getenv("CF_LOG_LEVEL", "info")
Expand All @@ -30,6 +32,8 @@ class CFEnv:
CF_BLOB_BUCKET = lambda: os.getenv("CF_BLOB_BUCKET", "")
CF_BLOB_PREFIX = lambda: os.getenv("CF_BLOB_PREFIX", "")
CF_BLOB_AWS_CLOUD_FRONT = lambda: os.getenv("CF_BLOB_AWS_CLOUD_FRONT", "")
CF_URL = lambda: os.getenv("CF_URL", "")
CF_TOKEN = lambda: os.getenv("CF_TOKEN", "")


def store_blob(key: str, value: bytes, engine: str = "", bucket: str = "") -> str:
Expand Down

0 comments on commit 0e175d1

Please sign in to comment.