Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions packages/autorest.python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
"dependencies": {
"@typespec/http-client-python": "~0.8.3-dev.2",
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNDcwOTg1Ny9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.8.2.tgz",
"@autorest/system-requirements": "~1.0.2",
"fs-extra": "~11.2.0",
"tsx": "~4.19.1"
Expand All @@ -47,4 +47,4 @@
"requirements.txt",
"generator/"
]
}
}
60 changes: 30 additions & 30 deletions packages/typespec-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,43 +45,43 @@
"generator/**"
],
"peerDependencies": {
"@typespec/compiler": ">=0.67.0 <1.0.0",
"@typespec/http": ">=0.67.0 <1.0.0",
"@typespec/rest": ">=0.67.0 <1.0.0",
"@typespec/versioning": ">=0.67.0 <1.0.0",
"@typespec/openapi": ">=0.67.0 <1.0.0",
"@typespec/events": ">=0.67.0 <1.0.0",
"@typespec/sse": ">=0.67.0 <1.0.0",
"@typespec/streams": ">=0.67.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.53.0 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.53.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.53.0 <1.0.0",
"@azure-tools/typespec-azure-rulesets": ">=0.53.0 <3.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.53.1 <1.0.0"
"@typespec/compiler": ">=0.68.0-dev.11 <1.0.0",
"@typespec/http": ">=0.68.0-dev.8 <1.0.0",
"@typespec/rest": ">=0.68.0-dev.3 <1.0.0",
"@typespec/versioning": ">=0.68.0-dev.2 <1.0.0",
"@typespec/openapi": ">=0.68.0-dev.3 <1.0.0",
"@typespec/events": ">=0.68.0-dev.2 <1.0.0",
"@typespec/sse": ">=0.68.0-dev.2 <1.0.0",
"@typespec/streams": ">=0.68.0-dev.2 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.54.0-dev.5 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.54.0-dev.3 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.54.0-dev.5 <1.0.0",
"@azure-tools/typespec-azure-rulesets": ">=0.54.0-dev.2 <3.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.54.0-dev.19 <1.0.0"
},
"dependencies": {
"js-yaml": "~4.1.0",
"semver": "~7.6.2",
"tsx": "~4.19.1",
"@typespec/http-client-python": "~0.8.3-dev.2",
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNDcwOTg1Ny9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.8.2.tgz",
"fs-extra": "~11.2.0"
},
"devDependencies": {
"@typespec/compiler": "~0.67.0",
"@typespec/http": "~0.67.0",
"@typespec/rest": "~0.67.0",
"@typespec/versioning": "~0.67.0",
"@typespec/openapi": "~0.67.0",
"@typespec/events": "~0.67.0",
"@typespec/sse": "~0.67.0",
"@typespec/streams": "~0.67.0",
"@azure-tools/typespec-azure-resource-manager": "~0.53.0",
"@azure-tools/typespec-azure-core": "~0.53.0",
"@azure-tools/typespec-azure-rulesets": "~0.53.0",
"@azure-tools/typespec-autorest": "~0.53.0",
"@azure-tools/typespec-client-generator-core": "~0.53.1",
"@azure-tools/azure-http-specs": "0.1.0-alpha.10",
"@typespec/http-specs": "0.1.0-alpha.15-dev.3",
"@typespec/compiler": "~0.68.0-dev.11",
"@typespec/http": "~0.68.0-dev.8",
"@typespec/rest": "~0.68.0-dev.3",
"@typespec/versioning": "~0.68.0-dev.2",
"@typespec/openapi": "~0.68.0-dev.3",
"@typespec/events": "~0.68.0-dev.2",
"@typespec/sse": "~0.68.0-dev.2",
"@typespec/streams": "~0.68.0-dev.2",
"@azure-tools/typespec-azure-resource-manager": "~0.54.0-dev.3",
"@azure-tools/typespec-azure-core": "~0.54.0-dev.5",
"@azure-tools/typespec-azure-rulesets": "~0.54.0-dev.2",
"@azure-tools/typespec-autorest": "~0.54.0-dev.5",
"@azure-tools/typespec-client-generator-core": "~0.54.0-dev.19",
"@azure-tools/azure-http-specs": "0.1.0-alpha.13-dev.1",
"@typespec/http-specs": "0.1.0-alpha.17-dev.1",
"@types/js-yaml": "~4.0.5",
"@types/node": "~22.5.4",
"@types/yargs": "~17.0.33",
Expand All @@ -95,4 +95,4 @@
"chalk": "5.3.0",
"@types/fs-extra": "11.0.4"
}
}
}
10 changes: 8 additions & 2 deletions packages/typespec-python/src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { SdkContext, SdkServiceOperation } from "@azure-tools/typespec-client-generator-core";
import { SdkContext, SdkServiceOperation, BrandedSdkEmitterOptions } from "@azure-tools/typespec-client-generator-core";
import { createTypeSpecLibrary, JSONSchemaType } from "@typespec/compiler";
import { PythonEmitterOptions, PythonEmitterOptionsSchema } from "@typespec/http-client-python";

