Skip to content

Commit ea5e73f

Browse files
author
SDKAuto
committed
CodeGen from PR 29258 in Azure/azure-rest-api-specs
Merge e4d52a050cd93bc1e4ce7cd4b71475f5688615c6 into 262a9d16d94c3448fc7f37c840757f6e74acf7de
1 parent 6db5edb commit ea5e73f

31 files changed

+6197
-0
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 (1970-01-01)
4+
5+
- Initial version
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (c) Microsoft Corporation.
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include *.md
2+
include LICENSE
3+
include microsoft/app/py.typed
4+
recursive-include tests *.py
5+
recursive-include samples *.py *.md
6+
include microsoft/__init__.py
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
3+
# Microsoft App client library for Python
4+
<!-- write necessary description of service -->
5+
6+
## Getting started
7+
8+
### Install the package
9+
10+
```bash
11+
python -m pip install microsoft-app
12+
```
13+
14+
#### Prequisites
15+
16+
- Python 3.8 or later is required to use this package.
17+
- You need an [Azure subscription][azure_sub] to use this package.
18+
- An existing Microsoft App instance.
19+
#### Create with an Azure Active Directory Credential
20+
To use an [Azure Active Directory (AAD) token credential][authenticate_with_token],
21+
provide an instance of the desired credential type obtained from the
22+
[azure-identity][azure_identity_credentials] library.
23+
24+
To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip]
25+
26+
After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use.
27+
As an example, [DefaultAzureCredential][default_azure_credential] can be used to authenticate the client:
28+
29+
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
30+
`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`
31+
32+
Use the returned token credential to authenticate the client:
33+
34+
```python
35+
>>> from microsoft.app import AppClient
36+
>>> from azure.identity import DefaultAzureCredential
37+
>>> client = AppClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
38+
```
39+
40+
## Examples
41+
42+
```python
43+
>>> from microsoft.app import AppClient
44+
>>> from azure.identity import DefaultAzureCredential
45+
>>> from azure.core.exceptions import HttpResponseError
46+
47+
>>> client = AppClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
48+
>>> try:
49+
<!-- write test code here -->
50+
except HttpResponseError as e:
51+
print('service responds error: {}'.format(e.response.json()))
52+
53+
```
54+
55+
## Contributing
56+
57+
This project welcomes contributions and suggestions. Most contributions require
58+
you to agree to a Contributor License Agreement (CLA) declaring that you have
59+
the right to, and actually do, grant us the rights to use your contribution.
60+
For details, visit https://cla.microsoft.com.
61+
62+
When you submit a pull request, a CLA-bot will automatically determine whether
63+
you need to provide a CLA and decorate the PR appropriately (e.g., label,
64+
comment). Simply follow the instructions provided by the bot. You will only
65+
need to do this once across all repos using our CLA.
66+
67+
This project has adopted the
68+
[Microsoft Open Source Code of Conduct][code_of_conduct]. For more information,
69+
see the Code of Conduct FAQ or contact [email protected] with any
70+
additional questions or comments.
71+
72+
<!-- LINKS -->
73+
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
74+
[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token
75+
[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials
76+
[azure_identity_pip]: https://pypi.org/project/azure-identity/
77+
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential
78+
[pip]: https://pypi.org/project/pip/
79+
[azure_sub]: https://azure.microsoft.com/free/
80+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-e ../../../tools/azure-sdk-tools
2+
../../core/azure-core
3+
../../identity/azure-identity
4+
aiohttp
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from ._client import AppClient
10+
from ._version import VERSION
11+
12+
__version__ = VERSION
13+
14+
try:
15+
from ._patch import __all__ as _patch_all
16+
from ._patch import * # pylint: disable=unused-wildcard-import
17+
except ImportError:
18+
_patch_all = []
19+
from ._patch import patch_sdk as _patch_sdk
20+
21+
__all__ = [
22+
"AppClient",
23+
]
24+
__all__.extend([p for p in _patch_all if p not in __all__])
25+
26+
_patch_sdk()
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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) Python 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 Any, TYPE_CHECKING
11+
from typing_extensions import Self
12+
13+
from azure.core import PipelineClient
14+
from azure.core.pipeline import policies
15+
from azure.core.rest import HttpRequest, HttpResponse
16+
17+
from ._configuration import AppClientConfiguration
18+
from ._serialization import Deserializer, Serializer
19+
from .operations import CodeExecutionFilesOperations, CodeExecutionOperations
20+
21+
if TYPE_CHECKING:
22+
# pylint: disable=unused-import,ungrouped-imports
23+
from azure.core.credentials import TokenCredential
24+
25+
26+
class AppClient: # pylint: disable=client-accepts-api-version-keyword
27+
"""AppClient.
28+
29+
:ivar code_execution: CodeExecutionOperations operations
30+
:vartype code_execution: microsoft.app.operations.CodeExecutionOperations
31+
:ivar code_execution_files: CodeExecutionFilesOperations operations
32+
:vartype code_execution_files: microsoft.app.operations.CodeExecutionFilesOperations
33+
:param endpoint: Service host. Required.
34+
:type endpoint: str
35+
:param credential: Credential used to authenticate requests to the service. Required.
36+
:type credential: ~azure.core.credentials.TokenCredential
37+
:keyword api_version: The API version to use for this operation. Default value is
38+
"2023-08-01-preview". Note that overriding this default value may result in unsupported
39+
behavior.
40+
:paramtype api_version: str
41+
"""
42+
43+
def __init__(self, endpoint: str, credential: "TokenCredential", **kwargs: Any) -> None:
44+
_endpoint = "{endpoint}"
45+
self._config = AppClientConfiguration(endpoint=endpoint, credential=credential, **kwargs)
46+
_policies = kwargs.pop("policies", None)
47+
if _policies is None:
48+
_policies = [
49+
policies.RequestIdPolicy(**kwargs),
50+
self._config.headers_policy,
51+
self._config.user_agent_policy,
52+
self._config.proxy_policy,
53+
policies.ContentDecodePolicy(**kwargs),
54+
self._config.redirect_policy,
55+
self._config.retry_policy,
56+
self._config.authentication_policy,
57+
self._config.custom_hook_policy,
58+
self._config.logging_policy,
59+
policies.DistributedTracingPolicy(**kwargs),
60+
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
61+
self._config.http_logging_policy,
62+
]
63+
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)
64+
65+
self._serialize = Serializer()
66+
self._deserialize = Deserializer()
67+
self._serialize.client_side_validation = False
68+
self.code_execution = CodeExecutionOperations(self._client, self._config, self._serialize, self._deserialize)
69+
self.code_execution_files = CodeExecutionFilesOperations(
70+
self._client, self._config, self._serialize, self._deserialize
71+
)
72+
73+
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
74+
"""Runs the network request through the client's chained policies.
75+
76+
>>> from azure.core.rest import HttpRequest
77+
>>> request = HttpRequest("GET", "https://www.example.org/")
78+
<HttpRequest [GET], url: 'https://www.example.org/'>
79+
>>> response = client.send_request(request)
80+
<HttpResponse: 200 OK>
81+
82+
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
83+
84+
:param request: The network request you want to make. Required.
85+
:type request: ~azure.core.rest.HttpRequest
86+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
87+
:return: The response of your network call. Does not do error handling on your response.
88+
:rtype: ~azure.core.rest.HttpResponse
89+
"""
90+
91+
request_copy = deepcopy(request)
92+
path_format_arguments = {
93+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
94+
}
95+
96+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
97+
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore
98+
99+
def close(self) -> None:
100+
self._client.close()
101+
102+
def __enter__(self) -> Self:
103+
self._client.__enter__()
104+
return self
105+
106+
def __exit__(self, *exc_details: Any) -> None:
107+
self._client.__exit__(*exc_details)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from typing import Any, TYPE_CHECKING
10+
11+
from azure.core.pipeline import policies
12+
13+
from ._version import VERSION
14+
15+
if TYPE_CHECKING:
16+
# pylint: disable=unused-import,ungrouped-imports
17+
from azure.core.credentials import TokenCredential
18+
19+
20+
class AppClientConfiguration: # pylint: disable=too-many-instance-attributes
21+
"""Configuration for AppClient.
22+
23+
Note that all parameters used to create this instance are saved as instance
24+
attributes.
25+
26+
:param endpoint: Service host. Required.
27+
:type endpoint: str
28+
:param credential: Credential used to authenticate requests to the service. Required.
29+
:type credential: ~azure.core.credentials.TokenCredential
30+
:keyword api_version: The API version to use for this operation. Default value is
31+
"2023-08-01-preview". Note that overriding this default value may result in unsupported
32+
behavior.
33+
:paramtype api_version: str
34+
"""
35+
36+
def __init__(self, endpoint: str, credential: "TokenCredential", **kwargs: Any) -> None:
37+
api_version: str = kwargs.pop("api_version", "2023-08-01-preview")
38+
39+
if endpoint is None:
40+
raise ValueError("Parameter 'endpoint' must not be None.")
41+
if credential is None:
42+
raise ValueError("Parameter 'credential' must not be None.")
43+
44+
self.endpoint = endpoint
45+
self.credential = credential
46+
self.api_version = api_version
47+
self.credential_scopes = kwargs.pop("credential_scopes", ["https://dynamicsessions.io/.default"])
48+
kwargs.setdefault("sdk_moniker", "microsoft-app/{}".format(VERSION))
49+
self.polling_interval = kwargs.get("polling_interval", 30)
50+
self._configure(**kwargs)
51+
52+
def _configure(self, **kwargs: Any) -> None:
53+
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
54+
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
55+
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
56+
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
57+
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
58+
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
59+
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
60+
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
61+
self.authentication_policy = kwargs.get("authentication_policy")
62+
if self.credential and not self.authentication_policy:
63+
self.authentication_policy = policies.BearerTokenCredentialPolicy(
64+
self.credential, *self.credential_scopes, **kwargs
65+
)

0 commit comments

Comments
 (0)