-
Notifications
You must be signed in to change notification settings - Fork 2
Feat: event api disable via event registry address #109
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package middleware | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "github.com/gin-gonic/gin" | ||
| "github.com/shutter-network/shutter-api/common" | ||
| sherror "github.com/shutter-network/shutter-api/internal/error" | ||
| ) | ||
|
|
||
| // EventAPIGuard returns 501 Not Implemented when DisableEventAPI is true | ||
| // (i.e., when SHUTTER_EVENT_REGISTRY_CONTRACT_ADDRESS is not configured). | ||
| // When enabled, requests proceed to the event handlers. | ||
| func EventAPIGuard(config *common.Config) gin.HandlerFunc { | ||
| return func(ctx *gin.Context) { | ||
| if config.DisableEventAPI { | ||
| err := sherror.NewHttpError( | ||
| "Service is unavailable.", | ||
| "Service is unavailable.", | ||
| http.StatusNotImplemented, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new response is not reflected on the API docs, example here: https://github.com/shutter-network/shutter-api/blob/main/internal/service/crypto.go#L53 and in other endpoints. |
||
| ) | ||
| ctx.Error(err) | ||
| ctx.Abort() | ||
| return | ||
| } | ||
| ctx.Next() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -187,6 +187,11 @@ func main() { | |
| log.Err(err).Msg("unable to parse keyper http url") | ||
| return | ||
| } | ||
| // Disable event API if event registry contract address is not configured | ||
| config.DisableEventAPI = shutterEventRegistryContractAddressStringified == "" | ||
|
||
| if config.DisableEventAPI { | ||
| log.Info().Msg("Event API disabled: SHUTTER_EVENT_REGISTRY_CONTRACT_ADDRESS not configured") | ||
| } | ||
| app := router.NewRouter(ctx, db, contract, client, config) | ||
| watcher := watcher.NewWatcher(config, db) | ||
| group, deferFn := service.RunBackground(ctx, watcher) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should then align this error message with the 501 error, and have it as "Event API is disabled on this deployment" instead of "Service unavailable" which is usually with the 503 error code?