Skip to content

Commit 9ae2490

Browse files
authored
code and test (Azure#31317)
Co-authored-by: PythonSdkPipelines <PythonSdkPipelines>
1 parent 164aac9 commit 9ae2490

File tree

84 files changed

+21707
-0
lines changed

Some content is hidden

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

84 files changed

+21707
-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 (2023-07-21)
4+
5+
* Initial Release

sdk/sphere/azure-mgmt-sphere/LICENSE

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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
include _meta.json
2+
recursive-include tests *.py *.json
3+
recursive-include samples *.py *.md
4+
include *.md
5+
include azure/__init__.py
6+
include azure/mgmt/__init__.py
7+
include LICENSE
8+
include azure/mgmt/sphere/py.typed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Microsoft Azure SDK for Python
2+
3+
This is the Microsoft Azure Sphere Management Client Library.
4+
This package has been tested with Python 3.7+.
5+
For a more complete view of Azure libraries, see the [azure sdk python release](https://aka.ms/azsdk/python/all).
6+
7+
## _Disclaimer_
8+
9+
_Azure SDK Python packages support for Python 2.7 has ended 01 January 2022. For more information and questions, please refer to https://github.com/Azure/azure-sdk-for-python/issues/20691_
10+
11+
## Getting started
12+
13+
### Prerequisites
14+
15+
- Python 3.7+ is required to use this package.
16+
- [Azure subscription](https://azure.microsoft.com/free/)
17+
18+
### Install the package
19+
20+
```bash
21+
pip install azure-mgmt-sphere
22+
pip install azure-identity
23+
```
24+
25+
### Authentication
26+
27+
By default, [Azure Active Directory](https://aka.ms/awps/aad) token authentication depends on correct configure of following environment variables.
28+
29+
- `AZURE_CLIENT_ID` for Azure client ID.
30+
- `AZURE_TENANT_ID` for Azure tenant ID.
31+
- `AZURE_CLIENT_SECRET` for Azure client secret.
32+
33+
In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`.
34+
35+
With above configuration, client can be authenticated by following code:
36+
37+
```python
38+
from azure.identity import DefaultAzureCredential
39+
from azure.mgmt.sphere import AzureSphereMgmtClient
40+
import os
41+
42+
sub_id = os.getenv("AZURE_SUBSCRIPTION_ID")
43+
client = AzureSphereMgmtClient(credential=DefaultAzureCredential(), subscription_id=sub_id)
44+
```
45+
46+
## Examples
47+
48+
Code samples for this package can be found at:
49+
- [Search Sphere Management](https://docs.microsoft.com/samples/browse/?languages=python&term=Getting%20started%20-%20Managing&terms=Getting%20started%20-%20Managing) on docs.microsoft.com
50+
- [Azure Python Mgmt SDK Samples Repo](https://aka.ms/azsdk/python/mgmt/samples)
51+
52+
53+
## Troubleshooting
54+
55+
## Next steps
56+
57+
## Provide Feedback
58+
59+
If you encounter any bugs or have suggestions, please file an issue in the
60+
[Issues](https://github.com/Azure/azure-sdk-for-python/issues)
61+
section of the project.
62+
63+
64+
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2Fazure-mgmt-sphere%2FREADME.png)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"commit": "23d88533ddfde4d1565a897fe95d42fb0d9333e5",
3+
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
4+
"autorest": "3.9.6",
5+
"use": [
6+
"@autorest/[email protected]",
7+
"@autorest/[email protected]"
8+
],
9+
"autorest_command": "autorest specification/sphere/resource-manager/readme.md --generate-sample=True --include-x-ms-examples-original-file=True --python --python-sdks-folder=/home/vsts/work/1/azure-sdk-for-python/sdk --use=@autorest/[email protected] --use=@autorest/[email protected] --version=3.9.6 --version-tolerant=False",
10+
"readme": "specification/sphere/resource-manager/readme.md"
11+
}
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__)
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__)
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) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from ._azure_sphere_mgmt_client import AzureSphereMgmtClient
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+
"AzureSphereMgmtClient",
23+
]
24+
__all__.extend([p for p in _patch_all if p not in __all__])
25+
26+
_patch_sdk()
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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 Any, TYPE_CHECKING
11+
12+
from azure.core.rest import HttpRequest, HttpResponse
13+
from azure.mgmt.core import ARMPipelineClient
14+
15+
from . import models as _models
16+
from ._configuration import AzureSphereMgmtClientConfiguration
17+
from ._serialization import Deserializer, Serializer
18+
from .operations import (
19+
CatalogsOperations,
20+
CertificatesOperations,
21+
DeploymentsOperations,
22+
DeviceGroupsOperations,
23+
DevicesOperations,
24+
ImagesOperations,
25+
Operations,
26+
ProductsOperations,
27+
)
28+
29+
if TYPE_CHECKING:
30+
# pylint: disable=unused-import,ungrouped-imports
31+
from azure.core.credentials import TokenCredential
32+
33+
34+
class AzureSphereMgmtClient: # pylint: disable=client-accepts-api-version-keyword,too-many-instance-attributes
35+
"""Azure Sphere resource management API.
36+
37+
:ivar operations: Operations operations
38+
:vartype operations: azure.mgmt.sphere.operations.Operations
39+
:ivar catalogs: CatalogsOperations operations
40+
:vartype catalogs: azure.mgmt.sphere.operations.CatalogsOperations
41+
:ivar certificates: CertificatesOperations operations
42+
:vartype certificates: azure.mgmt.sphere.operations.CertificatesOperations
43+
:ivar images: ImagesOperations operations
44+
:vartype images: azure.mgmt.sphere.operations.ImagesOperations
45+
:ivar products: ProductsOperations operations
46+
:vartype products: azure.mgmt.sphere.operations.ProductsOperations
47+
:ivar device_groups: DeviceGroupsOperations operations
48+
:vartype device_groups: azure.mgmt.sphere.operations.DeviceGroupsOperations
49+
:ivar deployments: DeploymentsOperations operations
50+
:vartype deployments: azure.mgmt.sphere.operations.DeploymentsOperations
51+
:ivar devices: DevicesOperations operations
52+
:vartype devices: azure.mgmt.sphere.operations.DevicesOperations
53+
:param credential: Credential needed for the client to connect to Azure. Required.
54+
:type credential: ~azure.core.credentials.TokenCredential
55+
:param subscription_id: The ID of the target subscription. Required.
56+
:type subscription_id: str
57+
:param base_url: Service URL. Default value is "https://management.azure.com".
58+
:type base_url: str
59+
:keyword api_version: Api Version. Default value is "2022-09-01-preview". Note that overriding
60+
this default value may result in unsupported behavior.
61+
:paramtype api_version: str
62+
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
63+
Retry-After header is present.
64+
"""
65+
66+
def __init__(
67+
self,
68+
credential: "TokenCredential",
69+
subscription_id: str,
70+
base_url: str = "https://management.azure.com",
71+
**kwargs: Any
72+
) -> None:
73+
self._config = AzureSphereMgmtClientConfiguration(
74+
credential=credential, subscription_id=subscription_id, **kwargs
75+
)
76+
self._client: ARMPipelineClient = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs)
77+
78+
client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)}
79+
self._serialize = Serializer(client_models)
80+
self._deserialize = Deserializer(client_models)
81+
self._serialize.client_side_validation = False
82+
self.operations = Operations(self._client, self._config, self._serialize, self._deserialize)
83+
self.catalogs = CatalogsOperations(self._client, self._config, self._serialize, self._deserialize)
84+
self.certificates = CertificatesOperations(self._client, self._config, self._serialize, self._deserialize)
85+
self.images = ImagesOperations(self._client, self._config, self._serialize, self._deserialize)
86+
self.products = ProductsOperations(self._client, self._config, self._serialize, self._deserialize)
87+
self.device_groups = DeviceGroupsOperations(self._client, self._config, self._serialize, self._deserialize)
88+
self.deployments = DeploymentsOperations(self._client, self._config, self._serialize, self._deserialize)
89+
self.devices = DevicesOperations(self._client, self._config, self._serialize, self._deserialize)
90+
91+
def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
92+
"""Runs the network request through the client's chained policies.
93+
94+
>>> from azure.core.rest import HttpRequest
95+
>>> request = HttpRequest("GET", "https://www.example.org/")
96+
<HttpRequest [GET], url: 'https://www.example.org/'>
97+
>>> response = client._send_request(request)
98+
<HttpResponse: 200 OK>
99+
100+
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
101+
102+
:param request: The network request you want to make. Required.
103+
:type request: ~azure.core.rest.HttpRequest
104+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
105+
:return: The response of your network call. Does not do error handling on your response.
106+
:rtype: ~azure.core.rest.HttpResponse
107+
"""
108+
109+
request_copy = deepcopy(request)
110+
request_copy.url = self._client.format_url(request_copy.url)
111+
return self._client.send_request(request_copy, **kwargs)
112+
113+
def close(self) -> None:
114+
self._client.close()
115+
116+
def __enter__(self) -> "AzureSphereMgmtClient":
117+
self._client.__enter__()
118+
return self
119+
120+
def __exit__(self, *exc_details: Any) -> None:
121+
self._client.__exit__(*exc_details)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 Any, TYPE_CHECKING
10+
11+
from azure.core.configuration import Configuration
12+
from azure.core.pipeline import policies
13+
from azure.mgmt.core.policies import ARMChallengeAuthenticationPolicy, ARMHttpLoggingPolicy
14+
15+
from ._version import VERSION
16+
17+
if TYPE_CHECKING:
18+
# pylint: disable=unused-import,ungrouped-imports
19+
from azure.core.credentials import TokenCredential
20+
21+
22+
class AzureSphereMgmtClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
23+
"""Configuration for AzureSphereMgmtClient.
24+
25+
Note that all parameters used to create this instance are saved as instance
26+
attributes.
27+
28+
:param credential: Credential needed for the client to connect to Azure. Required.
29+
:type credential: ~azure.core.credentials.TokenCredential
30+
:param subscription_id: The ID of the target subscription. Required.
31+
:type subscription_id: str
32+
:keyword api_version: Api Version. Default value is "2022-09-01-preview". Note that overriding
33+
this default value may result in unsupported behavior.
34+
:paramtype api_version: str
35+
"""
36+
37+
def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs: Any) -> None:
38+
super(AzureSphereMgmtClientConfiguration, self).__init__(**kwargs)
39+
api_version: str = kwargs.pop("api_version", "2022-09-01-preview")
40+
41+
if credential is None:
42+
raise ValueError("Parameter 'credential' must not be None.")
43+
if subscription_id is None:
44+
raise ValueError("Parameter 'subscription_id' must not be None.")
45+
46+
self.credential = credential
47+
self.subscription_id = subscription_id
48+
self.api_version = api_version
49+
self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"])
50+
kwargs.setdefault("sdk_moniker", "mgmt-sphere/{}".format(VERSION))
51+
self._configure(**kwargs)
52+
53+
def _configure(self, **kwargs: Any) -> None:
54+
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
55+
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
56+
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
57+
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
58+
self.http_logging_policy = kwargs.get("http_logging_policy") or ARMHttpLoggingPolicy(**kwargs)
59+
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
60+
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
61+
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
62+
self.authentication_policy = kwargs.get("authentication_policy")
63+
if self.credential and not self.authentication_policy:
64+
self.authentication_policy = ARMChallengeAuthenticationPolicy(
65+
self.credential, *self.credential_scopes, **kwargs
66+
)

0 commit comments

Comments
 (0)