3
0

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.
This commit is contained in:
Tomaž Jerman
2022-07-27 15:35:33 +02:00
parent 978c538748
commit 76b99bd0ed
7 changed files with 27 additions and 181 deletions

View File

@@ -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) {

View File

@@ -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))
}
}

View File

@@ -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
}

View File

@@ -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))

115
system/types/rbac.gen.go generated
View File

@@ -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

View File

@@ -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"

View File

@@ -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"