diff --git a/pkg/apiserver/server.go b/pkg/apiserver/server.go index acea21be6c..8938f0986f 100644 --- a/pkg/apiserver/server.go +++ b/pkg/apiserver/server.go @@ -187,12 +187,6 @@ func Start(params *APIServerParams) { handlers.RegisterTokenAuthRoutes(handler, debugRouter, loggingRouter) - /********************************************************************** - * License ID auth routes - **********************************************************************/ - - handlers.RegisterLicenseIDAuthRoutes(r.PathPrefix("").Subrouter(), kotsStore, handler) - /********************************************************************** * Session auth routes **********************************************************************/ diff --git a/pkg/handlers/handlers.go b/pkg/handlers/handlers.go index aa711b7b89..637f1651ab 100644 --- a/pkg/handlers/handlers.go +++ b/pkg/handlers/handlers.go @@ -357,12 +357,6 @@ func RegisterUnauthenticatedRoutes(handler *Handler, kotsStore store.Store, debu loggingRouter.Path("/api/v1/app/custom-metrics").Methods("POST").HandlerFunc(handler.GetSendCustomAppMetricsHandler(kotsStore)) } -func RegisterLicenseIDAuthRoutes(r *mux.Router, kotsStore store.Store, handler KOTSHandler) { - r.Use(LoggingMiddleware, RequireValidLicenseMiddleware(kotsStore)) - - r.Name("GetAppMetrics").Path("/api/v1/app/metrics").Methods("GET").HandlerFunc(handler.GetAppMetrics) -} - func StreamJSON(c *websocket.Conn, payload interface{}) { response, err := json.Marshal(payload) if err != nil { diff --git a/pkg/handlers/interface.go b/pkg/handlers/interface.go index c6cb2a00db..69b3539288 100644 --- a/pkg/handlers/interface.go +++ b/pkg/handlers/interface.go @@ -162,7 +162,4 @@ type KOTSHandler interface { // Helm IsHelmManaged(w http.ResponseWriter, r *http.Request) GetAppValuesFile(w http.ResponseWriter, r *http.Request) - - // APIs available to applications (except legacy /license/v1/license) - GetAppMetrics(w http.ResponseWriter, r *http.Request) } diff --git a/pkg/handlers/metrics.go b/pkg/handlers/metrics.go index 38de662f2b..62677c9ea0 100644 --- a/pkg/handlers/metrics.go +++ b/pkg/handlers/metrics.go @@ -10,19 +10,9 @@ import ( "github.com/replicatedhq/kots/pkg/kotsutil" "github.com/replicatedhq/kots/pkg/logger" "github.com/replicatedhq/kots/pkg/replicatedapp" - "github.com/replicatedhq/kots/pkg/reporting" - "github.com/replicatedhq/kots/pkg/session" "github.com/replicatedhq/kots/pkg/store" ) -func (h *Handler) GetAppMetrics(w http.ResponseWriter, r *http.Request) { - app := session.ContextGetApp(r) - reportingInfo := reporting.GetReportingInfo(app.ID) - headers := reporting.GetReportingInfoHeaders(reportingInfo) - - JSON(w, http.StatusOK, headers) -} - type SendCustomAppMetricsRequest struct { Data CustomAppMetricsData `json:"data"` } diff --git a/pkg/handlers/middleware.go b/pkg/handlers/middleware.go index 82ca484693..ea328f8a89 100644 --- a/pkg/handlers/middleware.go +++ b/pkg/handlers/middleware.go @@ -107,21 +107,3 @@ func RequireValidSessionQuietMiddleware(kotsStore store.Store) mux.MiddlewareFun }) } } - -func RequireValidLicenseMiddleware(kotsStore store.Store) mux.MiddlewareFunc { - return func(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - license, app, err := requireValidLicense(kotsStore, w, r) - if err != nil { - if !kotsStore.IsNotFound(err) { - logger.Error(errors.Wrapf(err, "request %q", r.RequestURI)) - } - return - } - - r = session.ContextSetLicense(r, license) - r = session.ContextSetApp(r, app) - next.ServeHTTP(w, r) - }) - } -} diff --git a/pkg/handlers/mock/mock.go b/pkg/handlers/mock/mock.go index cf9fe09ede..7440665850 100644 --- a/pkg/handlers/mock/mock.go +++ b/pkg/handlers/mock/mock.go @@ -598,18 +598,6 @@ func (mr *MockKOTSHandlerMockRecorder) GetAppIdentityServiceConfig(w, r interfac return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAppIdentityServiceConfig", reflect.TypeOf((*MockKOTSHandler)(nil).GetAppIdentityServiceConfig), w, r) } -// GetAppMetrics mocks base method. -func (m *MockKOTSHandler) GetAppMetrics(w http.ResponseWriter, r *http.Request) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "GetAppMetrics", w, r) -} - -// GetAppMetrics indicates an expected call of GetAppMetrics. -func (mr *MockKOTSHandlerMockRecorder) GetAppMetrics(w, r interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAppMetrics", reflect.TypeOf((*MockKOTSHandler)(nil).GetAppMetrics), w, r) -} - // GetAppRegistry mocks base method. func (m *MockKOTSHandler) GetAppRegistry(w http.ResponseWriter, r *http.Request) { m.ctrl.T.Helper() diff --git a/pkg/handlers/session.go b/pkg/handlers/session.go index 819e41db1c..2179f996ed 100644 --- a/pkg/handlers/session.go +++ b/pkg/handlers/session.go @@ -8,16 +8,13 @@ import ( "time" "github.com/pkg/errors" - apptypes "github.com/replicatedhq/kots/pkg/app/types" "github.com/replicatedhq/kots/pkg/handlers/types" "github.com/replicatedhq/kots/pkg/k8sutil" - "github.com/replicatedhq/kots/pkg/kotsutil" "github.com/replicatedhq/kots/pkg/logger" "github.com/replicatedhq/kots/pkg/session" sessiontypes "github.com/replicatedhq/kots/pkg/session/types" "github.com/replicatedhq/kots/pkg/store" "github.com/replicatedhq/kots/pkg/util" - kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1" kuberneteserrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -158,47 +155,3 @@ func requireValidKOTSToken(w http.ResponseWriter, r *http.Request) error { return errors.New("invalid auth") } - -func requireValidLicense(kotsStore store.Store, w http.ResponseWriter, r *http.Request) (*kotsv1beta1.License, *apptypes.App, error) { - if r.Method == "OPTIONS" { - return nil, nil, nil - } - - licenseID := r.Header.Get("authorization") - if licenseID == "" { - err := errors.New("missing authorization header") - response := types.ErrorResponse{Error: util.StrPointer(err.Error())} - JSON(w, http.StatusUnauthorized, response) - return nil, nil, err - } - - apps, err := kotsStore.ListInstalledApps() - if err != nil { - return nil, nil, errors.Wrap(err, "get all apps") - } - - var license *kotsv1beta1.License - var app *apptypes.App - - for _, a := range apps { - l, err := kotsutil.LoadLicenseFromBytes([]byte(a.License)) - if err != nil { - return nil, nil, errors.Wrap(err, "load license") - } - - if l.Spec.LicenseID == licenseID { - license = l - app = a - break - } - } - - if license == nil { - err := errors.New("license ID is not valid") - response := types.ErrorResponse{Error: util.StrPointer(err.Error())} - JSON(w, http.StatusUnauthorized, response) - return nil, nil, err - } - - return license, app, nil -}