pub fn token_host_origin(instance_host: &GitlabInstanceHost) -> Option<String>Expand description
The one host PRIVATE-TOKEN may be attached to (FR-005a): the configured
registries.gitlab_instance_host’s origin when set, replacing — not joined with —
GITLAB_COM_ORIGIN otherwise.
Returns None when the setting is configured but invalid (security review, issue
#466): the pre-fix version collapsed “unset” and “invalid” into the same fallback,
silently redirecting PRIVATE-TOKEN to gitlab.com for a rejected value instead of
disabling it — an invalid value must send the token nowhere, not to a default host the
user never configured. Callers compare with .is_some_and(|o| o == host.origin())
(never .unwrap_or(...)) so None can never equal any host’s origin.
§Examples
use deps_core::net_policy::RegistryAccessPolicy;
use deps_gitlab_ci::host::{GITLAB_COM_ORIGIN, GitlabInstanceHost, token_host_origin};
use std::sync::{Arc, RwLock};
let policy = Arc::new(RegistryAccessPolicy::default());
let unset = GitlabInstanceHost::new(Arc::new(RwLock::new(None)), Arc::clone(&policy));
assert_eq!(token_host_origin(&unset).as_deref(), Some(GITLAB_COM_ORIGIN));
let set = GitlabInstanceHost::new(
Arc::new(RwLock::new(Some("gitlab.mycorp.dev".to_string()))),
Arc::clone(&policy),
);
assert_eq!(token_host_origin(&set).as_deref(), Some("https://gitlab.mycorp.dev"));
// An invalid value is disabled outright, never redirected to `gitlab.com`.
let invalid = GitlabInstanceHost::new(
Arc::new(RwLock::new(Some("127.0.0.1".to_string()))),
policy,
);
assert_eq!(token_host_origin(&invalid), None);