File tree Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ GITHUB_WEBHOOK_SECRET=MUST_BE_CONFIGURED
20
20
# ZULIP_API_TOKEN=yyy
21
21
22
22
# Authenticates inbound webhooks from Github
23
- # ZULIP_TOKEN =xxx
23
+ # ZULIP_WEBHOOK_SECRET =xxx
24
24
25
25
# Use another endpoint to retrieve teams of the Rust project (useful for local testing)
26
26
# default: https://team-api.infra.rust-lang.org/v1
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ curl http://localhost:8000/zulip-hook \
107
107
-H " Content-Type: application/json" \
108
108
-d ' {
109
109
"data": "<CMD>",
110
- "token": "<ZULIP_TOKEN >",
110
+ "token": "<ZULIP_WEBHOOK_SECRET >",
111
111
"message": {
112
112
"sender_id": <YOUR_ID>,
113
113
"recipient_id": <YOUR_ID>,
@@ -121,7 +121,7 @@ curl http://localhost:8000/zulip-hook \
121
121
Where:
122
122
- ` CMD ` is the exact command you would issue @triagebot on Zulip (ex. open a direct chat with the
123
123
bot and send "work show")
124
- - ` ZULIP_TOKEN ` : can be anything. Must correspond to the env var ` $ZULIP_TOKEN ` on your workstation
124
+ - ` ZULIP_WEBHOOK_SECRET ` : can be anything. Must correspond to the env var ` $ZULIP_WEBHOOK_SECRET ` on your workstation
125
125
- ` YOUR_ID ` : your GitHub user ID. Must be existing in your local triagebot database (table ` users ` and as
126
126
foreign key also in ` review_prefs ` )
127
127
Original file line number Diff line number Diff line change @@ -127,12 +127,29 @@ pub async fn respond(ctx: &Context, req: Request) -> String {
127
127
serde_json:: to_string ( & Response { content } ) . unwrap ( )
128
128
}
129
129
130
+ pub fn get_token_from_env ( ) -> Result < String , anyhow:: Error > {
131
+ // ZULIP_WEBHOOK_SECRET is preferred, ZULIP_TOKEN is kept for retrocompatibility but will be deprecated
132
+ match std:: env:: var ( "ZULIP_WEBHOOK_SECRET" ) {
133
+ Ok ( v) => return Ok ( v) ,
134
+ Err ( _) => ( ) ,
135
+ }
136
+
137
+ match std:: env:: var ( "ZULIP_TOKEN" ) {
138
+ Ok ( v) => return Ok ( v) ,
139
+ Err ( _) => ( ) ,
140
+ }
141
+
142
+ log:: error!(
143
+ "Cannot communicate with Zulip: neither ZULIP_WEBHOOK_SECRET or ZULIP_TOKEN are set."
144
+ ) ;
145
+ anyhow:: bail!( "Cannot communicate with Zulip." ) ;
146
+ }
147
+
130
148
/// Processes a Zulip webhook.
131
149
///
132
150
/// Returns a string of the response, or None if no response is needed.
133
151
async fn process_zulip_request ( ctx : & Context , req : Request ) -> anyhow:: Result < Option < String > > {
134
- let expected_token = std:: env:: var ( "ZULIP_TOKEN" ) . expect ( "`ZULIP_TOKEN` set for authorization" ) ;
135
-
152
+ let expected_token = get_token_from_env ( ) ?;
136
153
if !bool:: from ( req. token . as_bytes ( ) . ct_eq ( expected_token. as_bytes ( ) ) ) {
137
154
anyhow:: bail!( "Invalid authorization." ) ;
138
155
}
You can’t perform that action at this time.
0 commit comments