Tweak dal connection meta for easier FE work
* Default capabilities to empty slice * Include primary connection connection parameters in REST responses.
This commit is contained in:
@@ -470,6 +470,7 @@ func (app *CortezaApp) InitServices(ctx context.Context) (err error) {
|
||||
Discovery: app.Opt.Discovery,
|
||||
Storage: app.Opt.ObjStore,
|
||||
Template: app.Opt.Template,
|
||||
DB: app.Opt.DB,
|
||||
Auth: app.Opt.Auth,
|
||||
RBAC: app.Opt.RBAC,
|
||||
Limit: app.Opt.Limit,
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
federationTypes "github.com/cortezaproject/corteza-server/federation/types"
|
||||
"github.com/cortezaproject/corteza-server/pkg/api"
|
||||
"github.com/cortezaproject/corteza-server/pkg/dal"
|
||||
"github.com/cortezaproject/corteza-server/pkg/dal/capabilities"
|
||||
"github.com/cortezaproject/corteza-server/pkg/filter"
|
||||
"github.com/cortezaproject/corteza-server/pkg/handle"
|
||||
"github.com/cortezaproject/corteza-server/pkg/payload"
|
||||
@@ -145,6 +146,20 @@ func (ctrl DalConnection) Undelete(ctx context.Context, r *request.DalConnection
|
||||
}
|
||||
|
||||
func (ctrl DalConnection) makeFilterPayload(ctx context.Context, connections types.DalConnectionSet, f types.DalConnectionFilter) (out *connectionSetPayload, err error) {
|
||||
for _, c := range connections {
|
||||
if c.Capabilities.Enforced == nil {
|
||||
c.Capabilities.Enforced = capabilities.Set{}
|
||||
}
|
||||
if c.Capabilities.Supported == nil {
|
||||
c.Capabilities.Supported = capabilities.Set{}
|
||||
}
|
||||
if c.Capabilities.Unsupported == nil {
|
||||
c.Capabilities.Unsupported = capabilities.Set{}
|
||||
}
|
||||
if c.Capabilities.Enabled == nil {
|
||||
c.Capabilities.Enabled = capabilities.Set{}
|
||||
}
|
||||
}
|
||||
out = &connectionSetPayload{
|
||||
Set: connections,
|
||||
Filter: f,
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
a "github.com/cortezaproject/corteza-server/pkg/auth"
|
||||
"github.com/cortezaproject/corteza-server/pkg/dal"
|
||||
"github.com/cortezaproject/corteza-server/pkg/dal/capabilities"
|
||||
"github.com/cortezaproject/corteza-server/pkg/options"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
@@ -20,6 +21,7 @@ type (
|
||||
store store.Storer
|
||||
ac connectionAccessController
|
||||
dal dalConnections
|
||||
dbConf options.DBOpt
|
||||
}
|
||||
|
||||
connectionAccessController interface {
|
||||
@@ -39,12 +41,13 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func Connection(ctx context.Context, dal dalConnections) *dalConnection {
|
||||
func Connection(ctx context.Context, dal dalConnections, dbConf options.DBOpt) *dalConnection {
|
||||
return &dalConnection{
|
||||
ac: DefaultAccessControl,
|
||||
actionlog: DefaultActionlog,
|
||||
store: DefaultStore,
|
||||
dal: dal,
|
||||
dbConf: dbConf,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,9 +71,9 @@ func (svc *dalConnection) FindByID(ctx context.Context, ID uint64) (q *types.Dal
|
||||
return DalConnectionErrNotAllowedToRead(rProps)
|
||||
}
|
||||
|
||||
svc.assurePrimaryConnection(q)
|
||||
return nil
|
||||
}()
|
||||
|
||||
return q, svc.recordAction(ctx, rProps, DalConnectionActionLookup, err)
|
||||
}
|
||||
|
||||
@@ -127,6 +130,8 @@ func (svc *dalConnection) Update(ctx context.Context, upd *types.DalConnection)
|
||||
return DalConnectionErrNotFound(qProps)
|
||||
}
|
||||
|
||||
svc.assurePrimaryConnection(old)
|
||||
|
||||
if !svc.ac.CanUpdateDalConnection(ctx, old) {
|
||||
return DalConnectionErrNotAllowedToUpdate(qProps)
|
||||
}
|
||||
@@ -147,6 +152,18 @@ func (svc *dalConnection) Update(ctx context.Context, upd *types.DalConnection)
|
||||
return fmt.Errorf("can not update handle for primary connection")
|
||||
}
|
||||
|
||||
if old.Config.DefaultModelIdent != upd.Config.DefaultModelIdent {
|
||||
return fmt.Errorf("can not update defaultModelIdent for primary connection")
|
||||
}
|
||||
|
||||
if old.Config.DefaultAttributeIdent != upd.Config.DefaultAttributeIdent {
|
||||
return fmt.Errorf("can not update defaultAttributeIdent for primary connection")
|
||||
}
|
||||
|
||||
if old.Handle != upd.Handle {
|
||||
return fmt.Errorf("can not update handle for primary connection")
|
||||
}
|
||||
|
||||
if old.Type != upd.Type {
|
||||
return fmt.Errorf("can not update type for primary connection")
|
||||
}
|
||||
@@ -158,6 +175,7 @@ func (svc *dalConnection) Update(ctx context.Context, upd *types.DalConnection)
|
||||
}
|
||||
|
||||
q = upd
|
||||
svc.assurePrimaryConnection(q)
|
||||
|
||||
var cm dal.ConnectionMeta
|
||||
cm, err = svc.makeConnectionMeta(ctx, upd)
|
||||
@@ -167,7 +185,6 @@ func (svc *dalConnection) Update(ctx context.Context, upd *types.DalConnection)
|
||||
|
||||
return svc.dal.UpdateConnection(ctx, upd.ID, upd.Config.Connection, cm, upd.ActiveCapabilities()...)
|
||||
}()
|
||||
|
||||
return q, svc.recordAction(ctx, qProps, DalConnectionActionUpdate, err)
|
||||
}
|
||||
|
||||
@@ -272,9 +289,9 @@ func (svc *dalConnection) Search(ctx context.Context, filter types.DalConnection
|
||||
return err
|
||||
}
|
||||
|
||||
svc.assurePrimaryConnection(r...)
|
||||
return nil
|
||||
}()
|
||||
|
||||
return r, f, svc.recordAction(ctx, aProps, DalConnectionActionSearch, err)
|
||||
}
|
||||
|
||||
@@ -311,3 +328,12 @@ func (svc *dalConnection) makeConnectionMeta(ctx context.Context, c *types.DalCo
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (svc *dalConnection) assurePrimaryConnection(connections ...*types.DalConnection) {
|
||||
for _, c := range connections {
|
||||
if c.Type == types.DalPrimaryConnectionResourceType {
|
||||
c.Config.Connection = dal.NewDSNConnection(svc.dbConf.DSN)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ type (
|
||||
ActionLog options.ActionLogOpt
|
||||
Discovery options.DiscoveryOpt
|
||||
Storage options.ObjectStoreOpt
|
||||
DB options.DBOpt
|
||||
Template options.TemplateOpt
|
||||
Auth options.AuthOpt
|
||||
RBAC options.RbacOpt
|
||||
@@ -150,7 +151,7 @@ func Initialize(ctx context.Context, log *zap.Logger, s store.Storer, primaryCon
|
||||
DefaultSettings = Settings(ctx, DefaultStore, DefaultLogger, DefaultAccessControl, CurrentSettings)
|
||||
|
||||
primaryConnectionConfig = primaryConn
|
||||
DefaultDalConnection = Connection(ctx, dal.Service())
|
||||
DefaultDalConnection = Connection(ctx, dal.Service(), c.DB)
|
||||
|
||||
DefaultDalSensitivityLevel = SensitivityLevel(ctx, dal.Service())
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user