foxops 2.10.1__tar.gz → 2.10.2__tar.gz
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.
- {foxops-2.10.1 → foxops-2.10.2}/PKG-INFO +1 -1
- {foxops-2.10.1 → foxops-2.10.2}/pyproject.toml +1 -1
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/engine/update.py +3 -5
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/external/git.py +24 -2
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/hosters/gitlab.py +31 -11
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/hosters/local.py +7 -3
- {foxops-2.10.1 → foxops-2.10.2}/LICENSE +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/README.md +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/__init__.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/__main__.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/database/__init__.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/database/engine.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/database/repositories/__init__.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/database/repositories/change/__init__.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/database/repositories/change/errors.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/database/repositories/change/model.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/database/repositories/change/repository.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/database/repositories/incarnation/__init__.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/database/repositories/incarnation/errors.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/database/repositories/incarnation/model.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/database/repositories/incarnation/repository.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/database/schema.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/dependencies.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/engine/__init__.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/engine/__main__.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/engine/custom_filters.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/engine/errors.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/engine/initialization.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/engine/models/__init__.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/engine/models/incarnation_state.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/engine/models/template_config.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/engine/patching/__init__.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/engine/patching/git_diff_patch.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/engine/rendering.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/error_handlers.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/errors.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/external/__init__.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/hosters/__init__.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/hosters/types.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/logger.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/middlewares.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/models/__init__.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/models/change.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/models/errors.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/models/incarnation.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/openapi.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/routers/__init__.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/routers/auth.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/routers/changes.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/routers/incarnations.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/routers/not_found.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/routers/version.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/services/__init__.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/services/change.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/services/incarnation.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/settings.py +0 -0
- {foxops-2.10.1 → foxops-2.10.2}/src/foxops/utils.py +0 -0
|
@@ -6,6 +6,7 @@ from foxops import utils
|
|
|
6
6
|
from foxops.engine import initialize_incarnation
|
|
7
7
|
from foxops.engine.models.incarnation_state import IncarnationState, TemplateData
|
|
8
8
|
from foxops.engine.patching.git_diff_patch import PatchResult
|
|
9
|
+
from foxops.external.git import validate_refspec
|
|
9
10
|
from foxops.logger import get_logger
|
|
10
11
|
|
|
11
12
|
#: Holds the module logger
|
|
@@ -48,11 +49,7 @@ async def update_incarnation_from_git_template_repository(
|
|
|
48
49
|
- the new template version with the data that was provided for the update
|
|
49
50
|
* diff the two incarnations - then apply the patch on the actual incarnation that should be updated
|
|
50
51
|
"""
|
|
51
|
-
|
|
52
|
-
raise ValueError(
|
|
53
|
-
f"update_template_repository_version must ba a valid git refspec and "
|
|
54
|
-
f"not start with a dash (-): {update_template_repository_version}"
|
|
55
|
-
)
|
|
52
|
+
validate_refspec(update_template_repository_version)
|
|
56
53
|
|
|
57
54
|
# initialize pristine incarnation from current incarnation state
|
|
58
55
|
current_incarnation_state = IncarnationState.from_file(incarnation_root_dir / ".fengine.yaml")
|
|
@@ -78,6 +75,7 @@ async def update_incarnation_from_git_template_repository(
|
|
|
78
75
|
"git",
|
|
79
76
|
"worktree",
|
|
80
77
|
"add",
|
|
78
|
+
"--end-of-options",
|
|
81
79
|
updated_template_root_dir,
|
|
82
80
|
update_template_repository_version,
|
|
83
81
|
cwd=template_git_repository,
|
|
@@ -32,6 +32,20 @@ class RevisionNotFoundError(GitError, FoxopsUserError):
|
|
|
32
32
|
super().__init__(f"Revision '{ref.decode('utf-8')}' not found.")
|
|
33
33
|
|
|
34
34
|
|
|
35
|
+
class InvalidRefspecError(FoxopsUserError):
|
|
36
|
+
"""Error raised when a refspec could be interpreted by git as a command line option."""
|
|
37
|
+
|
|
38
|
+
def __init__(self, refspec: str):
|
|
39
|
+
super().__init__(f"Invalid git refspec '{refspec}': must not start with a dash (-).")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def validate_refspec(refspec: str) -> str:
|
|
43
|
+
"""Guard against user-provided refspecs being interpreted as git options (e.g. `--upload-pack=...`)."""
|
|
44
|
+
if refspec.startswith("-"):
|
|
45
|
+
raise InvalidRefspecError(refspec)
|
|
46
|
+
return refspec
|
|
47
|
+
|
|
48
|
+
|
|
35
49
|
GIT_ERROR_ORACLE = {
|
|
36
50
|
re.compile(
|
|
37
51
|
rb"hint: Updates were rejected because the remote contains work that you do.*not.*have locally.",
|
|
@@ -55,6 +69,14 @@ async def git_exec(*args, **kwargs) -> asyncio.subprocess.Process:
|
|
|
55
69
|
raise GitError(message=exc.stderr.decode()) from exc
|
|
56
70
|
|
|
57
71
|
|
|
72
|
+
async def shallow_checkout_refspec(directory: Path | str, refspec: str) -> None:
|
|
73
|
+
"""Shallow-fetch `refspec` (plus all tags) from `origin` and check it out in the repository at `directory`."""
|
|
74
|
+
await git_exec(
|
|
75
|
+
"fetch", "--depth=1", "--tags", "--end-of-options", "origin", validate_refspec(refspec), cwd=directory
|
|
76
|
+
)
|
|
77
|
+
await git_exec("reset", "--hard", "FETCH_HEAD", cwd=directory)
|
|
78
|
+
|
|
79
|
+
|
|
58
80
|
def add_authentication_to_git_clone_url(source: str, username: str, password: str):
|
|
59
81
|
if not source.startswith(("http://", "https://")):
|
|
60
82
|
raise ValueError("only http:// and https:// repository URLs are allowed")
|
|
@@ -236,9 +258,9 @@ class GitRepository:
|
|
|
236
258
|
async def fetch(self, refspec: str | None = None) -> None:
|
|
237
259
|
args = []
|
|
238
260
|
if refspec is not None:
|
|
239
|
-
args.append(refspec)
|
|
261
|
+
args.append(validate_refspec(refspec))
|
|
240
262
|
|
|
241
|
-
await self._run("fetch", "origin", *args)
|
|
263
|
+
await self._run("fetch", "--end-of-options", "origin", *args)
|
|
242
264
|
|
|
243
265
|
async def rebase(self, branch: str | None = None) -> None:
|
|
244
266
|
if branch is None:
|
|
@@ -9,7 +9,7 @@ from pathlib import Path
|
|
|
9
9
|
from ssl import SSLZeroReturnError
|
|
10
10
|
from tempfile import mkdtemp
|
|
11
11
|
from typing import Any, AsyncIterator, TypedDict
|
|
12
|
-
from urllib.parse import quote_plus
|
|
12
|
+
from urllib.parse import quote_plus, urlsplit
|
|
13
13
|
|
|
14
14
|
import httpx
|
|
15
15
|
from tenacity import retry
|
|
@@ -18,11 +18,16 @@ from tenacity.stop import stop_after_delay
|
|
|
18
18
|
from tenacity.wait import wait_fixed
|
|
19
19
|
|
|
20
20
|
from foxops.engine import IncarnationState
|
|
21
|
-
from foxops.errors import
|
|
21
|
+
from foxops.errors import (
|
|
22
|
+
FoxopsUserError,
|
|
23
|
+
IncarnationRepositoryNotFound,
|
|
24
|
+
MergeRequestCreationFailedError,
|
|
25
|
+
)
|
|
22
26
|
from foxops.external.git import (
|
|
23
27
|
GitRepository,
|
|
24
28
|
add_authentication_to_git_clone_url,
|
|
25
29
|
git_exec,
|
|
30
|
+
shallow_checkout_refspec,
|
|
26
31
|
)
|
|
27
32
|
from foxops.hosters.types import (
|
|
28
33
|
GitSha,
|
|
@@ -84,6 +89,20 @@ def evaluate_gitlab_address(address: str) -> tuple[str, str]:
|
|
|
84
89
|
return address, f"{address}/api/v4"
|
|
85
90
|
|
|
86
91
|
|
|
92
|
+
class RepositoryNotOnHosterError(FoxopsUserError):
|
|
93
|
+
"""Exception raised when a repository URL points to a host other than the configured GitLab instance."""
|
|
94
|
+
|
|
95
|
+
def __init__(self, repository: str):
|
|
96
|
+
super().__init__(f"Repository '{repository}' is not hosted on the configured GitLab instance.")
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _url_origin(url: str) -> tuple[str, str | None, int | None]:
|
|
100
|
+
"""Return the (scheme, host, port) of the given URL, filling in the default port of the scheme."""
|
|
101
|
+
parts = urlsplit(url)
|
|
102
|
+
scheme = parts.scheme.lower()
|
|
103
|
+
return scheme, parts.hostname, parts.port or {"http": 80, "https": 443}.get(scheme)
|
|
104
|
+
|
|
105
|
+
|
|
87
106
|
class GitlabHoster(Hoster):
|
|
88
107
|
"""REST API client for GitLab"""
|
|
89
108
|
|
|
@@ -97,6 +116,12 @@ class GitlabHoster(Hoster):
|
|
|
97
116
|
async def validate(self) -> None:
|
|
98
117
|
(await self.client.get("/version")).raise_for_status()
|
|
99
118
|
|
|
119
|
+
def _is_on_gitlab(self, url: str) -> bool:
|
|
120
|
+
try:
|
|
121
|
+
return _url_origin(url) == _url_origin(self.web_address)
|
|
122
|
+
except ValueError:
|
|
123
|
+
return False
|
|
124
|
+
|
|
100
125
|
async def __project_exists(self, project_identifier: str) -> bool:
|
|
101
126
|
response = await self.client.head(f"/projects/{quote_plus(project_identifier)}")
|
|
102
127
|
return response.status_code == HTTPStatus.OK
|
|
@@ -274,6 +299,9 @@ class GitlabHoster(Hoster):
|
|
|
274
299
|
# it's not a URL, but a `path_with_namespace`, so, let's think it a URL
|
|
275
300
|
metadata = await self.get_repository_metadata(repository)
|
|
276
301
|
repository = metadata["http_url"]
|
|
302
|
+
elif not self._is_on_gitlab(repository):
|
|
303
|
+
# NOTE: the clone URL carries the GitLab token, so it must never point to any other host
|
|
304
|
+
raise RepositoryNotOnHosterError(repository)
|
|
277
305
|
|
|
278
306
|
clone_url = add_authentication_to_git_clone_url(repository, "oauth2", self.token)
|
|
279
307
|
|
|
@@ -306,15 +334,7 @@ class GitlabHoster(Hoster):
|
|
|
306
334
|
# So we need to fetch all tag refs, which should be fine.
|
|
307
335
|
await git_exec("init", local_clone_directory, cwd=Path.home())
|
|
308
336
|
await git_exec("remote", "add", "origin", clone_url, cwd=local_clone_directory)
|
|
309
|
-
await
|
|
310
|
-
"fetch",
|
|
311
|
-
"--depth=1",
|
|
312
|
-
"origin",
|
|
313
|
-
"--tags",
|
|
314
|
-
refspec,
|
|
315
|
-
cwd=local_clone_directory,
|
|
316
|
-
)
|
|
317
|
-
await git_exec("reset", "--hard", "FETCH_HEAD", cwd=local_clone_directory)
|
|
337
|
+
await shallow_checkout_refspec(local_clone_directory, refspec)
|
|
318
338
|
|
|
319
339
|
# NOTE(TF): set author data
|
|
320
340
|
await git_exec(
|
|
@@ -8,7 +8,12 @@ from typing import AsyncIterator, Iterator
|
|
|
8
8
|
from pydantic import BaseModel
|
|
9
9
|
|
|
10
10
|
from foxops.engine import IncarnationState
|
|
11
|
-
from foxops.external.git import
|
|
11
|
+
from foxops.external.git import (
|
|
12
|
+
GitError,
|
|
13
|
+
GitRepository,
|
|
14
|
+
git_exec,
|
|
15
|
+
shallow_checkout_refspec,
|
|
16
|
+
)
|
|
12
17
|
from foxops.hosters import GitSha, Hoster, MergeRequestId, ReconciliationStatus
|
|
13
18
|
from foxops.hosters.types import MergeRequestStatus, RepositoryMetadata
|
|
14
19
|
|
|
@@ -171,8 +176,7 @@ class LocalHoster(Hoster):
|
|
|
171
176
|
else:
|
|
172
177
|
await git_exec("init", cwd=tmpdir)
|
|
173
178
|
await git_exec("remote", "add", "origin", repo_path, cwd=tmpdir)
|
|
174
|
-
await
|
|
175
|
-
await git_exec("reset", "--hard", "FETCH_HEAD", cwd=tmpdir)
|
|
179
|
+
await shallow_checkout_refspec(tmpdir, refspec)
|
|
176
180
|
|
|
177
181
|
# set author data
|
|
178
182
|
await git_exec("config", "user.name", "foxops", cwd=tmpdir)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|