Skip to content

Commit 0078094

Browse files
authored
[purview] add scanning client (Azure#17780)
* generate azure-purview-scanning * basic head smoke test * regenerate * add get datasources smoke test * add dev requirements * regen with new public swagger and request builder ordering * use powershell preparer for tests * fix setup.py * regenerate * regenerate and add packaging files * fix 2.7 tests (hopefully) * add tuesday as release date * add scanning to ci * switch to new aka link for llc quickstart * remove low level client reference * remove more llc references * AzurePurviewScanningClient -> PurviewScanningClient * remove pkgutil init info from core and rest folders
1 parent 5d8bf17 commit 0078094

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+7363
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Release History
2+
3+
## 1.0.0b1 (2021-05-11)
4+
5+
- This is the initial release of the Azure Purview Scanning library.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
recursive-include tests *.py
2+
recursive-include samples *.py *.md
3+
include *.md
4+
include azure/__init__.py
5+
include azure/purview/__init__.py
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Azure Purview Scanning client library for Python
2+
3+
Azure Purview Scanning is a fully managed cloud service whose users can scan your data into your data estate (also known as your **catalog**). Scanning is a process by which the catalog connects directly to a data source on a user-specified schedule.
4+
5+
- Scan your data into your catalog
6+
- Examine your data
7+
- Extract schemas from your data
8+
9+
**Please rely heavily on the [service's documentation][scanning_product_documentation] and our [client docs][request_builders_and_client] to use this library**
10+
11+
[Source code][source_code] | [Package (PyPI)][scanning_pypi] | [API reference documentation][scanning_ref_docs]| [Product documentation][scanning_product_documentation]
12+
13+
## Getting started
14+
15+
### Prerequisites
16+
17+
- Python 2.7, or 3.6 or later is required to use this package.
18+
- You must have an [Azure subscription][azure_subscription] and a [Purview][purview_resource] to use this package.
19+
20+
#### Create a Purview Resource
21+
22+
Follow [these][purview_resource] instructions to create your Purview resource
23+
24+
### Install the package
25+
26+
Install the Azure Purview Scanning client library for Python with [pip][pip]:
27+
28+
```bash
29+
pip install azure-purview-scanning
30+
```
31+
32+
### Authenticate the client
33+
34+
To use an [Azure Active Directory (AAD) token credential][authenticate_with_token],
35+
provide an instance of the desired credential type obtained from the
36+
[azure-identity][azure_identity_credentials] library.
37+
38+
To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip] and
39+
[enable AAD authentication on your Purview resource][enable_aad]
40+
41+
After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use.
42+
As an example, [DefaultAzureCredential][default_azure_credential]
43+
can be used to authenticate the client:
44+
45+
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
46+
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
47+
48+
Use the returned token credential to authenticate the client:
49+
50+
```python
51+
from azure.purview.scanning import PurviewScanningClient
52+
from azure.identity import DefaultAzureCredential
53+
54+
credential = DefaultAzureCredential()
55+
client = PurviewScanningClient(endpoint="https://<my-account-name>.scanning.purview.azure.com", credential=credential)
56+
```
57+
58+
## Key concepts
59+
60+
### Client
61+
62+
This package offers request builders so you can build http requests and send these requests to the service using the `send_request` method.
63+
For more information on how to use request builders and our clients, see [here][request_builders_and_client].
64+
65+
## Examples
66+
67+
The following section shows you how to initialize and authenticate your client, then list all of your data sources.
68+
69+
- [List All Data Sources](#list-all-data-sources "List All Data Sources")
70+
71+
### List All Data Sources
72+
73+
```python
74+
from azure.purview.scanning import PurviewScanningClient
75+
from azure.identity import DefaultAzureCredential
76+
from azure.purview.scanning.rest import data_sources
77+
from azure.core.exceptions import HttpResponseError
78+
79+
credential = DefaultAzureCredential()
80+
client = PurviewScanningClient(endpoint="https://<my-account-name>.scanning.purview.azure.com", credential=credential)
81+
82+
request = data_sources.build_list_all_request()
83+
84+
response = client.send_request(request)
85+
try:
86+
response.raise_for_status()
87+
json_response = response.json()
88+
89+
assert len(json_response['value']) == json_response['count']
90+
for value in json_response['value']:
91+
print(value)
92+
93+
except HttpResponseError as e:
94+
print(e)
95+
```
96+
97+
## Troubleshooting
98+
99+
### General
100+
101+
The Purview Scanning client will raise exceptions defined in [Azure Core][azure_core] if you call `.raise_for_status()` on your responses.
102+
103+
### Logging
104+
105+
This library uses the standard
106+
[logging][python_logging] library for logging.
107+
Basic information about HTTP sessions (URLs, headers, etc.) is logged at INFO
108+
level.
109+
110+
Detailed DEBUG level logging, including request/response bodies and unredacted
111+
headers, can be enabled on a client with the `logging_enable` keyword argument:
112+
113+
```python
114+
import sys
115+
import logging
116+
from azure.identity import DefaultAzureCredential
117+
from azure.purview.scanning import PurviewScanningClient
118+
119+
# Create a logger for the 'azure' SDK
120+
logger = logging.getLogger('azure')
121+
logger.setLevel(logging.DEBUG)
122+
123+
# Configure a console output
124+
handler = logging.StreamHandler(stream=sys.stdout)
125+
logger.addHandler(handler)
126+
127+
endpoint = "https://<my-account-name>.scanning.purview.azure.com"
128+
credential = DefaultAzureCredential()
129+
130+
# This client will log detailed information about its HTTP sessions, at DEBUG level
131+
client = PurviewScanningClient(endpoint=endpoint, credential=credential, logging_enable=True)
132+
```
133+
134+
Similarly, `logging_enable` can enable detailed logging for a single `send_request` call,
135+
even when it isn't enabled for the client:
136+
137+
```python
138+
result = client.send_request(request, logging_enable=True)
139+
```
140+
141+
## Next steps
142+
143+
For more generic samples, see our [client docs][request_builders_and_client].
144+
145+
## Contributing
146+
147+
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [cla.microsoft.com][cla].
148+
149+
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
150+
151+
This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information see the [Code of Conduct FAQ][coc_faq] or contact [opencode@microsoft.com][coc_contact] with any additional questions or comments.
152+
153+
<!-- LINKS -->
154+
155+
[source_code]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/purview/azure-purview-scanning/azure/purview/scanning
156+
[scanning_pypi]: https://aka.ms/azsdk/python/purviewscanning/pypi
157+
[scanning_ref_docs]: https://aka.ms/azsdk/python/purviewscanning/ref-docs
158+
[scanning_product_documentation]: https://azure.microsoft.com/services/purview/
159+
[azure_subscription]: https://azure.microsoft.com/free/
160+
[purview_resource]: https://docs.microsoft.com/azure/purview/create-catalog-portal
161+
[pip]: https://pypi.org/project/pip/
162+
[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token
163+
[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/identity/azure-identity#credentials
164+
[azure_identity_pip]: https://pypi.org/project/azure-identity/
165+
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/identity/azure-identity#defaultazurecredential
166+
[request_builders_and_client]: https://aka.ms/azsdk/python/protocol/quickstart
167+
[enable_aad]: https://docs.microsoft.com/azure/purview/create-catalog-portal#add-a-security-principal-to-a-data-plane-role
168+
[python_logging]: https://docs.python.org/3.5/library/logging.html
169+
[cla]: https://cla.microsoft.com
170+
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
171+
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
172+
[coc_contact]: mailto:opencode@microsoft.com
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from ._azure_purview_scanning_client import PurviewScanningClient
10+
from ._version import VERSION
11+
12+
__version__ = VERSION
13+
__all__ = ['PurviewScanningClient']
14+
15+
try:
16+
from ._patch import patch_sdk # type: ignore
17+
patch_sdk()
18+
except ImportError:
19+
pass
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from copy import deepcopy
10+
from typing import TYPE_CHECKING
11+
12+
from azure.core import PipelineClient
13+
from azure.purview.scanning.core.rest import HttpResponse, _StreamContextManager
14+
from msrest import Deserializer, Serializer
15+
16+
if TYPE_CHECKING:
17+
# pylint: disable=unused-import,ungrouped-imports
18+
from typing import Any, Dict
19+
20+
from azure.core.credentials import TokenCredential
21+
from azure.purview.scanning.core.rest import HttpRequest
22+
23+
from ._configuration import PurviewScanningClientConfiguration
24+
25+
26+
class PurviewScanningClient(object):
27+
"""Creates a Microsoft.Scanning management client.
28+
29+
:param credential: Credential needed for the client to connect to Azure.
30+
:type credential: ~azure.core.credentials.TokenCredential
31+
:param endpoint: The scanning endpoint of your purview account. Example: https://{accountName}.scan.purview.azure.com.
32+
:type endpoint: str
33+
"""
34+
35+
def __init__(
36+
self,
37+
credential, # type: "TokenCredential"
38+
endpoint, # type: str
39+
**kwargs # type: Any
40+
):
41+
# type: (...) -> None
42+
base_url = '{Endpoint}'
43+
self._config = PurviewScanningClientConfiguration(credential, endpoint, **kwargs)
44+
self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs)
45+
46+
self._serialize = Serializer()
47+
self._deserialize = Deserializer()
48+
self._serialize.client_side_validation = False
49+
50+
def send_request(self, http_request, **kwargs):
51+
# type: (HttpRequest, Any) -> HttpResponse
52+
"""Runs the network request through the client's chained policies.
53+
54+
We have helper methods to create requests specific to this service in `azure.purview.scanning.rest`.
55+
Use these helper methods to create the request you pass to this method. See our example below:
56+
57+
>>> from azure.purview.scanning.rest import build_get_request
58+
>>> request = build_get_request(key_vault_name)
59+
<HttpRequest [GET], url: '/azureKeyVaults/{keyVaultName}'>
60+
>>> response = client.send_request(request)
61+
<HttpResponse: 200 OK>
62+
63+
For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart
64+
65+
For advanced cases, you can also create your own :class:`~azure.purview.scanning.core.rest.HttpRequest`
66+
and pass it in.
67+
68+
:param http_request: The network request you want to make. Required.
69+
:type http_request: ~azure.purview.scanning.core.rest.HttpRequest
70+
:keyword bool stream_response: Whether the response payload will be streamed. Defaults to False.
71+
:return: The response of your network call. Does not do error handling on your response.
72+
:rtype: ~azure.purview.scanning.core.rest.HttpResponse
73+
"""
74+
request_copy = deepcopy(http_request)
75+
path_format_arguments = {
76+
'Endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
77+
}
78+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
79+
if kwargs.pop("stream_response", False):
80+
return _StreamContextManager(
81+
client=self._client._pipeline,
82+
request=request_copy,
83+
)
84+
pipeline_response = self._client._pipeline.run(request_copy._internal_request, **kwargs)
85+
response = HttpResponse(
86+
status_code=pipeline_response.http_response.status_code,
87+
request=request_copy,
88+
_internal_response=pipeline_response.http_response
89+
)
90+
response.read()
91+
return response
92+
93+
def close(self):
94+
# type: () -> None
95+
self._client.close()
96+
97+
def __enter__(self):
98+
# type: () -> PurviewScanningClient
99+
self._client.__enter__()
100+
return self
101+
102+
def __exit__(self, *exc_details):
103+
# type: (Any) -> None
104+
self._client.__exit__(*exc_details)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from typing import TYPE_CHECKING
10+
11+
from azure.core.configuration import Configuration
12+
from azure.core.pipeline import policies
13+
14+
from ._version import VERSION
15+
16+
if TYPE_CHECKING:
17+
# pylint: disable=unused-import,ungrouped-imports
18+
from typing import Any
19+
20+
from azure.core.credentials import TokenCredential
21+
22+
23+
class PurviewScanningClientConfiguration(Configuration):
24+
"""Configuration for PurviewScanningClient.
25+
26+
Note that all parameters used to create this instance are saved as instance
27+
attributes.
28+
29+
:param credential: Credential needed for the client to connect to Azure.
30+
:type credential: ~azure.core.credentials.TokenCredential
31+
:param endpoint: The scanning endpoint of your purview account. Example: https://{accountName}.scan.purview.azure.com.
32+
:type endpoint: str
33+
"""
34+
35+
def __init__(
36+
self,
37+
credential, # type: "TokenCredential"
38+
endpoint, # type: str
39+
**kwargs # type: Any
40+
):
41+
# type: (...) -> None
42+
if credential is None:
43+
raise ValueError("Parameter 'credential' must not be None.")
44+
if endpoint is None:
45+
raise ValueError("Parameter 'endpoint' must not be None.")
46+
super(PurviewScanningClientConfiguration, self).__init__(**kwargs)
47+
48+
self.credential = credential
49+
self.endpoint = endpoint
50+
self.api_version = "2018-12-01-preview"
51+
self.credential_scopes = kwargs.pop('credential_scopes', ['https://purview.azure.net/.default'])
52+
kwargs.setdefault('sdk_moniker', 'purview-scanning/{}'.format(VERSION))
53+
self._configure(**kwargs)
54+
55+
def _configure(
56+
self,
57+
**kwargs # type: Any
58+
):
59+
# type: (...) -> None
60+
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
61+
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
62+
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
63+
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
64+
self.http_logging_policy = kwargs.get('http_logging_policy') or policies.HttpLoggingPolicy(**kwargs)
65+
self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs)
66+
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
67+
self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs)
68+
self.authentication_policy = kwargs.get('authentication_policy')
69+
if self.credential and not self.authentication_policy:
70+
self.authentication_policy = policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
VERSION = "1.0.0b1"

0 commit comments

Comments
 (0)