You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
oliverpool b6e81357bd
Add Webhook authorization header (#20926)
_This is a different approach to #20267, I took the liberty of adapting
some parts, see below_

## Context

In some cases, a weebhook endpoint requires some kind of authentication.
The usual way is by sending a static `Authorization` header, with a
given token. For instance:

- Matrix expects a `Bearer <token>` (already implemented, by storing the
header cleartext in the metadata - which is buggy on retry #19872)
- TeamCity #18667
- Gitea instances #20267
- SourceHut https://man.sr.ht/graphql.md#authentication-strategies (this
is my actual personal need :)

## Proposed solution

Add a dedicated encrypt column to the webhook table (instead of storing
it as meta as proposed in #20267), so that it gets available for all
present and future hook types (especially the custom ones #19307).

This would also solve the buggy matrix retry #19872.

As a first step, I would recommend focusing on the backend logic and
improve the frontend at a later stage. For now the UI is a simple
`Authorization` field (which could be later customized with `Bearer` and
`Basic` switches):


![2022-08-23-142911](https://user-images.githubusercontent.com/3864879/186162483-5b721504-eef5-4932-812e-eb96a68494cc.png)

The header name is hard-coded, since I couldn't fine any usecase
justifying otherwise.

## Questions

- What do you think of this approach? @justusbunsi @Gusted @silverwind 
- ~~How are the migrations generated? Do I have to manually create a new
file, or is there a command for that?~~
- ~~I started adding it to the API: should I complete it or should I
drop it? (I don't know how much the API is actually used)~~

## Done as well:

- add a migration for the existing matrix webhooks and remove the
`Authorization` logic there


_Closes #19872_

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Gusted <williamzijl7@hotmail.com>
Co-authored-by: delvh <dev.lh@web.de>
2 years ago
..
activity.go Respect user's locale when rendering the date range in the repo activity page (#21410) 2 years ago
attachment.go Move some repository related code into sub package (#19711) 2 years ago
blame.go Refactor git command arguments and make all arguments to be safe to be used (#21535) 2 years ago
branch.go Keep path when creating a new branch (#21153) 2 years ago
cherry_pick.go Remove `RequireHighlightJS` field, update plantuml example. (#19615) 2 years ago
commit.go Fix pagination limit parameter problem (#21109) 2 years ago
compare.go Refactor git command arguments and make all arguments to be safe to be used (#21535) 2 years ago
download.go Slightly simplify LastCommitCache (#20444) 2 years ago
editor.go Move some files into models' sub packages (#20262) 2 years ago
editor_test.go Add more linters to improve code readability (#19989) 2 years ago
find.go Feature: Find files in repo (#15028) 2 years ago
http.go Refactor git command arguments and make all arguments to be safe to be used (#21535) 2 years ago
http_test.go Fix http path bug (#16117) 3 years ago
issue.go Add generic set type (#21408) 2 years ago
issue_content_history.go Make better use of i18n (#20096) 2 years ago
issue_dependency.go Move issues related files into models/issues (#19931) 2 years ago
issue_label.go Move issues related files into models/issues (#19931) 2 years ago
issue_label_test.go Move issues related files into models/issues (#19931) 2 years ago
issue_lock.go Move issues related files into models/issues (#19931) 2 years ago
issue_stopwatch.go Stop spurious APIFormat stopwatches logs (#20008) 2 years ago
issue_test.go Move issues related files into models/issues (#19931) 2 years ago
issue_timetrack.go Move issues related files into models/issues (#19931) 2 years ago
issue_watch.go Move issues related files into models/issues (#19931) 2 years ago
lfs.go Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
main_test.go Use a struct as test options (#19393) 2 years ago
middlewares.go Add system setting table with cache and also add cache supports for user setting (#18058) 2 years ago
migrate.go Unify repo settings & show better error (#19828) 2 years ago
milestone.go Move milestone to models/issues/ (#19278) 2 years ago
packages.go Show hint to link package to repo when viewing empty repo package list (#20504) 2 years ago
patch.go Remove `RequireHighlightJS` field, update plantuml example. (#19615) 2 years ago
projects.go Check if project has the same repository id with issue when assign project to issue (#20133) 2 years ago
projects_test.go Decouple unit test code from business code (#17623) 3 years ago
pull.go feat: notify doers of a merge when automerging (#21553) 2 years ago
pull_review.go Dismiss prior pull reviews if done via web in review dismiss (#20197) 2 years ago
release.go Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
release_test.go Move some files into models' sub packages (#20262) 2 years ago
render.go Allow render HTML with css/js external links (#19017) 2 years ago
repo.go Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
search.go Add user/organization code search (#19977) 2 years ago
setting.go Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
setting_protected_branch.go Move some code into models/git (#19879) 2 years ago
settings_test.go test: use `T.TempDir` to create temporary test directory (#21043) 2 years ago
tag.go Move some code into models/git (#19879) 2 years ago
topic.go Renamed ctx.User to ctx.Doer. (#19161) 2 years ago
treelist.go Refactor parseTreeEntries, speed up tree list (#21368) 2 years ago
view.go adapt README_{Country}.md stype name in localizedExtensions (#21486) 2 years ago
view_test.go adapt README_{Country}.md stype name in localizedExtensions (#21486) 2 years ago
webhook.go Add Webhook authorization header (#20926) 2 years ago
wiki.go [refactor] Use const for wiki DefaultBranch (#21466) 2 years ago
wiki_test.go Make git.OpenRepository accept Context (#19260) 2 years ago