mirror of
https://github.com/facebook/sapling.git
synced 2024-10-03 21:37:23 +03:00
Prefer module filenames instead of mod.rs
Summary: > Note: Prior to rustc 1.30, using `mod.rs` files was the way to load a > module with nested children. It is encouraged to use the new naming > convention as it is more consistent, and avoids having many files > named `mod.rs` within a project. https://doc.rust-lang.org/reference/items/modules.html#module-source-filenames Reviewed By: davidbarsky Differential Revision: D55921363 fbshipit-source-id: 31cdc981117649c9d8a64f7239429ca40cdfc1e0
This commit is contained in:
parent
03255b3eba
commit
4195c3dbf4
53
common/rust/shed/hostcaps/src/facebook.rs
Normal file
53
common/rust/shed/hostcaps/src/facebook.rs
Normal file
@ -0,0 +1,53 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
use fbwhoami::FbWhoAmI;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
#[repr(u8)]
|
||||
pub enum Env {
|
||||
Prod = 0,
|
||||
Corp = 1,
|
||||
Lab = 2,
|
||||
}
|
||||
|
||||
pub fn get_env() -> Env {
|
||||
let whoami = if let Ok(whoami) = FbWhoAmI::get() {
|
||||
whoami
|
||||
} else {
|
||||
// default to corp env if no fbwhoami
|
||||
return Env::Corp;
|
||||
};
|
||||
|
||||
// Corp host e.g. a lab
|
||||
if let Some(hostname_scheme) = &whoami.hostname_scheme {
|
||||
if hostname_scheme.starts_with("corp_") {
|
||||
return Env::Corp;
|
||||
}
|
||||
if hostname_scheme.starts_with("lab_") {
|
||||
return Env::Lab;
|
||||
}
|
||||
}
|
||||
|
||||
// Cloud hosts e.g. AWS are treated like corp
|
||||
if whoami.cloud_provider.is_some() {
|
||||
return Env::Corp;
|
||||
}
|
||||
|
||||
// Default to prod
|
||||
Env::Prod
|
||||
}
|
||||
|
||||
/// Returns true if the running host is on the production network.
|
||||
pub fn is_prod() -> bool {
|
||||
get_env() == Env::Prod
|
||||
}
|
||||
|
||||
/// Returns true if the running host is on the corp network.
|
||||
pub fn is_corp() -> bool {
|
||||
get_env() == Env::Corp
|
||||
}
|
||||
|
||||
/// Returns true if the running host is on the lab network.
|
||||
pub fn is_lab() -> bool {
|
||||
get_env() == Env::Lab
|
||||
}
|
Loading…
Reference in New Issue
Block a user