Added registry, updated handlers

Updated modules

Added function definition endpoint
This commit is contained in:
Peter Grlica
2021-08-11 17:25:04 +02:00
parent 2388158141
commit 4e43020bf0
18 changed files with 526 additions and 245 deletions
+29 -26
View File
@@ -1510,7 +1510,6 @@ endpoints:
entrypoint: route
authentication: []
imports:
# - github.com/cortezaproject/corteza-server/system/types
- github.com/cortezaproject/corteza-server/pkg/label
apis:
- name: list
@@ -1521,8 +1520,8 @@ endpoints:
get:
- { name: routeID, type: "[]string", title: "Filter by route ID" }
- { name: query, type: "string", title: "Filter routes" }
- { name: deleted, type: "uint64", title: "Exclude (0, default), include (1) or return only (2) deleted routes" }
- { name: disabled, type: "uint64", title: "Exclude (0, default), include (1) or return only (2) disabled routes" }
- { name: deleted, type: "uint64", title: "Exclude (0, default), include (1) or return only (2) deleted routes" }
- { name: disabled, type: "uint64", title: "Exclude (0, default), include (1) or return only (2) disabled routes" }
- { name: labels, type: "map[string]string", title: "Labels", parser: "label.ParseStrings" }
- { name: limit, type: "uint", title: "Limit" }
- { name: pageCursor, type: "string", title: "Page cursor" }
@@ -1535,10 +1534,9 @@ endpoints:
post:
- { name: endpoint, type: string, required: true, title: "Route endpoint" }
- { name: method, type: string, title: "Route method" }
# - { name: meta, type: "*types.RouteMeta", title: "Route meta data", parser: "types.ParseRouteMeta" }
- { name: debug, type: bool, title: "Debug route" }
- { name: enabled, type: bool, title: "Is route enabled" }
- { name: group, type: uint64, title: "Route group" }
- { name: group, type: uint64, title: "Route group" }
- name: update
method: PUT
title: Update route details
@@ -1550,7 +1548,7 @@ endpoints:
- { name: method, type: string, title: "Route method" }
- { name: debug, type: bool, title: "Debug route" }
- { name: enabled, type: bool, title: "Is route enabled" }
- { name: group, type: uint64, title: "Route group" }
- { name: group, type: uint64, title: "Route group" }
- name: read
method: GET
title: Read route details
@@ -1585,7 +1583,6 @@ endpoints:
authentication: []
imports:
- github.com/cortezaproject/corteza-server/system/types
# - github.com/cortezaproject/corteza-server/pkg/label
apis:
- name: list
method: GET
@@ -1593,26 +1590,25 @@ endpoints:
path: "/"
parameters:
get:
- { name: functionID, type: "[]string", title: "Filter by function ID" }
- { name: routeID, type: "string", title: "Filter by route ID" }
- { name: query, type: "string", title: "Filter functions" }
- { name: deleted, type: "uint64", title: "Exclude (0, default), include (1) or return only (2) deleted functions" }
- { name: disabled, type: "uint64", title: "Exclude (0, default), include (1) or return only (2) disabled functions" }
# - { name: labels, type: "map[string]string", title: "Labels", parser: "label.ParseStrings" }
- { name: limit, type: "uint", title: "Limit" }
- { name: pageCursor, type: "string", title: "Page cursor" }
- { name: sort, type: "string", title: "Sort items" }
- { name: functionID, type: "[]string", title: "Filter by function ID" }
- { name: routeID, type: "string", title: "Filter by route ID" }
- { name: query, type: "string", title: "Filter functions" }
- { name: deleted, type: "uint64", title: "Exclude (0, default), include (1) or return only (2) deleted functions" }
- { name: disabled, type: "uint64", title: "Exclude (0, default), include (1) or return only (2) disabled functions" }
- { name: limit, type: "uint", title: "Limit" }
- { name: pageCursor, type: "string", title: "Page cursor" }
- { name: sort, type: "string", title: "Sort items" }
- name: create
method: PUT
title: Create function
path: ""
parameters:
post:
- { name: routeID, type: uint64, required: true, title: "Route" }
- { name: weight, type: uint64, title: "Function priority" }
- { name: kind, type: "types.ApigwFunctionKind", title: "Function kind" }
- { name: ref, type: string, title: "Function ref" }
- { name: params, type: "types.FuncParams", title: "Function parameters", parser: "types.ParseApigwfFunctionParams" }
- { name: routeID, type: uint64, title: "Route", required: true }
- { name: weight, type: uint64, title: "Function priority" }
- { name: kind, type: "types.ApigwFunctionKind", title: "Function kind" }
- { name: ref, type: string, title: "Function ref" }
- { name: params, type: "types.FuncParams", title: "Function parameters", parser: "types.ParseApigwfFunctionParams" }
- name: update
method: POST
title: Update route details
@@ -1620,11 +1616,11 @@ endpoints:
parameters:
path: [ { name: functionID, type: uint64, required: true, title: "Function ID" } ]
post:
- { name: routeID, type: uint64, required: true, title: "Route" }
- { name: weight, type: uint64, title: "Function priority" }
- { name: kind, type: "types.ApigwFunctionKind", title: "Function kind" }
- { name: ref, type: string, title: "Function ref" }
- { name: params, type: "types.FuncParams", title: "Function parameters", parser: "types.ParseApigwfFunctionParams" }
- { name: routeID, type: uint64, title: "Route", required: true }
- { name: weight, type: uint64, title: "Function priority" }
- { name: kind, type: "types.ApigwFunctionKind", title: "Function kind" }
- { name: ref, type: string, title: "Function ref" }
- { name: params, type: "types.FuncParams", title: "Function parameters", parser: "types.ParseApigwfFunctionParams" }
- name: read
method: GET
title: Read function details
@@ -1640,3 +1636,10 @@ endpoints:
title: Undelete function
path: "/{functionID}/undelete"
parameters: { path: [ { name: functionID, type: uint64, required: true, title: "Function ID" } ] }
- name: definitions
method: GET
title: Function definitions
path: "/def"
parameters:
get:
- { name: kind, type: "string", title: "Filter functions by kind" }
+5
View File
@@ -32,6 +32,7 @@ type (
Update(ctx context.Context, upd *types.Function) (*types.Function, error)
DeleteByID(ctx context.Context, ID uint64) error
UndeleteByID(ctx context.Context, ID uint64) error
Definitions(context.Context, string) (interface{}, error)
}
)
@@ -106,6 +107,10 @@ func (ctrl *Function) Delete(ctx context.Context, r *request.FunctionDelete) (in
return api.OK(), ctrl.svc.DeleteByID(ctx, r.FunctionID)
}
func (ctrl *Function) Definitions(ctx context.Context, r *request.FunctionDefinitions) (interface{}, error) {
return ctrl.svc.Definitions(ctx, r.Kind)
}
func (ctrl *Function) Undelete(ctx context.Context, r *request.FunctionUndelete) (interface{}, error) {
return api.OK(), ctrl.svc.UndeleteByID(ctx, r.FunctionID)
}
+25 -6
View File
@@ -25,16 +25,18 @@ type (
Read(context.Context, *request.FunctionRead) (interface{}, error)
Delete(context.Context, *request.FunctionDelete) (interface{}, error)
Undelete(context.Context, *request.FunctionUndelete) (interface{}, error)
Definitions(context.Context, *request.FunctionDefinitions) (interface{}, error)
}
// HTTP API interface
Function struct {
List func(http.ResponseWriter, *http.Request)
Create func(http.ResponseWriter, *http.Request)
Update func(http.ResponseWriter, *http.Request)
Read func(http.ResponseWriter, *http.Request)
Delete func(http.ResponseWriter, *http.Request)
Undelete func(http.ResponseWriter, *http.Request)
List func(http.ResponseWriter, *http.Request)
Create func(http.ResponseWriter, *http.Request)
Update func(http.ResponseWriter, *http.Request)
Read func(http.ResponseWriter, *http.Request)
Delete func(http.ResponseWriter, *http.Request)
Undelete func(http.ResponseWriter, *http.Request)
Definitions func(http.ResponseWriter, *http.Request)
}
)
@@ -134,6 +136,22 @@ func NewFunction(h FunctionAPI) *Function {
return
}
api.Send(w, r, value)
},
Definitions: func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
params := request.NewFunctionDefinitions()
if err := params.Fill(r); err != nil {
api.Send(w, r, err)
return
}
value, err := h.Definitions(r.Context(), params)
if err != nil {
api.Send(w, r, err)
return
}
api.Send(w, r, value)
},
}
@@ -148,5 +166,6 @@ func (h Function) MountRoutes(r chi.Router, middlewares ...func(http.Handler) ht
r.Get("/apigw/function/{functionID}", h.Read)
r.Delete("/apigw/function/{functionID}", h.Delete)
r.Post("/apigw/function/{functionID}/undelete", h.Undelete)
r.Get("/apigw/function/def", h.Definitions)
})
}
+42
View File
@@ -155,6 +155,13 @@ type (
// Function ID
FunctionID uint64 `json:",string"`
}
FunctionDefinitions struct {
// Kind GET parameter
//
// Filter functions by kind
Kind string
}
)
// NewFunctionList request
@@ -615,3 +622,38 @@ func (r *FunctionUndelete) Fill(req *http.Request) (err error) {
return err
}
// NewFunctionDefinitions request
func NewFunctionDefinitions() *FunctionDefinitions {
return &FunctionDefinitions{}
}
// Auditable returns all auditable/loggable parameters
func (r FunctionDefinitions) Auditable() map[string]interface{} {
return map[string]interface{}{
"kind": r.Kind,
}
}
// Auditable returns all auditable/loggable parameters
func (r FunctionDefinitions) GetKind() string {
return r.Kind
}
// Fill processes request and fills internal variables
func (r *FunctionDefinitions) Fill(req *http.Request) (err error) {
{
// GET params
tmp := req.URL.Query()
if val, ok := tmp["kind"]; ok && len(val) > 0 {
r.Kind, err = val[0], nil
if err != nil {
return err
}
}
}
return err
}
+6
View File
@@ -4,6 +4,7 @@ import (
"context"
"github.com/cortezaproject/corteza-server/pkg/actionlog"
"github.com/cortezaproject/corteza-server/pkg/apigw"
a "github.com/cortezaproject/corteza-server/pkg/auth"
"github.com/cortezaproject/corteza-server/store"
"github.com/cortezaproject/corteza-server/system/types"
@@ -221,3 +222,8 @@ func (svc *function) Search(ctx context.Context, filter types.FunctionFilter) (r
return r, f, svc.recordAction(ctx, aProps, FunctionActionSearch, err)
}
func (svc *function) Definitions(ctx context.Context, kind string) (interface{}, error) {
// get the definitions from registry
return apigw.Service().Funcs(kind), nil
}