-
Notifications
You must be signed in to change notification settings - Fork 1
refactor router to reduce duplication and remove an external dependency #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3dea567
refactor router to reduce duplication and remove an external dependency
briskt c3471c6
limit test server to DELETE
briskt 4230fbf
add /router to Docker image
briskt 8f52fd7
clean up .dockerignore
briskt 940426d
Merge branch 'new-totp-endpoint' into route-refactor
briskt f732781
add missing route, BeginRegistration, which was defined for Lambda
briskt 2f60d6c
Merge branch 'develop' into route-refactor
briskt e71f1d9
address a SonarQube security alert about log injection
briskt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package router | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| mfa "github.com/silinternational/serverless-mfa-api-go" | ||
| ) | ||
|
|
||
| // NewMux forms a new ServeMux router, see https://pkg.go.dev/net/http#ServeMux. | ||
| func NewMux(app *mfa.App) *http.ServeMux { | ||
| mux := http.NewServeMux() | ||
|
|
||
| for _, r := range getRoutes(app) { | ||
| mux.Handle(r.Pattern, authenticationMiddleware(r.HandlerFunc)) | ||
| } | ||
| return mux | ||
| } | ||
|
|
||
| // route is used to pass information about a particular route. | ||
| type route struct { | ||
briskt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Pattern string | ||
| HandlerFunc http.HandlerFunc | ||
| } | ||
|
|
||
| // getRoutes returns a list of routes for the server | ||
| func getRoutes(app *mfa.App) []route { | ||
| return []route{ | ||
| { | ||
| Pattern: "POST /api-key/activate", | ||
| HandlerFunc: app.ActivateApiKey, | ||
| }, | ||
| { | ||
| Pattern: "POST /api-key/rotate", | ||
| HandlerFunc: app.RotateApiKey, | ||
| }, | ||
| { | ||
| Pattern: "POST /api-key", | ||
| HandlerFunc: app.CreateApiKey, | ||
| }, | ||
| { | ||
| Pattern: "POST /webauthn/register", | ||
| HandlerFunc: app.BeginRegistration, | ||
| }, | ||
| { | ||
| Pattern: "PUT /webauthn/register", | ||
| HandlerFunc: app.FinishRegistration, | ||
| }, | ||
| { | ||
| Pattern: "POST /webauthn/login", | ||
| HandlerFunc: app.BeginLogin, | ||
| }, | ||
| { | ||
| Pattern: "PUT /webauthn/login", | ||
| HandlerFunc: app.FinishLogin, | ||
| }, | ||
| { | ||
| Pattern: "DELETE /webauthn/user", | ||
| HandlerFunc: app.DeleteUser, | ||
| }, | ||
| { // This expects a path param that is the id that was previously returned | ||
| // as the key_handle_hash from the FinishRegistration call. | ||
| // Alternatively, if the id param indicates that a legacy U2F key should be removed | ||
| // (e.g. by matching the string "u2f") | ||
| // then that user is saved with all of its legacy u2f fields blanked out. | ||
briskt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Pattern: "DELETE /webauthn/credential/{" + mfa.IDParam + "}/", | ||
| HandlerFunc: app.DeleteCredential, | ||
| }, | ||
| { | ||
| Pattern: "POST /totp", | ||
| HandlerFunc: app.CreateTOTP, | ||
| }, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package main | ||
| package router | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.