mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-06-04 11:25:52 +08:00

* feat: added license manager and feature flags * feat: completed org domain api * chore: checking in saml auth handler code * feat: added signup with sso * feat: added login support for admins * feat: added pem support for certificate * ci(build-workflow): 👷 include EE query-service * fix: 🐛 update package name * chore(ee): 🔧 LD_FLAGS related changes Signed-off-by: Prashant Shahi <prashant@signoz.io> Co-authored-by: Prashant Shahi <prashant@signoz.io> Co-authored-by: nityanandagohain <nityanandagohain@gmail.com>
125 lines
3.4 KiB
Go
125 lines
3.4 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"go.signoz.io/signoz/ee/query-service/dao"
|
|
"go.signoz.io/signoz/ee/query-service/interfaces"
|
|
"go.signoz.io/signoz/ee/query-service/license"
|
|
baseapp "go.signoz.io/signoz/pkg/query-service/app"
|
|
baseint "go.signoz.io/signoz/pkg/query-service/interfaces"
|
|
rules "go.signoz.io/signoz/pkg/query-service/rules"
|
|
"go.signoz.io/signoz/pkg/query-service/version"
|
|
)
|
|
|
|
type APIHandlerOptions struct {
|
|
DataConnector interfaces.DataConnector
|
|
AppDao dao.ModelDao
|
|
RulesManager *rules.Manager
|
|
FeatureFlags baseint.FeatureLookup
|
|
LicenseManager *license.Manager
|
|
}
|
|
|
|
type APIHandler struct {
|
|
opts APIHandlerOptions
|
|
baseapp.APIHandler
|
|
}
|
|
|
|
// NewAPIHandler returns an APIHandler
|
|
func NewAPIHandler(opts APIHandlerOptions) (*APIHandler, error) {
|
|
|
|
baseHandler, err := baseapp.NewAPIHandler(baseapp.APIHandlerOpts{
|
|
Reader: opts.DataConnector,
|
|
AppDao: opts.AppDao,
|
|
RuleManager: opts.RulesManager,
|
|
FeatureFlags: opts.FeatureFlags})
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ah := &APIHandler{
|
|
opts: opts,
|
|
APIHandler: *baseHandler,
|
|
}
|
|
return ah, nil
|
|
}
|
|
|
|
func (ah *APIHandler) FF() baseint.FeatureLookup {
|
|
return ah.opts.FeatureFlags
|
|
}
|
|
|
|
func (ah *APIHandler) RM() *rules.Manager {
|
|
return ah.opts.RulesManager
|
|
}
|
|
|
|
func (ah *APIHandler) LM() *license.Manager {
|
|
return ah.opts.LicenseManager
|
|
}
|
|
|
|
func (ah *APIHandler) AppDao() dao.ModelDao {
|
|
return ah.opts.AppDao
|
|
}
|
|
|
|
func (ah *APIHandler) CheckFeature(f string) bool {
|
|
err := ah.FF().CheckFeature(f)
|
|
return err == nil
|
|
}
|
|
|
|
// RegisterRoutes registers routes for this handler on the given router
|
|
func (ah *APIHandler) RegisterRoutes(router *mux.Router) {
|
|
// note: add ee override methods first
|
|
|
|
// routes available only in ee version
|
|
router.HandleFunc("/api/v1/licenses",
|
|
baseapp.AdminAccess(ah.listLicenses)).
|
|
Methods(http.MethodGet)
|
|
|
|
router.HandleFunc("/api/v1/licenses",
|
|
baseapp.AdminAccess(ah.applyLicense)).
|
|
Methods(http.MethodPost)
|
|
|
|
router.HandleFunc("/api/v1/featureFlags",
|
|
baseapp.OpenAccess(ah.getFeatureFlags)).
|
|
Methods(http.MethodGet)
|
|
|
|
router.HandleFunc("/api/v1/loginPrecheck",
|
|
baseapp.OpenAccess(ah.precheckLogin)).
|
|
Methods(http.MethodGet)
|
|
|
|
// paid plans specific routes
|
|
router.HandleFunc("/api/v1/complete/saml",
|
|
baseapp.OpenAccess(ah.receiveSAML)).
|
|
Methods(http.MethodPost)
|
|
|
|
router.HandleFunc("/api/v1/orgs/{orgId}/domains",
|
|
baseapp.AdminAccess(ah.listDomainsByOrg)).
|
|
Methods(http.MethodGet)
|
|
|
|
router.HandleFunc("/api/v1/domains",
|
|
baseapp.AdminAccess(ah.postDomain)).
|
|
Methods(http.MethodPost)
|
|
|
|
router.HandleFunc("/api/v1/domains/{id}",
|
|
baseapp.AdminAccess(ah.putDomain)).
|
|
Methods(http.MethodPut)
|
|
|
|
router.HandleFunc("/api/v1/domains/{id}",
|
|
baseapp.AdminAccess(ah.deleteDomain)).
|
|
Methods(http.MethodDelete)
|
|
|
|
// base overrides
|
|
router.HandleFunc("/api/v1/version", baseapp.OpenAccess(ah.getVersion)).Methods(http.MethodGet)
|
|
router.HandleFunc("/api/v1/invite/{token}", baseapp.OpenAccess(ah.getInvite)).Methods(http.MethodGet)
|
|
router.HandleFunc("/api/v1/register", baseapp.OpenAccess(ah.registerUser)).Methods(http.MethodPost)
|
|
router.HandleFunc("/api/v1/login", baseapp.OpenAccess(ah.loginUser)).Methods(http.MethodPost)
|
|
ah.APIHandler.RegisterRoutes(router)
|
|
|
|
}
|
|
|
|
func (ah *APIHandler) getVersion(w http.ResponseWriter, r *http.Request) {
|
|
version := version.GetVersion()
|
|
ah.WriteJSON(w, r, map[string]string{"version": version, "ee": "Y"})
|
|
}
|