Skip to content

Commit

Permalink
Apply pre-commit fix
Browse files Browse the repository at this point in the history
From the artifact of the previous workflow run
  • Loading branch information
geo-ghci-int[bot] committed Feb 27, 2025
1 parent 814604d commit 0df88d3
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 35 deletions.
1 change: 0 additions & 1 deletion acceptance_tests/acceptance/file/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def composition(request):
os.chown(path, 33, 0)
utils.wait_url("http://api_file:8080/scm/c2c/health_check?max_level=2")

return None


@pytest.fixture
Expand Down
1 change: 0 additions & 1 deletion acceptance_tests/acceptance/inline/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def composition(request):
os.chown(path, 33, 0)
utils.wait_url("http://api_inline:8080/scm/c2c/health_check?max_level=2")

return None


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion app/gunicorn.conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"format": "%(asctime)s [%(process)d] [%(levelname)-5.5s] %(message)s",
"datefmt": "[%Y-%m-%d %H:%M:%S %z]",
"class": "logging.Formatter",
}
},
},
}

Expand Down
4 changes: 2 additions & 2 deletions app/shared_config_manager/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def identity(self, request: pyramid.request.Request) -> User:
digestmod=hashlib.sha256,
).hexdigest()
if hmac.compare_digest(
our_signature, request.headers["X-Hub-Signature-256"].split("=", 1)[1]
our_signature, request.headers["X-Hub-Signature-256"].split("=", 1)[1],
):
user = User("github_webhook", None, None, None, True, None, request)
else:
Expand Down Expand Up @@ -131,7 +131,7 @@ def authenticated_userid(self, request: pyramid.request.Request) -> str | None:
return identity.login

def permits(
self, request: pyramid.request.Request, context: SourceConfig, permission: str
self, request: pyramid.request.Request, context: SourceConfig, permission: str,
) -> Allowed | Denied:
"""Allow access to everything if signed in."""
identity = self.identity(request)
Expand Down
3 changes: 1 addition & 2 deletions app/shared_config_manager/slave_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ def get_source_status(id_: str) -> SourceStatus:
source = registry.get_source(id_)
if source is None:
return {"filtered": id_ in registry.FILTERED_SOURCES}
else:
return source.get_stats()
return source.get_stats()
18 changes: 8 additions & 10 deletions app/shared_config_manager/sources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@

_REFRESH_SUMMARY = Summary("sharedconfigmanager_source_refresh", "Number of source refreshes", ["source"])
_REFRESH_ERROR_COUNTER = Counter(
"sharedconfigmanager_source_refresh_error_counter", "Number of source errors", ["source"]
"sharedconfigmanager_source_refresh_error_counter", "Number of source errors", ["source"],
)
_REFRESH_ERROR_GAUGE = Gauge(
"sharedconfigmanager_source_refresh_error_status", "Sources in error", ["source"]
"sharedconfigmanager_source_refresh_error_status", "Sources in error", ["source"],
)
_TEMPLATE_SUMMARY = Summary(
"sharedconfigmanager_source_template", "Number of template evaluations", ["source", "type"]
"sharedconfigmanager_source_template", "Number of template evaluations", ["source", "type"],
)
_FETCH_SUMMARY = Summary("sharedconfigmanager_source_fetch", "Number of source fetches", ["source"])
_FETCH_ERROR_COUNTER = Counter(
"sharedconfigmanager_source_fetch_error_counter", "Number of source errors", ["source"]
"sharedconfigmanager_source_fetch_error_counter", "Number of source errors", ["source"],
)
_FETCH_ERROR_GAUGE = Gauge("sharedconfigmanager_source_fetch_error_status", "Sources in error", ["source"])
_DO_FETCH_ERROR_COUNTER = Counter(
"sharedconfigmanager_source_do_fetch_error", "Number of source fetch errors", ["source"]
"sharedconfigmanager_source_do_fetch_error", "Number of source fetch errors", ["source"],
)
_COPY_SUMMARY = Summary("sharedconfigmanager_source_copy", "Number of source copies", ["source"])

Expand Down Expand Up @@ -189,10 +189,8 @@ def get_path(self) -> str:
target_dir = self._config["target_dir"]
if target_dir.startswith("/"):
return target_dir
else:
return _MASTER_TARGET if self._is_master else os.path.join(_TARGET, target_dir)
else:
return _MASTER_TARGET if self._is_master else os.path.join(_TARGET, self.get_id())
return _MASTER_TARGET if self._is_master else os.path.join(_TARGET, target_dir)
return _MASTER_TARGET if self._is_master else os.path.join(_TARGET, self.get_id())

def get_id(self) -> str:
return self._id
Expand All @@ -209,7 +207,7 @@ def get_stats(self) -> SourceStatus:
config_copy = copy.deepcopy(self._config)
stats_ = cast(SourceStatus, config_copy)
for template_stats, template_engine in zip(
stats_.get("template_engines", []), self._template_engines, strict=False
stats_.get("template_engines", []), self._template_engines, strict=False,
):
template_engine.get_stats(template_stats)

