apache-airflow-providers-standard 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of apache-airflow-providers-standard might be problematic. Click here for more details.

Files changed (28) hide show
  1. airflow/providers/standard/LICENSE +253 -0
  2. airflow/providers/standard/__init__.py +39 -0
  3. airflow/providers/standard/get_provider_info.py +95 -0
  4. airflow/providers/standard/hooks/__init__.py +16 -0
  5. airflow/providers/standard/hooks/filesystem.py +89 -0
  6. airflow/providers/standard/hooks/package_index.py +95 -0
  7. airflow/providers/standard/hooks/subprocess.py +119 -0
  8. airflow/providers/standard/operators/__init__.py +16 -0
  9. airflow/providers/standard/operators/bash.py +304 -0
  10. airflow/providers/standard/operators/datetime.py +110 -0
  11. airflow/providers/standard/operators/generic_transfer.py +133 -0
  12. airflow/providers/standard/operators/python.py +1172 -0
  13. airflow/providers/standard/operators/weekday.py +120 -0
  14. airflow/providers/standard/sensors/__init__.py +16 -0
  15. airflow/providers/standard/sensors/bash.py +114 -0
  16. airflow/providers/standard/sensors/date_time.py +152 -0
  17. airflow/providers/standard/sensors/python.py +80 -0
  18. airflow/providers/standard/sensors/time.py +130 -0
  19. airflow/providers/standard/sensors/time_delta.py +134 -0
  20. airflow/providers/standard/sensors/weekday.py +104 -0
  21. airflow/providers/standard/utils/__init__.py +16 -0
  22. airflow/providers/standard/utils/python_virtualenv.py +209 -0
  23. airflow/providers/standard/utils/python_virtualenv_script.jinja2 +101 -0
  24. airflow/providers/standard/utils/version_references.py +26 -0
  25. apache_airflow_providers_standard-0.0.1.dist-info/METADATA +112 -0
  26. apache_airflow_providers_standard-0.0.1.dist-info/RECORD +28 -0
  27. apache_airflow_providers_standard-0.0.1.dist-info/WHEEL +4 -0
  28. apache_airflow_providers_standard-0.0.1.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,253 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
