mirror of https://github.com/rwf2/Rocket.git
Emit warning when no 'secret_key' is set in prod.
This commit is contained in:
parent
b8ba7b855f
commit
d09920c021
|
@ -14,17 +14,26 @@ pub enum SecretKey {
|
||||||
|
|
||||||
impl SecretKey {
|
impl SecretKey {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn kind(&self) -> &'static str {
|
pub(crate) fn inner(&self) -> &Key {
|
||||||
match *self {
|
match *self {
|
||||||
SecretKey::Generated(_) => "generated",
|
SecretKey::Generated(ref key) | SecretKey::Provided(ref key) => key
|
||||||
SecretKey::Provided(_) => "provided",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn inner(&self) -> &Key {
|
pub(crate) fn is_generated(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
SecretKey::Generated(ref key) | SecretKey::Provided(ref key) => key
|
SecretKey::Generated(_) => true,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for SecretKey {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match *self {
|
||||||
|
SecretKey::Generated(_) => write!(f, "generated"),
|
||||||
|
SecretKey::Provided(_) => write!(f, "provided"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,62 @@ pub enum Environment {
|
||||||
Production,
|
Production,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Environment {
|
||||||
|
/// Returns `true` if `self` is `Environment::Development`.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// use rocket::config::Environment;
|
||||||
|
///
|
||||||
|
/// assert!(Environment::Development.is_dev());
|
||||||
|
/// assert!(!Environment::Production.is_dev());
|
||||||
|
/// ```
|
||||||
|
#[inline]
|
||||||
|
pub fn is_dev(self) -> bool {
|
||||||
|
match self {
|
||||||
|
Development => true,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if `self` is `Environment::Staging`.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// use rocket::config::Environment;
|
||||||
|
///
|
||||||
|
/// assert!(Environment::Staging.is_stage());
|
||||||
|
/// assert!(!Environment::Production.is_stage());
|
||||||
|
/// ```
|
||||||
|
#[inline]
|
||||||
|
pub fn is_stage(self) -> bool {
|
||||||
|
match self {
|
||||||
|
Staging => true,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if `self` is `Environment::Production`.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// use rocket::config::Environment;
|
||||||
|
///
|
||||||
|
/// assert!(Environment::Production.is_prod());
|
||||||
|
/// assert!(!Environment::Staging.is_prod());
|
||||||
|
/// ```
|
||||||
|
#[inline]
|
||||||
|
pub fn is_prod(self) -> bool {
|
||||||
|
match self {
|
||||||
|
Production => true,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Environment {
|
impl Environment {
|
||||||
/// Retrieves the "active" environment as determined by the `ROCKET_ENV`
|
/// Retrieves the "active" environment as determined by the `ROCKET_ENV`
|
||||||
/// environment variable. If `ROCKET_ENV` is not set, returns `Development`.
|
/// environment variable. If `ROCKET_ENV` is not set, returns `Development`.
|
||||||
|
|
|
@ -391,19 +391,21 @@ impl Rocket {
|
||||||
info_!("port: {}", Paint::white(&config.port));
|
info_!("port: {}", Paint::white(&config.port));
|
||||||
info_!("log: {}", Paint::white(config.log_level));
|
info_!("log: {}", Paint::white(config.log_level));
|
||||||
info_!("workers: {}", Paint::white(config.workers));
|
info_!("workers: {}", Paint::white(config.workers));
|
||||||
info_!("secret key: {}", Paint::white(config.secret_key.kind()));
|
info_!("secret key: {}", Paint::white(&config.secret_key));
|
||||||
info_!("limits: {}", Paint::white(&config.limits));
|
info_!("limits: {}", Paint::white(&config.limits));
|
||||||
|
|
||||||
let tls_configured = config.tls.is_some();
|
let tls_configured = config.tls.is_some();
|
||||||
if tls_configured && cfg!(feature = "tls") {
|
if tls_configured && cfg!(feature = "tls") {
|
||||||
info_!("tls: {}", Paint::white("enabled"));
|
info_!("tls: {}", Paint::white("enabled"));
|
||||||
} else {
|
} else if tls_configured {
|
||||||
if tls_configured {
|
|
||||||
error_!("tls: {}", Paint::white("disabled"));
|
error_!("tls: {}", Paint::white("disabled"));
|
||||||
error_!("tls is configured, but the tls feature is disabled");
|
error_!("tls is configured, but the tls feature is disabled");
|
||||||
} else {
|
} else {
|
||||||
info_!("tls: {}", Paint::white("disabled"));
|
info_!("tls: {}", Paint::white("disabled"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.secret_key.is_generated() && config.environment.is_prod() {
|
||||||
|
warn!("environment is 'production', but no `secret_key` is configured");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (name, value) in config.extras() {
|
for (name, value) in config.extras() {
|
||||||
|
|
Loading…
Reference in New Issue