Skip to content

Commit

Permalink
Add openAPI endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kurlov committed Dec 6, 2024
1 parent ed13540 commit 5b90179
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ emailsender_image_repository:=$(EMAILSENDER_IMAGE)
external_image_registry:=quay.io/rhacs-eng
internal_image_registry:=image-registry.openshift-image-registry.svc:5000

DOCKER ?= docker
DOCKER ?= podman
DOCKER_CONFIG ?= "${HOME}/.docker"

# Default Variables
Expand Down
14 changes: 14 additions & 0 deletions emailsender/pkg/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@ import (
"net/http"
)

// Represents Emailsender openAPI definition
type openAPIHandler struct {
OpenAPIDefinition string
}

// NewOpenAPIHandler ...
func NewOpenAPIHandler(openAPIDefinition string) *openAPIHandler {
return &openAPIHandler{openAPIDefinition}
}

// HealthCheckHandler returns 200 HTTP status code
func HealthCheckHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}

func (h openAPIHandler) Get(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(h.OpenAPIDefinition))
}
6 changes: 6 additions & 0 deletions emailsender/pkg/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/pkg/errors"

"github.com/stackrox/acs-fleet-manager/emailsender/config"
"github.com/stackrox/acs-fleet-manager/emailsender/pkg/client"
acscsAPI "github.com/stackrox/acs-fleet-manager/pkg/api"
acscsErrors "github.com/stackrox/acs-fleet-manager/pkg/errors"
acscsHandlers "github.com/stackrox/acs-fleet-manager/pkg/handlers"
Expand All @@ -33,6 +34,7 @@ func SetupRoutes(authConfig config.AuthConfig, emailHandler *EmailHandler) (http
func setupRoutes(authnHandlerFunc authnHandlerBuilder, authConfig config.AuthConfig, emailHandler *EmailHandler) (http.Handler, error) {
router := mux.NewRouter()
errorsHandler := acscsHandlers.NewErrorsHandler()
openAPIHandler := NewOpenAPIHandler(client.OpenAPIDefinition)

router.NotFoundHandler = http.HandlerFunc(acscsAPI.SendNotFound)
router.MethodNotAllowedHandler = http.HandlerFunc(acscsAPI.SendMethodNotAllowed)
Expand All @@ -55,6 +57,9 @@ func setupRoutes(authnHandlerFunc authnHandlerBuilder, authConfig config.AuthCon
// health endpoint
router.HandleFunc("/health", HealthCheckHandler).Methods("GET")

// openAPI definiton endpoint
router.HandleFunc("/openapi", openAPIHandler.Get).Methods("GET")

// errors endpoint
router.HandleFunc("/api/v1/acscsemail/errors/{id}", errorsHandler.Get).Methods(http.MethodGet)
router.HandleFunc("/api/v1/acscsemail/errors", errorsHandler.List).Methods(http.MethodGet)
Expand Down Expand Up @@ -86,6 +91,7 @@ func buildAuthnHandler(router http.Handler, cfg config.AuthConfig) (http.Handler
Service(emailsenderPrefix).
Next(router).
Public("/health").
Public("/openapi").
Public("/api/v1/acscsemail/errors/?[0-9]*")

for _, keyURL := range cfg.JwksURLs {
Expand Down
9 changes: 9 additions & 0 deletions emailsender/pkg/client/openapiloader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Reads generated openAPI definition for Email Sender service
package client

import _ "embed"

// Loads openAPI difinition .yaml to variable
//
//go:embed openapi/api/openapi.yaml
var OpenAPIDefinition string

0 comments on commit 5b90179

Please sign in to comment.