kaxil commented on code in PR #60651:
URL: https://github.com/apache/airflow/pull/60651#discussion_r2783190679
##########
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/hooks/winrm.py:
##########
@@ -191,47 +192,74 @@ def get_conn(self):
if not self.endpoint:
self.endpoint =
f"http://{self.remote_host}:{self.remote_port}/wsman"
+ if not self.password or not self.password.strip():
+ raise AirflowException(f"Missing password for WinRM connection to
host: {self.remote_host}")
+
try:
- if self.password and self.password.strip():
- self.winrm_protocol = Protocol(
- endpoint=self.endpoint,
- transport=self.transport,
- username=self.username,
- password=self.password,
- service=self.service,
- keytab=self.keytab,
- ca_trust_path=self.ca_trust_path,
- cert_pem=self.cert_pem,
- cert_key_pem=self.cert_key_pem,
- server_cert_validation=self.server_cert_validation,
- kerberos_delegation=self.kerberos_delegation,
- read_timeout_sec=self.read_timeout_sec,
- operation_timeout_sec=self.operation_timeout_sec,
- kerberos_hostname_override=self.kerberos_hostname_override,
- message_encryption=self.message_encryption,
- credssp_disable_tlsv1_2=self.credssp_disable_tlsv1_2,
- send_cbt=self.send_cbt,
+ winrm_protocol = Protocol(
+ endpoint=self.endpoint,
+ transport=cast(
+ "Literal['auto', 'basic', 'certificate', 'ntlm',
'kerberos', 'credssp', 'plaintext', 'ssl']",
+ self.transport,
+ ),
+ username=self.username,
+ password=self.password,
+ service=self.service,
+ keytab=cast("Any", self.keytab),
+ ca_trust_path=cast("str | Literal['legacy_requests']",
self.ca_trust_path),
+ cert_pem=self.cert_pem,
+ cert_key_pem=self.cert_key_pem,
+ server_cert_validation=cast(
+ "Literal['validate', 'ignore'] | None",
self.server_cert_validation
+ ),
+ kerberos_delegation=self.kerberos_delegation,
+ read_timeout_sec=self.read_timeout_sec,
+ operation_timeout_sec=self.operation_timeout_sec,
+ kerberos_hostname_override=self.kerberos_hostname_override,
+ message_encryption=cast("Literal['auto', 'always', 'never']",
self.message_encryption),
+ credssp_disable_tlsv1_2=self.credssp_disable_tlsv1_2,
+ send_cbt=self.send_cbt,
+ )
+
+ if not hasattr(winrm_protocol, "get_command_output_raw"):
+ # since pywinrm>=0.5 get_command_output_raw replace
_raw_get_command_output
+ winrm_protocol.get_command_output_raw = ( # type:
ignore[method-assign]
+ winrm_protocol._raw_get_command_output
)
+ if winrm_protocol is None:
+ raise AirflowException("WinRM protocol was not initialized")
+
+ self.log.info("Establishing WinRM connection to host: %s",
self.remote_host)
+
+ return winrm_protocol
except Exception as error:
error_msg = f"Error creating connection to host:
{self.remote_host}, error: {error}"
self.log.error(error_msg)
raise AirflowException(error_msg)
- if not hasattr(self.winrm_protocol, "get_command_output_raw"):
- # since pywinrm>=0.5 get_command_output_raw replace
_raw_get_command_output
- self.winrm_protocol.get_command_output_raw =
self.winrm_protocol._raw_get_command_output
+ def get_conn(self) -> Protocol:
+ if self.winrm_protocol is None:
+ self.winrm_protocol = self.create_protocol(
+ self.get_connection(self.ssh_conn_id) if self.ssh_conn_id else
None
+ )
+ return self.winrm_protocol
+ async def get_async_conn(self) -> Protocol:
+ if self.winrm_protocol is None:
+ self.winrm_protocol = self.create_protocol(
Review Comment:
`create_protocol()` instantiates `Protocol(...)` which may perform network
I/O (TLS handshake, etc.). Only `get_async_connection()` (the Airflow
connection fetch) is async. The actual WinRM protocol creation still blocks the
asyncio event loop.
Worth wrapping `create_protocol()` with `sync_to_async`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]