Skip to content

Commit 467439a

Browse files
committed
Remove not_transient_error_if and add transient_error_if_cmd.
I've long felt `not_transient_error_if` was an awkward name, so it's time to bite the bullet and change it. `transient_error_if_cmd` fits in better with pizauth's other option names, but does require changing the way the command runs. Fortunately, in general, simply changing: ``` not_transient_error_if = "shell-cmd"; ``` to: ``` transient_error_if_cmd = "! shell-cmd"; ``` is all that is required.
1 parent ddbb608 commit 467439a

7 files changed

Lines changed: 57 additions & 33 deletions

File tree

CHANGES.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
# pizauth 0.3.0 (2023-XX-YY)
2+
3+
## Breaking changes
4+
5+
* `not_transient_error_if` has been removed as a global and per-account option.
6+
In its place has been added the global option `transient_error_if_cmd`.
7+
8+
If you have an existing `not_transient_error_if` option, you will need
9+
to reconsider the shell command you execute. One possibility is to change:
10+
11+
```
12+
not_transient_error_if = "shell-cmd";
13+
```
14+
15+
to:
16+
17+
```
18+
transient_error_if_cmd = "! shell-cmd";
19+
```
20+
21+
`transient_error_if_cmd` sets the environment variable `$PIZAUTH_ACCOUNT` to
22+
allow you to perform different actions for different accounts if you desire.
23+
24+
125
# pizauth 0.2.2 (2023-04-03)
226

327
* Added a global `token_event_cmd` option, which runs a command whenever an

pizauth.conf.5

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ specifies the address for the
4242
HTTP server to listen on.
4343
Defaults to
4444
.Qq 127.0.0.1:0 .
45-
.It Sy not_transient_error_if = Qo Em shell-cmd Qc ;
45+
.It Sy transient_error_if_cmd = Qo Em shell-cmd Qc ;
4646
specifies a shell command to be run when pizauth repeatedly encounters
4747
errors when trying to refresh a token.
4848
One special environment variable is set:
4949
.Em $PIZAUTH_ACCOUNT
5050
is set to the account name.
5151
If
5252
.Em shell-cmd
53-
returns a zero exit code, or exceeds a 3 minute timeout, pizauth treats
54-
the errors as permanent: the access token is invalidated (forcing the user
55-
to later reauthenicate).
53+
returns a zero exit code, the transient errors are ignored.
5654
If
5755
.Em shell-cmd
58-
returns a non-zero exit code, the transient errors are ignored.
56+
returns a non-zero exit code, or exceeds a 3 minute timeout, pizauth treats
57+
the errors as permanent: the access token is invalidated (forcing the user
58+
to later reauthenicate).
5959
Defaults to ignoring non-fatal errors if not specified.
6060
.It Sy refresh_at_least = Em time ;
6161
specifies the maximum period of time before an access token will be forcibly

src/config.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ client_secret "CLIENT_SECRET"
2121
error_notify_cmd "ERROR_NOTIFY_CMD"
2222
http_listen "HTTP_LISTEN"
2323
login_hint "LOGIN_HINT"
24-
not_transient_error_if "NOT_TRANSIENT_ERROR_IF"
24+
transient_error_if_cmd "TRANSIENT_ERROR_IF_CMD"
2525
refresh_retry "REFRESH_RETRY"
2626
redirect_uri "REDIRECT_URI"
2727
refresh_before_expiry "REFRESH_BEFORE_EXPIRY"