203
+ ============================================================================
204
+ APACHE AIRFLOW SUBCOMPONENTS:
205
+
206
+ The Apache Airflow project contains subcomponents with separate copyright
207
+ notices and license terms. Your use of the source code for the these
208
+ subcomponents is subject to the terms and conditions of the following
209
+ licenses.
210
+
211
+
212
+ ========================================================================
213
+ Third party Apache 2.0 licenses
214
+ ========================================================================
215
+
216
+ The following components are provided under the Apache 2.0 License.
217
+ See project link for details. The text of each license is also included
218
+ at 3rd-party-licenses/LICENSE-[project].txt.
219
+
220
+ (ALv2 License) hue v4.3.0 (https://github.com/cloudera/hue/)
221
+ (ALv2 License) jqclock v2.3.0 (https://github.com/JohnRDOrazio/jQuery-Clock-Plugin)
222
+ (ALv2 License) bootstrap3-typeahead v4.0.2 (https://github.com/bassjobsen/Bootstrap-3-Typeahead)
223
+ (ALv2 License) connexion v2.7.0 (https://github.com/zalando/connexion)
224
+
225
+ ========================================================================
226
+ MIT licenses
227
+ ========================================================================
228
+
229
+ The following components are provided under the MIT License. See project link for details.
230
+ The text of each license is also included at 3rd-party-licenses/LICENSE-[project].txt.
231
+
232
+ (MIT License) jquery v3.5.1 (https://jquery.org/license/)
233
+ (MIT License) dagre-d3 v0.6.4 (https://github.com/cpettitt/dagre-d3)
234
+ (MIT License) bootstrap v3.4.1 (https://github.com/twbs/bootstrap/)
235
+ (MIT License) d3-tip v0.9.1 (https://github.com/Caged/d3-tip)
236
+ (MIT License) dataTables v1.10.25 (https://datatables.net)
237
+ (MIT License) normalize.css v3.0.2 (http://necolas.github.io/normalize.css/)
238
+ (MIT License) ElasticMock v1.3.2 (https://github.com/vrcmarcos/elasticmock)
239
+ (MIT License) MomentJS v2.24.0 (http://momentjs.com/)
240
+ (MIT License) eonasdan-bootstrap-datetimepicker v4.17.49 (https://github.com/eonasdan/bootstrap-datetimepicker/)
241
+
242
+ ========================================================================
243
+ BSD 3-Clause licenses
244
+ ========================================================================
245
+ The following components are provided under the BSD 3-Clause license. See project links for details.
246
+ The text of each license is also included at 3rd-party-licenses/LICENSE-[project].txt.
247
+
248
+ (BSD 3 License) d3 v5.16.0 (https://d3js.org)
249
+ (BSD 3 License) d3-shape v2.1.0 (https://github.com/d3/d3-shape)
250
+ (BSD 3 License) cgroupspy 0.2.1 (https://github.com/cloudsigma/cgroupspy)
251
+
252
+ ========================================================================
253
+ See 3rd-party-licenses/LICENSES-ui.txt for packages used in `/airflow/www`
@@ -0,0 +1,39 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+ #
18
+ # NOTE! THIS FILE IS AUTOMATICALLY GENERATED AND WILL BE
19
+ # OVERWRITTEN WHEN PREPARING DOCUMENTATION FOR THE PACKAGES.
20
+ #
21
+ # IF YOU WANT TO MODIFY THIS FILE, YOU SHOULD MODIFY THE TEMPLATE
22
+ # `PROVIDER__INIT__PY_TEMPLATE.py.jinja2` IN the `dev/breeze/src/airflow_breeze/templates` DIRECTORY
23
+ #
24
+ from __future__ import annotations
25
+
26
+ import packaging.version
27
+
28
+ from airflow import __version__ as airflow_version
29
+
30
+ __all__ = ["__version__"]
31
+
32
+ __version__ = "0.0.1"
33
+
34
+ if packaging.version.parse(packaging.version.parse(airflow_version).base_version) < packaging.version.parse(
35
+ "2.8.0"
36
+ ):
37
+ raise RuntimeError(
38
+ f"The package `apache-airflow-providers-standard:{__version__}` needs Apache Airflow 2.8.0+"
39
+ )
@@ -0,0 +1,95 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ # NOTE! THIS FILE IS AUTOMATICALLY GENERATED AND WILL BE
19
+ # OVERWRITTEN WHEN PREPARING PACKAGES.
20
+ #
21
+ # IF YOU WANT TO MODIFY THIS FILE, YOU SHOULD MODIFY THE TEMPLATE
22
+ # `get_provider_info_TEMPLATE.py.jinja2` IN the `dev/breeze/src/airflow_breeze/templates` DIRECTORY
23
+
24
+
25
+ def get_provider_info():
26
+ return {
27
+ "package-name": "apache-airflow-providers-standard",
28
+ "name": "Standard",
29
+ "description": "Airflow Standard Provider\n",
30
+ "state": "ready",
31
+ "source-date-epoch": 1718603992,
32
+ "versions": ["0.0.1"],
33
+ "dependencies": ["apache-airflow>=2.8.0", "apache-airflow-providers-common-sql>=1.20.0"],
34
+ "integrations": [
35
+ {
36
+ "integration-name": "Standard",
37
+ "external-doc-url": "https://airflow.apache.org/",
38
+ "tags": ["apache"],
39
+ "how-to-guide": [
40
+ "/docs/apache-airflow-providers-standard/operators/bash.rst",
41
+ "/docs/apache-airflow-providers-standard/operators/python.rst",
42
+ "/docs/apache-airflow-providers-standard/operators/datetime.rst",
43
+ ],
44
+ }
45
+ ],
46
+ "operators": [
47
+ {
48
+ "integration-name": "Standard",
49
+ "python-modules": [
50
+ "airflow.providers.standard.operators.datetime",
51
+ "airflow.providers.standard.operators.weekday",
52
+ "airflow.providers.standard.operators.bash",
53
+ "airflow.providers.standard.operators.python",
54
+ "airflow.providers.standard.operators.generic_transfer",
55
+ ],
56
+ }
57
+ ],
58
+ "sensors": [
59
+ {
60
+ "integration-name": "Standard",
61
+ "python-modules": [
62
+ "airflow.providers.standard.sensors.date_time",
63
+ "airflow.providers.standard.sensors.time_delta",
64
+ "airflow.providers.standard.sensors.time",
65
+ "airflow.providers.standard.sensors.weekday",
66
+ "airflow.providers.standard.sensors.bash",
67
+ "airflow.providers.standard.sensors.python",
68
+ ],
69
+ }
70
+ ],
71
+ "hooks": [
72
+ {
73
+ "integration-name": "Standard",
74
+ "python-modules": [
75
+ "airflow.providers.standard.hooks.filesystem",
76
+ "airflow.providers.standard.hooks.package_index",
77
+ "airflow.providers.standard.hooks.subprocess",
78
+ ],
79
+ }
80
+ ],
81
+ "config": {
82
+ "standard": {
83
+ "description": "Options for the standard provider operators.",
84
+ "options": {
85
+ "venv_install_method": {
86
+ "description": "Which python tooling should be used to install the virtual environment.\n\nThe following options are available:\n- ``auto``: Automatically select, use ``uv`` if available, otherwise use ``pip``.\n- ``pip``: Use pip to install the virtual environment.\n- ``uv``: Use uv to install the virtual environment. Must be available in environment PATH.\n",
87
+ "version_added": None,
88
+ "type": "string",
89
+ "example": "uv",
90
+ "default": "auto",
91
+ }
92
+ },
93
+ }
94
+ },
95
+ }
@@ -0,0 +1,16 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
@@ -0,0 +1,89 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ from __future__ import annotations
19
+
20
+ from pathlib import Path
21
+ from typing import Any
22
+
23
+ from airflow.hooks.base import BaseHook
24
+
25
+
26
+ class FSHook(BaseHook):
27
+ """
28
+ Allows for interaction with an file server.
29
+
30
+ Connection should have a name and a path specified under extra:
31
+
32
+ example:
33
+ Connection Id: fs_test
34
+ Connection Type: File (path)
35
+ Host, Schema, Login, Password, Port: empty
36
+ Extra: {"path": "/tmp"}
37
+ """
38
+
39
+ conn_name_attr = "fs_conn_id"
40
+ default_conn_name = "fs_default"
41
+ conn_type = "fs"
42
+ hook_name = "File (path)"
43
+
44
+ @classmethod
45
+ def get_connection_form_widgets(cls) -> dict[str, Any]:
46
+ """Return connection widgets to add to connection form."""
47
+ from flask_appbuilder.fieldwidgets import BS3TextFieldWidget
48
+ from flask_babel import lazy_gettext
49
+ from wtforms import StringField
50
+
51
+ return {"path": StringField(lazy_gettext("Path"), widget=BS3TextFieldWidget())}
52
+
53
+ @classmethod
54
+ def get_ui_field_behaviour(cls) -> dict[str, Any]:
55
+ """Return custom field behaviour."""
56
+ return {
57
+ "hidden_fields": ["host", "schema", "port", "login", "password", "extra"],
58
+ "relabeling": {},
59
+ "placeholders": {},
60
+ }
61
+
62
+ def __init__(self, fs_conn_id: str = default_conn_name, **kwargs):
63
+ super().__init__(**kwargs)
64
+ conn = self.get_connection(fs_conn_id)
65
+ self.basepath = conn.extra_dejson.get("path", "")
66
+ self.conn = conn
67
+
68
+ def get_conn(self) -> None:
69
+ pass
70
+
71
+ def get_path(self) -> str:
72
+ """
73
+ Get the path to the filesystem location.
74
+
75
+ :return: the path.
76
+ """
77
+ return self.basepath
78
+
79
+ def test_connection(self):
80
+ """Test File connection."""
81
+ try:
82
+ p = self.get_path()
83
+ if not p:
84
+ return False, "File Path is undefined."
85
+ if not Path(p).exists():
86
+ return False, f"Path {p} does not exist."
87
+ return True, f"Path {p} is existing."
88
+ except Exception as e:
89
+ return False, str(e)
@@ -0,0 +1,95 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ """Hook for additional Package Indexes (Python)."""
19
+
20
+ from __future__ import annotations
21
+
22
+ import subprocess
23
+ from typing import Any
24
+ from urllib.parse import quote, urlparse
25
+
26
+ from airflow.hooks.base import BaseHook
27
+
28
+
29
+ class PackageIndexHook(BaseHook):
30
+ """Specify package indexes/Python package sources using Airflow connections."""
31
+
32
+ conn_name_attr = "pi_conn_id"
33
+ default_conn_name = "package_index_default"
34
+ conn_type = "package_index"
35
+ hook_name = "Package Index (Python)"
36
+
37
+ def __init__(self, pi_conn_id: str = default_conn_name, **kwargs) -> None:
38
+ super().__init__(**kwargs)
39
+ self.pi_conn_id = pi_conn_id
40
+ self.conn = None
41
+
42
+ @staticmethod
43
+ def get_ui_field_behaviour() -> dict[str, Any]:
44
+ """Return custom field behaviour."""
45
+ return {
46
+ "hidden_fields": ["schema", "port", "extra"],
47
+ "relabeling": {"host": "Package Index URL"},
48
+ "placeholders": {
49
+ "host": "Example: https://my-package-mirror.net/pypi/repo-name/simple",
50
+ "login": "Username for package index",
51
+ "password": "Password for package index (will be masked)",
52
+ },
53
+ }
54
+
55
+ @staticmethod
56
+ def _get_basic_auth_conn_url(index_url: str, user: str | None, password: str | None) -> str:
57
+ """Return a connection URL with basic auth credentials based on connection config."""
58
+ url = urlparse(index_url)
59
+ host = url.netloc.split("@")[-1]
60
+ if user:
61
+ if password:
62
+ host = f"{quote(user)}:{quote(password)}@{host}"
63
+ else:
64
+ host = f"{quote(user)}@{host}"
65
+ return url._replace(netloc=host).geturl()
66
+
67
+ def get_conn(self) -> Any:
68
+ """Return connection for the hook."""
69
+ return self.get_connection_url()
70
+
71
+ def get_connection_url(self) -> Any:
72
+ """Return a connection URL with embedded credentials."""
73
+ conn = self.get_connection(self.pi_conn_id)
74
+ index_url = conn.host
75
+ if not index_url:
76
+ raise ValueError("Please provide an index URL.")
77
+ return self._get_basic_auth_conn_url(index_url, conn.login, conn.password)
78
+
79
+ def test_connection(self) -> tuple[bool, str]:
80
+ """Test connection to package index url."""
81
+ conn_url = self.get_connection_url()
82
+ proc = subprocess.run(
83
+ ["pip", "search", "not-existing-test-package", "--no-input", "--index", conn_url],
84
+ check=False,
85
+ capture_output=True,
86
+ )
87
+ conn = self.get_connection(self.pi_conn_id)
88
+ if proc.returncode not in [
89
+ 0, # executed successfully, found package
90
+ 23, # executed successfully, didn't find any packages
91
+ # (but we do not expect it to find 'not-existing-test-package')
92
+ ]:
93
+ return False, f"Connection test to {conn.host} failed. Error: {str(proc.stderr)}"
94
+
95
+ return True, f"Connection to {conn.host} tested successfully!"