foxops 2.10.0__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.
Files changed (57) hide show
  1. {foxops-2.10.0 → foxops-2.10.2}/PKG-INFO +1 -1
  2. {foxops-2.10.0 → foxops-2.10.2}/pyproject.toml +1 -1
  3. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/engine/update.py +3 -5
  4. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/external/git.py +24 -2
  5. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/hosters/gitlab.py +35 -12
  6. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/hosters/local.py +7 -3
  7. {foxops-2.10.0 → foxops-2.10.2}/LICENSE +0 -0
  8. {foxops-2.10.0 → foxops-2.10.2}/README.md +0 -0
  9. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/__init__.py +0 -0
  10. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/__main__.py +0 -0
  11. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/database/__init__.py +0 -0
  12. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/database/engine.py +0 -0
  13. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/database/repositories/__init__.py +0 -0
  14. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/database/repositories/change/__init__.py +0 -0
  15. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/database/repositories/change/errors.py +0 -0
  16. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/database/repositories/change/model.py +0 -0
  17. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/database/repositories/change/repository.py +0 -0
  18. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/database/repositories/incarnation/__init__.py +0 -0
  19. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/database/repositories/incarnation/errors.py +0 -0
  20. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/database/repositories/incarnation/model.py +0 -0
  21. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/database/repositories/incarnation/repository.py +0 -0
  22. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/database/schema.py +0 -0
  23. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/dependencies.py +0 -0
  24. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/engine/__init__.py +0 -0
  25. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/engine/__main__.py +0 -0
  26. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/engine/custom_filters.py +0 -0
  27. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/engine/errors.py +0 -0
  28. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/engine/initialization.py +0 -0
  29. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/engine/models/__init__.py +0 -0
  30. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/engine/models/incarnation_state.py +0 -0
  31. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/engine/models/template_config.py +0 -0
  32. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/engine/patching/__init__.py +0 -0
  33. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/engine/patching/git_diff_patch.py +0 -0
  34. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/engine/rendering.py +0 -0
  35. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/error_handlers.py +0 -0
  36. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/errors.py +0 -0
  37. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/external/__init__.py +0 -0
  38. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/hosters/__init__.py +0 -0
  39. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/hosters/types.py +0 -0
  40. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/logger.py +0 -0
  41. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/middlewares.py +0 -0
  42. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/models/__init__.py +0 -0
  43. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/models/change.py +0 -0
  44. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/models/errors.py +0 -0
  45. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/models/incarnation.py +0 -0
  46. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/openapi.py +0 -0
  47. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/routers/__init__.py +0 -0
  48. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/routers/auth.py +0 -0
  49. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/routers/changes.py +0 -0
  50. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/routers/incarnations.py +0 -0
  51. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/routers/not_found.py +0 -0
  52. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/routers/version.py +0 -0
  53. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/services/__init__.py +0 -0
  54. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/services/change.py +0 -0
  55. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/services/incarnation.py +0 -0
  56. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/settings.py +0 -0
  57. {foxops-2.10.0 → foxops-2.10.2}/src/foxops/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: foxops
3
- Version: 2.10.0
3
+ Version: 2.10.2
4
4
  Summary: Foxops 🦊
5
5
  License: Apache-2.0
6
6
  License-File: LICENSE
@@ -1,7 +1,7 @@
1
1
  [tool.poetry]
2
2
  name = "foxops"
3
3
  # managed by poetry-dynamic-versioning, do not change.
4
- version = "2.10.0"
4
+ version = "2.10.2"
5
5
  description = "Foxops 🦊"
6
6
  license = "Apache-2.0"
7
7
  authors = [
@@ -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
- if update_template_repository_version.startswith("-"):
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 IncarnationRepositoryNotFound, MergeRequestCreationFailedError
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,
@@ -37,7 +42,10 @@ from foxops.logger import bound, get_logger
37
42
  #: Holds the module logger
38
43
  logger = get_logger(__name__)
39
44
 
40
- MERGE_REQUEST_SOURCE_BRANCH_RETRY_TIMEOUT = timedelta(seconds=10)
45
+ # Has to share the load balancer's 60s idle timeout with the mergeability loop below, which
46
+ # can spend 25s of it. 10s was not enough: in production it recovered 1 of the 4 races seen
47
+ # over two weeks, and running out leaves a pushed branch behind with no merge request.
48
+ MERGE_REQUEST_SOURCE_BRANCH_RETRY_TIMEOUT = timedelta(seconds=30)
41
49
  MERGE_REQUEST_SOURCE_BRANCH_RETRY_WAIT = timedelta(seconds=1)
42
50
 
43
51
  _SOURCE_BRANCH_MISSING_PATTERN = re.compile(r'"source_branch":\s*\["does not exist"')
@@ -81,6 +89,20 @@ def evaluate_gitlab_address(address: str) -> tuple[str, str]:
81
89
  return address, f"{address}/api/v4"
82
90
 
83
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
+
84
106
  class GitlabHoster(Hoster):
85
107
  """REST API client for GitLab"""
86
108
 
@@ -94,6 +116,12 @@ class GitlabHoster(Hoster):
94
116
  async def validate(self) -> None:
95
117
  (await self.client.get("/version")).raise_for_status()
96
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
+
97
125
  async def __project_exists(self, project_identifier: str) -> bool:
98
126
  response = await self.client.head(f"/projects/{quote_plus(project_identifier)}")
99
127
  return response.status_code == HTTPStatus.OK
@@ -271,6 +299,9 @@ class GitlabHoster(Hoster):
271
299
  # it's not a URL, but a `path_with_namespace`, so, let's think it a URL
272
300
  metadata = await self.get_repository_metadata(repository)
273
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)
274
305
 
275
306
  clone_url = add_authentication_to_git_clone_url(repository, "oauth2", self.token)
276
307
 
@@ -303,15 +334,7 @@ class GitlabHoster(Hoster):
303
334
  # So we need to fetch all tag refs, which should be fine.
304
335
  await git_exec("init", local_clone_directory, cwd=Path.home())
305
336
  await git_exec("remote", "add", "origin", clone_url, cwd=local_clone_directory)
306
- await git_exec(
307
- "fetch",
308
- "--depth=1",
309
- "origin",
310
- "--tags",
311
- refspec,
312
- cwd=local_clone_directory,
313
- )
314
- await git_exec("reset", "--hard", "FETCH_HEAD", cwd=local_clone_directory)
337
+ await shallow_checkout_refspec(local_clone_directory, refspec)
315
338
 
316
339
  # NOTE(TF): set author data
317
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 GitError, GitRepository, git_exec
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 git_exec("fetch", "--depth=1", "origin", "--tags", refspec, cwd=tmpdir)
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