Skip to content

Commit cfbc939

Browse files
authored
[purview account] first release for azure-purview-account (Azure#20335)
* purview account * CI * verion-tolerant * endpoint order * add test for collections * Update CHANGELOG.md * review * update reamdme
1 parent 986302f commit cfbc939

40 files changed

+4865
-0
lines changed

eng/.docsettings.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ known_content_issues:
9292
- ['sdk/purview/azure-purview-catalog/swagger/README.md',  '#4554']
9393
- ['sdk/purview/azure-purview-scanning/swagger/README.md',  '#4554']
9494
- ['sdk/agrifood/azure-agrifood-farming/swagger/README.md',  '#4554']
95+
- ['sdk/purview/azure-purview-account/swagger/README.md', '#4554']
9596
- ['sdk/containerregistry/azure-containerregistry/swagger/README.md', '#4554']
9697
- ['sdk/appconfiguration/azure-appconfiguration/swagger/README.md', '#4554']
9798
- ['sdk/attestation/azure-security-attestation/swagger/README.md', '#4554']

eng/tox/allowed_pylint_failures.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"azure-purview-nspkg",
5555
"azure-purview-scanning",
5656
"azure-purview-catalog",
57+
"azure-purview-account",
5758
"azure-messaging-nspkg",
5859
"azure-agrifood-farming",
5960
"azure-eventhub",
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-08-23)
4+
5+
- This is the initial release of the Azure Purview Account 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: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# Azure Purview Account client library for Python
2+
3+
Azure Purview Account is a fully managed cloud service.
4+
5+
**Please rely heavily on the [service's documentation][account_product_documentation] and our [client docs][request_builders_and_client] to use this library**
6+
7+
[Source code][source_code] | [Package (PyPI)][account_pypi] | [API reference documentation][account_ref_docs]| [Product documentation][account_product_documentation]
8+
9+
## Getting started
10+
11+
### Prerequisites
12+
13+
- Python 2.7, or 3.6 or later is required to use this package.
14+
- You must have an [Azure subscription][azure_subscription] and a [Purview][purview_resource] to use this package.
15+
16+
#### Create a Purview Resource
17+
18+
Follow [these][purview_resource] instructions to create your Purview resource
19+
20+
### Install the package
21+
22+
Install the Azure Purview Account client library for Python with [pip][pip]:
23+
24+
```bash
25+
pip install azure-purview-account
26+
```
27+
28+
### Authenticate the client
29+
30+
To use an [Azure Active Directory (AAD) token credential][authenticate_with_token],
31+
provide an instance of the desired credential type obtained from the
32+
[azure-identity][azure_identity_credentials] library.
33+
34+
To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip] and
35+
[enable AAD authentication on your Purview resource][enable_aad]
36+
37+
After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use.
38+
As an example, [DefaultAzureCredential][default_azure_credential]
39+
can be used to authenticate the client:
40+
41+
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
42+
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
43+
44+
Use the returned token credential to authenticate the client:
45+
46+
```python
47+
from azure.purview.account import PurviewAccountClient
48+
from azure.identity import DefaultAzureCredential
49+
50+
credential = DefaultAzureCredential()
51+
client = PurviewAccountClient(endpoint="https://<my-account-name>.purview.azure.com", credential=credential)
52+
```
53+
54+
## Key concepts
55+
56+
### Client
57+
58+
## Examples
59+
60+
The following section shows you how to initialize and authenticate your client, then list all of your keys.
61+
62+
- [Get Keys](#get-keys "Get All Keys")
63+
64+
### Get Keys
65+
66+
```python
67+
from azure.purview.account import PurviewAccountClient
68+
from azure.identity import DefaultAzureCredential
69+
70+
credential = DefaultAzureCredential()
71+
client = PurviewAccountClient(endpoint="https://<my-account-name>.purview.azure.com", credential=credential)
72+
response = client.accounts.get_access_keys()
73+
print(response)
74+
```
75+
76+
## Troubleshooting
77+
78+
### General
79+
80+
The Purview Account client will raise exceptions if status code of your responses is not defined.
81+
82+
### Logging
83+
84+
This library uses the standard
85+
[logging][python_logging] library for logging.
86+
Basic information about HTTP sessions (URLs, headers, etc.) is logged at INFO
87+
level.
88+
89+
Detailed DEBUG level logging, including request/response bodies and unredacted
90+
headers, can be enabled on a client with the `logging_enable` keyword argument:
91+
92+
```python
93+
import sys
94+
import logging
95+
from azure.identity import DefaultAzureCredential
96+
from azure.purview.account import PurviewAccountClient
97+
98+
# Create a logger for the 'azure' SDK
99+
logger = logging.getLogger('azure')
100+
logger.setLevel(logging.DEBUG)
101+
102+
# Configure a console output
103+
handler = logging.StreamHandler(stream=sys.stdout)
104+
logger.addHandler(handler)
105+
106+
endpoint = "https://<my-account-name>.purview.azure.com"
107+
credential = DefaultAzureCredential()
108+
109+
# This client will log detailed information about its HTTP sessions, at DEBUG level
110+
client = PurviewAccountClient(endpoint=endpoint, credential=credential, logging_enable=True)
111+
```
112+
113+
Similarly, `logging_enable` can enable detailed logging for a single call,
114+
even when it isn't enabled for the client:
115+
116+
```python
117+
result = client.accounts.get_access_keys(logging_enable=True)
118+
```
119+
120+
## Next steps
121+
122+
For more generic samples, see our [client docs][request_builders_and_client].
123+
124+
## Contributing
125+
126+
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].
127+
128+
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.
129+
130+
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.
131+
132+
<!-- LINKS -->
133+
134+
[source_code]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/purview/
135+
[account_pypi]: https://pypi.org/project/azure-purview-catalog/#history
136+
[account_ref_docs]: https://azure.github.io/azure-sdk-for-python/
137+
[account_product_documentation]: https://azure.microsoft.com/services/purview/
138+
[azure_subscription]: https://azure.microsoft.com/free/
139+
[purview_resource]: https://docs.microsoft.com/azure/purview/create-catalog-portal
140+
[pip]: https://pypi.org/project/pip/
141+
[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token
142+
[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials
143+
[azure_identity_pip]: https://pypi.org/project/azure-identity/
144+
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential
145+
[request_builders_and_client]: https://aka.ms/azsdk/python/protocol/quickstart
146+
[enable_aad]: https://docs.microsoft.com/azure/purview/create-catalog-portal#add-a-security-principal-to-a-data-plane-role
147+
[python_logging]: https://docs.python.org/3.5/library/logging.html
148+
[cla]: https://cla.microsoft.com
149+
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
150+
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
151+
[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 ._purview_account_client import PurviewAccountClient
10+
from ._version import VERSION
11+
12+
__version__ = VERSION
13+
__all__ = ['PurviewAccountClient']
14+
15+
try:
16+
from ._patch import patch_sdk # type: ignore
17+
patch_sdk()
18+
except ImportError:
19+
pass
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 PurviewAccountClientConfiguration(Configuration):
24+
"""Configuration for PurviewAccountClient.
25+
26+
Note that all parameters used to create this instance are saved as instance
27+
attributes.
28+
29+
:param endpoint: The account endpoint of your Purview account. Example: https://{accountName}.purview.azure.com/account/.
30+
:type endpoint: str
31+
:param credential: Credential needed for the client to connect to Azure.
32+
:type credential: ~azure.core.credentials.TokenCredential
33+
"""
34+
35+
def __init__(
36+
self,
37+
endpoint, # type: str
38+
credential, # type: "TokenCredential"
39+
**kwargs # type: Any
40+
):
41+
# type: (...) -> None
42+
if endpoint is None:
43+
raise ValueError("Parameter 'endpoint' must not be None.")
44+
if credential is None:
45+
raise ValueError("Parameter 'credential' must not be None.")
46+
super(PurviewAccountClientConfiguration, self).__init__(**kwargs)
47+
48+
self.endpoint = endpoint
49+
self.credential = credential
50+
self.api_version = "2019-11-01-preview"
51+
self.credential_scopes = kwargs.pop('credential_scopes', ['https://purview.azure.net/.default'])
52+
kwargs.setdefault('sdk_moniker', 'purview-account/{}'.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: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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 msrest import Deserializer, Serializer
14+
15+
from ._configuration import PurviewAccountClientConfiguration
16+
from .operations import AccountsOperations, CollectionsOperations, ResourceSetRulesOperations
17+
18+
if TYPE_CHECKING:
19+
# pylint: disable=unused-import,ungrouped-imports
20+
from typing import Any, Dict, Optional
21+
22+
from azure.core.credentials import TokenCredential
23+
from azure.core.rest import HttpRequest, HttpResponse
24+
25+
class PurviewAccountClient(object):
26+
"""Creates a Microsoft.Purview data plane account client.
27+
28+
:ivar accounts: AccountsOperations operations
29+
:vartype accounts: azure.purview.account.operations.AccountsOperations
30+
:ivar collections: CollectionsOperations operations
31+
:vartype collections: azure.purview.account.operations.CollectionsOperations
32+
:ivar resource_set_rules: ResourceSetRulesOperations operations
33+
:vartype resource_set_rules: azure.purview.account.operations.ResourceSetRulesOperations
34+
:param endpoint: The account endpoint of your Purview account. Example:
35+
https://{accountName}.purview.azure.com/account/.
36+
:type endpoint: str
37+
:param credential: Credential needed for the client to connect to Azure.
38+
:type credential: ~azure.core.credentials.TokenCredential
39+
"""
40+
41+
def __init__(
42+
self,
43+
endpoint, # type: str
44+
credential, # type: "TokenCredential"
45+
**kwargs # type: Any
46+
):
47+
# type: (...) -> None
48+
_endpoint = '{endpoint}'
49+
self._config = PurviewAccountClientConfiguration(endpoint, credential, **kwargs)
50+
self._client = PipelineClient(base_url=_endpoint, config=self._config, **kwargs)
51+
52+
self._serialize = Serializer()
53+
self._deserialize = Deserializer()
54+
self._serialize.client_side_validation = False
55+
self.accounts = AccountsOperations(self._client, self._config, self._serialize, self._deserialize)
56+
self.collections = CollectionsOperations(self._client, self._config, self._serialize, self._deserialize)
57+
self.resource_set_rules = ResourceSetRulesOperations(self._client, self._config, self._serialize, self._deserialize)
58+
59+
60+
def send_request(
61+
self,
62+
request, # type: HttpRequest
63+
**kwargs # type: Any
64+
):
65+
# type: (...) -> HttpResponse
66+
"""Runs the network request through the client's chained policies.
67+
68+
We have helper methods to create requests specific to this service in `azure.purview.account.rest`.
69+
Use these helper methods to create the request you pass to this method.
70+
71+
72+
For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart
73+
74+
For advanced cases, you can also create your own :class:`~azure.core.rest.HttpRequest`
75+
and pass it in.
76+
77+
:param request: The network request you want to make. Required.
78+
:type request: ~azure.core.rest.HttpRequest
79+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
80+
:return: The response of your network call. Does not do error handling on your response.
81+
:rtype: ~azure.core.rest.HttpResponse
82+
"""
83+
84+
request_copy = deepcopy(request)
85+
path_format_arguments = {
86+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
87+
}
88+
89+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
90+
return self._client.send_request(request_copy, **kwargs)
91+
92+
def close(self):
93+
# type: () -> None
94+
self._client.close()
95+
96+
def __enter__(self):
97+
# type: () -> PurviewAccountClient
98+
self._client.__enter__()
99+
return self
100+
101+
def __exit__(self, *exc_details):
102+
# type: (Any) -> None
103+
self._client.__exit__(*exc_details)
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)