Skip to content

Commit

Permalink
don't log errors in subroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
yasunariw committed Dec 29, 2020
1 parent 62c123c commit b4cfce5
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions lib/slack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ open Common
open Github_j
open Slack_j

let log = Log.from "slack"

let empty_attachments =
{
mrkdwn_in = None;
Expand Down Expand Up @@ -361,23 +359,19 @@ let generate_commit_comment_notification api_commit notification channel =
in
{ channel; text = None; attachments = Some [ attachment ]; blocks = None }

let has_valid_signature ?(version = "v0") ?signing_key ~headers body =
let validate_signature ?(version = "v0") ?signing_key ~headers body =
match signing_key with
| None -> true
| None -> Ok ()
| Some key ->
match List.Assoc.find headers "x-slack-signature" ~equal:String.equal with
| None ->
log#error "unable to find header X-Slack-Signature";
false
| None -> Error "unable to find header X-Slack-Signature"
| Some signature ->
match List.Assoc.find headers "x-slack-request-timestamp" ~equal:String.equal with
| None ->
log#error "unable to find header X-Slack-Request-Timestamp";
false
| None -> Error "unable to find header X-Slack-Request-Timestamp"
| Some timestamp ->
let basestring = Printf.sprintf "%s:%s:%s" version timestamp body in
let expected_signature = Printf.sprintf "%s=%s" version (Common.sign_string_sha256 ~key ~basestring) in
String.equal expected_signature signature
if String.equal expected_signature signature then Ok () else Error "signatures don't match"

let has_valid_state ?oauth_state ~args =
match oauth_state with
Expand Down

0 comments on commit b4cfce5

Please sign in to comment.