Skip to content

Commit

Permalink
bug: Accept either paths or strings containing the cert for APNS (#241)
Browse files Browse the repository at this point in the history
* bug: Accept either paths or strings containing the cert for APNS

Closes: #240

* bug: allow APNS env credentials to include serialized keys

Closes #240

* f fix settings comment
  • Loading branch information
jrconlin authored Dec 2, 2020
1 parent 0f168c9 commit b3dd8a3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 21 deletions.
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

0 comments on commit b3dd8a3

Please sign in to comment.