Skip to content

Commit

Permalink
Set remaning ManagerConfig values in the declaration block
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Peck <mpeck@chef.io>
  • Loading branch information
Matthew Peck committed Dec 14, 2018
1 parent 0c68740 commit 3c31952
Show file tree
Hide file tree
Showing 19 changed files with 308 additions and 244 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions components/common/src/cli_defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@
//! Eventually this will be composed of fully typed default values. But as a first step we
//! need a spot to consolidate those values and help simplify some of the logic around them.

use ListenCtlAddr;
use types::ListenCtlAddr;

pub const GOSSIP_DEFAULT_IP: &'static str = "0.0.0.0";
pub const GOSSIP_DEFAULT_IP: &str = "0.0.0.0";
pub const GOSSIP_DEFAULT_PORT: u16 = 9638;
lazy_static! {
pub static ref GOSSIP_DEFAULT_ADDR: String =
{ format!("{}:{}", GOSSIP_DEFAULT_IP, GOSSIP_DEFAULT_PORT) };
}
pub const GOSSIP_LISTEN_ADDRESS_ENVVAR: &'static str = "HAB_LISTEN_GOSSIP";
pub const RING_ENVVAR: &'static str = "HAB_RING";
pub const RING_KEY_ENVVAR: &'static str = "HAB_RING_KEY";
pub const GOSSIP_LISTEN_ADDRESS_ENVVAR: &str = "HAB_LISTEN_GOSSIP";
pub const RING_ENVVAR: &str = "HAB_RING";
pub const RING_KEY_ENVVAR: &str = "HAB_RING_KEY";

pub const LISTEN_HTTP_DEFAULT_PORT: u16 = 9631;
pub const LISTEN_HTTP_DEFAULT_IP: &'static str = "0.0.0.0";
pub const LISTEN_HTTP_DEFAULT_IP: &str = "0.0.0.0";
lazy_static! {
pub static ref LISTEN_HTTP_DEFAULT_ADDR: String =
{ format!("{}:{}", LISTEN_HTTP_DEFAULT_IP, LISTEN_HTTP_DEFAULT_PORT) };
}
pub const LISTEN_HTTP_ADDRESS_ENVVAR: &'static str = "HAB_LISTEN_HTTP";
pub const LISTEN_HTTP_ADDRESS_ENVVAR: &str = "HAB_LISTEN_HTTP";

lazy_static! {
pub static ref LISTEN_CTL_DEFAULT_ADDR_STRING: String =
Expand Down
6 changes: 1 addition & 5 deletions components/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,5 @@ pub mod command;
pub mod error;
pub mod locked_env_var;
pub mod package_graph;
pub mod types;
pub mod ui;

mod listen_ctl_addr;
pub use listen_ctl_addr::ListenCtlAddr;
mod env_config;
pub use env_config::EnvConfig;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016-2018 Chef Software Inc. and/or applicable contributors
// Copyright (c) 2018 Chef Software Inc. and/or applicable contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,14 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Configuration for the Supervisor.
//!
//! This module is populated from the CLI options in `main.rs`, and then passed through to the
//! [command](../command) modules. Check out the `config_from_args(..)` function there for more
//! details.
//!
//! See the [Config](struct.Config.html) struct for the specific options available.

use std::env::VarError;
use std::str::FromStr;

Expand Down Expand Up @@ -63,7 +55,7 @@ pub trait EnvConfig: Default + FromStr {
/// value was found and was successfully parsed as a `Self`.
///
/// By default, we log a message at the `warn` level.
fn log_parsable(env_value: &String) {
fn log_parsable(env_value: &str) {
warn!(
"Found '{}' in environment; using value '{}'",
Self::ENVVAR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
// limitations under the License.

use std::fmt;
use std::io;
use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4, ToSocketAddrs};
use std::option;
use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4};
use std::result;
use std::str::FromStr;

use super::env_config::EnvConfig;
use error::{Error, Result};
use EnvConfig;

#[derive(Clone, PartialEq, Eq, Debug)]
pub struct ListenCtlAddr(SocketAddr);

impl ListenCtlAddr {
pub const DEFAULT_PORT: u16 = 9632;

pub fn new(ip: Ipv4Addr, port: u16) -> Self {
ListenCtlAddr(SocketAddr::V4(SocketAddrV4::new(ip, port)))
}
Expand All @@ -41,7 +41,7 @@ impl ListenCtlAddr {

impl Default for ListenCtlAddr {
fn default() -> ListenCtlAddr {
ListenCtlAddr::new(Ipv4Addr::LOCALHOST, 9632)
ListenCtlAddr::new(Ipv4Addr::LOCALHOST, ListenCtlAddr::DEFAULT_PORT)
}
}

Expand All @@ -53,20 +53,24 @@ impl FromStr for ListenCtlAddr {
type Err = Error;

fn from_str(val: &str) -> Result<Self> {
Ok(ListenCtlAddr(SocketAddr::from_str(val)?))
Ok(val.parse::<SocketAddr>()?.into())
}
}

impl ToSocketAddrs for ListenCtlAddr {
type Iter = option::IntoIter<SocketAddr>;
impl fmt::Display for ListenCtlAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> {
write!(f, "{}", self.0)
}
}

fn to_socket_addrs(&self) -> io::Result<Self::Iter> {
self.0.to_socket_addrs()
impl From<SocketAddr> for ListenCtlAddr {
fn from(socket_addr: SocketAddr) -> Self {
ListenCtlAddr(socket_addr)
}
}

impl fmt::Display for ListenCtlAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> {
write!(f, "{}", self.0)
impl AsRef<SocketAddr> for ListenCtlAddr {
fn as_ref(&self) -> &SocketAddr {
&self.0
}
}
19 changes: 19 additions & 0 deletions components/common/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2018 Chef Software Inc. and/or applicable contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

mod env_config;
mod listen_ctl_addr;

pub use self::env_config::EnvConfig;
pub use self::listen_ctl_addr::ListenCtlAddr;

0 comments on commit 3c31952

Please sign in to comment.