Skip to content
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
12 changes: 11 additions & 1 deletion .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
"prepareCmd": "pip install --no-cache-dir build && python -m build"
}
],
[
"semantic-release-plugin-update-version-in-files",
{
"files": [
"zitadel_client/version.py"
],
"placeholder": "0.0.0"
}
],
[
"@semantic-release/github",
{
Expand All @@ -25,7 +34,8 @@
{
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
"assets": [
"pyproject.toml"
"pyproject.toml",
"zitadel_client/version.py"
]
}
]
Expand Down
3 changes: 3 additions & 0 deletions test/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def test_assert_headers_and_content_type(self):
"headers": {
"Authorization": {
"equalTo": "Bearer mm"
},
"User-Agent": {
"matches": "^zitadel-client/0\\.0\\.0 \\(lang=python; lang_version=[^;]+; os=[^;]+; arch=[^;]+\\)$"
}
}
},
Expand Down
20 changes: 20 additions & 0 deletions test/test_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import unittest

from zitadel_client.auth.no_auth_authenticator import NoAuthAuthenticator
from zitadel_client.configuration import Configuration


class ConfigurationTest(unittest.TestCase):

def test_user_agent_getter_and_setter(self):
"""
Test user agent getter and setter.

@return void
"""
config = Configuration(NoAuthAuthenticator())

self.assertRegex(config.user_agent,
r"^zitadel-client/0\.0\.0 \(lang=python; lang_version=[^;]+; os=[^;]+; arch=[^;]+\)$")
config.user_agent = "CustomUserAgent/1.0"
self.assertEqual(config.user_agent, "CustomUserAgent/1.0")
14 changes: 3 additions & 11 deletions zitadel_client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ def __init__(
self.configuration = configuration

self.rest_client = rest.RESTClientObject(configuration)
self.default_headers = {}
self.default_headers = {
'User-Agent': configuration.user_agent
}
if header_name is not None:
self.default_headers[header_name] = header_value
self.user_agent = 'OpenAPI-Generator/0.0.1/python'
self.client_side_validation = configuration.client_side_validation

def __enter__(self):
Expand All @@ -73,15 +74,6 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, traceback):
pass

@property
def user_agent(self):
"""User agent for this API client"""
return self.default_headers['User-Agent']

@user_agent.setter
def user_agent(self, value):
self.default_headers['User-Agent'] = value

def set_default_header(self, header_name, header_value):
self.default_headers[header_name] = header_value

Expand Down
25 changes: 24 additions & 1 deletion zitadel_client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
import http.client as httplib
import logging
import multiprocessing
import platform
import sys
from logging import FileHandler
from typing import Any, Dict, Optional, Union

from typing_extensions import Self

from zitadel_client.auth.authenticator import Authenticator

from zitadel_client.version import Version

class Configuration:
"""This class contains various settings of the API client.
"""
USER_AGENT = f"zitadel-client/{Version.VERSION} (lang=python; lang_version={platform.python_version()}; os={platform.system()}; arch={platform.machine()})".lower()

def __init__(
self,
Expand All @@ -26,6 +28,7 @@ def __init__(
) -> None:
"""Constructor
"""
self._user_agent = Configuration.USER_AGENT
self.authenticator = authenticator
self.api_key_prefix = {}
self.refresh_api_key_hook = None
Expand Down Expand Up @@ -195,3 +198,23 @@ def to_debug_report() -> str:
def host(self) -> str:
"""Return generated host."""
return self.authenticator.get_host()

@property
def user_agent(self):
"""
Get the user agent string.

Returns:
str: The current value of the user agent.
"""
return self._user_agent

@user_agent.setter
def user_agent(self, value):
"""
Set the user agent string.

Args:
value (str): The new user agent string to set.
"""
self._user_agent = value
2 changes: 2 additions & 0 deletions zitadel_client/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Version:
VERSION = "0.0.0"