-
Notifications
You must be signed in to change notification settings - Fork 39
Add listing of sanatized integrations. #261
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
Closed
Closed
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,12 @@ | |
| - Label constants for managed-runtime fragment types | ||
| - Fragment listing by label (MCP, A2A, IAS) | ||
| - IAS fragment name lookup for auth flows | ||
| - Active integration listing for tenant context | ||
| """ | ||
|
|
||
| import logging | ||
| from enum import Enum | ||
| from typing import Optional | ||
|
|
||
| from sap_cloud_sdk.destination import ( | ||
| create_fragment_client, | ||
|
|
@@ -25,6 +27,9 @@ | |
|
|
||
| _DESTINATION_INSTANCE = "default" | ||
|
|
||
| # URL mode path segments used by system integration fragments | ||
| _INTEGRATION_URL_MODES = ("mcp", "a2a") | ||
|
|
||
|
|
||
| class FragmentLabel(str, Enum): | ||
| """Label values for the sap-managed-runtime-type fragment label key.""" | ||
|
|
@@ -118,3 +123,91 @@ def get_ias_user_fragment_name(tenant_subdomain: str) -> str: | |
| f"for tenant '{tenant_subdomain}'" | ||
| ) | ||
| return fragments[0].name | ||
|
|
||
|
|
||
| def list_active_integrations(tenant_subdomain: str) -> list[dict]: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weak typing on return. Add type hints to dictionary |
||
| """List all active backend system integrations for the given tenant. | ||
|
|
||
| Reads Destination Service instance fragments to discover active backend | ||
| system integrations for the given tenant. Each fragment represents a | ||
| connected backend system (e.g. SAP PCE, SAP S/4HANA). | ||
|
|
||
| Extracts integration details from the fragment URL, which always has the form: | ||
| {agw_base_url}/v1/mcp/{ord_id}/{gtid} (MCP integrations) | ||
| {agw_base_url}/v1/a2a/{ord_id}/{gtid} (A2A integrations) | ||
|
|
||
| Args: | ||
| tenant_subdomain: Subscriber tenant subdomain. | ||
|
|
||
| Returns: | ||
| List of dicts, each with keys: | ||
| - global_tenant_id: GTID of the connected partner system. | ||
| - system_type: Application namespace of the partner (e.g. "sap.pce"). | ||
| - integration_dependency: ORD ID of the integration dependency fulfilled. | ||
| Returns empty list if no active integrations exist. | ||
| """ | ||
| client = create_fragment_client( | ||
| instance=_DESTINATION_INSTANCE, | ||
| _telemetry_source=Module.AGENTGATEWAY, | ||
| ) | ||
| fragments = client.list_instance_fragments( | ||
| filter=ListOptions( | ||
| filter_labels=[ | ||
| Label( | ||
| key=LABEL_KEY, | ||
| values=[FragmentLabel.MCP.value, FragmentLabel.A2A.value], | ||
| ) | ||
| ] | ||
| ), | ||
| tenant=tenant_subdomain, | ||
| ) | ||
|
|
||
| result = [] | ||
| for fragment in fragments: | ||
| url = fragment.properties.get("URL", "") | ||
| entry = _parse_integration_from_url(url) | ||
| if entry is not None: | ||
| result.append(entry) | ||
| return result | ||
|
|
||
|
|
||
| def _parse_integration_from_url(url: str) -> Optional[dict]: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weak typing. Dict can be typed respective to its key and value types. |
||
| """Extract integration metadata from a system fragment URL. | ||
|
|
||
| Fragment URLs have the form: | ||
| {base}/v1/{mode}/{ord_id}/{gtid} | ||
| where mode is "mcp" or "a2a", ord_id may contain colons and slashes, | ||
| and gtid is the last path segment. | ||
|
|
||
| Args: | ||
| url: The fragment URL property value. | ||
|
|
||
| Returns: | ||
| Dict with global_tenant_id, system_type, integration_dependency, | ||
| or None if the URL does not match the expected pattern. | ||
| """ | ||
| parts = url.rstrip("/").split("/") | ||
|
|
||
| mode_idx = None | ||
| for i, part in enumerate(parts): | ||
| if i > 0 and parts[i - 1] == "v1" and part in _INTEGRATION_URL_MODES: | ||
| mode_idx = i | ||
| break | ||
|
|
||
| if mode_idx is None or mode_idx + 2 > len(parts) - 1: | ||
| logger.debug("Skipping fragment with unexpected URL pattern: %s", url) | ||
| return None | ||
|
|
||
| gtid = parts[-1] | ||
| ord_id = "/".join(parts[mode_idx + 1 : -1]) | ||
| system_type = ord_id.split(":")[0] | ||
|
|
||
| if not gtid or not ord_id: | ||
| logger.debug("Skipping fragment with empty gtid or ord_id in URL: %s", url) | ||
| return None | ||
|
|
||
| return { | ||
| "global_tenant_id": gtid, | ||
| "system_type": system_type, | ||
| "integration_dependency": ord_id, | ||
| } | ||
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
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.
Make it private by convention. Also, this function name already exists in this module although in another file.