pub struct GitHubHost { /* private fields */ }Expand description
The GitHub host an operation targets: SaaS github.com or a GitHub
Enterprise Server (GHES) host. gh picks the credential environment variable
it reads per host — GH_TOKEN for github.com, GH_ENTERPRISE_TOKEN for a
GHES host — and its auth status can be scoped to a single host, so this type
carries that host so the client (1) injects a supplied credential into the
variable gh actually reads for it (see GitHub::with_host) and (2) can
probe auth for exactly that host (see GitHubApi::auth_status_for).
Build it for github.com (github_com), from a bare
hostname (new), or from a repository’s remote URL
(from_remote_url). A hostname that cannot be
determined is an error, never a silent fall back to github.com — so an
ambiguous or unknown host is a diagnosable result at the call site rather than
a quiet authentication against the wrong host with the github.com token.
let saas = GitHubHost::github_com();
assert!(saas.is_github_com() && !saas.is_enterprise());
let ghes = GitHubHost::new("ghe.example.com").unwrap();
assert!(ghes.is_enterprise());
assert_eq!(ghes.as_str(), "ghe.example.com");
// github.com (any case) classifies as SaaS; every other valid host is GHES.
assert!(GitHubHost::new("GitHub.com").unwrap().is_github_com());
// An unparseable / hostless remote is an error, not a github.com guess.
assert!(GitHubHost::from_remote_url("not-a-url").is_err());Implementations§
Source§impl GitHubHost
impl GitHubHost
Sourcepub fn github_com() -> Self
pub fn github_com() -> Self
The SaaS github.com host — a supplied credential is injected as GH_TOKEN.
Sourcepub fn new(host: impl AsRef<str>) -> Result<Self>
pub fn new(host: impl AsRef<str>) -> Result<Self>
Classify a bare host: github.com (case-insensitive) is SaaS; any other
valid hostname is treated as a GitHub Enterprise Server host (its credential
goes to GH_ENTERPRISE_TOKEN). Returns an error for an empty, flag-like, or
otherwise malformed hostname (a scheme, path, port, userinfo, or whitespace)
rather than guessing — the value must be a bare DNS-style host.
Sourcepub fn from_remote_url(url: &str) -> Result<Self>
pub fn from_remote_url(url: &str) -> Result<Self>
Derive the host from a repository remote URL and classify it. Handles
scheme://[user@]host[:port]/… (HTTPS/SSH/…) and the scp-like
[user@]host:path SSH form; any userinfo and port are dropped. A remote
whose host can’t be determined (unparseable, hostless, or ambiguous — an
IPv6 literal, a bare single-label scp authority, a local path) is an
error, not a silent github.com fallback, so the caller can surface an
ambiguous remote as a diagnosable result.
Sourcepub fn is_enterprise(&self) -> bool
pub fn is_enterprise(&self) -> bool
Whether this is a GitHub Enterprise Server host (anything but github.com).
Sourcepub fn is_github_com(&self) -> bool
pub fn is_github_com(&self) -> bool
Whether this is SaaS github.com.
Trait Implementations§
Source§impl Clone for GitHubHost
impl Clone for GitHubHost
Source§fn clone(&self) -> GitHubHost
fn clone(&self) -> GitHubHost
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more