Skip to content

Commit e9569e0

Browse files
Merge pull request #144 from cortexapps/143-base_url-not-honored-from-configuration-file
143 base url not honored from configuration file
2 parents b680215 + c9678e9 commit e9569e0

File tree

7 files changed

+61
-52
lines changed

7 files changed

+61
-52
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# the repo. Unless a later match takes precedence,
66
# @global-owner1 and @global-owner2 will be requested for
77
# review when someone opens a pull request.
8-
* @jeff-schnitter
8+
* @jeff-schnitter @Cantaley

DEVELOPER.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,8 @@ Available recipes:
1818
test testname # Run a single test, ie: just test tests/test_catalog.py
1919
test-all # Run all tests
2020
test-import # Run import test, a pre-requisite for any tests that rely on test data.
21-
test-parallel # Run tests that can run in parallel
22-
test-serial # Run tests that have to run sequentially
2321
```
2422

25-
## Sequential and parallel tests
26-
Most tests can run in a parallel but a handful have dependencies that can impact other tests,
27-
for example changing the scope of CORTEX_API_KEY, so they have to run sequentially.
28-
29-
The `test-all` target runs all the tests that can be run in parallel, followed by those that
30-
have to run sequentially.
31-
3223
# Commit messages
3324
The CLI uses [git-changelog](https://pypi.org/project/git-changelog/) to dynamically generate
3425
the [HISTORY.md](./HISTORY.md) file.

HISTORY.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

88
<!-- insertion marker -->
9+
## [1.0.5](https://github.com/cortexapps/cli/releases/tag/1.0.5) - 2025-08-25
10+
11+
<small>[Compare with 1.0.4](https://github.com/cortexapps/cli/compare/1.0.4...1.0.5)</small>
12+
13+
### Fixed
14+
15+
- fix: correct end endpoint for adding multiple configurations ([8e325bb](https://github.com/cortexapps/cli/commit/8e325bbfd71a38f9d6ac4439276ad7eef8e34fff) by Jeff Schnitter).
16+
917
## [1.0.4](https://github.com/cortexapps/cli/releases/tag/1.0.4) - 2025-08-01
1018

1119
<small>[Compare with 1.0.3](https://github.com/cortexapps/cli/compare/1.0.3...1.0.4)</small>

Justfile

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,17 @@ _setup:
1212
@if [ -f .coverage ]; then rm .coverage; fi
1313

1414
# Run all tests
15-
test-all: _setup test-parallel test-serial
16-
17-
# Run tests that can run in parallel
18-
test-parallel: test-import
19-
{{pytest}} -n auto -m "not setup and not serial" --html=report-parallel.html --self-contained-html --cov=cortexapps_cli --cov-append --cov-report term-missing tests
15+
test-all: _setup test-import
16+
{{pytest}} -n auto -m "not setup" --html=report.html --self-contained-html --cov=cortexapps_cli --cov-append --cov-report term-missing tests
2017

2118
# Run all tests serially - helpful to see if any tests seem to be hanging
2219
_test-all-individual: test-import
2320
{{pytest}} --html=report-all-invidual.html --self-contained-html --cov=cortexapps_cli --cov-append --cov-report term-missing tests
2421

25-
# Run tests that have to run sequentially
26-
test-serial: test-import
27-
{{pytest}} -n auto -m "serial" --html=report-serial.html --self-contained-html --cov=cortexapps_cli --cov-append --cov-report term-missing tests
28-
2922
# Run import test, a pre-requisite for any tests that rely on test data.
3023
test-import:
31-
{{pytest}} tests/test_import.py --cov=cortexapps_cli --cov-report=
24+
{{pytest}} tests/test_import.py --cov=cortexapps_cli --cov-report=
3225

3326
# Run a single test, ie: just test tests/test_catalog.py
3427
test testname:
35-
{{pytest}} {{testname}}
28+
{{pytest}} -n auto {{testname}}

cortexapps_cli/cli.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
def global_callback(
7979
ctx: typer.Context,
8080
api_key: str = typer.Option(None, "--api-key", "-k", help="API key", envvar="CORTEX_API_KEY"),
81-
url: str = typer.Option("https://api.getcortexapp.com", "--url", "-u", help="Base URL for the API", envvar="CORTEX_BASE_URL"),
81+
url: str = typer.Option(None, "--url", "-u", help="Base URL for the API", envvar="CORTEX_BASE_URL"),
8282
config_file: str = typer.Option(os.path.join(os.path.expanduser('~'), '.cortex', 'config'), "--config", "-c", help="Config file path", envvar="CORTEX_CONFIG"),
8383
tenant: str = typer.Option("default", "--tenant", "-t", help="Tenant alias", envvar="CORTEX_TENANT_ALIAS"),
8484
log_level: Annotated[str, typer.Option("--log-level", "-l", help="Set the logging level")] = "INFO"
@@ -109,16 +109,17 @@ def global_callback(
109109
else:
110110
# config file found
111111
# if api_key is provided, use that in preference to the config file
112+
config = configparser.ConfigParser()
113+
config.read(config_file)
114+
if tenant not in config:
115+
raise typer.BadParameter(f"Tenant {tenant} not found in config file")
112116
if not api_key:
113-
config = configparser.ConfigParser()
114-
config.read(config_file)
115-
if tenant not in config:
116-
raise typer.BadParameter(f"Tenant {tenant} not found in config file")
117117
api_key = config[tenant]["api_key"]
118-
if url not in config[tenant]:
119-
url = url
118+
if not url:
119+
if 'base_url' in config[tenant].keys():
120+
url = config[tenant]['base_url']
120121
else:
121-
url = config[tenant]["base_url"]
122+
url = "https://api.getcortexapp.com"
122123

123124
# strip any quotes or spaces from the api_key and url
124125
api_key = api_key.strip('"\' ')
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from tests.helpers.utils import *
22

33
def test():
4-
cli(["catalog", "archive", "-t", "archive-entity"])
4+
cli(["catalog", "archive", "-t", "cli-test-archive-entity"])
55

6-
response = cli(["catalog", "details", "-t", "archive-entity"])
6+
response = cli(["catalog", "details", "-t", "cli-test-archive-entity"])
77
assert response['isArchived'] == True, "isArchived attribute should be true"

tests/test_config_file.py

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,12 @@
33
Tests for the cortex CLI config file
44
"""
55

6-
# These tests are all marked to run in serial order because they make modifications to the
7-
# cortex config file and/or CORTEX_API_KEY value and would potentially impact other tests
8-
# that are running in parallel (with poetry run pytest -n auto), so they are run separately.
9-
10-
# Additionally, order is VERY IMPORTANT in this file because of the way CORTEX_API key is
11-
# deleted, set to invalid values, etc. Moving test order could impact the overall success
12-
# of pytest. Tread carefully here.
13-
146
import io
157
import os
168
import pytest
179
import sys
1810
from string import Template
1911

20-
# Requires user input, so use monkeypatch to set it.
21-
@pytest.fixture(scope="session")
22-
def delete_cortex_api_key():
23-
if "CORTEX_API_KEY" in os.environ:
24-
del os.environ['CORTEX_API_KEY']
25-
26-
@pytest.mark.serial
2712
def test_config_file_api_key_quotes(tmp_path):
2813
cortex_api_key = os.getenv('CORTEX_API_KEY')
2914
f = tmp_path / "cortex_config_api_key_quotes"
@@ -35,22 +20,53 @@ def test_config_file_api_key_quotes(tmp_path):
3520
f.write_text(content)
3621
cli(["-c", str(f), "entity-types", "list"])
3722

38-
@pytest.mark.serial
3923
def test_config_file_create(monkeypatch, tmp_path):
4024
monkeypatch.setattr('sys.stdin', io.StringIO('y'))
4125
f = tmp_path / "test-config.txt"
4226
response = cli(["-c", str(f), "-k", os.getenv('CORTEX_API_KEY'), "scorecards", "list"])
4327
assert any(scorecard['tag'] == 'cli-test-scorecard' for scorecard in response['scorecards']), "Should find scorecard with tag cli-test-scorecard"
4428

45-
@pytest.mark.serial
46-
def test_config_file_bad_api_key(monkeypatch, tmp_path, delete_cortex_api_key):
29+
def test_config_file_bad_api_key(monkeypatch, tmp_path):
30+
monkeypatch.delenv("CORTEX_API_KEY")
4731
monkeypatch.setattr('sys.stdin', io.StringIO('y'))
4832
f = tmp_path / "test-config-bad-api-key.txt"
4933
response = cli(["-c", str(f), "-k", "invalidApiKey", "scorecards", "list"], return_type=ReturnType.RAW)
5034
assert "401 Client Error: Unauthorized" in str(response), "should get Unauthorized error"
5135

52-
@pytest.mark.serial
53-
def test_environment_variable_invalid_key():
54-
os.environ["CORTEX_API_KEY"] = "invalidKey"
36+
def test_environment_variable_invalid_key(monkeypatch):
37+
monkeypatch.setenv("CORTEX_API_KEY", "invalidKey")
5538
response = cli(["scorecards", "list"], return_type=ReturnType.RAW)
5639
assert "401 Client Error: Unauthorized" in str(response), "should get Unauthorized error"
40+
41+
def test_config_file_bad_url(monkeypatch, tmp_path):
42+
monkeypatch.delenv("CORTEX_BASE_URL")
43+
cortex_api_key = os.getenv('CORTEX_API_KEY')
44+
f = tmp_path / "cortex_config_api_key_quotes"
45+
template = Template("""
46+
[default]
47+
api_key = "${cortex_api_key}"
48+
49+
[mySection]
50+
api_key = "${cortex_api_key}"
51+
base_url = https://bogus.url
52+
""")
53+
content = template.substitute(cortex_api_key=cortex_api_key)
54+
f.write_text(content)
55+
response = cli(["-c", str(f), "-l", "DEBUG", "-t", "mySection", "entity-types", "list"], return_type=ReturnType.RAW)
56+
assert "Max retries exceeded with url" in str(response), "should get max retries error"
57+
58+
def test_config_file_base_url_env_var(monkeypatch, tmp_path):
59+
cortex_api_key = os.getenv('CORTEX_API_KEY')
60+
f = tmp_path / "cortex_config_api_key_quotes"
61+
template = Template("""
62+
[default]
63+
api_key = "${cortex_api_key}"
64+
65+
[mySection]
66+
api_key = "${cortex_api_key}"
67+
base_url = https://bogus.url
68+
""")
69+
content = template.substitute(cortex_api_key=cortex_api_key)
70+
f.write_text(content)
71+
monkeypatch.setenv("CORTEX_BASE_URL", "https://api.getcortexapp.com")
72+
cli(["-c", str(f), "-t", "mySection", "entity-types", "list"])

0 commit comments

Comments
 (0)