pub fn public_url(url: &str) -> StringExpand description
A URL as it may be shown and written down: without its credentials.
A remote configured as https://x-access-token:<token>@host/o/r.git is how a CI clone
and many a laptop are configured, and until this function the whole string was what
session.identity answered — to an MCP client, over HTTP, in the Cockpit. Which
repository this is does not depend on who is allowed to push to it.
Over HTTP the whole userinfo goes, because a token is as often the user name as the
password. Over any other scheme only a password does: ssh://git@host/... names a
login that is no secret and is part of how the remote is reached. The scp form has no
scheme and carries no password. The same rule as mj_url_public in lib/common.sh,
which writes this value into shared records.
use majordomus_cli::session::public_url;
assert_eq!(public_url("https://x-access-token:ghs_secret@github.com/o/r.git"), "https://github.com/o/r.git");
assert_eq!(public_url("https://ghp_secret@github.com/o/r.git"), "https://github.com/o/r.git");
assert_eq!(public_url("ssh://git:hunter2@host:22/o/r.git"), "ssh://git@host:22/o/r.git");
// nothing to remove, nothing changed
assert_eq!(public_url("ssh://git@github.com/o/r.git"), "ssh://git@github.com/o/r.git");
assert_eq!(public_url("git@github.com:o/r.git"), "git@github.com:o/r.git");
assert_eq!(public_url("https://github.com/o/r.git"), "https://github.com/o/r.git");
// an at sign in the path is not userinfo
assert_eq!(public_url("https://host/o/r@v1.git"), "https://host/o/r@v1.git");