Skip to content

Commit 43d7a2e

Browse files
authored
fix: use collection version in User-Agent instead of Ansible version (#29)
1 parent fd471bb commit 43d7a2e

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Use collection version in User-Agent header instead of Ansible version.
13+
1014
## [0.8.0] - 2025-08-18
1115

1216
### Added

plugins/inventory/servers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@
128128
from ansible.errors import AnsibleError
129129
from ansible.module_utils._text import to_native
130130
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable
131-
from ansible.release import __version__
132131
from ansible.utils.display import Display
133132

133+
from ..version import collection_version
134+
134135
display = Display()
135136

136137
try:
@@ -182,7 +183,8 @@ def _initialize_upcloud_client(self):
182183
'Update upcloud-api to version 2.8.0 or later.'
183184
) from None
184185

185-
self.client.api.user_agent = f"upcloud-ansible-inventory/{__version__}"
186+
version = collection_version() or "dev"
187+
self.client.api.user_agent = f"upcloud-ansible-inventory/{version}"
186188

187189
api_root_env = "UPCLOUD_API_ROOT"
188190
if os.getenv(api_root_env):

plugins/version.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import json
2+
import os
3+
import yaml
4+
5+
6+
def collection_version():
7+
'''Read collection version from MANIFEST.json or galaxy.yml'''
8+
plugins_dir = os.path.dirname(os.path.abspath(__file__))
9+
10+
try:
11+
with open(os.path.join(plugins_dir, '../MANIFEST.json')) as f:
12+
data = json.load(f)
13+
return data.get('collection_info', {}).get('version')
14+
except (FileNotFoundError, json.JSONDecodeError):
15+
pass
16+
17+
try:
18+
with open(os.path.join(plugins_dir, '../galaxy.yml')) as f:
19+
data = yaml.safe_load(f)
20+
return data.get('version')
21+
except (FileNotFoundError, yaml.YAMLError):
22+
pass
23+
24+
return None

0 commit comments

Comments
 (0)