-
Notifications
You must be signed in to change notification settings - Fork 27
User experience #141
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
User experience #141
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| """ADT System Information wrappers""" | ||
|
|
||
| from xml.etree import ElementTree | ||
|
|
||
| from sap.adt.core import Connection | ||
|
|
||
|
|
||
| XMLNS_ATOM = '{http://www.w3.org/2005/Atom}' | ||
|
|
||
| JSON_KEY_MAPPING = { | ||
| 'systemID': 'SID', | ||
| } | ||
|
|
||
|
|
||
| # pylint: disable=too-few-public-methods | ||
| class SystemInfoEntry: | ||
| """A single entry from the system information feed""" | ||
|
|
||
| def __init__(self, identity, title): | ||
| self.identity = identity | ||
| self.title = title | ||
|
|
||
|
|
||
| class SystemInformation: | ||
| """Parsed system information from ADT""" | ||
|
|
||
| def __init__(self, entries): | ||
| self._entries = {entry.identity: entry for entry in entries} | ||
|
|
||
| @property | ||
| def entries(self): | ||
| """Returns a list of all system information entries""" | ||
| return list(self._entries.values()) | ||
|
|
||
| def get(self, identity): | ||
| """Returns the title for the given identity or None if not found""" | ||
| entry = self._entries.get(identity) | ||
| return entry.title if entry else None | ||
|
|
||
| def __iter__(self): | ||
| return iter(self._entries.values()) | ||
|
|
||
|
|
||
| def _fetch_xml_entries(connection): | ||
| """Fetch entries from the Atom feed endpoint /sap/bc/adt/system/information""" | ||
|
|
||
| resp = connection.execute( | ||
| 'GET', | ||
| 'system/information', | ||
| accept='application/atom+xml;type=feed', | ||
| ) | ||
|
|
||
| root = ElementTree.fromstring(resp.text) | ||
|
|
||
| entries = [] | ||
| for entry_elem in root.findall(f'{XMLNS_ATOM}entry'): | ||
| identity = entry_elem.find(f'{XMLNS_ATOM}id').text | ||
| title = entry_elem.find(f'{XMLNS_ATOM}title').text | ||
| entries.append(SystemInfoEntry(identity, title)) | ||
|
|
||
| return entries | ||
|
|
||
|
|
||
| def _fetch_json_entries(connection): | ||
| """Fetch entries from the JSON endpoint /sap/bc/adt/core/http/systeminformation""" | ||
|
|
||
| resp = connection.execute( | ||
| 'GET', | ||
| 'core/http/systeminformation', | ||
| accept='application/vnd.sap.adt.core.http.systeminformation.v1+json' | ||
| ) | ||
|
|
||
| data = resp.json() | ||
|
|
||
| return [SystemInfoEntry(JSON_KEY_MAPPING.get(key, key), value) for key, value in data.items()] | ||
|
|
||
|
|
||
| def get_information(connection: Connection) -> SystemInformation: | ||
| """Fetch system information from ADT endpoints | ||
|
|
||
| Sends GET requests to /sap/bc/adt/system/information and | ||
| /sap/bc/adt/core/http/systeminformation, merges the results | ||
| into a single SystemInformation object. Entries from the XML | ||
| endpoint take precedence over entries from the JSON endpoint | ||
| if the same key exists in both. | ||
| """ | ||
|
|
||
| xml_entries = _fetch_xml_entries(connection) | ||
| json_entries = _fetch_json_entries(connection) | ||
|
|
||
| merged = {entry.identity: entry for entry in json_entries} | ||
| for entry in xml_entries: | ||
| merged[entry.identity] = entry | ||
|
|
||
| return SystemInformation(list(merged.values())) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| """System Information ADT fixtures""" | ||
|
|
||
| from mock import Response | ||
|
|
||
| SYSTEM_INFORMATION_XML = '''<?xml version="1.0" encoding="utf-8"?> | ||
| <atom:feed xmlns:atom="http://www.w3.org/2005/Atom"> | ||
| <atom:author> | ||
| <atom:name>SAP SE</atom:name> | ||
| </atom:author> | ||
| <atom:title>System Information</atom:title> | ||
| <atom:updated>2026-03-23T13:43:39Z</atom:updated> | ||
| <atom:entry> | ||
| <atom:id>ApplicationServerName</atom:id> | ||
| <atom:title>C50_ddci</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>DBLibrary</atom:id> | ||
| <atom:title>SQLDBC 2.27.024.1772569942</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>DBName</atom:id> | ||
| <atom:title>C50/02</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>DBRelease</atom:id> | ||
| <atom:title>2.00.089.01.1769502981</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>DBSchema</atom:id> | ||
| <atom:title>SAPHANADB</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>DBServer</atom:id> | ||
| <atom:title>saphost</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>DBSystem</atom:id> | ||
| <atom:title>HDB</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>IPAddress</atom:id> | ||
| <atom:title>172.27.4.5</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>KernelCompilationDate</atom:id> | ||
| <atom:title>Linux GNU SLES-15 x86_64 cc10.3.0 use-pr260304 Mar 09 2026 11:05:09</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>KernelKind</atom:id> | ||
| <atom:title>opt</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>KernelPatchLevel</atom:id> | ||
| <atom:title>0</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>KernelRelease</atom:id> | ||
| <atom:title>920</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>MachineType</atom:id> | ||
| <atom:title>x86_64</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>NodeName</atom:id> | ||
| <atom:title>saphost</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>NotAuthorizedDB</atom:id> | ||
| <atom:title>false</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>NotAuthorizedHost</atom:id> | ||
| <atom:title>false</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>NotAuthorizedKernel</atom:id> | ||
| <atom:title>false</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>NotAuthorizedSystem</atom:id> | ||
| <atom:title>false</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>NotAuthorizedUser</atom:id> | ||
| <atom:title>false</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>OSName</atom:id> | ||
| <atom:title>Linux</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>OSVersion</atom:id> | ||
| <atom:title>6.4.0-150600.23.60-default</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>SAPSystemID</atom:id> | ||
| <atom:title>390</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>SAPSystemNumber</atom:id> | ||
| <atom:title>000000000000000001</atom:title> | ||
| </atom:entry> | ||
| <atom:entry> | ||
| <atom:id>UnicodeSystem</atom:id> | ||
| <atom:title>True</atom:title> | ||
| </atom:entry> | ||
| </atom:feed>''' | ||
|
|
||
| RESPONSE_SYSTEM_INFORMATION = Response( | ||
| text=SYSTEM_INFORMATION_XML, | ||
| status_code=200, | ||
| headers={'Content-Type': 'application/atom+xml;type=feed'} | ||
| ) | ||
|
|
||
| JSON_SYSTEM_INFORMATION = { | ||
| 'systemID': 'C50', | ||
| 'userName': 'DEVELOPER', | ||
| 'userFullName': '', | ||
| 'client': '100', | ||
| 'language': 'EN', | ||
| } | ||
|
|
||
| RESPONSE_JSON_SYSTEM_INFORMATION = Response( | ||
| status_code=200, | ||
| json=JSON_SYSTEM_INFORMATION, | ||
| headers={'Content-Type': 'application/vnd.sap.adt.core.http.systeminformation.v1+json'} | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential
AttributeErrorif XML entry lacksidortitleelement.If the server returns an
<entry>without an<atom:id>or<atom:title>child,find()returnsNoneand accessing.textwill raiseAttributeError. Consider adding defensive checks.🛡️ Suggested defensive handling
for entry_elem in root.findall(f'{XMLNS_ATOM}entry'): - identity = entry_elem.find(f'{XMLNS_ATOM}id').text - title = entry_elem.find(f'{XMLNS_ATOM}title').text - entries.append(SystemInfoEntry(identity, title)) + id_elem = entry_elem.find(f'{XMLNS_ATOM}id') + title_elem = entry_elem.find(f'{XMLNS_ATOM}title') + if id_elem is not None and title_elem is not None: + entries.append(SystemInfoEntry(id_elem.text, title_elem.text))🧰 Tools
🪛 Ruff (0.15.7)
[error] 53-53: Using
xmlto parse untrusted data is known to be vulnerable to XML attacks; usedefusedxmlequivalents(S314)
🤖 Prompt for AI Agents