apache-airflow-providers-git 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.
@@ -0,0 +1,201 @@
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.
@@ -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
+ "3.0.0"
36
+ ):
37
+ raise RuntimeError(
38
+ f"The package `apache-airflow-providers-git:{__version__}` needs Apache Airflow 3.0.0+"
39
+ )
@@ -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,239 @@
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
+ from __future__ import annotations
18
+
19
+ import os
20
+ from pathlib import Path
21
+ from urllib.parse import urlparse
22
+
23
+ import structlog
24
+ from git import Repo
25
+ from git.exc import BadName, GitCommandError, NoSuchPathError
26
+
27
+ from airflow.dag_processing.bundles.base import (
28
+ BaseDagBundle,
29
+ )
30
+ from airflow.exceptions import AirflowException
31
+ from airflow.providers.git.hooks.git import GitHook
32
+
33
+ log = structlog.get_logger(__name__)
34
+
35
+
36
+ class GitDagBundle(BaseDagBundle):
37
+ """
38
+ git DAG bundle - exposes a git repository as a DAG bundle.
39
+
40
+ Instead of cloning the repository every time, we clone the repository once into a bare repo from the source
41
+ and then do a clone for each version from there.
42
+
43
+ :param tracking_ref: Branch or tag for this DAG bundle
44
+ :param subdir: Subdirectory within the repository where the DAGs are stored (Optional)
45
+ :param git_conn_id: Connection ID for SSH/token based connection to the repository (Optional)
46
+ :param repo_url: Explicit Git repository URL to override the connection's host. (Optional)
47
+ """
48
+
49
+ supports_versioning = True
50
+
51
+ def __init__(
52
+ self,
53
+ *,
54
+ tracking_ref: str,
55
+ subdir: str | None = None,
56
+ git_conn_id: str = "git_default",
57
+ repo_url: str | None = None,
58
+ **kwargs,
59
+ ) -> None:
60
+ super().__init__(**kwargs)
61
+ self.tracking_ref = tracking_ref
62
+ self.subdir = subdir
63
+ self.bare_repo_path = self.base_dir / "bare"
64
+ if self.version:
65
+ self.repo_path = self.versions_dir / self.version
66
+ else:
67
+ self.repo_path = self.base_dir / "tracking_repo"
68
+ self.git_conn_id = git_conn_id
69
+ self.repo_url = repo_url
70
+
71
+ self._log = log.bind(
72
+ bundle_name=self.name,
73
+ version=self.version,
74
+ bare_repo_path=self.bare_repo_path,
75
+ repo_path=self.repo_path,
76
+ versions_path=self.versions_dir,
77
+ git_conn_id=self.git_conn_id,
78
+ repo_url=self.repo_url,
79
+ )
80
+
81
+ self._log.debug("bundle configured")
82
+ try:
83
+ self.hook = GitHook(git_conn_id=self.git_conn_id, repo_url=self.repo_url)
84
+ self.repo_url = self.hook.repo_url
85
+ self._log.debug("repo_url updated from hook", repo_url=self.repo_url)
86
+ except AirflowException as e:
87
+ self._log.warning("Could not create GitHook", conn_id=self.git_conn_id, exc=e)
88
+
89
+ def _initialize(self):
90
+ with self.lock():
91
+ with self.hook.configure_hook_env():
92
+ self._clone_bare_repo_if_required()
93
+ self._ensure_version_in_bare_repo()
94
+
95
+ self._clone_repo_if_required()
96
+ self.repo.git.checkout(self.tracking_ref)
97
+ self._log.debug("bundle initialize", version=self.version)
98
+ if self.version:
99
+ if not self._has_version(self.repo, self.version):
100
+ self.repo.remotes.origin.fetch()
101
+ self.repo.head.set_reference(str(self.repo.commit(self.version)))
102
+ self.repo.head.reset(index=True, working_tree=True)
103
+ else:
104
+ self.refresh()
105
+
106
+ def initialize(self) -> None:
107
+ if not self.repo_url:
108
+ raise AirflowException(f"Connection {self.git_conn_id} doesn't have a host url")
109
+ self._initialize()
110
+ super().initialize()
111
+
112
+ def _clone_repo_if_required(self) -> None:
113
+ if not os.path.exists(self.repo_path):
114
+ self._log.info("Cloning repository", repo_path=self.repo_path, bare_repo_path=self.bare_repo_path)
115
+ try:
116
+ Repo.clone_from(
117
+ url=self.bare_repo_path,
118
+ to_path=self.repo_path,
119
+ )
120
+ except NoSuchPathError as e:
121
+ # Protection should the bare repo be removed manually
122
+ raise AirflowException("Repository path: %s not found", self.bare_repo_path) from e
123
+ else:
124
+ self._log.debug("repo exists", repo_path=self.repo_path)
125
+ self.repo = Repo(self.repo_path)
126
+
127
+ def _clone_bare_repo_if_required(self) -> None:
128
+ if not self.repo_url:
129
+ raise AirflowException(f"Connection {self.git_conn_id} doesn't have a host url")
130
+ if not os.path.exists(self.bare_repo_path):
131
+ self._log.info("Cloning bare repository", bare_repo_path=self.bare_repo_path)
132
+ try:
133
+ Repo.clone_from(
134
+ url=self.repo_url,
135
+ to_path=self.bare_repo_path,
136
+ bare=True,
137
+ env=self.hook.env,
138
+ )
139
+ except GitCommandError as e:
140
+ raise AirflowException("Error cloning repository") from e
141
+ self.bare_repo = Repo(self.bare_repo_path)
142
+
143
+ def _ensure_version_in_bare_repo(self) -> None:
144
+ if not self.version:
145
+ return
146
+ if not self._has_version(self.bare_repo, self.version):
147
+ self._fetch_bare_repo()
148
+ if not self._has_version(self.bare_repo, self.version):
149
+ raise AirflowException(f"Version {self.version} not found in the repository")
150
+
151
+ def __repr__(self):
152
+ return (
153
+ f"<GitDagBundle("
154
+ f"name={self.name!r}, "
155
+ f"tracking_ref={self.tracking_ref!r}, "
156
+ f"subdir={self.subdir!r}, "
157
+ f"version={self.version!r}"
158
+ f")>"
159
+ )
160
+
161
+ def get_current_version(self) -> str:
162
+ return self.repo.head.commit.hexsha
163
+
164
+ @property
165
+ def path(self) -> Path:
166
+ if self.subdir:
167
+ return self.repo_path / self.subdir
168
+ return self.repo_path
169
+
170
+ @staticmethod
171
+ def _has_version(repo: Repo, version: str) -> bool:
172
+ try:
173
+ repo.commit(version)
174
+ return True
175
+ except (BadName, ValueError):
176
+ return False
177
+
178
+ def _fetch_bare_repo(self):
179
+ refspecs = ["+refs/heads/*:refs/heads/*", "+refs/tags/*:refs/tags/*"]
180
+ if self.hook.env:
181
+ with self.bare_repo.git.custom_environment(GIT_SSH_COMMAND=self.hook.env.get("GIT_SSH_COMMAND")):
182
+ self.bare_repo.remotes.origin.fetch(refspecs)
183
+ else:
184
+ self.bare_repo.remotes.origin.fetch(refspecs)
185
+
186
+ def refresh(self) -> None:
187
+ if self.version:
188
+ raise AirflowException("Refreshing a specific version is not supported")
189
+
190
+ with self.lock():
191
+ with self.hook.configure_hook_env():
192
+ self._fetch_bare_repo()
193
+ self.repo.remotes.origin.fetch(
194
+ ["+refs/heads/*:refs/remotes/origin/*", "+refs/tags/*:refs/tags/*"]
195
+ )
196
+ remote_branch = f"origin/{self.tracking_ref}"
197
+ if remote_branch in [ref.name for ref in self.repo.remotes.origin.refs]:
198
+ target = remote_branch
199
+ else:
200
+ target = self.tracking_ref
201
+ self.repo.head.reset(target, index=True, working_tree=True)
202
+
203
+ @staticmethod
204
+ def _convert_git_ssh_url_to_https(url: str) -> str:
205
+ if not url.startswith("git@"):
206
+ raise ValueError(f"Invalid git SSH URL: {url}")
207
+ parts = url.split(":")
208
+ domain = parts[0].replace("git@", "https://")
209
+ repo_path = parts[1].replace(".git", "")
210
+ return f"{domain}/{repo_path}"
211
+
212
+ def view_url(self, version: str | None = None) -> str | None:
213
+ if not version:
214
+ return None
215
+ url = self.repo_url
216
+ if not url:
217
+ return None
218
+ if url.startswith("git@"):
219
+ url = self._convert_git_ssh_url_to_https(url)
220
+ if url.endswith(".git"):
221
+ url = url[:-4]
222
+ parsed_url = urlparse(url)
223
+ host = parsed_url.hostname
224
+ if not host:
225
+ return None
226
+ if parsed_url.username or parsed_url.password:
227
+ new_netloc = host
228
+ if parsed_url.port:
229
+ new_netloc += f":{parsed_url.port}"
230
+ url = parsed_url._replace(netloc=new_netloc).geturl()
231
+ host_patterns = {
232
+ "github.com": f"{url}/tree/{version}",
233
+ "gitlab.com": f"{url}/-/tree/{version}",
234
+ "bitbucket.org": f"{url}/src/{version}",
235
+ }
236
+ for allowed_host, template in host_patterns.items():
237
+ if host == allowed_host or host.endswith(f".{allowed_host}"):
238
+ return template
239
+ return None
@@ -0,0 +1,41 @@
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 OVERWRITTEN!
19
+ #
20
+ # IF YOU WANT TO MODIFY THIS FILE, YOU SHOULD MODIFY THE TEMPLATE
21
+ # `get_provider_info_TEMPLATE.py.jinja2` IN the `dev/breeze/src/airflow_breeze/templates` DIRECTORY
22
+
23
+
24
+ def get_provider_info():
25
+ return {
26
+ "package-name": "apache-airflow-providers-git",
27
+ "name": "GIT",
28
+ "description": "`Distributed version control system (GIT) <https://git-scm.com/>`__\n",
29
+ "integrations": [
30
+ {
31
+ "integration-name": "GIT (Git)",
32
+ "external-doc-url": "https://git-scm.com/",
33
+ "tags": ["software"],
34
+ }
35
+ ],
36
+ "hooks": [{"integration-name": "GIT", "python-modules": ["airflow.providers.git.hooks.git"]}],
37
+ "bundles": [{"integration-name": "GIT", "python-modules": ["airflow.providers.git.bundles.git"]}],
38
+ "connection-types": [
39
+ {"hook-class-name": "airflow.providers.git.hooks.git.GitHook", "connection-type": "git"}
40
+ ],
41
+ }
@@ -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,110 @@
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
+ from __future__ import annotations
19
+
20
+ import contextlib
21
+ import json
22
+ import logging
23
+ import os
24
+ import tempfile
25
+ from typing import Any
26
+
27
+ from airflow.exceptions import AirflowException
28
+ from airflow.hooks.base import BaseHook
29
+
30
+ log = logging.getLogger(__name__)
31
+
32
+
33
+ class GitHook(BaseHook):
34
+ """
35
+ Hook for git repositories.
36
+
37
+ :param git_conn_id: Connection ID for SSH connection to the repository
38
+
39
+ """
40
+
41
+ conn_name_attr = "git_conn_id"
42
+ default_conn_name = "git_default"
43
+ conn_type = "git"
44
+ hook_name = "GIT"
45
+
46
+ @classmethod
47
+ def get_ui_field_behaviour(cls) -> dict[str, Any]:
48
+ return {
49
+ "hidden_fields": ["schema"],
50
+ "relabeling": {
51
+ "login": "Username",
52
+ "host": "Repository URL",
53
+ "password": "Access Token (optional)",
54
+ },
55
+ "placeholders": {
56
+ "extra": json.dumps(
57
+ {
58
+ "key_file": "optional/path/to/keyfile",
59
+ "private_key": "optional inline private key",
60
+ }
61
+ )
62
+ },
63
+ }
64
+
65
+ def __init__(
66
+ self, git_conn_id: str = "git_default", repo_url: str | None = None, *args, **kwargs
67
+ ) -> None:
68
+ super().__init__()
69
+ connection = self.get_connection(git_conn_id)
70
+ self.repo_url = repo_url or connection.host
71
+ self.auth_token = connection.password
72
+ self.private_key = connection.extra_dejson.get("private_key")
73
+ self.key_file = connection.extra_dejson.get("key_file")
74
+ self.strict_host_key_checking = connection.extra_dejson.get("strict_host_key_checking", "no")
75
+ self.env: dict[str, str] = {}
76
+
77
+ if self.key_file and self.private_key:
78
+ raise AirflowException("Both 'key_file' and 'private_key' cannot be provided at the same time")
79
+ self._process_git_auth_url()
80
+
81
+ def _build_ssh_command(self, key_path: str) -> str:
82
+ return (
83
+ f"ssh -i {key_path} "
84
+ f"-o IdentitiesOnly=yes "
85
+ f"-o StrictHostKeyChecking={self.strict_host_key_checking}"
86
+ )
87
+
88
+ def _process_git_auth_url(self):
89
+ if not isinstance(self.repo_url, str):
90
+ return
91
+ if self.auth_token and self.repo_url.startswith("https://"):
92
+ self.repo_url = self.repo_url.replace("https://", f"https://{self.auth_token}@")
93
+ elif not self.repo_url.startswith("git@") or not self.repo_url.startswith("https://"):
94
+ self.repo_url = os.path.expanduser(self.repo_url)
95
+
96
+ def set_git_env(self, key: str) -> None:
97
+ self.env["GIT_SSH_COMMAND"] = self._build_ssh_command(key)
98
+
99
+ @contextlib.contextmanager
100
+ def configure_hook_env(self):
101
+ if self.private_key:
102
+ with tempfile.NamedTemporaryFile(mode="w", delete=True) as tmp_keyfile:
103
+ tmp_keyfile.write(self.private_key)
104
+ tmp_keyfile.flush()
105
+ os.chmod(tmp_keyfile.name, 0o600)
106
+ self.set_git_env(tmp_keyfile.name)
107
+ yield
108
+ else:
109
+ self.set_git_env(self.key_file)
110
+ yield
@@ -0,0 +1,94 @@
1
+ Metadata-Version: 2.4
2
+ Name: apache-airflow-providers-git
3
+ Version: 0.0.1
4
+ Summary: Provider package apache-airflow-providers-git for Apache Airflow
5
+ Keywords: airflow-provider,git,airflow,integration
6
+ Author-email: Apache Software Foundation <dev@airflow.apache.org>
7
+ Maintainer-email: Apache Software Foundation <dev@airflow.apache.org>
8
+ Requires-Python: ~=3.9
9
+ Description-Content-Type: text/x-rst
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Environment :: Console
12
+ Classifier: Environment :: Web Environment
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: Framework :: Apache Airflow
16
+ Classifier: Framework :: Apache Airflow :: Provider
17
+ Classifier: License :: OSI Approved :: Apache Software License
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: System :: Monitoring
23
+ Requires-Dist: apache-airflow>=3.0.0
24
+ Requires-Dist: GitPython>=3.1.44
25
+ Project-URL: Bug Tracker, https://github.com/apache/airflow/issues
26
+ Project-URL: Changelog, https://airflow.apache.org/docs/apache-airflow-providers-git/0.0.1/changelog.html
27
+ Project-URL: Documentation, https://airflow.apache.org/docs/apache-airflow-providers-git/0.0.1
28
+ Project-URL: Mastodon, https://fosstodon.org/@airflow
29
+ Project-URL: Slack Chat, https://s.apache.org/airflow-slack
30
+ Project-URL: Source Code, https://github.com/apache/airflow
31
+ Project-URL: YouTube, https://www.youtube.com/channel/UCSXwxpWZQ7XZ1WL3wqevChA/
32
+
33
+
34
+ .. Licensed to the Apache Software Foundation (ASF) under one
35
+ or more contributor license agreements. See the NOTICE file
36
+ distributed with this work for additional information
37
+ regarding copyright ownership. The ASF licenses this file
38
+ to you under the Apache License, Version 2.0 (the
39
+ "License"); you may not use this file except in compliance
40
+ with the License. You may obtain a copy of the License at
41
+
42
+ .. http://www.apache.org/licenses/LICENSE-2.0
43
+
44
+ .. Unless required by applicable law or agreed to in writing,
45
+ software distributed under the License is distributed on an
46
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
47
+ KIND, either express or implied. See the License for the
48
+ specific language governing permissions and limitations
49
+ under the License.
50
+
51
+ .. NOTE! THIS FILE IS AUTOMATICALLY GENERATED AND WILL BE OVERWRITTEN!
52
+
53
+ .. IF YOU WANT TO MODIFY TEMPLATE FOR THIS FILE, YOU SHOULD MODIFY THE TEMPLATE
54
+ ``PROVIDER_README_TEMPLATE.rst.jinja2`` IN the ``dev/breeze/src/airflow_breeze/templates`` DIRECTORY
55
+
56
+ Package ``apache-airflow-providers-git``
57
+
58
+ Release: ``0.0.1``
59
+
60
+
61
+ `Distributed version control system (GIT) <https://git-scm.com/>`__
62
+
63
+
64
+ Provider package
65
+ ----------------
66
+
67
+ This is a provider package for ``git`` provider. All classes for this provider package
68
+ are in ``airflow.providers.git`` python package.
69
+
70
+ You can find package information and changelog for the provider
71
+ in the `documentation <https://airflow.apache.org/docs/apache-airflow-providers-git/0.0.1/>`_.
72
+
73
+ Installation
74
+ ------------
75
+
76
+ You can install this package on top of an existing Airflow 2 installation (see ``Requirements`` below
77
+ for the minimum Airflow version supported) via
78
+ ``pip install apache-airflow-providers-git``
79
+
80
+ The package supports the following python versions: 3.9,3.10,3.11,3.12
81
+
82
+ Requirements
83
+ ------------
84
+
85
+ ================== ==================
86
+ PIP package Version required
87
+ ================== ==================
88
+ ``apache-airflow`` ``>=3.0.0``
89
+ ``GitPython`` ``>=3.1.44``
90
+ ================== ==================
91
+
92
+ The changelog for the provider package can be found in the
93
+ `changelog <https://airflow.apache.org/docs/apache-airflow-providers-git/0.0.1/changelog.html>`_.
94
+
@@ -0,0 +1,11 @@
1
+ airflow/providers/git/LICENSE,sha256=gXPVwptPlW1TJ4HSuG5OMPg-a3h43OGMkZRR1rpwfJA,10850
2
+ airflow/providers/git/__init__.py,sha256=zNgp9rHGoc5roLS_cYTHNnTO1yjoAJCqdYAGmKhEuQ4,1490
3
+ airflow/providers/git/get_provider_info.py,sha256=6xC_Jru3CMrhO7r5aX03J4HR6Jl62rp9BWVcLKFjxQQ,1809
4
+ airflow/providers/git/bundles/__init__.py,sha256=9hdXHABrVpkbpjZgUft39kOFL2xSGeG4GEua0Hmelus,785
5
+ airflow/providers/git/bundles/git.py,sha256=rN6C9t0cltaDcKNZnYsXgbia6CFsiXtA0TsFPijpplw,9157
6
+ airflow/providers/git/hooks/__init__.py,sha256=9hdXHABrVpkbpjZgUft39kOFL2xSGeG4GEua0Hmelus,785
7
+ airflow/providers/git/hooks/git.py,sha256=RIhvVfd3J-GW9itJ0V1tXeEQSMxZFsMqqmLZGiUBfM4,3908
8
+ apache_airflow_providers_git-0.0.1.dist-info/entry_points.txt,sha256=k9QR9MAaAm9yDsRDBIK3QOt5Fos3fBCqCngNFPaJnKs,99
9
+ apache_airflow_providers_git-0.0.1.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
10
+ apache_airflow_providers_git-0.0.1.dist-info/METADATA,sha256=owWS8bAsS26Nj24UwaEnu3QUE1jXR3QfRofUHx7N8fc,3839
11
+ apache_airflow_providers_git-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: flit 3.12.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [apache_airflow_provider]
2
+ provider_info=airflow.providers.git.get_provider_info:get_provider_info
3
+