Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Accept either paths or strings containing the cert for APNS #241

Merged
merged 3 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion autoendpoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ reqwest = "0.10.6"
rusoto_core = "0.45.0"
rusoto_dynamodb = "0.45.0"
# Using debug-logs avoids https://github.com/getsentry/sentry-rust/issues/237
sentry = { version = "0.21", features = ["debug-logs"] }
sentry = { version = "0.20", features = ["debug-logs"] }
serde = { version = "1.0", features = ["derive"] }
serde_dynamodb = "0.6"
serde_json = "1.0"
Expand Down
12 changes: 10 additions & 2 deletions autoendpoint/src/routers/apns/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,16 @@ impl ApnsRouter {
} else {
Endpoint::Production
};
let cert = tokio::fs::read(settings.cert).await?;
let key = tokio::fs::read(settings.key).await?;
let cert = if !settings.cert.starts_with('-') {
tokio::fs::read(settings.cert).await?
} else {
settings.cert.as_bytes().to_vec()
};
let key = if !settings.key.starts_with('-') {
tokio::fs::read(settings.key).await?
} else {
settings.key.as_bytes().to_vec()
};
let client = ApnsClientData {
client: Box::new(
a2::Client::certificate_parts(&cert, &key, endpoint)
Expand Down
8 changes: 5 additions & 3 deletions autoendpoint/src/routers/apns/settings.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::HashMap;
use std::path::PathBuf;

/// Settings for `ApnsRouter`
#[derive(Clone, Debug, serde::Deserialize)]
Expand All @@ -18,8 +17,11 @@ pub struct ApnsSettings {
#[serde(default)]
#[serde(deny_unknown_fields)]
pub struct ApnsChannel {
pub cert: PathBuf,
pub key: PathBuf,
/// the cert and key are either paths
/// or an inline value that starts with "-"
/// e.g. `-----BEGIN PRIVATE KEY-----\n`
pub cert: String,
pub key: String,
pub topic: Option<String>,
pub sandbox: bool,
}
Expand Down
4 changes: 3 additions & 1 deletion autoendpoint/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ impl Settings {
}

// Merge the environment overrides
config.merge(Environment::with_prefix(ENV_PREFIX))?;
// Note: Specify the separator here so that the shell can properly pass args
// down to the sub structures.
config.merge(Environment::with_prefix(ENV_PREFIX).separator("__"))?;

config.try_into::<Self>().map_err(|error| match error {
// Configuration errors are not very sysop friendly, Try to make them
Expand Down