Expand Down
12 changes: 5 additions & 7 deletions app/shared_config_manager/sources/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ def _get_repo(self) -> str:
def _clone_dir(self) -> str:
if self._do_sparse():
return os.path.join(TEMP_DIR, self.get_id())
else:
# The directory we clone into is not fct(id), but in function of the repository and the
# branch. That way, if two sources are other sub-dirs of the same repo, we clone it only once.
encoded_repo = base64.urlsafe_b64encode(self._get_repo().encode("utf-8")).decode("utf-8")
return os.path.join(TEMP_DIR, encoded_repo)
# The directory we clone into is not fct(id), but in function of the repository and the
# branch. That way, if two sources are other sub-dirs of the same repo, we clone it only once.
encoded_repo = base64.urlsafe_b64encode(self._get_repo().encode("utf-8")).decode("utf-8")
return os.path.join(TEMP_DIR, encoded_repo)

def _do_sparse(self) -> bool:
return "sub_dir" in self._config and self._config.get("sparse", True)
Expand All @@ -69,8 +68,7 @@ def _copy_dir(self) -> str:
sub_dir = self._config.get("sub_dir")
if sub_dir is None:
return self._clone_dir()
else:
return os.path.join(self._clone_dir(), sub_dir)
return os.path.join(self._clone_dir(), sub_dir)

def get_stats(self) -> SourceStatus:
stats = super().get_stats()
Expand Down
9 changes: 4 additions & 5 deletions app/shared_config_manager/sources/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def reload_master_config() -> None:
"""Reload the master config."""
if MASTER_SOURCE:
with open(
os.path.join(MASTER_SOURCE.get_path(), "shared_config_manager.yaml"), encoding="utf-8"
os.path.join(MASTER_SOURCE.get_path(), "shared_config_manager.yaml"), encoding="utf-8",
) as config_file:
config = yaml.load(config_file, Loader=yaml.SafeLoader)
_handle_master_config(config)
Expand Down Expand Up @@ -159,7 +159,7 @@ def _prepare_ssh() -> None:
"--chmod=D0700,F0600",
str(other_ssh) + "/",
str(ssh) + "/",
]
],
)


Expand Down Expand Up @@ -216,7 +216,7 @@ def _slave_fetch(id_: str) -> None:


def get_source_check_auth(
id_: str, request: pyramid.request.Request | None
id_: str, request: pyramid.request.Request | None,
) -> tuple[base.BaseSource | None, bool]:
"""Get a source by id and check the auth."""
filtered = False
Expand All @@ -235,8 +235,7 @@ def get_source(id_: str) -> base.BaseSource | None:
"""Get a source by id."""
if MASTER_SOURCE and MASTER_SOURCE.get_id() == id_:
return MASTER_SOURCE
else:
return _SOURCES.get(id_)
return _SOURCES.get(id_)


def get_stats() -> dict[str, SourceStatus]:
Expand Down
7 changes: 3 additions & 4 deletions app/shared_config_manager/template_engines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
_LOG = logging.getLogger(__name__)
_ENV_PREFIXES = os.environ.get("SCM_ENV_PREFIXES", "MUTUALIZED_").split(":")
_ERROR_COUNTER = Counter(
"sharedconfigmanager_template_error_counter", "Number of template errors", ["source", "type"]
"sharedconfigmanager_template_error_counter", "Number of template errors", ["source", "type"],
)
_ERROR_GAUGE = Gauge("sharedconfigmanager_template_error_status", "Template in error", ["source", "type"])

Expand Down Expand Up @@ -52,7 +52,7 @@ def evaluate(self, root_dir: str, files: list[str]) -> None:
_ERROR_GAUGE.labels(source=self._source_id, type=self.get_type()).set(0)
except Exception: # pylint: disable=broad-exception-caught
_LOG.warning(
"Failed applying the %s template: %s", self._config["type"], src_path, exc_info=True
"Failed applying the %s template: %s", self._config["type"], src_path, exc_info=True,
)
_ERROR_COUNTER.labels(source=self._source_id, type=self.get_type()).inc()
_ERROR_GAUGE.labels(source=self._source_id, type=self.get_type()).set(1)
Expand All @@ -62,8 +62,7 @@ def evaluate(self, root_dir: str, files: list[str]) -> None:
def _get_dest_dir(self, root_dir: str) -> str:
if "dest_sub_dir" in self._config:
return os.path.join(root_dir, self._config["dest_sub_dir"])
else:
return root_dir
return root_dir

def _evaluate_file(self, src_path: str, dst_path: str) -> None:
pass
Expand Down
4 changes: 2 additions & 2 deletions app/shared_config_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def key_format(key: str) -> str:
attributes[index][1],
attributes[attributes4_height + index][0],
attributes[attributes4_height + index][1],
)
),
)
else:
attributes4.append((attributes[index][0], attributes[index][1], "", ""))
Expand All @@ -140,7 +140,7 @@ def key_format(key: str) -> str:
)
if not commit_response.ok:
_slave_status.append(
(slave, [f"Unable to get the commit status: {commit_response.reason}"])
(slave, [f"Unable to get the commit status: {commit_response.reason}"]),
)
else:
commit_json = commit_response.json()
Expand Down

0 comments on commit 0df88d3

Please sign in to comment.