fix(git): rewrite logical ip upstream aliases
This commit is contained in:
+11
-1
@@ -166,6 +166,17 @@ def git_gate_render_gitconfig(
|
|||||||
for entry in entries:
|
for entry in entries:
|
||||||
out.append(f'[url "git://{gate_host}/{entry.Name}.git"]\n')
|
out.append(f'[url "git://{gate_host}/{entry.Name}.git"]\n')
|
||||||
out.append(f"\tinsteadOf = {entry.Upstream}\n")
|
out.append(f"\tinsteadOf = {entry.Upstream}\n")
|
||||||
|
if entry.RemoteKey and entry.RemoteKey != entry.UpstreamHost:
|
||||||
|
port = (
|
||||||
|
f":{entry.UpstreamPort}"
|
||||||
|
if entry.UpstreamPort and entry.UpstreamPort != "22"
|
||||||
|
else ""
|
||||||
|
)
|
||||||
|
alias = (
|
||||||
|
f"ssh://{entry.UpstreamUser}@{entry.RemoteKey}{port}/"
|
||||||
|
f"{entry.UpstreamPath}"
|
||||||
|
)
|
||||||
|
out.append(f"\tinsteadOf = {alias}\n")
|
||||||
return "".join(out)
|
return "".join(out)
|
||||||
|
|
||||||
|
|
||||||
@@ -404,4 +415,3 @@ class GitGate(ABC):
|
|||||||
access_hook_script=access_hook,
|
access_hook_script=access_hook,
|
||||||
upstreams=upstreams,
|
upstreams=upstreams,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ class GitEntry:
|
|||||||
IdentityFile: str
|
IdentityFile: str
|
||||||
KnownHostKey: str = ""
|
KnownHostKey: str = ""
|
||||||
ExtraHosts: Mapping[str, str] = field(default_factory=_empty_str_dict)
|
ExtraHosts: Mapping[str, str] = field(default_factory=_empty_str_dict)
|
||||||
|
RemoteKey: str = ""
|
||||||
UpstreamUser: str = ""
|
UpstreamUser: str = ""
|
||||||
UpstreamHost: str = ""
|
UpstreamHost: str = ""
|
||||||
UpstreamPort: str = ""
|
UpstreamPort: str = ""
|
||||||
@@ -158,6 +159,7 @@ class GitEntry:
|
|||||||
IdentityFile=ident,
|
IdentityFile=ident,
|
||||||
KnownHostKey=khk,
|
KnownHostKey=khk,
|
||||||
ExtraHosts=extra_hosts,
|
ExtraHosts=extra_hosts,
|
||||||
|
RemoteKey=host_key or host,
|
||||||
UpstreamUser=user,
|
UpstreamUser=user,
|
||||||
UpstreamHost=host,
|
UpstreamHost=host,
|
||||||
UpstreamPort=port,
|
UpstreamPort=port,
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ class TestGitEntryCrossValidation(unittest.TestCase):
|
|||||||
"agents": {"demo": {"skills": [], "prompt": "", "bottle": "dev"}},
|
"agents": {"demo": {"skills": [], "prompt": "", "bottle": "dev"}},
|
||||||
})
|
})
|
||||||
e = m.bottles["dev"].git[0]
|
e = m.bottles["dev"].git[0]
|
||||||
|
self.assertEqual("gitea.dideric.is", e.RemoteKey)
|
||||||
self.assertEqual("100.78.141.42", e.UpstreamHost)
|
self.assertEqual("100.78.141.42", e.UpstreamHost)
|
||||||
self.assertEqual("30009", e.UpstreamPort)
|
self.assertEqual("30009", e.UpstreamPort)
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from bot_bottle.git_gate import (
|
|||||||
GIT_GATE_HOSTNAME,
|
GIT_GATE_HOSTNAME,
|
||||||
git_gate_render_gitconfig,
|
git_gate_render_gitconfig,
|
||||||
)
|
)
|
||||||
|
from bot_bottle.manifest import Manifest
|
||||||
from tests.fixtures import fixture_minimal, fixture_with_git
|
from tests.fixtures import fixture_minimal, fixture_with_git
|
||||||
|
|
||||||
|
|
||||||
@@ -59,6 +60,29 @@ class TestGitGateGitconfigRender(unittest.TestCase):
|
|||||||
'[url "git://192.168.20.2:9418/bot-bottle.git"]', out,
|
'[url "git://192.168.20.2:9418/bot-bottle.git"]', out,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_ip_upstream_also_rewrites_logical_remote_key(self):
|
||||||
|
m = Manifest.from_json_obj({
|
||||||
|
"bottles": {"dev": {"git": {"remotes": {
|
||||||
|
"gitea.dideric.is": {
|
||||||
|
"Name": "bot-bottle",
|
||||||
|
"Upstream": "ssh://git@100.78.141.42:30009/didericis/bot-bottle.git",
|
||||||
|
"IdentityFile": "/dev/null",
|
||||||
|
},
|
||||||
|
}}}},
|
||||||
|
"agents": {"demo": {"skills": [], "prompt": "", "bottle": "dev"}},
|
||||||
|
})
|
||||||
|
out = git_gate_render_gitconfig(m.bottles["dev"].git, GIT_GATE_HOSTNAME)
|
||||||
|
self.assertIn(
|
||||||
|
"\tinsteadOf = "
|
||||||
|
"ssh://git@100.78.141.42:30009/didericis/bot-bottle.git",
|
||||||
|
out,
|
||||||
|
)
|
||||||
|
self.assertIn(
|
||||||
|
"\tinsteadOf = "
|
||||||
|
"ssh://git@gitea.dideric.is:30009/didericis/bot-bottle.git",
|
||||||
|
out,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user