|
| 1 | +# -------------------------------------------------------------------------------------------- |
| 2 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +# Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | +# -------------------------------------------------------------------------------------------- |
| 5 | + |
| 6 | +# pylint: disable=protected-access |
| 7 | + |
| 8 | +from azext_cloudservice.aaz.latest.cloud_service.role_instance._show_remote_desktop_file import \ |
| 9 | + ShowRemoteDesktopFile as _ShowRemoteDesktopFile |
| 10 | + |
| 11 | + |
| 12 | +class RoleInstanceShowRemoteDesktopFile(_ShowRemoteDesktopFile): |
| 13 | + """The service returns the RDP file as application/x-rdp, not JSON.""" |
| 14 | + |
| 15 | + class CloudServiceRoleInstancesGetRemoteDesktopFile( |
| 16 | + _ShowRemoteDesktopFile.CloudServiceRoleInstancesGetRemoteDesktopFile): |
| 17 | + |
| 18 | + def __call__(self, *args, **kwargs): |
| 19 | + request = self.make_request() |
| 20 | + # stream=True keeps the content-decode policy from rejecting application/x-rdp |
| 21 | + session = self.client.send_request(request=request, stream=True, **kwargs) |
| 22 | + if session.http_response.status_code in [200]: |
| 23 | + return self.on_200(session) |
| 24 | + return self.on_error(session.http_response) |
| 25 | + |
| 26 | + @property |
| 27 | + def header_parameters(self): |
| 28 | + return { |
| 29 | + **self.serialize_header_param("Accept", "application/x-rdp"), |
| 30 | + } |
| 31 | + |
| 32 | + def on_200(self, session): |
| 33 | + data = session.http_response.body().decode('utf-8') |
| 34 | + self.ctx.set_var( |
| 35 | + "instance", |
| 36 | + data, |
| 37 | + schema_builder=self._build_schema_on_200 |
| 38 | + ) |
0 commit comments