|
package server
import (
"net/http"
"path/filepath"
httputils "github.com/RedHatInsights/insights-operator-utils/http"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
|
Paths for all REST API endpoints served by this service
|
const (
|
MainEndpoint defines suffix of the root endpoint
|
MainEndpoint = ""
|
GroupsEndpoint defines suffix of the groups request endpoint
|
GroupsEndpoint = "groups"
|
AllContentEndpoint defines suffix for all the content
|
AllContentEndpoint = "content"
|
MetricsEndpoint returns Prometheus metrics
|
MetricsEndpoint = "metrics"
|
StatusEndpoint returns status of all rules that have been read and
parsed
|
StatusEndpoint = "status"
|
InfoEndpoint returns basic information about content service
version, utils repository version, commit hash etc.
|
InfoEndpoint = "info"
)
|
addEndpointsToRouter method registers handlers for all REST API endpoints
|
func ( server * HTTPServer ) addEndpointsToRouter ( router * mux . Router ) {
apiPrefix := server . Config . APIPrefix
openAPIURL := apiPrefix + filepath . Base ( server . Config . APISpecFile )
|
common REST API endpoints
|
router . HandleFunc ( apiPrefix + MainEndpoint , server . mainEndpoint ) . Methods ( http . MethodGet )
router . HandleFunc ( apiPrefix + GroupsEndpoint , server . listOfGroups ) . Methods ( http . MethodGet , http . MethodOptions )
router . HandleFunc ( apiPrefix + AllContentEndpoint , server . getStaticContent ) . Methods ( http . MethodGet , http . MethodOptions )
router . HandleFunc ( apiPrefix + StatusEndpoint , server . ruleContentStates ) . Methods ( http . MethodGet , http . MethodOptions )
router . HandleFunc ( apiPrefix + InfoEndpoint , server . infoMap ) . Methods ( http . MethodGet , http . MethodOptions )
|
Prometheus metrics
|
router . Handle ( apiPrefix + MetricsEndpoint , promhttp . Handler ( ) ) . Methods ( http . MethodGet )
|
OpenAPI specs
|
router . HandleFunc (
openAPIURL ,
httputils . CreateOpenAPIHandler ( server . Config . APISpecFile , server . Config . Debug , true ) ,
) . Methods ( http . MethodGet )
}
|