export interface PythonAzureEmitterOptions extends PythonEmitterOptions {
"examples-dir"?: string;
"namespace"?: string;

"flavor"?: "azure";
"models-mode"?: string;
"generate-sample"?: boolean;
Expand All @@ -16,8 +19,11 @@ export interface PythonSdkContext<TServiceOperation extends SdkServiceOperation>

const PythonAzureEmitterOptionsSchema: JSONSchemaType<PythonAzureEmitterOptions> = {
type: "object",
additionalProperties: true,
additionalProperties: false,
properties: {
...BrandedSdkEmitterOptions["examples-dir"],
...BrandedSdkEmitterOptions["namespace"],

"flavor": {
type: "string",
nullable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def build_page_list_with_parameters_request(
_headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str")
_headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_page_list_with_custom_page_model_request(**kwargs: Any) -> HttpRequest: # pylint: disable=name-too-long
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include *.md
include LICENSE
include azure/resourcemanager/nonresource/py.typed
recursive-include tests *.py
recursive-include samples *.py *.md
include azure/__init__.py
include azure/resourcemanager/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,55 @@
# ResiliencySrvDriven1 client library for Python
# Azure Resourcemanager Nonresource client library for Python
<!-- write necessary description of service -->

## Getting started

### Install the package

```bash
python -m pip install resiliency-srv-driven1
python -m pip install azure-resourcemanager-nonresource
```

#### Prequisites

- Python 3.8 or later is required to use this package.
- You need an [Azure subscription][azure_sub] to use this package.
- An existing ResiliencySrvDriven1 instance.
- An existing Azure Resourcemanager Nonresource instance.

#### Create with an Azure Active Directory Credential
To use an [Azure Active Directory (AAD) token credential][authenticate_with_token],
provide an instance of the desired credential type obtained from the
[azure-identity][azure_identity_credentials] library.

To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip]

After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use.
As an example, [DefaultAzureCredential][default_azure_credential] can be used to authenticate the client:

Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`

Use the returned token credential to authenticate the client:

```python
>>> from azure.resourcemanager.nonresource import NonResourceClient
>>> from azure.identity import DefaultAzureCredential
>>> client = NonResourceClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
```

## Examples

```python
>>> from azure.resourcemanager.nonresource import NonResourceClient
>>> from azure.identity import DefaultAzureCredential
>>> from azure.core.exceptions import HttpResponseError

>>> client = NonResourceClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
>>> try:
<!-- write test code here -->
except HttpResponseError as e:
print('service responds error: {}'.format(e.response.json()))

```

## Contributing

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"CrossLanguagePackageId": "Azure.ResourceManager.NonResource",
"CrossLanguageDefinitionId": {
"azure.resourcemanager.nonresource.models.ErrorAdditionalInfo": "Azure.ResourceManager.CommonTypes.ErrorAdditionalInfo",
"azure.resourcemanager.nonresource.models.ErrorDetail": "Azure.ResourceManager.CommonTypes.ErrorDetail",
"azure.resourcemanager.nonresource.models.ErrorResponse": "Azure.ResourceManager.CommonTypes.ErrorResponse",
"azure.resourcemanager.nonresource.models.NonResource": "Azure.ResourceManager.NonResource.NonResource",
"azure.resourcemanager.nonresource.NonResourceClient.non_resource_operations.get": "Azure.ResourceManager.NonResource.NonResourceOperations.get",
"azure.resourcemanager.nonresource.NonResourceClient.non_resource_operations.create": "Azure.ResourceManager.NonResource.NonResourceOperations.create"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
if TYPE_CHECKING:
from ._patch import * # pylint: disable=unused-wildcard-import

from ._client import ResiliencyServiceDrivenClient # type: ignore
from ._client import NonResourceClient # type: ignore
from ._version import VERSION

__version__ = VERSION
Expand All @@ -19,7 +19,7 @@
from ._patch import patch_sdk as _patch_sdk

__all__ = [
"ResiliencyServiceDrivenClient",
"NonResourceClient",
]
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore

Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
# coding=utf-8

from copy import deepcopy
from typing import Any
from typing import Any, TYPE_CHECKING
from typing_extensions import Self

from azure.core import PipelineClient
from azure.core.pipeline import policies
from azure.core.rest import HttpRequest, HttpResponse
from azure.mgmt.core import ARMPipelineClient
from azure.mgmt.core.policies import ARMAutoResourceProviderRegistrationPolicy

from ._configuration import ResiliencyServiceDrivenClientConfiguration
from ._operations import ResiliencyServiceDrivenClientOperationsMixin
from ._configuration import NonResourceClientConfiguration
from ._serialization import Deserializer, Serializer


class ResiliencyServiceDrivenClient(ResiliencyServiceDrivenClientOperationsMixin):
"""Test that we can grow up a service spec and service deployment into a multi-versioned service
with full client support.

:param endpoint: Need to be set as '`http://localhost:3000 <http://localhost:3000>`_' in
client. Required.
:type endpoint: str
:param service_deployment_version: Pass in either 'v1' or 'v2'. This represents a version of
the service deployment in history. 'v1' is for the deployment when the service had only one api
version. 'v2' is for the deployment when the service had api-versions 'v1' and 'v2'. Required.
:type service_deployment_version: str
:keyword api_version: Pass in 'v1'. This represents the API version of the service. Will grow
up in the next deployment to be both 'v1' and 'v2'. Known values are "v1" and None. Default
value is "v1". Note that overriding this default value may result in unsupported behavior.
from .operations import NonResourceOperationsOperations

if TYPE_CHECKING:
from azure.core.credentials import TokenCredential


class NonResourceClient:
"""Arm Resource Provider management API.

:ivar non_resource_operations: NonResourceOperationsOperations operations
:vartype non_resource_operations:
azure.resourcemanager.nonresource.operations.NonResourceOperationsOperations
:param credential: Credential used to authenticate requests to the service. Required.
:type credential: ~azure.core.credentials.TokenCredential
:param subscription_id: The ID of the target subscription. The value must be an UUID. Required.
:type subscription_id: str
:param base_url: Service host. Default value is "https://management.azure.com".
:type base_url: str
:keyword api_version: The API version to use for this operation. Default value is
"2023-12-01-preview". Note that overriding this default value may result in unsupported
behavior.
:paramtype api_version: str
"""

def __init__( # pylint: disable=missing-client-constructor-parameter-credential
self, endpoint: str, service_deployment_version: str, **kwargs: Any
def __init__(
self,
credential: "TokenCredential",
subscription_id: str,
base_url: str = "https://management.azure.com",
**kwargs: Any
) -> None:
_endpoint = (
"{endpoint}/resiliency/service-driven/client:v1/service:{serviceDeploymentVersion}/api-version:{apiVersion}"
)
self._config = ResiliencyServiceDrivenClientConfiguration(
endpoint=endpoint, service_deployment_version=service_deployment_version, **kwargs
_endpoint = "{endpoint}"
self._config = NonResourceClientConfiguration(
credential=credential, subscription_id=subscription_id, base_url=base_url, **kwargs
)
_policies = kwargs.pop("policies", None)
if _policies is None:
Expand All @@ -47,6 +54,7 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
self._config.user_agent_policy,
self._config.proxy_policy,
policies.ContentDecodePolicy(**kwargs),
ARMAutoResourceProviderRegistrationPolicy(),
self._config.redirect_policy,
self._config.retry_policy,
self._config.authentication_policy,
Expand All @@ -56,11 +64,14 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
self._config.http_logging_policy,
]
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)
self._client: ARMPipelineClient = ARMPipelineClient(base_url=_endpoint, policies=_policies, **kwargs)

self._serialize = Serializer()
self._deserialize = Deserializer()
self._serialize.client_side_validation = False
self.non_resource_operations = NonResourceOperationsOperations(
self._client, self._config, self._serialize, self._deserialize
)

def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
"""Runs the network request through the client's chained policies.
Expand All @@ -82,16 +93,7 @@ def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs:

request_copy = deepcopy(request)
path_format_arguments = {
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
"serviceDeploymentVersion": self._serialize.url(
"self._config.service_deployment_version",
self._config.service_deployment_version,
"str",
skip_quote=True,
),
"apiVersion": self._serialize.url(
"self._config.api_version", self._config.api_version, "str", skip_quote=True
),
"endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True),
}

request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
Expand Down
Loading
Loading