Skip to content

Commit 2b561eb

Browse files
authored
Merge pull request #184 from DrDroidLab/fix/asset_refresh_output_handling
feat: Refine asset refresh logic to handle protobuf wrapper types and…
2 parents 5f8c36e + 749a6f2 commit 2b561eb

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

asset_manager/tasks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ def populate_connector_metadata(request_id, connector_name, connector_type, conn
2727
# Set API credentials for metadata saving
2828
extractor.api_host = drd_cloud_host
2929
extractor.api_token = drd_cloud_api_token
30+
# Only include extract_* methods that actually persist data (not get_*_data helper methods)
3031
extractor_methods = [method for method in dir(extractor) if
31-
callable(getattr(extractor, method)) and method not in dir(SourceMetadataExtractor)]
32+
callable(getattr(extractor, method)) and method not in dir(SourceMetadataExtractor)
33+
and method.startswith('extract_')]
3234
for extractor_method in extractor_methods:
3335
logger.info(f"Running method: {extractor_method} for connector: {connector_name}")
3436
try:

playbooks_engine/tasks.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
logger = logging.getLogger(__name__)
2020

2121

22+
def _extract_proto_value(field):
23+
"""Extract value from protobuf wrapper types (StringValue, UInt32Value, etc.) when serialized to dict."""
24+
if field is None:
25+
return None
26+
if isinstance(field, dict):
27+
return field.get('value')
28+
return field
29+
30+
2231
def _execute_asset_refresh_task(playbook_task_execution_log):
2332
"""Execute asset refresh task using the playbook infrastructure"""
2433
try:
@@ -28,22 +37,25 @@ def _execute_asset_refresh_task(playbook_task_execution_log):
2837
drd_proxy_agent = task.get('drd_proxy_agent', {})
2938

3039
asset_refresh = drd_proxy_agent.get('asset_refresh', {})
31-
connector_name = asset_refresh.get('connector_name')
32-
connector_type = asset_refresh.get('connector_type')
33-
extractor_method = asset_refresh.get('extractor_method') # Optional field for specific method
34-
40+
# Extract values from protobuf wrapper types (they become {'value': 'x'} in JSON)
41+
connector_name = _extract_proto_value(asset_refresh.get('connector_name'))
42+
connector_type = _extract_proto_value(asset_refresh.get('connector_type'))
43+
extractor_method = _extract_proto_value(asset_refresh.get('extractor_method'))
44+
3545
logger.info(f'_execute_asset_refresh_task:: Starting asset refresh for connector: {connector_name}, '
3646
f'type: {connector_type}, request_id: {request_id}, method: {extractor_method}')
37-
47+
3848
if not request_id or not connector_name or not connector_type:
3949
raise ValueError(f'Missing required fields: request_id={request_id}, connector_name={connector_name}, connector_type={connector_type}')
4050

4151
# Handle native kubernetes mode or find connector in loaded connections
4252
loaded_connections = settings.LOADED_CONNECTIONS if settings.LOADED_CONNECTIONS else {}
4353
credentials_dict = None
44-
54+
4555
# Check if this is a native kubernetes connector
46-
if settings.NATIVE_KUBERNETES_API_MODE and connector_type == 'KUBERNETES':
56+
# connector_type is now an integer (Source enum value) - KUBERNETES = 47
57+
is_kubernetes = connector_type == 47 or connector_type == 'KUBERNETES' or str(connector_type) == '47'
58+
if settings.NATIVE_KUBERNETES_API_MODE and is_kubernetes:
4759
# For native kubernetes, we don't need loaded connections
4860
credentials_dict = {}
4961
logger.info(f'Using native Kubernetes mode for connector: {connector_name}')
@@ -56,7 +68,10 @@ def _execute_asset_refresh_task(playbook_task_execution_log):
5668
break
5769

5870
if credentials_dict is None:
59-
raise ValueError(f'Connector not found or no credentials: {connector_name}')
71+
available_connectors = list(loaded_connections.keys()) if loaded_connections else []
72+
raise ValueError(f'Connector not found or no credentials: {connector_name}. '
73+
f'Available connectors in config: {available_connectors}. '
74+
f'Please ensure the connector is configured in the VPC agent credentials.')
6075

6176
# Execute asset refresh for the specific connector
6277
from asset_manager.tasks import populate_connector_metadata, extractor_async_method_call

0 commit comments

Comments
 (0)