Skip to content

Commit

Permalink
feat(api): Validate monitors run command's --timezone argument (#…
Browse files Browse the repository at this point in the history
…1847)

The `sentry-cli monitors run` command's `--timezone` argument will now be validated against a list of valid IANA time zone database identifiers. If the user provides a `--timezone` argument, which does not match a valid IANA time zone identifier, the command will fail with an error. Previously, the command would appear to run successfully, but the monitor upsert would silently fail in the Sentry backend, since the backend rejects monitor upserts that have an invalid timezone string.

Fixes GH-1845
  • Loading branch information
szokeasaurusrex authored Nov 29, 2023
1 parent 570526b commit 791a1f8
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 40 deletions.
122 changes: 85 additions & 37 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ backtrace = "0.3.67"
brotli2 = "0.3.2"
bytecount = "0.6.3"
chardet = "0.2.4"
chrono = { version = "0.4.23", features = ["serde"] }
chrono = { version = "0.4.31", features = ["serde"] }
clap = { version = "4.1.6", default-features = false, features = [
"std",
"suggestions",
Expand Down Expand Up @@ -77,6 +77,7 @@ which = "4.4.0"
zip = "0.6.4"
data-encoding = "2.3.3"
magic_string = "0.3.4"
chrono-tz = "0.8.4"

[dev-dependencies]
insta = { version = "1.26.0", features = ["redactions", "yaml"] }
Expand Down
11 changes: 9 additions & 2 deletions src/commands/monitors/run.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chrono_tz::Tz;
use log::warn;
use std::process;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -73,10 +74,16 @@ pub fn make_command(command: Command) -> Command {
.arg(
Arg::new("timezone")
.long("timezone")
.value_parser(|value: &str| {
value.parse::<Tz>().map_err(|err| {
err + "\n\tSee here for a list of valid timezone strings: \
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List"
})
})
.requires("schedule")
.help(
"A tz database string (e.g. \"Europe/Vienna\") representing the monitor's \
execution schedule's timezone. Requires --schedule.",
execution schedule's timezone. Requires --schedule.",
),
)
}
Expand Down Expand Up @@ -202,7 +209,7 @@ fn parse_monitor_config_args(matches: &ArgMatches) -> Result<Option<MonitorConfi
schedule,
checkin_margin: matches.get_one("checkin_margin").copied(),
max_runtime: matches.get_one("max_runtime").copied(),
timezone: matches.get_one("timezone").cloned(),
timezone: matches.get_one("timezone").map(Tz::to_string),
}))
}

Expand Down

0 comments on commit 791a1f8

Please sign in to comment.