3
0

Refactor JWT implementation

This commit is contained in:
Denis Arh
2022-01-14 22:19:25 +01:00
parent 2e0adf43b7
commit 59ec77e204
47 changed files with 730 additions and 536 deletions

View File

@@ -7,34 +7,37 @@ import (
"github.com/cortezaproject/corteza-server/pkg/auth"
)
func MountRoutes(r chi.Router) {
var (
namespace = Namespace{}.New()
module = Module{}.New()
record = Record{}.New()
page = Page{}.New()
chart = Chart{}.New()
notification = Notification{}.New()
attachment = Attachment{}.New()
automation = Automation{}.New()
)
func MountRoutes(mv auth.MiddlewareValidator) func(r chi.Router) {
return func(r chi.Router) {
var (
namespace = Namespace{}.New()
module = Module{}.New()
record = Record{}.New()
page = Page{}.New()
chart = Chart{}.New()
notification = Notification{}.New()
attachment = Attachment{}.New()
automation = Automation{}.New()
)
// Initialize handlers & controllers.
r.Group(func(r chi.Router) {
// Use alternative handlers that support file serving
handlers.NewAttachment(attachment).MountRoutes(r)
})
// Initialize handlers & controllers.
r.Group(func(r chi.Router) {
// Use alternative handlers that support file serving
handlers.NewAttachment(attachment).MountRoutes(r)
})
// Protect all _private_ routes
r.Group(func(r chi.Router) {
r.Use(auth.MiddlewareValidOnly)
handlers.NewPermissions(Permissions{}.New()).MountRoutes(r)
handlers.NewNamespace(namespace).MountRoutes(r)
handlers.NewPage(page).MountRoutes(r)
handlers.NewAutomation(automation).MountRoutes(r)
handlers.NewModule(module).MountRoutes(r)
handlers.NewRecord(record).MountRoutes(r)
handlers.NewChart(chart).MountRoutes(r)
handlers.NewNotification(notification).MountRoutes(r)
})
// Protect all _private_ routes
r.Group(func(r chi.Router) {
r.Use(mv.HttpValidator("api"))
handlers.NewPermissions(Permissions{}.New()).MountRoutes(r)
handlers.NewNamespace(namespace).MountRoutes(r)
handlers.NewPage(page).MountRoutes(r)
handlers.NewAutomation(automation).MountRoutes(r)
handlers.NewModule(module).MountRoutes(r)
handlers.NewRecord(record).MountRoutes(r)
handlers.NewChart(chart).MountRoutes(r)
handlers.NewNotification(notification).MountRoutes(r)
})
}
}

View File

@@ -14,9 +14,8 @@ package types
import (
"fmt"
"strconv"
"github.com/cortezaproject/corteza-server/pkg/locale"
"strconv"
)
type (

View File

@@ -57,17 +57,17 @@ func (m Module) LabelResourceID() uint64 {
}
// SetLabel adds new label to label map
func (f *ModuleField) SetLabel(key string, value string) {
if f.Labels == nil {
f.Labels = make(map[string]string)
func (m *ModuleField) SetLabel(key string, value string) {
if m.Labels == nil {
m.Labels = make(map[string]string)
}
f.Labels[key] = value
m.Labels[key] = value
}
// GetLabels adds new label to label map
func (f ModuleField) GetLabels() map[string]string {
return f.Labels
func (m ModuleField) GetLabels() map[string]string {
return m.Labels
}
// GetLabels adds new label to label map
@@ -76,8 +76,8 @@ func (ModuleField) LabelResourceKind() string {
}
// GetLabels adds new label to label map
func (f ModuleField) LabelResourceID() uint64 {
return f.ID
func (m ModuleField) LabelResourceID() uint64 {
return m.ID
}
// SetLabel adds new label to label map