Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions odoo_devkit/local_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@
runtime_values: dict[str, str],
) -> tuple[dict[str, str], tuple[dict[str, str], ...]]:
resolved_values = dict(runtime_values)
github_token = resolve_source_github_token(runtime_values)
github_token, github_token_source = resolve_source_github_token(runtime_values)
selector_metadata: list[dict[str, str]] = []
for env_key in ARTIFACT_SOURCE_ENV_KEYS:
raw_value = runtime_values.get(env_key, "")
Expand All @@ -2103,6 +2103,7 @@
repository=repository,
ref=ref,
github_token=github_token,
github_token_source=github_token_source,
)
selector_metadata.append(
{
Expand All @@ -2116,13 +2117,24 @@
return resolved_values, tuple(selector_metadata)


def resolve_source_github_token(runtime_values: dict[str, str]) -> str | None:
return clean_optional_value(runtime_values.get("GITHUB_TOKEN")) or first_clean_optional_value(
os.environ.get(environment_key) for environment_key in (*SOURCE_GITHUB_TOKEN_ENV_KEYS, "GITHUB_TOKEN", "GH_TOKEN")
)
def resolve_source_github_token(runtime_values: dict[str, str]) -> tuple[str | None, str]:
configured_token = clean_optional_value(runtime_values.get("GITHUB_TOKEN"))
if configured_token is not None:
return configured_token, "runtime:GITHUB_TOKEN"
for environment_key in (*SOURCE_GITHUB_TOKEN_ENV_KEYS, "GITHUB_TOKEN", "GH_TOKEN"):
environment_token = clean_optional_value(os.environ.get(environment_key))
if environment_token is not None:
return environment_token, f"env:{environment_key}"
return None, "none"


def resolve_source_repository_ref_to_git_sha(*, repository: str, ref: str, github_token: str | None = None) -> str:
def resolve_source_repository_ref_to_git_sha(
*,
repository: str,
ref: str,
github_token: str | None = None,
github_token_source: str = "unknown",
) -> str:
normalized_repository = repository.strip()
normalized_ref = ref.strip()
if GIT_SHA_PATTERN.fullmatch(normalized_ref):
Expand All @@ -2139,6 +2151,7 @@
"GIT_CONFIG_VALUE_0": f"AUTHORIZATION: basic {encoded_auth}",
}
)
print(f"artifact_source_token_source={github_token_source} auth_header_configured={str(normalized_token is not None).lower()}")

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
ls_remote_result = subprocess.run(
["git", "ls-remote", "--refs", remote_url, normalized_ref],
capture_output=True,
Expand Down
6 changes: 6 additions & 0 deletions tests/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ def fake_run_command(
repository="cbusillo/disable_odoo_online",
ref="main",
github_token="gh-token",
github_token_source="runtime:GITHUB_TOKEN",
)
addon_build_arg = next(argument for argument in captured_build_args if argument.startswith("ODOO_ADDON_REPOSITORIES="))
self.assertEqual(
Expand Down Expand Up @@ -1361,6 +1362,7 @@ def fake_run_command(
repository="cbusillo/disable_odoo_online",
ref="release-19",
github_token="gh-token",
github_token_source="runtime:GITHUB_TOKEN",
)
addon_build_arg = next(argument for argument in captured_build_args if argument.startswith("ODOO_ADDON_REPOSITORIES="))
self.assertEqual(
Expand Down Expand Up @@ -1627,6 +1629,7 @@ def test_resolve_artifact_runtime_source_refs_uses_environment_token_fallback(se
repository="cbusillo/disable_odoo_online",
ref="main",
github_token="env-token",
github_token_source="env:GITHUB_TOKEN",
)
self.assertEqual(
resolved_values["ODOO_ADDON_REPOSITORIES"],
Expand Down Expand Up @@ -1664,6 +1667,7 @@ def test_resolve_artifact_runtime_source_refs_uses_dedicated_source_token_env(se
repository="cbusillo/disable_odoo_online",
ref="main",
github_token="source-env-token",
github_token_source="env:ODOO_DEVKIT_SOURCE_GITHUB_TOKEN",
)

def test_resolve_artifact_runtime_source_refs_supports_ci_source_token_env(self) -> None:
Expand All @@ -1687,6 +1691,7 @@ def test_resolve_artifact_runtime_source_refs_supports_ci_source_token_env(self)
repository="cbusillo/disable_odoo_online",
ref="main",
github_token="ci-source-token",
github_token_source="env:ODOO_SOURCE_GITHUB_TOKEN",
)

def test_resolve_artifact_runtime_source_refs_prefers_runtime_github_token(self) -> None:
Expand All @@ -1705,6 +1710,7 @@ def test_resolve_artifact_runtime_source_refs_prefers_runtime_github_token(self)
repository="cbusillo/disable_odoo_online",
ref="main",
github_token="source-token",
github_token_source="runtime:GITHUB_TOKEN",
)

def test_resolve_source_repository_ref_to_git_sha_rejects_ambiguous_matches(self) -> None:
Expand Down