mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-13 04:29:04 +08:00
chore(license): clean up the older endpoints (#6971)
This commit is contained in:
parent
70169986be
commit
cc9eb32c50
@ -117,13 +117,6 @@ func (ah *APIHandler) RegisterRoutes(router *mux.Router, am *baseapp.AuthMiddlew
|
|||||||
// note: add ee override methods first
|
// note: add ee override methods first
|
||||||
|
|
||||||
// routes available only in ee version
|
// routes available only in ee version
|
||||||
router.HandleFunc("/api/v1/licenses",
|
|
||||||
am.AdminAccess(ah.listLicenses)).
|
|
||||||
Methods(http.MethodGet)
|
|
||||||
|
|
||||||
router.HandleFunc("/api/v1/licenses",
|
|
||||||
am.AdminAccess(ah.applyLicense)).
|
|
||||||
Methods(http.MethodPost)
|
|
||||||
|
|
||||||
router.HandleFunc("/api/v1/featureFlags",
|
router.HandleFunc("/api/v1/featureFlags",
|
||||||
am.OpenAccess(ah.getFeatureFlags)).
|
am.OpenAccess(ah.getFeatureFlags)).
|
||||||
@ -178,11 +171,6 @@ func (ah *APIHandler) RegisterRoutes(router *mux.Router, am *baseapp.AuthMiddlew
|
|||||||
router.HandleFunc("/api/v1/dashboards/{uuid}/lock", am.EditAccess(ah.lockDashboard)).Methods(http.MethodPut)
|
router.HandleFunc("/api/v1/dashboards/{uuid}/lock", am.EditAccess(ah.lockDashboard)).Methods(http.MethodPut)
|
||||||
router.HandleFunc("/api/v1/dashboards/{uuid}/unlock", am.EditAccess(ah.unlockDashboard)).Methods(http.MethodPut)
|
router.HandleFunc("/api/v1/dashboards/{uuid}/unlock", am.EditAccess(ah.unlockDashboard)).Methods(http.MethodPut)
|
||||||
|
|
||||||
// v2
|
|
||||||
router.HandleFunc("/api/v2/licenses",
|
|
||||||
am.ViewAccess(ah.listLicensesV2)).
|
|
||||||
Methods(http.MethodGet)
|
|
||||||
|
|
||||||
// v3
|
// v3
|
||||||
router.HandleFunc("/api/v3/licenses", am.ViewAccess(ah.listLicensesV3)).Methods(http.MethodGet)
|
router.HandleFunc("/api/v3/licenses", am.ViewAccess(ah.listLicensesV3)).Methods(http.MethodGet)
|
||||||
router.HandleFunc("/api/v3/licenses", am.AdminAccess(ah.applyLicenseV3)).Methods(http.MethodPost)
|
router.HandleFunc("/api/v3/licenses", am.AdminAccess(ah.applyLicenseV3)).Methods(http.MethodPost)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -64,55 +63,8 @@ type ApplyLicenseRequest struct {
|
|||||||
LicenseKey string `json:"key"`
|
LicenseKey string `json:"key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListLicenseResponse map[string]interface{}
|
|
||||||
|
|
||||||
func convertLicenseV3ToListLicenseResponse(licensesV3 []*model.LicenseV3) []ListLicenseResponse {
|
|
||||||
listLicenses := []ListLicenseResponse{}
|
|
||||||
|
|
||||||
for _, license := range licensesV3 {
|
|
||||||
listLicenses = append(listLicenses, license.Data)
|
|
||||||
}
|
|
||||||
return listLicenses
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ah *APIHandler) listLicenses(w http.ResponseWriter, r *http.Request) {
|
|
||||||
licenses, apiError := ah.LM().GetLicenses(context.Background())
|
|
||||||
if apiError != nil {
|
|
||||||
RespondError(w, apiError, nil)
|
|
||||||
}
|
|
||||||
ah.Respond(w, licenses)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ah *APIHandler) applyLicense(w http.ResponseWriter, r *http.Request) {
|
|
||||||
var l model.License
|
|
||||||
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&l); err != nil {
|
|
||||||
RespondError(w, model.BadRequest(err), nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if l.Key == "" {
|
|
||||||
RespondError(w, model.BadRequest(fmt.Errorf("license key is required")), nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
license, apiError := ah.LM().ActivateV3(r.Context(), l.Key)
|
|
||||||
if apiError != nil {
|
|
||||||
RespondError(w, apiError, nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ah.Respond(w, license)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ah *APIHandler) listLicensesV3(w http.ResponseWriter, r *http.Request) {
|
func (ah *APIHandler) listLicensesV3(w http.ResponseWriter, r *http.Request) {
|
||||||
licenses, apiError := ah.LM().GetLicensesV3(r.Context())
|
ah.listLicensesV2(w, r)
|
||||||
|
|
||||||
if apiError != nil {
|
|
||||||
RespondError(w, apiError, nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ah.Respond(w, convertLicenseV3ToListLicenseResponse(licenses))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ah *APIHandler) getActiveLicenseV3(w http.ResponseWriter, r *http.Request) {
|
func (ah *APIHandler) getActiveLicenseV3(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -121,6 +73,7 @@ func (ah *APIHandler) getActiveLicenseV3(w http.ResponseWriter, r *http.Request)
|
|||||||
RespondError(w, &model.ApiError{Typ: model.ErrorInternal, Err: err}, nil)
|
RespondError(w, &model.ApiError{Typ: model.ErrorInternal, Err: err}, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// return 404 not found if there is no active license
|
// return 404 not found if there is no active license
|
||||||
if activeLicense == nil {
|
if activeLicense == nil {
|
||||||
RespondError(w, &model.ApiError{Typ: model.ErrorNotFound, Err: fmt.Errorf("no active license found")}, nil)
|
RespondError(w, &model.ApiError{Typ: model.ErrorNotFound, Err: fmt.Errorf("no active license found")}, nil)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import axios from 'api';
|
import { ApiV3Instance as axios } from 'api';
|
||||||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
|
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
|
||||||
import { AxiosError } from 'axios';
|
import { AxiosError } from 'axios';
|
||||||
import { ErrorResponse, SuccessResponse } from 'types/api';
|
import { ErrorResponse, SuccessResponse } from 'types/api';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ApiV2Instance as axios } from 'api';
|
import { ApiV3Instance as axios } from 'api';
|
||||||
import { ErrorResponse, SuccessResponse } from 'types/api';
|
import { ErrorResponse, SuccessResponse } from 'types/api';
|
||||||
import { PayloadProps } from 'types/api/licenses/getAll';
|
import { PayloadProps } from 'types/api/licenses/getAll';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user