Skip to content

Commit

Permalink
no-tls gateway panic (#499)
Browse files Browse the repository at this point in the history
* fix gtw panic

* add safety breaker clause
  • Loading branch information
gertd authored Nov 27, 2024
1 parent 4068599 commit bc88a4d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
13 changes: 11 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,17 @@ container-tag:
@scripts/container-tag.sh > .container-tag.env

.PHONY: test
test: test-snapshot
@echo -e "$(ATTN_COLOR)==> test github.com/aserto-dev/topaz/pkg/app/tests/... $(NO_COLOR)"
test: test-snapshot run-test
@echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)"

.PHONY: run-test
run-test:
@echo -e "$(ATTN_COLOR)==> run-test github.com/aserto-dev/topaz/pkg/app/tests/... $(NO_COLOR)"
@${EXT_BIN_DIR}/gotestsum --format short-verbose -- -count=1 -timeout 120s -parallel=1 -v -coverprofile=cover.out -coverpkg=github.com/aserto-dev/topaz/pkg/app/tests/... github.com/aserto-dev/topaz/pkg/app/tests/...

.PHONY: run-tests
run-tests:
@echo -e "$(ATTN_COLOR)==> run-tests github.com/aserto-dev/topaz/pkg/app/tests/... $(NO_COLOR)"
@${EXT_BIN_DIR}/gotestsum --format short-verbose -- -count=1 -timeout 120s -parallel=1 -v -coverprofile=cover.out -coverpkg=github.com/aserto-dev/topaz/pkg/app/tests/authz/... github.com/aserto-dev/topaz/pkg/app/tests/authz/...
@${EXT_BIN_DIR}/gotestsum --format short-verbose -- -count=1 -timeout 120s -parallel=1 -v -coverprofile=cover.out -coverpkg=github.com/aserto-dev/topaz/pkg/app/tests/builtin/... github.com/aserto-dev/topaz/pkg/app/tests/builtin/...
@${EXT_BIN_DIR}/gotestsum --format short-verbose -- -count=1 -timeout 120s -parallel=1 -v -coverprofile=cover.out -coverpkg=github.com/aserto-dev/topaz/pkg/app/tests/manifest/... github.com/aserto-dev/topaz/pkg/app/tests/manifest/...
Expand Down
29 changes: 16 additions & 13 deletions pkg/app/topaz.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (e *Topaz) Start() error {
return nil
}

// nolint: gocyclo
func (e *Topaz) ConfigServices() error {
metricsMiddleware, err := e.setupHealthAndMetrics()
if err != nil {
Expand Down Expand Up @@ -181,20 +182,22 @@ func (e *Topaz) ConfigServices() error {
}

if con, ok := e.Services[consoleService]; ok {
apiKeyAuthMiddleware, err := auth.NewAPIKeyAuthMiddleware(e.Context, &e.Configuration.Auth, e.Logger)
if err != nil {
return err
}
if lo.Contains(serviceConfig.registeredServices, consoleService) {
if server.Gateway != nil && server.Gateway.Mux != nil {
apiKeyAuthMiddleware, err := auth.NewAPIKeyAuthMiddleware(e.Context, &e.Configuration.Auth, e.Logger)
if err != nil {
return err
}

if lo.Contains(serviceConfig.registeredServices, "console") {
consoleConfig := con.(*ConsoleService).PrepareConfig(e.Configuration)
// config service.
server.Gateway.Mux.HandleFunc("/api/v1/config", handlers.ConfigHandler(consoleConfig))
server.Gateway.Mux.Handle("/api/v2/config", apiKeyAuthMiddleware.ConfigAuth(handlers.ConfigHandlerV2(consoleConfig), e.Configuration.Auth))
server.Gateway.Mux.HandleFunc("/api/v1/authorizers", handlers.AuthorizersHandler(consoleConfig))
// console service. depends on config service.
server.Gateway.Mux.Handle("/ui/", handlers.UIHandler(http.FS(console.FS)))
server.Gateway.Mux.Handle("/public/", handlers.UIHandler(http.FS(console.FS)))
consoleConfig := con.(*ConsoleService).PrepareConfig(e.Configuration)
// config service.
server.Gateway.Mux.HandleFunc("/api/v1/config", handlers.ConfigHandler(consoleConfig))
server.Gateway.Mux.Handle("/api/v2/config", apiKeyAuthMiddleware.ConfigAuth(handlers.ConfigHandlerV2(consoleConfig), e.Configuration.Auth))
server.Gateway.Mux.HandleFunc("/api/v1/authorizers", handlers.AuthorizersHandler(consoleConfig))
// console service. depends on config service.
server.Gateway.Mux.Handle("/ui/", handlers.UIHandler(http.FS(console.FS)))
server.Gateway.Mux.Handle("/public/", handlers.UIHandler(http.FS(console.FS)))
}
}
}

Expand Down

0 comments on commit bc88a4d

Please sign in to comment.