comparison mod_pubsub_github/mod_pubsub_github.lua @ 3509:94414cadfcaa

mod_pubsub_github: Return appropriate status code on failure to publish Snippet lifted from mod_pubsub_post
author Kim Alvefur <zash@zash.se>
date Sun, 31 Mar 2019 16:07:11 +0200
parents a98a3922bc01
children f09423c29f31
comparison
equal deleted inserted replaced
3508:a98a3922bc01 3509:94414cadfcaa
5 local hmac_sha1 = require "util.hashes".hmac_sha1; 5 local hmac_sha1 = require "util.hashes".hmac_sha1;
6 6
7 local pubsub_service = module:depends("pubsub").service; 7 local pubsub_service = module:depends("pubsub").service;
8 local node = module:get_option("github_node", "github"); 8 local node = module:get_option("github_node", "github");
9 local secret = module:get_option("github_secret"); 9 local secret = module:get_option("github_secret");
10
11 local error_mapping = {
12 ["forbidden"] = 403;
13 ["item-not-found"] = 404;
14 ["internal-server-error"] = 500;
15 ["conflict"] = 409;
16 };
10 17
11 function handle_POST(event) 18 function handle_POST(event)
12 local request, response = event.request, event.response; 19 local request, response = event.request, event.response;
13 if secret and ("sha1=" .. hmac_sha1(secret, request.body, true)) ~= request.headers.x_hub_signature then 20 if secret and ("sha1=" .. hmac_sha1(secret, request.body, true)) ~= request.headers.x_hub_signature then
14 return 401; 21 return 401;
30 :tag("author") 37 :tag("author")
31 :tag("name"):text(commit.author.name):up() 38 :tag("name"):text(commit.author.name):up()
32 :tag("email"):text(commit.author.email):up() 39 :tag("email"):text(commit.author.email):up()
33 :up() 40 :up()
34 ); 41 );
42 if not ok then
43 return error_mapping[err] or 500;
44 end
35 end 45 end
36 46
37 module:log("debug", "Handled POST: \n%s\n", tostring(request.body)); 47 module:log("debug", "Handled POST: \n%s\n", tostring(request.body));
38 response.status_code = 202; 48 response.status_code = 202;
39 return "Thank you Github!"; 49 return "Thank you Github!";