src/config.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct Config {
3434
pub auth_notify_interval: Duration,
3535
pub error_notify_cmd: Option<String>,
3636
pub http_listen: String,
37-
pub not_transient_error_if: Option<String>,
37+
pub transient_error_if_cmd: Option<String>,
3838
refresh_at_least: Option<Duration>,
3939
refresh_before_expiry: Option<Duration>,
4040
refresh_retry: Option<Duration>,
@@ -69,7 +69,7 @@ impl Config {
6969
let mut auth_notify_interval = None;
7070
let mut error_notify_cmd = None;
7171
let mut http_listen = None;
72-
let mut not_transient_error_if = None;
72+
let mut transient_error_if_cmd = None;
7373
let mut refresh_at_least = None;
7474
let mut refresh_before_expiry = None;
7575
let mut refresh_retry = None;
@@ -130,12 +130,12 @@ impl Config {
130130
http_listen,
131131
)?)
132132
}
133-
config_ast::TopLevel::NotTransientErrorIf(span) => {
134-
not_transient_error_if = Some(check_not_assigned_str(
133+
config_ast::TopLevel::TransientErrorIfCmd(span) => {
134+
transient_error_if_cmd = Some(check_not_assigned_str(
135135
&lexer,
136-
"not_transient_error_if",
136+
"transient_error_if_cmd",
137137
span,
138-
not_transient_error_if,
138+
transient_error_if_cmd,
139139
)?)
140140
}
141141
config_ast::TopLevel::RefreshAtLeast(span) => {
@@ -188,7 +188,7 @@ impl Config {
188188
.unwrap_or_else(|| Duration::from_secs(AUTH_NOTIFY_INTERVAL_DEFAULT)),
189189
error_notify_cmd,
190190
http_listen: http_listen.unwrap_or_else(|| HTTP_LISTEN_DEFAULT.to_owned()),
191-
not_transient_error_if,
191+
transient_error_if_cmd,
192192
refresh_at_least,
193193
refresh_before_expiry,
194194
refresh_retry,
@@ -637,7 +637,7 @@ mod test {
637637
auth_notify_interval = 88m;
638638
error_notify_cmd = "j";
639639
http_listen = "127.0.0.1:56789";
640-
not_transient_error_if = "k";
640+
transient_error_if_cmd = "k";
641641
token_event_cmd = "q";
642642
account "x" {
643643
// Mandatory fields
@@ -661,7 +661,7 @@ mod test {
661661
assert_eq!(c.auth_notify_cmd, Some("g".to_owned()));
662662
assert_eq!(c.auth_notify_interval, Duration::from_secs(88 * 60));
663663
assert_eq!(c.http_listen, "127.0.0.1:56789".to_owned());
664-
assert_eq!(c.not_transient_error_if, Some("k".to_owned()));
664+
assert_eq!(c.transient_error_if_cmd, Some("k".to_owned()));
665665
assert_eq!(c.token_event_cmd, Some("q".to_owned()));
666666

667667
let act = &c.accounts["x"];
@@ -718,8 +718,8 @@ mod test {
718718
Err(s) if s.contains("Mustn't specify 'token_event_cmd' more than once") => (),
719719
_ => panic!(),
720720
}
721-
match Config::from_str(r#"not_transient_error_if = "a"; not_transient_error_if = "b";"#) {
722-
Err(s) if s.contains("Mustn't specify 'not_transient_error_if' more than once") => (),
721+
match Config::from_str(r#"transient_error_if_cmd = "a"; transient_error_if_cmd = "b";"#) {
722+
Err(s) if s.contains("Mustn't specify 'transient_error_if_cmd' more than once") => (),
723723
_ => panic!(),
724724
}
725725
match Config::from_str(r#"http_listen = "a"; http_listen = "b";"#) {
@@ -816,7 +816,7 @@ mod test {
816816
"#,
817817
)
818818
.unwrap();
819-
assert_eq!(c.not_transient_error_if, None);
819+
assert_eq!(c.transient_error_if_cmd, None);
820820
assert_eq!(c.refresh_at_least, None);
821821
assert_eq!(c.refresh_before_expiry, None);
822822
assert_eq!(c.refresh_retry, None);
@@ -829,7 +829,7 @@ mod test {
829829
// Global only
830830
let c = Config::from_str(
831831
r#"
832-
not_transient_error_if = "e";
832+
transient_error_if_cmd = "e";
833833
refresh_at_least = 1s;
834834
refresh_before_expiry = 2s;
835835
refresh_retry = 3s;
@@ -842,7 +842,7 @@ mod test {
842842
"#,
843843
)
844844
.unwrap();
845-
assert_eq!(c.not_transient_error_if, Some("e".to_owned()));
845+
assert_eq!(c.transient_error_if_cmd, Some("e".to_owned()));
846846
assert_eq!(c.refresh_at_least, Some(Duration::from_secs(1)));
847847
assert_eq!(c.refresh_before_expiry, Some(Duration::from_secs(2)));
848848
assert_eq!(c.refresh_retry, Some(Duration::from_secs(3)));
@@ -868,7 +868,7 @@ mod test {
868868
)
869869
.unwrap();
870870

871-
assert_eq!(c.not_transient_error_if, None);
871+
assert_eq!(c.transient_error_if_cmd, None);
872872
assert_eq!(c.refresh_at_least, None);
873873
assert_eq!(c.refresh_before_expiry, None);
874874
assert_eq!(c.refresh_retry, None);
@@ -881,7 +881,7 @@ mod test {
881881
// Local overrides global
882882
let c = Config::from_str(
883883
r#"
884-
not_transient_error_if = "e";
884+
transient_error_if_cmd = "e";
885885
refresh_at_least = 1s;
886886
refresh_before_expiry = 2s;
887887
refresh_retry = 3s;
@@ -897,7 +897,7 @@ mod test {
897897
"#,
898898
)
899899
.unwrap();
900-
assert_eq!(c.not_transient_error_if, Some("e".to_owned()));
900+
assert_eq!(c.transient_error_if_cmd, Some("e".to_owned()));
901901
assert_eq!(c.refresh_at_least, Some(Duration::from_secs(1)));
902902
assert_eq!(c.refresh_before_expiry, Some(Duration::from_secs(2)));
903903
assert_eq!(c.refresh_retry, Some(Duration::from_secs(3)));
@@ -910,7 +910,7 @@ mod test {
910910
// Local overrides global
911911
let c = Config::from_str(
912912
r#"
913-
not_transient_error_if = "e";
913+
transient_error_if_cmd = "e";
914914
refresh_at_least = 1s;
915915
refresh_before_expiry = 2s;
916916
refresh_retry = 3s;
@@ -941,7 +941,7 @@ mod test {
941941
"#,
942942
)
943943
.unwrap();
944-
assert_eq!(c.not_transient_error_if, Some("e".to_owned()));
944+
assert_eq!(c.transient_error_if_cmd, Some("e".to_owned()));
945945
assert_eq!(c.refresh_at_least, Some(Duration::from_secs(1)));
946946
assert_eq!(c.refresh_before_expiry, Some(Duration::from_secs(2)));
947947
assert_eq!(c.refresh_retry, Some(Duration::from_secs(3)));

src/config.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ TopLevel -> Result<TopLevel, ()>:
1717
| "AUTH_NOTIFY_INTERVAL" "=" "TIME" ";" { Ok(TopLevel::AuthNotifyInterval(map_err($3)?)) }
1818
| "ERROR_NOTIFY_CMD" "=" "STRING" ";" { Ok(TopLevel::ErrorNotifyCmd(map_err($3)?)) }
1919
| "HTTP_LISTEN" "=" "STRING" ";" { Ok(TopLevel::HttpListen(map_err($3)?)) }
20-
| "NOT_TRANSIENT_ERROR_IF" "=" "STRING" ";" { Ok(TopLevel::NotTransientErrorIf(map_err($3)?)) }
20+
| "TRANSIENT_ERROR_IF_CMD" "=" "STRING" ";" { Ok(TopLevel::TransientErrorIfCmd(map_err($3)?)) }
2121
| "REFRESH_AT_LEAST" "=" "TIME" ";" { Ok(TopLevel::RefreshAtLeast(map_err($3)?)) }
2222
| "REFRESH_BEFORE_EXPIRY" "=" "TIME" ";" { Ok(TopLevel::RefreshBeforeExpiry(map_err($3)?)) }
2323
| "REFRESH_RETRY" "=" "TIME" ";" { Ok(TopLevel::RefreshRetry(map_err($3)?)) }

src/config_ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub enum TopLevel {
77
AuthNotifyInterval(Span),
88
ErrorNotifyCmd(Span),
99
HttpListen(Span),
10-
NotTransientErrorIf(Span),
10+
TransientErrorIfCmd(Span),
1111
RefreshAtLeast(Span),
1212
RefreshBeforeExpiry(Span),
1313
RefreshRetry(Span),

src/server/refresher.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use super::{
2222

2323
/// How many times can a transient error be encountered before we try `not_transient_error_if`?
2424
const TRANSIENT_ERROR_RETRIES: u64 = 6;
25-
/// How long to run `not_transient_error_if` commands before killing them?
26-
const NOT_TRANSIENT_ERROR_IF_TIMEOUT: Duration = Duration::from_secs(3 * 60);
25+
/// How long to run `transient_error_if_cmd` commands before killing them?
26+
const TRANSIENT_ERROR_IF_CMD_TIMEOUT: Duration = Duration::from_secs(3 * 60);
2727

2828
/// The outcome of an attempted refresh.
2929
#[derive(Debug)]
@@ -100,7 +100,7 @@ impl Refresher {
100100
== 0
101101
{
102102
if let Some(ref cmd) =
103-
ct_lk.config().not_transient_error_if
103+
ct_lk.config().transient_error_if_cmd
104104
{
105105
let cmd = cmd.to_owned();
106106
drop(ct_lk);
@@ -173,17 +173,17 @@ impl Refresher {
173173
.args(["-c", &cmd])
174174
.spawn()
175175
{
176-
Ok(mut child) => match child.wait_timeout(NOT_TRANSIENT_ERROR_IF_TIMEOUT) {
176+
Ok(mut child) => match child.wait_timeout(TRANSIENT_ERROR_IF_CMD_TIMEOUT) {
177177
Ok(Some(status)) => {
178-
if !status.success() {
178+
if status.success() {
179179
Ok(())
180180
} else {
181181
Err(format!(
182182
"'{cmd:}' returned {}",
183183
status
184184
.code()
185185
.map(|x| x.to_string())
186-
.unwrap_or_else(|| "<Unknown exit code".to_string())
186+
.unwrap_or_else(|| "<Unknown exit code>".to_string())
187187
))
188188
}
189189
}

0 commit comments

Comments
 (0)