Skip to content

Commit

Permalink
cleanup: remove sample token, default conn info struct
Browse files Browse the repository at this point in the history
Signed-off-by: Gina Peers <gpeers@chef.io>
  • Loading branch information
Gina Peers authored and christophermaier committed Apr 11, 2019
1 parent 40f5b38 commit cbce5f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 33 deletions.
38 changes: 8 additions & 30 deletions components/sup/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ use futures::{sync::{mpsc as futures_mpsc,
Stream};
use habitat_common::types::EventStreamMetadata;
use nitox::{commands::ConnectCommand,
streaming::{client::NatsStreamingClient,
error::NatsStreamingError},
streaming::client::NatsStreamingClient,
NatsClient,
NatsClientOptions};
use state::Container;
Expand Down Expand Up @@ -228,23 +227,6 @@ impl EventStream {
/// All messages are published under this subject.
const HABITAT_SUBJECT: &str = "habitat";

/// Defines default connection information for a NATS Streaming server
/// running on localhost.
// TODO: As we become clear on the interaction between Habitat and A2,
// this implementation *may* disappear. It's useful for testing and
// prototyping, though.
impl Default for EventConnectionInfo {
fn default() -> Self {
EventConnectionInfo { name: String::from("habitat"),
verbose: true,
cluster_uri: String::from("127.0.0.1:4223"),
cluster_id: String::from("test-cluster"),
// DON'T LEAVE THIS ADMIN TOKEN IN HERE!
auth_token:
AutomateAuthToken("D6fHxsfc_FlGG4coaZXdNv-vSUM=".to_string()), }
}
}

fn init_nats_stream(conn_info: EventConnectionInfo) -> Result<EventStream> {
// TODO (CM): Investigate back-pressure scenarios
let (event_tx, event_rx) = futures_mpsc::unbounded();
Expand All @@ -261,17 +243,14 @@ fn init_nats_stream(conn_info: EventConnectionInfo) -> Result<EventStream> {
cluster_uri,
cluster_id,
auth_token, } = conn_info;

let cc =
ConnectCommand::builder()
// .user(Some("nats".to_string()))
// .pass(Some("S3Cr3TP@5w0rD".to_string()))
.name(Some(name))
.verbose(verbose)
.auth_token(Some(auth_token.as_str().to_string()))
.tls_required(false)
.build()
.unwrap();
ConnectCommand::builder().name(Some(name))
.verbose(verbose)
.auth_token(Some(auth_token.as_str()
.to_string()))
.tls_required(false)
.build()
.unwrap();
let opts =
NatsClientOptions::builder().connect_command(cc)
.cluster_uri(cluster_uri.as_str())
Expand All @@ -281,7 +260,6 @@ fn init_nats_stream(conn_info: EventConnectionInfo) -> Result<EventStream> {
let publisher = NatsClient::from_options(opts)
.map_err(|e| {
error!("Error creating Nats Client from options: {}", e);
//Into::<NatsStreamingError>::into(e)
e.into()
})
.and_then(|client| {
Expand Down
8 changes: 5 additions & 3 deletions components/sup/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,10 @@ impl Manager {
let ec = EventCore::new(es_config, &sys);
// unwrap won't fail here; if there were an issue, from_env()
// would have already propagated an error up the stack.
let c = AutomateAuthToken::from_env().unwrap();
event::init_stream(Self::init_conn_info(&c), ec);
event::init_stream(
Self::init_conn_info(AutomateAuthToken::from_env().unwrap()),
ec,
);
}

Ok(Manager { state: Arc::new(ManagerState { cfg: cfg_static,
Expand Down Expand Up @@ -519,7 +521,7 @@ impl Manager {
/// Initialize struct containing the connection information required to
/// connect to the Automate messaging server: subject, verbosity, messaging
/// cluster id and uri, and authentication token.
fn init_conn_info(msg_auth_token: &AutomateAuthToken) -> event::EventConnectionInfo {
fn init_conn_info(msg_auth_token: AutomateAuthToken) -> event::EventConnectionInfo {
// Messaging connection information is hard-coded for now,
// with the exception of the Authomate authentication token.
// TODO: Determine what the actual connection parameters
Expand Down

0 comments on commit cbce5f4

Please sign in to comment.