From 76b99bd0edc97bc226a5fdfd74820bad440f3609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Wed, 27 Jul 2022 15:35:33 +0200 Subject: [PATCH] Umbrella commit for generic commits * Removed f.Check requirement from compose/dalutils. * Added ref to original module when preparing target records for DAL value setter processing (helps with properly setting Ref field). * Updated codegen & added missing imports. --- compose/dalutils/records.go | 19 +-- compose/service/access_control.gen.go | 6 +- .../resource/rbac_references_system.gen.go | 39 ------ pkg/envoy/resource/rbac_rules_parse.gen.go | 27 ---- system/types/rbac.gen.go | 115 ++---------------- tests/automation/main_test.go | 1 + tests/messagebus/main_test.go | 1 + 7 files changed, 27 insertions(+), 181 deletions(-) diff --git a/compose/dalutils/records.go b/compose/dalutils/records.go index 91a8f6127..97222b470 100644 --- a/compose/dalutils/records.go +++ b/compose/dalutils/records.go @@ -139,10 +139,6 @@ func drainIterator(ctx context.Context, iter dal.Iterator, mod *types.Module, f refetchFactor = 1.2 ) - if f.Check == nil { - panic("filter check function not set, this is probably a mistake") - } - var ( // counter for false checks checked uint @@ -176,10 +172,12 @@ func drainIterator(ctx context.Context, iter dal.Iterator, mod *types.Module, f } // check fetched record - if ok, err = f.Check(r); err != nil { - return - } else if !ok { - continue + if f.Check != nil { + if ok, err = f.Check(r); err != nil { + return + } else if !ok { + continue + } } checked++ @@ -242,11 +240,14 @@ func drainIterator(ctx context.Context, iter dal.Iterator, mod *types.Module, f func prepareRecordTarget(module *types.Module) *types.Record { // so we can avoid some code later involving (non)partitioned modules :seenoevil: - return &types.Record{ + r := &types.Record{ ModuleID: module.ID, NamespaceID: module.NamespaceID, Values: make(types.RecordValueSet, 0, len(module.Fields)), } + r.SetModule(module) + + return r } func recToGetters(rr ...*types.Record) (out []dal.ValueGetter) { diff --git a/compose/service/access_control.gen.go b/compose/service/access_control.gen.go index 3924ba03b..eb7a172bb 100644 --- a/compose/service/access_control.gen.go +++ b/compose/service/access_control.gen.go @@ -9,6 +9,8 @@ package service import ( "context" "fmt" + "strings" + "github.com/cortezaproject/corteza-server/compose/types" "github.com/cortezaproject/corteza-server/pkg/actionlog" internalAuth "github.com/cortezaproject/corteza-server/pkg/auth" @@ -17,7 +19,6 @@ import ( "github.com/cortezaproject/corteza-server/store" systemTypes "github.com/cortezaproject/corteza-server/system/types" "github.com/spf13/cast" - "strings" ) type ( @@ -123,7 +124,8 @@ func (svc accessControl) Trace(ctx context.Context, userID uint64, roles []uint6 session := rbac.ParamsToSession(ctx, userID, roles...) for _, res := range resources { - for op := range rbacResourceOperations(res.RbacResource()) { + r := res.RbacResource() + for op := range rbacResourceOperations(r) { ee = append(ee, svc.rbac.Trace(session, op, res)) } } diff --git a/pkg/envoy/resource/rbac_references_system.gen.go b/pkg/envoy/resource/rbac_references_system.gen.go index 23419fc00..1b0f66733 100644 --- a/pkg/envoy/resource/rbac_references_system.gen.go +++ b/pkg/envoy/resource/rbac_references_system.gen.go @@ -62,19 +62,6 @@ func SystemDataPrivacyRequestRbacReferences(dataPrivacyRequest string) (res *Ref return } -// SystemDataPrivacyRequestCommentRbacReferences generates RBAC references -// -// Resources with "envoy: false" are skipped -// -// This function is auto-generated -func SystemDataPrivacyRequestCommentRbacReferences(dataPrivacyRequestComment string) (res *Ref, pp []*Ref, err error) { - if dataPrivacyRequestComment != "*" { - res = &Ref{ResourceType: types.DataPrivacyRequestCommentResourceType, Identifiers: MakeIdentifiers(dataPrivacyRequestComment)} - } - - return -} - // SystemQueueRbacReferences generates RBAC references // // Resources with "envoy: false" are skipped @@ -88,19 +75,6 @@ func SystemQueueRbacReferences(queue string) (res *Ref, pp []*Ref, err error) { return } -// SystemQueueMessageRbacReferences generates RBAC references -// -// Resources with "envoy: false" are skipped -// -// This function is auto-generated -func SystemQueueMessageRbacReferences(queueMessage string) (res *Ref, pp []*Ref, err error) { - if queueMessage != "*" { - res = &Ref{ResourceType: types.QueueMessageResourceType, Identifiers: MakeIdentifiers(queueMessage)} - } - - return -} - // SystemReportRbacReferences generates RBAC references // // Resources with "envoy: false" are skipped @@ -165,16 +139,3 @@ func SystemDalConnectionRbacReferences(dalConnection string) (res *Ref, pp []*Re return } - -// SystemDalSensitivityLevelRbacReferences generates RBAC references -// -// Resources with "envoy: false" are skipped -// -// This function is auto-generated -func SystemDalSensitivityLevelRbacReferences(dalSensitivityLevel string) (res *Ref, pp []*Ref, err error) { - if dalSensitivityLevel != "*" { - res = &Ref{ResourceType: types.DalSensitivityLevelResourceType, Identifiers: MakeIdentifiers(dalSensitivityLevel)} - } - - return -} diff --git a/pkg/envoy/resource/rbac_rules_parse.gen.go b/pkg/envoy/resource/rbac_rules_parse.gen.go index 03e3159b3..b75291b80 100644 --- a/pkg/envoy/resource/rbac_rules_parse.gen.go +++ b/pkg/envoy/resource/rbac_rules_parse.gen.go @@ -83,15 +83,6 @@ func ParseRule(res string) (string, *Ref, []*Ref, error) { ) return resourceType, ref, pp, err - case systemTypes.DataPrivacyRequestCommentResourceType: - if len(path) != 1 { - return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path)) - } - ref, pp, err := SystemDataPrivacyRequestCommentRbacReferences( - path[0], - ) - return resourceType, ref, pp, err - case systemTypes.QueueResourceType: if len(path) != 1 { return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path)) @@ -101,15 +92,6 @@ func ParseRule(res string) (string, *Ref, []*Ref, error) { ) return resourceType, ref, pp, err - case systemTypes.QueueMessageResourceType: - if len(path) != 1 { - return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path)) - } - ref, pp, err := SystemQueueMessageRbacReferences( - path[0], - ) - return resourceType, ref, pp, err - case systemTypes.ReportResourceType: if len(path) != 1 { return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path)) @@ -155,15 +137,6 @@ func ParseRule(res string) (string, *Ref, []*Ref, error) { ) return resourceType, ref, pp, err - case systemTypes.DalSensitivityLevelResourceType: - if len(path) != 1 { - return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path)) - } - ref, pp, err := SystemDalSensitivityLevelRbacReferences( - path[0], - ) - return resourceType, ref, pp, err - case composeTypes.ChartResourceType: if len(path) != 2 { return "", nil, nil, fmt.Errorf("expecting 2 reference components in path, got %d", len(path)) diff --git a/system/types/rbac.gen.go b/system/types/rbac.gen.go index 14404fe6e..3085870b8 100644 --- a/system/types/rbac.gen.go +++ b/system/types/rbac.gen.go @@ -24,20 +24,17 @@ var ( ) const ( - ApplicationResourceType = "corteza::system:application" - ApigwRouteResourceType = "corteza::system:apigw-route" - AuthClientResourceType = "corteza::system:auth-client" - DataPrivacyRequestResourceType = "corteza::system:data-privacy-request" - DataPrivacyRequestCommentResourceType = "corteza::system:data-privacy-request_comment" - QueueResourceType = "corteza::system:queue" - QueueMessageResourceType = "corteza::system:queue_message" - ReportResourceType = "corteza::system:report" - RoleResourceType = "corteza::system:role" - TemplateResourceType = "corteza::system:template" - UserResourceType = "corteza::system:user" - DalConnectionResourceType = "corteza::system:dal-connection" - DalSensitivityLevelResourceType = "corteza::system:dal-sensitivity-level" - ComponentResourceType = "corteza::system" + ApplicationResourceType = "corteza::system:application" + ApigwRouteResourceType = "corteza::system:apigw-route" + AuthClientResourceType = "corteza::system:auth-client" + DataPrivacyRequestResourceType = "corteza::system:data-privacy-request" + QueueResourceType = "corteza::system:queue" + ReportResourceType = "corteza::system:report" + RoleResourceType = "corteza::system:role" + TemplateResourceType = "corteza::system:template" + UserResourceType = "corteza::system:user" + DalConnectionResourceType = "corteza::system:dal-connection" + ComponentResourceType = "corteza::system" ) // RbacResource returns string representation of RBAC resource for Application by calling ApplicationRbacResource fn @@ -160,36 +157,6 @@ func DataPrivacyRequestRbacResourceTpl() string { return "%s/%s" } -// RbacResource returns string representation of RBAC resource for DataPrivacyRequestComment by calling DataPrivacyRequestCommentRbacResource fn -// -// RBAC resource is in the corteza::system:data-privacy-request_comment/... format -// -// This function is auto-generated -func (r DataPrivacyRequestComment) RbacResource() string { - return DataPrivacyRequestCommentRbacResource(r.ID) -} - -// DataPrivacyRequestCommentRbacResource returns string representation of RBAC resource for DataPrivacyRequestComment -// -// RBAC resource is in the corteza::system:data-privacy-request_comment/... format -// -// This function is auto-generated -func DataPrivacyRequestCommentRbacResource(id uint64) string { - cpts := []interface{}{DataPrivacyRequestCommentResourceType} - if id != 0 { - cpts = append(cpts, strconv.FormatUint(id, 10)) - } else { - cpts = append(cpts, "*") - } - - return fmt.Sprintf(DataPrivacyRequestCommentRbacResourceTpl(), cpts...) - -} - -func DataPrivacyRequestCommentRbacResourceTpl() string { - return "%s/%s" -} - // RbacResource returns string representation of RBAC resource for Queue by calling QueueRbacResource fn // // RBAC resource is in the corteza::system:queue/... format @@ -220,36 +187,6 @@ func QueueRbacResourceTpl() string { return "%s/%s" } -// RbacResource returns string representation of RBAC resource for QueueMessage by calling QueueMessageRbacResource fn -// -// RBAC resource is in the corteza::system:queue_message/... format -// -// This function is auto-generated -func (r QueueMessage) RbacResource() string { - return QueueMessageRbacResource(r.ID) -} - -// QueueMessageRbacResource returns string representation of RBAC resource for QueueMessage -// -// RBAC resource is in the corteza::system:queue_message/... format -// -// This function is auto-generated -func QueueMessageRbacResource(id uint64) string { - cpts := []interface{}{QueueMessageResourceType} - if id != 0 { - cpts = append(cpts, strconv.FormatUint(id, 10)) - } else { - cpts = append(cpts, "*") - } - - return fmt.Sprintf(QueueMessageRbacResourceTpl(), cpts...) - -} - -func QueueMessageRbacResourceTpl() string { - return "%s/%s" -} - // RbacResource returns string representation of RBAC resource for Report by calling ReportRbacResource fn // // RBAC resource is in the corteza::system:report/... format @@ -400,36 +337,6 @@ func DalConnectionRbacResourceTpl() string { return "%s/%s" } -// RbacResource returns string representation of RBAC resource for DalSensitivityLevel by calling DalSensitivityLevelRbacResource fn -// -// RBAC resource is in the corteza::system:dal-sensitivity-level/... format -// -// This function is auto-generated -func (r DalSensitivityLevel) RbacResource() string { - return DalSensitivityLevelRbacResource(r.ID) -} - -// DalSensitivityLevelRbacResource returns string representation of RBAC resource for DalSensitivityLevel -// -// RBAC resource is in the corteza::system:dal-sensitivity-level/... format -// -// This function is auto-generated -func DalSensitivityLevelRbacResource(id uint64) string { - cpts := []interface{}{DalSensitivityLevelResourceType} - if id != 0 { - cpts = append(cpts, strconv.FormatUint(id, 10)) - } else { - cpts = append(cpts, "*") - } - - return fmt.Sprintf(DalSensitivityLevelRbacResourceTpl(), cpts...) - -} - -func DalSensitivityLevelRbacResourceTpl() string { - return "%s/%s" -} - // RbacResource returns string representation of RBAC resource for Component by calling ComponentRbacResource fn // // RBAC resource is in the corteza::system/... format diff --git a/tests/automation/main_test.go b/tests/automation/main_test.go index b83bbb9d6..a65fd1cbe 100644 --- a/tests/automation/main_test.go +++ b/tests/automation/main_test.go @@ -20,6 +20,7 @@ import ( "github.com/cortezaproject/corteza-server/pkg/logger" "github.com/cortezaproject/corteza-server/pkg/rand" "github.com/cortezaproject/corteza-server/store" + "github.com/cortezaproject/corteza-server/store/adapters/rdbms/drivers/sqlite" sysTypes "github.com/cortezaproject/corteza-server/system/types" "github.com/cortezaproject/corteza-server/tests/helpers" "github.com/go-chi/chi/v5" diff --git a/tests/messagebus/main_test.go b/tests/messagebus/main_test.go index b168db4bf..9631fceb0 100644 --- a/tests/messagebus/main_test.go +++ b/tests/messagebus/main_test.go @@ -16,6 +16,7 @@ import ( "github.com/cortezaproject/corteza-server/pkg/messagebus" "github.com/cortezaproject/corteza-server/pkg/options" "github.com/cortezaproject/corteza-server/pkg/rand" + "github.com/cortezaproject/corteza-server/store/adapters/rdbms/drivers/sqlite" "github.com/cortezaproject/corteza-server/system/service" sysTypes "github.com/cortezaproject/corteza-server/system/types" "github.com/cortezaproject/corteza-server/tests/helpers"