Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Completely hide internal auth if disabled (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
swift1337 authored Jul 2, 2023
1 parent a72d008 commit f77aab1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
1 change: 1 addition & 0 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
ports: [ '80:80' ]
networks: [ net-oxygen ]
depends_on: [ postgres ]
restart: on-failure

postgres:
image: postgres:15-alpine
Expand Down
36 changes: 15 additions & 21 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,13 @@ func (app *App) RunServer() {
app.services.JobLogger(),
)

withInternalAPI := httpServer.NoOpt()
if app.config.Oxygen.Server.EnableInternalAPI {
admin := internalapi.New(
app.services.WalletService(),
app.services.BlockchainService(),
schedulerHandler,
app.logger,
)

withInternalAPI = httpServer.WithInternalAPI(admin)
}

withEmbeddedFrontend := httpServer.NoOpt()
if app.config.EmbedFrontend {
app.Logger().Info().Msg("Enabled frontend embedding")
withEmbeddedFrontend = httpServer.WithEmbeddedFrontend(uidashboard.Files(), uipayment.Files())
}
withInternalAPI := app.config.Oxygen.Server.EnableInternalAPI

srv := httpServer.New(
app.config.Oxygen.Server,
app.config.Debug,
httpServer.WithRecover(),
httpServer.WithLogger(app.logger),
httpServer.WithAuthDebug(web.AuthDebugFiles()),
httpServer.WithDocs(web.SwaggerFiles()),
httpServer.WithMerchantAPI(merchantAPIHandler, app.services.TokenManagerService()),
httpServer.WithDashboardAPI(
app.config.Oxygen.Server,
Expand All @@ -143,8 +125,20 @@ func (app *App) RunServer() {
),
httpServer.WithPaymentAPI(paymentAPIHandler, app.config.Oxygen.Server),
httpServer.WithWebhookAPI(incomingWebhooksHandler),
withInternalAPI,
withEmbeddedFrontend,
httpServer.When(
app.config.EmbedFrontend,
httpServer.WithEmbeddedFrontend(uidashboard.Files(), uipayment.Files()),
),
httpServer.When(withInternalAPI, httpServer.WithInternalAPI(
internalapi.New(
app.services.WalletService(),
app.services.BlockchainService(),
schedulerHandler,
app.logger,
),
)),
httpServer.When(withInternalAPI, httpServer.WithDocs(web.SwaggerFiles())),
httpServer.When(withInternalAPI, httpServer.WithAuthDebug(web.AuthDebugFiles())),
)

app.registerEventHandlers()
Expand Down
8 changes: 8 additions & 0 deletions internal/server/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ func NoOpt() Opt {
return func(_ *Server) {}
}

func When(cond bool, opt Opt) Opt {
if !cond {
return NoOpt()
}

return opt
}

func New(cfg Config, logRequests bool, opts ...Opt) *Server {
e := echo.New()
e.HideBanner = true
Expand Down

0 comments on commit f77aab1

Please sign in to comment.