Added a list of mapped federated modules
This commit is contained in:
@@ -301,7 +301,7 @@ endpoints:
|
||||
title: Module ID
|
||||
- name: listAll
|
||||
method: GET
|
||||
title: List of shared/exposed modules
|
||||
title: List of shared/exposed/mapped modules
|
||||
path: "/"
|
||||
parameters:
|
||||
path:
|
||||
@@ -318,6 +318,10 @@ endpoints:
|
||||
type: bool
|
||||
required: false
|
||||
title: List exposed modules
|
||||
- name: mapped
|
||||
type: bool
|
||||
required: false
|
||||
title: List exposed modules
|
||||
|
||||
- title: Sync structure
|
||||
description: Sync structure
|
||||
|
||||
@@ -2,7 +2,6 @@ package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/federation/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/federation/service"
|
||||
@@ -23,6 +22,10 @@ type (
|
||||
|
||||
CanMapModule bool `json:"canMapModule"`
|
||||
}
|
||||
|
||||
moduleMappingPayload struct {
|
||||
*types.ModuleMapping
|
||||
}
|
||||
)
|
||||
|
||||
func (ManageStructure) New() *ManageStructure {
|
||||
@@ -110,6 +113,7 @@ func (ctrl ManageStructure) ReadMappings(ctx context.Context, r *request.ManageS
|
||||
return (service.DefaultModuleMapping).FindByID(ctx, r.ModuleID)
|
||||
}
|
||||
|
||||
// ListAll show the list of exposed / shared / mapped modules
|
||||
func (ctrl ManageStructure) ListAll(ctx context.Context, r *request.ManageStructureListAll) (interface{}, error) {
|
||||
var (
|
||||
list interface{}
|
||||
@@ -127,8 +131,13 @@ func (ctrl ManageStructure) ListAll(ctx context.Context, r *request.ManageStruct
|
||||
NodeID: r.NodeID,
|
||||
})
|
||||
break
|
||||
case r.Mapped:
|
||||
list, _, err = (service.DefaultModuleMapping).Find(ctx, types.ModuleMappingFilter{
|
||||
NodeID: r.NodeID,
|
||||
})
|
||||
break
|
||||
default:
|
||||
return nil, errors.New("TODO - http 400 bad request - either use ?exposed or ?shared")
|
||||
return nil, service.ExposedModuleErrRequestParametersInvalid()
|
||||
}
|
||||
|
||||
return ctrl.makePayload(ctx, list, err)
|
||||
@@ -158,6 +167,16 @@ func (ctrl ManageStructure) makeExposedModulePayload(ctx context.Context, em *ty
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (ctrl ManageStructure) makeModuleMappingPayload(ctx context.Context, em *types.ModuleMapping, err error) (*moduleMappingPayload, error) {
|
||||
if err != nil || em == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &moduleMappingPayload{
|
||||
ModuleMapping: em,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (ctrl ManageStructure) makePayload(ctx context.Context, payload interface{}, err error) (interface{}, error) {
|
||||
if err != nil || payload == nil {
|
||||
return nil, err
|
||||
@@ -181,6 +200,15 @@ func (ctrl ManageStructure) makePayload(ctx context.Context, payload interface{}
|
||||
set[i] = *mp
|
||||
}
|
||||
|
||||
return set, err
|
||||
case types.ModuleMappingSet:
|
||||
set := make([]moduleMappingPayload, len(payload.(types.ModuleMappingSet)))
|
||||
|
||||
for i, d := range payload.(types.ModuleMappingSet) {
|
||||
mp, _ := ctrl.makeModuleMappingPayload(ctx, d, err)
|
||||
set[i] = *mp
|
||||
}
|
||||
|
||||
return set, err
|
||||
case *types.ExposedModule:
|
||||
return ctrl.makeExposedModulePayload(ctx, payload.(*types.ExposedModule), err)
|
||||
|
||||
@@ -189,6 +189,11 @@ type (
|
||||
//
|
||||
// List exposed modules
|
||||
Exposed bool
|
||||
|
||||
// Mapped GET parameter
|
||||
//
|
||||
// List exposed modules
|
||||
Mapped bool
|
||||
}
|
||||
)
|
||||
|
||||
@@ -783,6 +788,7 @@ func (r ManageStructureListAll) Auditable() map[string]interface{} {
|
||||
"nodeID": r.NodeID,
|
||||
"shared": r.Shared,
|
||||
"exposed": r.Exposed,
|
||||
"mapped": r.Mapped,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -801,6 +807,11 @@ func (r ManageStructureListAll) GetExposed() bool {
|
||||
return r.Exposed
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r ManageStructureListAll) GetMapped() bool {
|
||||
return r.Mapped
|
||||
}
|
||||
|
||||
// Fill processes request and fills internal variables
|
||||
func (r *ManageStructureListAll) Fill(req *http.Request) (err error) {
|
||||
if strings.ToLower(req.Header.Get("content-type")) == "application/json" {
|
||||
@@ -830,6 +841,12 @@ func (r *ManageStructureListAll) Fill(req *http.Request) (err error) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if val, ok := tmp["mapped"]; ok && len(val) > 0 {
|
||||
r.Mapped, err = payload.ParseBool(val[0]), nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -694,6 +694,36 @@ func ExposedModuleErrComposeNamespaceNotFound(mm ...*exposedModuleActionProps) *
|
||||
return e
|
||||
}
|
||||
|
||||
// ExposedModuleErrRequestParametersInvalid returns "federation:exposed_module.requestParametersInvalid" as *errors.Error
|
||||
//
|
||||
//
|
||||
// This function is auto-generated.
|
||||
//
|
||||
func ExposedModuleErrRequestParametersInvalid(mm ...*exposedModuleActionProps) *errors.Error {
|
||||
var p = &exposedModuleActionProps{}
|
||||
if len(mm) > 0 {
|
||||
p = mm[0]
|
||||
}
|
||||
|
||||
var e = errors.New(
|
||||
errors.KindInternal,
|
||||
|
||||
p.Format("request parameters invalid", nil),
|
||||
|
||||
errors.Meta("type", "requestParametersInvalid"),
|
||||
errors.Meta("resource", "federation:exposed_module"),
|
||||
|
||||
errors.Meta(exposedModulePropsMetaKey{}, p),
|
||||
|
||||
errors.StackSkip(1),
|
||||
)
|
||||
|
||||
if len(mm) > 0 {
|
||||
}
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
// ExposedModuleErrNotAllowedToCreate returns "federation:exposed_module.notAllowedToCreate" as *errors.Error
|
||||
//
|
||||
//
|
||||
|
||||
@@ -83,6 +83,10 @@ errors:
|
||||
message: "compose namespace not found"
|
||||
severity: "warning"
|
||||
|
||||
- error: requestParametersInvalid
|
||||
message: "request parameters invalid"
|
||||
severity: "warning"
|
||||
|
||||
- error: notAllowedToCreate
|
||||
message: "not allowed to create modules"
|
||||
log: "could not create modules; insufficient permissions"
|
||||
|
||||
@@ -97,6 +97,11 @@ func (svc moduleMapping) Find(ctx context.Context, filter types.ModuleMappingFil
|
||||
return nil
|
||||
}()
|
||||
|
||||
set.Walk(func(mm *types.ModuleMapping) error {
|
||||
mm.NodeID = f.NodeID
|
||||
return nil
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user