Skip to content

Fix Python client not respecting CORTEX_CLI_CONFIG_DIR environment variable for client-id.txt #1953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions pkg/cortex/client/cortex/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@
from cortex import util


def cli_config_dir() -> Path:
cli_config_dir = os.environ.get("CORTEX_CLI_CONFIG_DIR", "")
if cli_config_dir == "":
return Path.home() / ".cortex"
return Path(cli_config_dir).expanduser().resolve()


class Client:
@sentry_wrapper
def __init__(self, env: dict):
Expand Down Expand Up @@ -129,7 +122,7 @@ def create_api(
if api_spec.get("name") is None:
raise ValueError("`api_spec` must have the `name` key set")

project_dir = cli_config_dir() / "deployments" / api_spec["name"]
project_dir = util.cli_config_dir() / "deployments" / api_spec["name"]

if project_dir.exists():
shutil.rmtree(str(project_dir))
Expand Down Expand Up @@ -367,7 +360,9 @@ def patch(self, api_spec: dict, force: bool = False) -> dict:
force: Override an already in-progress API update.
"""

cortex_yaml_file = cli_config_dir() / "deployments" / f"cortex-{str(uuid.uuid4())}.yaml"
cortex_yaml_file = (
util.cli_config_dir() / "deployments" / f"cortex-{str(uuid.uuid4())}.yaml"
)
with util.open_temporarily(cortex_yaml_file, "w") as f:
yaml.dump([api_spec], f)
args = ["patch", cortex_yaml_file, "--env", self.env_name, "-o", "json"]
Expand Down
3 changes: 2 additions & 1 deletion pkg/cortex/client/cortex/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
CORTEX_TELEMETRY_SENTRY_DSN,
CORTEX_TELEMETRY_SENTRY_ENVIRONMENT,
)
from cortex import util


def _sentry_client(
Expand Down Expand Up @@ -81,7 +82,7 @@ def _create_default_scope(optional_tags: dict = {}) -> sentry_sdk.Scope:
scope = sentry_sdk.Scope()

user_id = None
client_id_file_path = pathlib.Path.home() / ".cortex" / "client-id.txt"
client_id_file_path = util.cli_config_dir() / "client-id.txt"
if not client_id_file_path.is_file():
client_id_file_path.parent.mkdir(parents=True, exist_ok=True)
client_id_file_path.write_text(str(uuid4()))
Expand Down
7 changes: 7 additions & 0 deletions pkg/cortex/client/cortex/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
import shutil


def cli_config_dir() -> Path:
cli_config_dir = os.environ.get("CORTEX_CLI_CONFIG_DIR", "")
if cli_config_dir == "":
return Path.home() / ".cortex"
return Path(cli_config_dir).expanduser().resolve()


@contextmanager
def open_temporarily(path, mode):
Path(path).parent.mkdir(parents=True, exist_ok=True)
Expand Down