Commit c7579249024a119b56abcd2978a46a59ea0bb56a
Exists in
master
and in
4 other branches
Merge pull request #1184 from karuna/master
Hook url should be able to contain http basic authentication
Showing
1 changed file
with
10 additions
and
1 deletions
Show diff stats
app/models/web_hook.rb
| @@ -11,7 +11,16 @@ class WebHook < ActiveRecord::Base | @@ -11,7 +11,16 @@ class WebHook < ActiveRecord::Base | ||
| 11 | message: "should be a valid url" } | 11 | message: "should be a valid url" } |
| 12 | 12 | ||
| 13 | def execute(data) | 13 | def execute(data) |
| 14 | - WebHook.post(url, body: data.to_json, headers: { "Content-Type" => "application/json" }) | 14 | + parsed_url = URI.parse(url) |
| 15 | + if parsed_url.userinfo.blank? | ||
| 16 | + WebHook.post(url, body: data.to_json, headers: { "Content-Type" => "application/json" }) | ||
| 17 | + else | ||
| 18 | + post_url = url.gsub(parsed_url.userinfo+"@", "") | ||
| 19 | + WebHook.post(post_url, | ||
| 20 | + body: data.to_json, | ||
| 21 | + headers: { "Content-Type" => "application/json" }, | ||
| 22 | + basic_auth: {username: parsed_url.user, password: parsed_url.password}) | ||
| 23 | + end | ||
| 15 | end | 24 | end |
| 16 | 25 | ||
| 17 | end | 26 | end |