Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
ConditionalSkill,
CorsOptions,
CustomAnalyzer,
DataSourceCredentials,
DataContainer,
DictionaryDecompounderTokenFilter,
DistanceScoringFunction,
DistanceScoringParameters,
Expand Down Expand Up @@ -115,7 +117,7 @@
WebApiSkill,
WordDelimiterTokenFilter,
)
from ._service._models import PatternAnalyzer, PatternTokenizer
from ._service._models import PatternAnalyzer, PatternTokenizer, DataSource
from ._version import VERSION

__version__ = VERSION
Expand All @@ -135,6 +137,9 @@
"ConditionalSkill",
"CorsOptions",
"CustomAnalyzer",
"DataSource",
"DataSourceCredentials",
"DataContainer",
"DictionaryDecompounderTokenFilter",
"DistanceScoringFunction",
"DistanceScoringParameters",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from ._generated.models import Analyzer, Tokenizer
from ._generated.models import (
Analyzer,
Tokenizer,
DataSource as _DataSource
)


class PatternAnalyzer(Analyzer):
Expand Down Expand Up @@ -87,3 +91,57 @@ def __init__(self, **kwargs):
self.pattern = kwargs.get("pattern", r"\W+")
self.flags = kwargs.get("flags", None)
self.group = kwargs.get("group", -1)


class DataSource(_DataSource):

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor

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 SuggestQuery etc, that are not themselves Models, but do some helper/convenience work to create the actual model objects more simply for users.

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed for now

"""Represents a datasource definition, which can be used to configure an indexer.

All required parameters must be populated in order to send to Azure.

:param name: Required. The name of the datasource.
:type name: str
:param description: The description of the datasource.
:type description: str
:param type: Required. The type of the datasource. Possible values include: 'azuresql',
'cosmosdb', 'azureblob', 'azuretable', 'mysql'.
:type type: str or ~search_service_client.models.DataSourceType
:param credentials: Required. Credentials for the datasource.
:type credentials: ~search_service_client.models.DataSourceCredentials
:param container: Required. The data container for the datasource.
:type container: ~search_service_client.models.DataContainer
:param data_change_detection_policy: The data change detection policy for the datasource.
:type data_change_detection_policy: ~search_service_client.models.DataChangeDetectionPolicy
:param data_deletion_detection_policy: The data deletion detection policy for the datasource.
:type data_deletion_detection_policy: ~search_service_client.models.DataDeletionDetectionPolicy
:param e_tag: The ETag of the DataSource.
:type e_tag: str
"""

_validation = {
'name': {'required': True},
'type': {'required': True},
'credentials': {'required': True},
'container': {'required': True},
}

_attribute_map = {
'name': {'key': 'name', 'type': 'str'},
'description': {'key': 'description', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
'credentials': {'key': 'credentials', 'type': 'DataSourceCredentials'},
'container': {'key': 'container', 'type': 'DataContainer'},
'data_change_detection_policy': {'key': 'dataChangeDetectionPolicy', 'type': 'DataChangeDetectionPolicy'},
'data_deletion_detection_policy': {'key': 'dataDeletionDetectionPolicy', 'type': 'DataDeletionDetectionPolicy'},
'e_tag': {'key': '@odata\\.etag', 'type': 'str'},
}

def __init__(self, **kwargs):
super(DataSource, self).__init__(**kwargs)
self.name = kwargs.get('name', None)
self.description = kwargs.get('description', None)
self.type = kwargs.get('type', None)
self.credentials = kwargs.get('credentials', None)
self.container = kwargs.get('container', None)
self.data_change_detection_policy = kwargs.get('data_change_detection_policy', None)
self.data_deletion_detection_policy = kwargs.get('data_deletion_detection_policy', None)
self.e_tag = kwargs.get('e_tag', None)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Comment thread
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per @johanste This will either need to return a PagedItem or be renamed to get_datasources (same comment for async version) @brjohnstmsft has indicated that the only one that realistically might be paged on the service side is the indexes list.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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?

@rakshith91 rakshith91 Apr 23, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

#11025

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So with #11025 closed, this should be renamed to get_datasources I think?


@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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
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
Expand Down Expand Up @@ -555,3 +555,109 @@ async def create_or_update_skillset(self, name, **kwargs):
)

return await self._client.skillsets.create_or_update(name, skillset, **kwargs)

@distributed_trace_async
async 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/async_samples/sample_data_source_operations_async.py
:start-after: [START create_data_source_async]
:end-before: [END create_data_source_async]
:language: python
:dedent: 4
:caption: Create a DataSource
"""
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
result = await self._client.data_sources.create(data_source, **kwargs)
return result

@distributed_trace_async
async 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
"""
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))

if name is not None:
data_source.name = name
result = await self._client.data_sources.create_or_update(data_source.name, data_source, **kwargs)
Comment thread
rakshith91 marked this conversation as resolved.
Outdated
return result

@distributed_trace_async
async 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/async_samples/sample_data_source_operations_async.py
:start-after: [START delete_data_source_async]
:end-before: [END delete_data_source_async]
:language: python
:dedent: 4
:caption: Delete a DataSource
"""
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
result = await self._client.data_sources.delete(name, **kwargs)
return result

@distributed_trace_async
async 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.

.. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py
:start-after: [START get_data_source_async]
:end-before: [END get_data_source_async]
:language: python
:dedent: 4
:caption: Retrieve a DataSource
"""
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
result = await self._client.data_sources.get(name, **kwargs)
return result

@distributed_trace_async
async 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/async_samples/sample_data_source_operations_async.py
:start-after: [START list_data_source_async]
:end-before: [END list_data_source_async]
:language: python
:dedent: 4
:caption: List all DataSources
"""
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
result = await self._client.data_sources.list(**kwargs)
return result.data_sources
Loading