22
33from __future__ import annotations
44
5+ import json
56import logging
67import subprocess
8+ from collections .abc import Mapping
79from pathlib import Path
8- from typing import Any , Mapping
10+ from typing import Any , TextIO
911
1012from airbyte_cdk .connector import BaseConnector
13+ from airbyte_cdk .models import ConnectorSpecification
1114from airbyte_cdk .test .standard_tests ._job_runner import IConnector
1215from airbyte_cdk .utils .docker import build_connector_image , run_docker_command
1316
@@ -34,7 +37,7 @@ def read_config(config_path: str) -> Mapping[str, Any]:
3437 f"The content of { config_path } is not an object and therefore is not a valid config. Please ensure the file represent a config."
3538 )
3639
37- def spec (
40+ def spec_ (
3841 self ,
3942 logger : logging .Logger ,
4043 ) -> Any :
@@ -58,17 +61,22 @@ def check(
5861 def _run_cli (
5962 self ,
6063 args : list [str ],
64+ * ,
6165 logger : logging .Logger ,
62- ) -> None :
66+ stdout : TextIO | None = None ,
67+ stdin : TextIO | None = None ,
68+ ) -> subprocess .CompletedProcess [str ]:
6369 """Run the CLI command."""
6470 logger .info (f"Running CLI connector: { self .connector_name } with args: { args } " )
6571 base_cmd : list [str ] = [
6672 self .connector_name ,
6773 * args ,
6874 ]
69- subprocess .run (
70- base_cmd ,
71- check = True ,
75+ return subprocess .run (
76+ args = base_cmd ,
77+ text = True ,
78+ stdout = stdout ,
79+ stdin = stdin ,
7280 )
7381
7482 def launch (
@@ -96,17 +104,37 @@ def __init__(
96104 logger : logging .Logger | None = None ,
97105 ) -> None :
98106 self .docker_image = docker_image
107+ self ._config_file_path : Path | None = None
99108 super ().__init__ (
100109 connector_name = connector_name ,
101110 logger = logger ,
102111 )
103112
113+ def spec (self , logger : logging .Logger ) -> ConnectorSpecification :
114+ """
115+ Returns the spec for this integration. The spec is a JSON-Schema object describing the required configurations (e.g: username and password)
116+ required to run this integration. By default, this will be loaded from a "spec.yaml" or a "spec.json" in the package root.
117+ """
118+ self .launch (
119+ ["spec" ],
120+ logger = logger ,
121+ )
122+
123+ def configure (self , config : Mapping [str , Any ], temp_dir : str ) -> Mapping [str , Any ]:
124+ """
125+ Persist config in temporary directory to run the Source job
126+ """
127+ self ._config_file_path = Path (temp_dir ) / "config.json"
128+ self ._config_file_path .write_text (json .dumps (config ))
129+
130+ return config
131+
104132 def launch (
105133 self ,
106134 args : list [str ],
107135 * ,
108136 logger : logging .Logger | None = None ,
109- ) -> None :
137+ ) -> subprocess . CompletedProcess [ str ] :
110138 """Run the connector."""
111139 _ = logger
112140 print (f"Running docker connector: { self .connector_name } with args: { args } " )
@@ -116,7 +144,7 @@ def launch(
116144 "--rm" ,
117145 "--network=host" ,
118146 ]
119- run_docker_command (
147+ return run_docker_command (
120148 cmd = [
121149 * docker_base_cmd ,
122150 self .docker_image ,
0 commit comments