Skip to content

Commit

Permalink
Add PSRP connection type (#34766)
Browse files Browse the repository at this point in the history
A new connection type "psrp" has been added along with a connection test

Co-authored-by: Andrey Anshin <Andrey.Anshin@taragol.is>
  • Loading branch information
arjunanan6 and Taragolis committed Feb 16, 2024
1 parent a3e939f commit bcf2673
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
10 changes: 10 additions & 0 deletions airflow/providers/microsoft/psrp/hooks/psrp.py
Expand Up @@ -75,6 +75,11 @@ class PsrpHook(BaseHook):
or by setting this key as the extra fields of your connection.
"""

conn_name_attr = "psrp_conn_id"
default_conn_name = "psrp_default"
conn_type = "psrp"
hook_name = "PowerShell Remoting Protocol"

_conn: RunspacePool | None = None
_wsman_ref: WeakKeyDictionary[RunspacePool, WSMan] = WeakKeyDictionary()

Expand Down Expand Up @@ -281,3 +286,8 @@ def _log_record(self, log, record):
log(INFO, "Progress: %s (%s)", record.activity, record.description)
else:
log(WARNING, "Unsupported message type: %s", message_type)

def test_connection(self):
"""Test PSRP Connection."""
with PsrpHook(psrp_conn_id=self.conn_id):
pass
10 changes: 7 additions & 3 deletions airflow/providers/microsoft/psrp/provider.yaml
Expand Up @@ -19,9 +19,9 @@
package-name: apache-airflow-providers-microsoft-psrp
name: PowerShell Remoting Protocol (PSRP)
description: |
This package provides remote execution capabilities via the
`PowerShell Remoting Protocol (PSRP)
<https://docs.microsoft.com/openspecs/windows_protocols/ms-psrp/>`__.
This package provides remote execution capabilities via the
`PowerShell Remoting Protocol (PSRP)
<https://docs.microsoft.com/openspecs/windows_protocols/ms-psrp/>`__.
state: ready
source-date-epoch: 1705912159
Expand Down Expand Up @@ -60,3 +60,7 @@ hooks:
- integration-name: Windows PowerShell Remoting Protocol
python-modules:
- airflow.providers.microsoft.psrp.hooks.psrp

connection-types:
- hook-class-name: airflow.providers.microsoft.psrp.hooks.psrp.PsrpHook
connection-type: psrp
6 changes: 6 additions & 0 deletions tests/providers/microsoft/psrp/hooks/test_psrp.py
Expand Up @@ -210,3 +210,9 @@ def test_invoke_local_context(self, *mocks):
hook = PsrpHook(CONNECTION_ID)
ps = hook.invoke_powershell("foo")
assert call("foo") in ps.add_script.mock_calls

def test_test_connection(self, runspace_pool, *mocks):
connection = Connection(conn_type="psrp")
connection.test_connection()

assert runspace_pool.return_value.__enter__.mock_calls == [call()]

0 comments on commit bcf2673

Please sign in to comment.