diff --git a/CLAUDE.md b/CLAUDE.md index a4fd14e..b0217e6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -224,6 +224,18 @@ git checkout --theirs HISTORY.md git add HISTORY.md ``` +### HISTORY.md Merge Conflicts +The `HISTORY.md` file is auto-generated when `staging` is merged to `main`. This means: +- `main` always has the latest HISTORY.md +- `staging` lags behind until the next release +- Feature branches created from `main` have the updated history + +When merging feature branches to `staging`, conflicts in HISTORY.md are expected. Resolve by accepting the incoming version: +```bash +git checkout --theirs HISTORY.md +git add HISTORY.md +``` + ### GitHub Actions - **`publish.yml`**: Triggered on push to `main`, handles versioning and multi-platform publishing - **`test-pr.yml`**: Runs tests on pull requests diff --git a/HISTORY.md b/HISTORY.md index a02d3f7..872e27b 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - remove rate limiter initialization log message (#169) #patch ([015107a](https://github.com/cortexapps/cli/commit/015107aca15d5a4cf4eb746834bcbb7dac607e1d) by Jeff Schnitter). + ## [1.5.0](https://github.com/cortexapps/cli/releases/tag/1.5.0) - 2025-11-13 [Compare with 1.4.0](https://github.com/cortexapps/cli/compare/1.4.0...1.5.0) diff --git a/cortexapps_cli/cortex_client.py b/cortexapps_cli/cortex_client.py index 5a7e349..320edc1 100644 --- a/cortexapps_cli/cortex_client.py +++ b/cortexapps_cli/cortex_client.py @@ -1,3 +1,4 @@ +import importlib.metadata import requests from requests.adapters import HTTPAdapter from urllib3.util.retry import Retry @@ -71,6 +72,11 @@ def __init__(self, api_key, tenant, numeric_level, base_url='https://api.getcort self.tenant = tenant self.base_url = base_url + try: + self.version = importlib.metadata.version('cortexapps_cli') + except importlib.metadata.PackageNotFoundError: + self.version = 'unknown' + logging.basicConfig(level=numeric_level) self.logger = logging.getLogger(__name__) @@ -110,6 +116,7 @@ def request(self, method, endpoint, params={}, headers={}, data=None, raw_body=F req_headers = { 'Authorization': f'Bearer {self.api_key}', 'Content-Type': content_type, + 'User-Agent': f'cortexapps-cli/{self.version}', **headers } url = '/'.join([self.base_url.rstrip('/'), endpoint.lstrip('/')]) diff --git a/tests/test_scim.py b/tests/test_scim.py index 3215747..ed5bda7 100644 --- a/tests/test_scim.py +++ b/tests/test_scim.py @@ -2,6 +2,7 @@ from urllib.error import HTTPError import pytest +@pytest.mark.skip(reason="Disabled until CET-23082 is resolved.") def test(): response = cli(["scim", "list"], ReturnType.STDOUT) diff --git a/tests/test_user_agent.py b/tests/test_user_agent.py new file mode 100644 index 0000000..56b63b1 --- /dev/null +++ b/tests/test_user_agent.py @@ -0,0 +1,20 @@ +from tests.helpers.utils import * + +@responses.activate +def test_user_agent_header_is_set(): + """Verify that all API requests include a User-Agent header identifying the CLI.""" + responses.add(responses.GET, os.getenv("CORTEX_BASE_URL") + "/api/v1/catalog", json={"entities": [], "total": 0, "page": 0, "totalPages": 0}, status=200) + cli(["catalog", "list", "-p", "0"]) + assert len(responses.calls) == 1 + user_agent = responses.calls[0].request.headers.get("User-Agent", "") + assert user_agent.startswith("cortexapps-cli/") + +@responses.activate +def test_user_agent_header_contains_version(): + """Verify that the User-Agent header contains the package version.""" + import importlib.metadata + expected_version = importlib.metadata.version('cortexapps_cli') + responses.add(responses.GET, os.getenv("CORTEX_BASE_URL") + "/api/v1/catalog", json={"entities": [], "total": 0, "page": 0, "totalPages": 0}, status=200) + cli(["catalog", "list", "-p", "0"]) + user_agent = responses.calls[0].request.headers.get("User-Agent", "") + assert user_agent == f"cortexapps-cli/{expected_version}"