-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Implementation for Datasources operations #11012
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
Changes from 4 commits
0297aa6
037ea83
1ff9d3a
c6eb6ed
c1adb7f
73551fa
bd3f0d1
82750e9
55d562d
1e10f71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,13 +27,14 @@ | |
|
|
||
| if TYPE_CHECKING: | ||
| # pylint:disable=unused-import,ungrouped-imports | ||
| from ._models import DataSource | ||
| from typing import Any, List, Sequence, Union | ||
| from azure.core.credentials import AzureKeyCredential | ||
| from ._generated.models import Skill | ||
| from .. import Index, AnalyzeResult, AnalyzeRequest | ||
|
|
||
|
|
||
| class SearchServiceClient(HeadersMixin): | ||
| class SearchServiceClient(HeadersMixin): # pylint: disable=too-many-public-methods | ||
| """A client to interact with an existing Azure search service. | ||
|
|
||
| :param endpoint: The URL endpoint of an Azure search service | ||
|
|
@@ -554,3 +555,114 @@ def create_or_update_skillset(self, name, **kwargs): | |
| ) | ||
|
|
||
| return self._client.skillsets.create_or_update(name, skillset, **kwargs) | ||
|
|
||
| @distributed_trace | ||
| def create_datasource(self, data_source, **kwargs): | ||
| # type: (str, DataSource, **Any) -> Dict[str, Any] | ||
| """Creates a new datasource. | ||
|
|
||
| :param data_source: The definition of the datasource to create. | ||
| :type data_source: ~search.models.DataSource | ||
| :return: The created DataSource | ||
| :rtype: dict | ||
|
|
||
| .. admonition:: Example: | ||
|
|
||
| .. literalinclude:: ../samples/sample_data_source_operations.py | ||
| :start-after: [START create_data_source] | ||
| :end-before: [END create_data_source] | ||
| :language: python | ||
| :dedent: 4 | ||
| :caption: Create a Data Source | ||
| """ | ||
| kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) | ||
| result = self._client.data_sources.create(data_source, **kwargs) | ||
| return result | ||
|
|
||
| @distributed_trace | ||
| def create_or_update_datasource(self, data_source, name=None, **kwargs): | ||
| # type: (str, DataSource, Optional[str], **Any) -> Dict[str, Any] | ||
| """Creates a new datasource or updates a datasource if it already exists. | ||
|
|
||
| :param name: The name of the datasource to create or update. | ||
| :type name: str | ||
| :param data_source: The definition of the datasource to create or update. | ||
| :type data_source: ~search.models.DataSource | ||
| :return: The created DataSource | ||
| :rtype: dict | ||
| """ | ||
| # TODO: access_condition | ||
| kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) | ||
|
|
||
| if name is not None: | ||
| data_source.name = name | ||
| result = self._client.data_sources.create_or_update(data_source.name, data_source, **kwargs) | ||
|
rakshith91 marked this conversation as resolved.
Outdated
|
||
| return result | ||
|
|
||
| @distributed_trace | ||
| def get_datasource(self, name, **kwargs): | ||
| # type: (str, **Any) -> Dict[str, Any] | ||
| """Retrieves a datasource definition. | ||
|
|
||
| :param name: The name of the datasource to retrieve. | ||
| :type name: str | ||
| :return: The DataSource that is fetched. | ||
| :rtype: dict | ||
|
|
||
| .. admonition:: Example: | ||
|
|
||
| .. literalinclude:: ../samples/sample_data_source_operations.py | ||
| :start-after: [START get_data_source] | ||
| :end-before: [END get_data_source] | ||
| :language: python | ||
| :dedent: 4 | ||
| :caption: Retrieve a DataSource | ||
| """ | ||
| kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) | ||
| result = self._client.data_sources.get(name, **kwargs) | ||
| return result | ||
|
|
||
| @distributed_trace | ||
| def list_datasources(self, **kwargs): | ||
| # type: (**Any) -> Sequence[DataSource] | ||
| """Lists all datasources available for a search service. | ||
|
|
||
| :return: List of all the data sources. | ||
| :rtype: `list[dict]` | ||
|
|
||
| .. admonition:: Example: | ||
|
|
||
| .. literalinclude:: ../samples/sample_data_source_operations.py | ||
| :start-after: [START list_data_source] | ||
| :end-before: [END list_data_source] | ||
| :language: python | ||
| :dedent: 4 | ||
| :caption: List all the DataSources | ||
| """ | ||
| kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) | ||
| result = self._client.data_sources.list(**kwargs) | ||
| return result.data_sources | ||
|
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. per @johanste This will either need to return a
Contributor
Author
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. Could you confirm if there is an upper limit for the number of data sources?
Contributor
Author
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. I will implement paging in a separate issue - that way this wont be blocked for indexers EDIT keeping in mind that service doesn't support paging yet, at this point we would want paging only for indexes (since there can be upto 3000 indexes). Realistically, datasources shouldn't have paging support.
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. So with #11025 closed, this should be renamed to |
||
|
|
||
| @distributed_trace | ||
| def delete_datasource(self, name, **kwargs): | ||
| # type: (str, **Any) -> None | ||
| """Deletes a datasource. | ||
|
|
||
| :param name: The name of the datasource to delete. | ||
| :type name: str | ||
|
|
||
| :return: None | ||
| :rtype: None | ||
|
|
||
| .. admonition:: Example: | ||
|
|
||
| .. literalinclude:: ../samples/sample_data_source_operations.py | ||
| :start-after: [START delete_data_source] | ||
| :end-before: [END delete_data_source] | ||
| :language: python | ||
| :dedent: 4 | ||
| :caption: Delete a DataSource | ||
| """ | ||
| kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) | ||
| result = self._client.data_sources.delete(name, **kwargs) | ||
| return result | ||
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.
I think I can prolly remove this.
Another option is to create a model which accepts credentials and pass it to the datasource credentials - but not sure if it brings more value other than not exposing an additional generated model.
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.
Agree I don't really see value in it as-is. For reference I was thinking more along the lines of
SuggestQueryetc, that are not themselves Models, but do some helper/convenience work to create the actual model objects more simply for users.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.
@rakshith91 did you still want to remove this before merge?
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.
removed for now