5
5
from enum import Enum
6
6
from azure .identity import DefaultAzureCredential
7
7
from azure .core .credentials import AzureKeyCredential
8
+ from azure .search .documents .indexes .models import SearchIndexerDataUserAssignedIdentity
8
9
9
10
class IndexerType (Enum ):
10
11
"""The type of the indexer"""
@@ -68,6 +69,26 @@ def ai_search_endpoint(self) -> str:
68
69
str: The ai search endpoint
69
70
"""
70
71
return os .environ .get ("AIService__AzureSearchOptions__Endpoint" )
72
+
73
+ @property
74
+ def ai_search_identity_id (self ) -> str :
75
+ """This function returns the ai search identity id.
76
+
77
+ Returns:
78
+ str: The ai search identity id
79
+ """
80
+ return os .environ .get ("AIService__AzureSearchOptions__Identity__ClientId" )
81
+
82
+ @property
83
+ def ai_search_user_assigned_identity (self ) -> SearchIndexerDataUserAssignedIdentity :
84
+ """This function returns the ai search user assigned identity.
85
+
86
+ Returns:
87
+ SearchIndexerDataUserAssignedIdentity: The ai search user assigned identity"""
88
+ user_assigned_identity = SearchIndexerDataUserAssignedIdentity (
89
+ user_assigned_identity = os .environ .get ("AIService__AzureSearchOptions__Identity__FQName" )
90
+ )
91
+ return user_assigned_identity
71
92
72
93
@property
73
94
def ai_search_credential (self ) -> DefaultAzureCredential | AzureKeyCredential :
@@ -79,9 +100,9 @@ def ai_search_credential(self) -> DefaultAzureCredential | AzureKeyCredential:
79
100
if self .identity_type in IdentityType .SYSTEM_ASSIGNED :
80
101
return DefaultAzureCredential ()
81
102
elif self .identity_type in IdentityType .USER_ASSIGNED :
82
- return DefaultAzureCredential (managed_identity_client_id = os . environ . get ( "AIService__AzureSearchOptions__ManagedIdentity__FQName" ) )
103
+ return DefaultAzureCredential (managed_identity_client_id = self . ai_search_identity_id )
83
104
else :
84
- return AzureKeyCredential (os .environ .get ("AIService__AzureSearchOptions__Key__Secret " ))
105
+ return AzureKeyCredential (os .environ .get ("AIService__AzureSearchOptions__Key " ))
85
106
86
107
@property
87
108
def storage_account_connection_string (self ) -> str :
@@ -125,15 +146,35 @@ def function_app_adi_route(self) -> str:
125
146
"""
126
147
This function returns function app adi name
127
148
"""
128
- return os .environ .get ("FunctionApp__DocumentIntelligence__FunctionName " )
149
+ return os .environ .get ("FunctionApp__ADI__FunctionName " )
129
150
130
151
@property
131
152
def function_app_key_phrase_extractor_route (self ) -> str :
132
153
"""
133
154
This function returns function app keyphrase extractor name
134
155
"""
135
- return os .environ .get ("FunctionApp__KeyphraseExtractor__FunctionName" )
156
+ return os .environ .get ("FunctionApp__KeyPhraseExtractor__FunctionName" )
157
+
158
+ @property
159
+ def ai_search_embedding_model_dimensions (self ) -> str :
160
+ """
161
+ This function returns dimensions for embedding model.
162
+
163
+ Returns:
164
+ str: The dimensions for embedding model
165
+ """
166
+
167
+ return os .environ .get (
168
+ f"AIService__AzureSearchOptions__{ self .normalised_indexer_type } __EmbeddingDimensions"
169
+ )
136
170
171
+ @property
172
+ def use_private_endpoint (self ) -> bool :
173
+ """
174
+ This function returns true if private endpoint is used
175
+ """
176
+ return os .environ .get ("AIService__AzureSearchOptions__UsePrivateEndpoint" ) == "true"
177
+
137
178
def get_custom_skill_function_url (self , skill_type : str ):
138
179
"""
139
180
Get the function app url that is hosting the custom skill
@@ -152,81 +193,9 @@ def get_custom_skill_function_url(self, skill_type: str):
152
193
return full_url
153
194
154
195
155
-
156
- # managed identity id
157
- def get_managed_identity_id () -> str :
158
- """
159
- This function returns maanged identity id
160
- """
161
- return os .environ .get ("AIService__AzureSearchOptions__ManagedIdentity__ClientId" )
162
-
163
-
164
- def get_managed_identity_fqname () -> str :
165
- """
166
- This function returns maanged identity name
167
- """
168
- return os .environ .get ("AIService__AzureSearchOptions__ManagedIdentity__FQName" )
169
-
170
-
171
196
# function app details
172
197
def get_function_app_authresourceid () -> str :
173
198
"""
174
199
This function returns apps registration in microsoft entra id
175
200
"""
176
- return os .environ .get ("FunctionApp__AuthResourceId" )
177
-
178
- # search
179
- def get_search_endpoint () -> str :
180
- """
181
- This function returns azure ai search service endpoint
182
- """
183
- return os .environ .get ("AIService__AzureSearchOptions__Endpoint" )
184
-
185
-
186
- def get_search_user_assigned_identity () -> str :
187
- """
188
- This function returns azure ai search service endpoint
189
- """
190
- return os .environ .get ("AIService__AzureSearchOptions__UserAssignedIdentity" )
191
-
192
-
193
- def get_search_key (client ) -> str :
194
- """
195
- This function returns azure ai search service admin key
196
- """
197
- search_service_key_secret_name = (
198
- str (os .environ .get ("AIService__AzureSearchOptions__name" )) + "-PrimaryKey"
199
- )
200
- retrieved_secret = client .get_secret (search_service_key_secret_name )
201
- return retrieved_secret .value
202
-
203
-
204
- def get_search_key_secret () -> str :
205
- """
206
- This function returns azure ai search service admin key
207
- """
208
- return os .environ .get ("AIService__AzureSearchOptions__Key__Secret" )
209
-
210
-
211
- def get_search_embedding_model_dimensions (indexer_type : IndexerType ) -> str :
212
- """
213
- This function returns dimensions for embedding model
214
- """
215
-
216
- normalised_indexer_type = (
217
- indexer_type .value .replace ("-" , " " ).title ().replace (" " , "" )
218
- )
219
-
220
- return os .environ .get (
221
- f"AIService__AzureSearchOptions__{ normalised_indexer_type } __EmbeddingDimensions"
222
- )
223
-
224
-
225
- def get_blob_container_name (indexer_type : str ) -> str :
226
- """
227
- This function returns azure blob container name
228
- """
229
- normalised_indexer_type = (
230
- indexer_type .value .replace ("-" , " " ).title ().replace (" " , "" )
231
- )
232
- return os .environ .get (f"StorageAccount__{ normalised_indexer_type } __Container" )
201
+ return os .environ .get ("FunctionApp__AuthResourceId" )
0 commit comments