3
3
import ast
4
4
import os
5
5
from dataclasses import dataclass , field
6
- from typing import Any , Dict , List , Optional
7
-
8
- from ..._services import AssetsService , BucketsService , ProcessesService
6
+ from typing import Any , Dict , List , Optional , Tuple
7
+
8
+ from ..._services import (
9
+ AssetsService ,
10
+ BucketsService ,
11
+ ContextGroundingService ,
12
+ ProcessesService ,
13
+ )
9
14
from ..._utils import get_inferred_bindings_names
15
+ from ._constants import BINDINGS_VERSION
10
16
11
17
12
18
@dataclass
@@ -33,6 +39,14 @@ def extract_string_arg(self, index: int = 0) -> Optional[str]:
33
39
"processes" : "process" ,
34
40
"buckets" : "bucket" ,
35
41
"connections" : "connection" ,
42
+ "context_grounding" : "index" ,
43
+ }
44
+
45
+ supported_bindings_by_service = {
46
+ "assets" : AssetsService ,
47
+ "processes" : ProcessesService ,
48
+ "buckets" : BucketsService ,
49
+ "context_grounding" : ContextGroundingService ,
36
50
}
37
51
38
52
@@ -67,48 +81,10 @@ class ServiceUsage:
67
81
def get_component_info (self ) -> List [Dict [str , str ]]:
68
82
"""Extract component names and folders based on the service type."""
69
83
result = []
70
-
71
- if self .service_name == "assets" :
72
- for call in self .method_calls :
73
- inferred_bindings = get_inferred_bindings_names (AssetsService )
74
- if call .method_name in inferred_bindings :
75
- name = extract_parameter (
76
- call , inferred_bindings [call .method_name ]["name" ], 0
77
- )
78
- folder_path = extract_parameter (
79
- call , inferred_bindings [call .method_name ]["folder_path" ]
80
- )
81
- if name :
82
- result .append (
83
- {
84
- "name" : name ,
85
- "folder" : folder_path or "" ,
86
- "method" : call .method_name ,
87
- }
88
- )
89
-
90
- elif self .service_name == "processes" :
91
- for call in self .method_calls :
92
- inferred_bindings = get_inferred_bindings_names (ProcessesService )
93
- if call .method_name in inferred_bindings :
94
- name = extract_parameter (
95
- call , inferred_bindings [call .method_name ]["name" ], 0
96
- )
97
- folder_path = extract_parameter (
98
- call , inferred_bindings [call .method_name ]["folder_path" ]
99
- )
100
- if name :
101
- result .append (
102
- {
103
- "name" : name ,
104
- "folder" : folder_path or "" ,
105
- "method" : call .method_name ,
106
- }
107
- )
108
-
109
- elif self .service_name == "buckets" :
84
+ has_support , service_cls = self ._support_for_bindings_inference ()
85
+ if has_support :
110
86
for call in self .method_calls :
111
- inferred_bindings = get_inferred_bindings_names (BucketsService )
87
+ inferred_bindings = get_inferred_bindings_names (service_cls )
112
88
if call .method_name in inferred_bindings :
113
89
name = extract_parameter (
114
90
call , inferred_bindings [call .method_name ]["name" ], 0
@@ -125,9 +101,9 @@ def get_component_info(self) -> List[Dict[str, str]]:
125
101
}
126
102
)
127
103
104
+ # custom logic for connections bindings
128
105
elif self .service_name == "connections" :
129
106
for call in self .method_calls :
130
- connection_id = None
131
107
if len (call .args ) > 0 :
132
108
connection_id = call .args [0 ]
133
109
if connection_id :
@@ -141,6 +117,12 @@ def get_component_info(self) -> List[Dict[str, str]]:
141
117
142
118
return result
143
119
120
+ def _support_for_bindings_inference (self ) -> Tuple [bool , Any ]:
121
+ return (
122
+ self .service_name in supported_bindings_by_service ,
123
+ supported_bindings_by_service .get (self .service_name , None ),
124
+ )
125
+
144
126
145
127
def extract_parameter (
146
128
method_call : ServiceMethodCall ,
@@ -462,11 +444,10 @@ def convert_to_bindings_format(sdk_usage_data):
462
444
"defaultValue" : connection_id ,
463
445
"isExpression" : is_connection_id_expression ,
464
446
"displayName" : "Connection" ,
465
- "description" : "The connection to be used" ,
466
447
}
467
448
},
468
449
"metadata" : {
469
- "BindingsVersion" : "2.1" ,
450
+ "BindingsVersion" : BINDINGS_VERSION ,
470
451
"Connector" : connector_name ,
471
452
"UseConnectionService" : "True" ,
472
453
},
@@ -500,7 +481,7 @@ def convert_to_bindings_format(sdk_usage_data):
500
481
},
501
482
"metadata" : {
502
483
"ActivityName" : method_name ,
503
- "BindingsVersion" : "2.1" ,
484
+ "BindingsVersion" : BINDINGS_VERSION ,
504
485
"DisplayLabel" : "FullName" ,
505
486
},
506
487
}
0 commit comments