Skip to content

Commit

Permalink
docs: Add a sample config for autopush and fix some settings (#216)
Browse files Browse the repository at this point in the history
* Add a sample config for autopush and fix some settings

- Removed unused `debug` setting
- Added default for `endpoint_hostname`
- Fixed invalid default for `crypto_key`

* Use a dummy crypto_key value which will crash if used

This prevents accidentally using no Fernet key in production.
  • Loading branch information
AzureMarker committed Aug 11, 2020
1 parent 3b30d69 commit 5badbfb
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 13 deletions.
2 changes: 0 additions & 2 deletions autopush/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ impl AutopushServer {
}

pub struct ServerOptions {
pub debug: bool,
pub router_port: u16,
pub port: u16,
pub fernet: MultiFernet,
Expand Down Expand Up @@ -172,7 +171,6 @@ impl ServerOptions {
let router_url = settings.router_url();
let endpoint_url = settings.endpoint_url();
Ok(Self {
debug: settings.debug,
port: settings.port,
fernet,
router_port: settings.router_port,
Expand Down
16 changes: 5 additions & 11 deletions autopush/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fn include_port(scheme: &str, port: u16) -> bool {

#[derive(Debug, Default, Deserialize)]
pub struct Settings {
pub debug: bool,
pub port: u16,
pub hostname: Option<String>,
pub resolve_hostname: bool,
Expand All @@ -43,7 +42,7 @@ pub struct Settings {
pub max_connections: u32,
pub close_handshake_timeout: u32,
pub endpoint_scheme: String,
pub endpoint_hostname: Option<String>,
pub endpoint_hostname: String,
pub endpoint_port: u16,
pub crypto_key: String,
pub statsd_host: String,
Expand Down Expand Up @@ -73,8 +72,9 @@ impl Settings {
s.set_default("max_connections", 0)?;
s.set_default("close_handshake_timeout", 0)?;
s.set_default("endpoint_scheme", "http")?;
s.set_default("endpoint_hostname", "localhost")?;
s.set_default("endpoint_port", 8082)?;
s.set_default("crypto_key", Fernet::generate_key())?;
s.set_default("crypto_key", format!("[{}]", Fernet::generate_key()))?;
s.set_default("statsd_host", "localhost")?;
s.set_default("statsd_port", 8125)?;
s.set_default("megaphone_poll_interval", 30)?;
Expand Down Expand Up @@ -112,13 +112,7 @@ impl Settings {
}

pub fn endpoint_url(&self) -> String {
let url = format!(
"{}://{}",
self.endpoint_scheme,
self.endpoint_hostname
.as_ref()
.expect("Endpoint hostname must be supplied"),
);
let url = format!("{}://{}", self.endpoint_scheme, self.endpoint_hostname,);
if include_port(&self.endpoint_scheme, self.endpoint_port) {
format!("{}:{}", url, self.endpoint_port)
} else {
Expand Down Expand Up @@ -171,7 +165,7 @@ mod tests {
#[test]
fn test_endpoint_url() {
let mut settings: Settings = Default::default();
settings.endpoint_hostname = Some("testname".to_string());
settings.endpoint_hostname = "testname".to_string();
settings.endpoint_port = 80;
settings.endpoint_scheme = "http".to_string();
let url = settings.endpoint_url();
Expand Down
83 changes: 83 additions & 0 deletions configs/autopush.toml.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# The host to use for HTTP connections. Defaults to the machine's hostname.
#hostname = "localhost"

# The WebSocket port
#port = 8080

# If the hostname should be resolved to an IP
#resolve_hostname = false

# If human-readable logging should be used
#human_logs = false

# The HTTP router host. Defaults to the hostname setting.
#router_hostname = "localhost"

# The HTTP router port
#router_port = 8081

# Path to the SSL key to use for the router HTTP server. If not set, only HTTP
# connections are supported.
#router_ssl_key = "..."

# Path to the SSL cert to use for the router HTTP server. Required if
# router_ssl_key is set.
#router_ssl_cert = "..."

# Optional path to Diffie-Hellman parameters to use during SSL key exchange
#router_ssl_dh_param = "..."

# The URI scheme to use for the endpoint server URL
#endpoint_scheme = "http"

# The hostname of the endpoint server
#endpoint_hostname = "localhost"

# The port of the endpoint server
#endpoint_port = 8082

# The URL to use for megaphone. If not set, megaphone functionality is disabled.
#megaphone_api_url = "..."

# The token to use for megaphone. Required if megaphone_api_url is set.
#megaphone_api_token = "..."

# The number of seconds between megaphone polls
#megaphone_poll_interval = 30

# The host of the metrics server. An empty string disables metrics.
#statsd_host = "localhost"

# The port of the metrics server
#statsd_port = 8125

# Override the DynamoDB endpoint via the AWS_LOCAL_DYNAMODB environment
# variable. No default value.
#aws_ddb_endpoint = "..."

# The name of the router table
#router_tablename = "router"

# The prefix of the message table(s)
#message_tablename = "message"

# A (stringified) list of Fernet keys to use when encrypting the notification
# endpoint URL. The default is a single auto-generated key.
#crypto_key = "[replace-me-with-a-real-key]"

# How often we send WebSocket pings. 0 indicates no limit.
#auto_ping_interval = 300

# How long to wait for the WebSocket ping to come back before we time out. 0
# indicates no limit.
#auto_ping_timeout = 4

# How long to wait for a closing handshake. 0 indicates no limit.
#close_handshake_timeout = 0

# Maximum number of WebSocket clients. 0 indicates no limit.
#max_connections = 0

# The max number of stored messages to return to a connecting client. If this
# limit is reached, the client is dropped and must re-register.
#msg_limit = 100

0 comments on commit 5badbfb

Please sign in to comment.