Skip to content

Commit

Permalink
add option to restrict handling of GH payloads to certain repo urls
Browse files Browse the repository at this point in the history
  • Loading branch information
yasunariw committed Dec 25, 2020
1 parent 97c9aee commit ab430e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/action.ml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
let signing_key = Context.gh_hook_token_of_secrets secrets repo.url in
Github.validate_signature ?signing_key ~headers body
in
let repo_is_allowed secrets payload =
let repo = Github.repo_of_notification payload in
let allowed_repositories = secrets.allowed_repositories in
List.is_empty allowed_repositories || List.exists allowed_repositories ~f:(String.equal repo.url)
in
try%lwt
let secrets = Context.get_secrets_exn ctx in
match Github.parse_exn headers body with
Expand All @@ -231,6 +236,9 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
match validate_signature secrets payload with
| Error e -> action_error e
| Ok () ->
match repo_is_allowed secrets payload with
| false -> action_error "unsupported repository"
| true ->
( match%lwt refresh_repo_config ctx payload with
| Error e -> action_error e
| Ok () ->
Expand Down
1 change: 1 addition & 0 deletions lib/config.atd
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ type secrets = {
?gh_token : string option; (* GitHub personal access token, if repo access requires it *)
?gh_hook_token : string option; (* GitHub webhook token to secure the webhook *)
~repositories <ocaml default="Common.StringMap.empty"> : gh_repo_secrets map_as_object;
~allowed_repositories <ocaml default="[]"> : string list; (* whitelist of repository URLs to handle notifications for *)
}

0 comments on commit ab430e4

Please sign in to comment.