From a437913f8553dc95e26197702541f4e5f8855705 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Wed, 29 Dec 2021 14:01:16 +0100 Subject: [PATCH] Migrate codegen for envoy to CUE --- codegen/all.cue | 1 + .../gocode/envoy/rbac-references.go.tpl | 32 +++ .../gocode/envoy/rbac-rules-parse.go.tpl | 69 ++++++ .../resource-resource_translation.go.tpl- | 31 +++ ...esource-resource_translation_parse.go.tpl- | 73 ++++++ ...ce-resource_translation_references.go.tpl- | 33 +++ codegen/envoy-rbac.cue | 72 ++++++ codegen/locale-service.cue | 2 +- compose/service/access_control.gen.go | 3 +- .../resource/rbac_references_compose.gen.go | 75 +++--- .../resource/rbac_references_system.gen.go | 11 - pkg/envoy/resource/rbac_rules_parse.gen.go | 223 +++++++----------- 12 files changed, 425 insertions(+), 200 deletions(-) create mode 100644 codegen/assets/templates/gocode/envoy/rbac-references.go.tpl create mode 100644 codegen/assets/templates/gocode/envoy/rbac-rules-parse.go.tpl create mode 100644 codegen/assets/templates/gocode/envoy/resource-resource_translation.go.tpl- create mode 100644 codegen/assets/templates/gocode/envoy/resource-resource_translation_parse.go.tpl- create mode 100644 codegen/assets/templates/gocode/envoy/resource-resource_translation_references.go.tpl- create mode 100644 codegen/envoy-rbac.cue diff --git a/codegen/all.cue b/codegen/all.cue index 693e5570d..a08ad5b7e 100644 --- a/codegen/all.cue +++ b/codegen/all.cue @@ -13,4 +13,5 @@ platform: [...schema.#codegen] & rbacAccessControl+ rbacTypes+ localeTypes+ + envoyRBAC+ [] // placeholder diff --git a/codegen/assets/templates/gocode/envoy/rbac-references.go.tpl b/codegen/assets/templates/gocode/envoy/rbac-references.go.tpl new file mode 100644 index 000000000..a9e825edb --- /dev/null +++ b/codegen/assets/templates/gocode/envoy/rbac-references.go.tpl @@ -0,0 +1,32 @@ +package {{ .package }} + +{{ template "gocode/header-gentext.tpl" }} + +import ( +{{- range .imports }} + {{ . }} +{{- end }} +) + +{{- range .resources }} +// {{ .rbacRefFunc }} generates RBAC references +// +// Resources with "envoy: false" are skipped +// +// This function is auto-generated +func {{ .rbacRefFunc }}({{- range .references }}{{ .param }} string, {{- end }}) (res *Ref, pp []*Ref, err error) { + {{- range .references }} + {{- if eq .refField "ID" }} + if {{ .param }} != "*" { + res = &Ref{ResourceType: types.{{ .expIdent }}ResourceType, Identifiers: MakeIdentifiers({{ .param }})} + } + {{- else }} + if {{ .param }} != "*" { + pp = append(pp, &Ref{ResourceType: types.{{ .expIdent }}ResourceType, Identifiers: MakeIdentifiers({{ .param }})}) + } + {{- end }} + {{- end }} + + return +} +{{- end }} diff --git a/codegen/assets/templates/gocode/envoy/rbac-rules-parse.go.tpl b/codegen/assets/templates/gocode/envoy/rbac-rules-parse.go.tpl new file mode 100644 index 000000000..6746acdcb --- /dev/null +++ b/codegen/assets/templates/gocode/envoy/rbac-rules-parse.go.tpl @@ -0,0 +1,69 @@ +package {{ .package }} + +{{ template "gocode/header-gentext.tpl" }} + +import ( + "fmt" + "strings" +{{- range .imports }} + {{ . }} +{{- end }} +) + + +// Parse generates resource setting logic for each resource +// +// Resources with "envoy: false" are skipped +// +// This function is auto-generated +func ParseRule(res string) (string, *Ref, []*Ref, error) { + if res == "" { + return "", nil, nil, fmt.Errorf("empty resource") + } + + sp := "/" + + res = strings.TrimSpace(res) + res = strings.TrimRight(res, sp) + rr := strings.Split(res, sp) + + // only service defined (corteza::system, corteza::compose, ...) + if len(rr) == 1 { + return res, nil, nil, nil + } + + // full thing + resourceType, path := rr[0], rr[1:] + + for p := 1; p < len(path); p++ { + if path[p] != "*" && path[p-1] == "*" { + return "", nil, nil, fmt.Errorf("invalid path wildcard combination for '%s'", res) + } + } + + + // make the resource provide the slice of parent resources we should nest under + switch resourceType { + {{- range .resources }} + case {{ .typeConst }}: + if len(path) != {{ len .references }} { + return "", nil, nil, fmt.Errorf("expecting {{ len .references }} reference components in path, got %d", len(path)) + } + {{- if gt (len .references) 0 }} + ref, pp, err := {{ .rbacRefFunc }}( + {{- range $i, $r := .references }} + path[{{ $i }}], + {{- end }} + ) + return resourceType, ref, pp, err + {{ else }} + + // Component resource, no path + return resourceType, nil, nil, nil + {{- end }} + {{- end}} + } + + // return unhandled resource as-is + return resourceType, nil, nil, nil +} diff --git a/codegen/assets/templates/gocode/envoy/resource-resource_translation.go.tpl- b/codegen/assets/templates/gocode/envoy/resource-resource_translation.go.tpl- new file mode 100644 index 000000000..580d1df0c --- /dev/null +++ b/codegen/assets/templates/gocode/envoy/resource-resource_translation.go.tpl- @@ -0,0 +1,31 @@ +package {{ .Package }} + +{{ template "header-gentext.tpl" }} +{{ template "header-definitions.tpl" . }} + +import ( + systemTypes "github.com/cortezaproject/corteza-server/system/types" +{{- range .Imports }} + {{ . }} +{{- end }} +) + +{{- range .Def }} +{{ $Component := .Component }} +{{ $Resource := .Resource }} +{{ $GoType := printf "types.%s" .Resource }} +func (r *{{if not (eq $Component "system")}}{{export $Component}}{{ end }}{{$Resource}}) EncodeTranslations() ([]*ResourceTranslation, error) { + out := make([]*ResourceTranslation, 0, 10) + + rr := r.Res.EncodeTranslations() + rr.SetLanguage(defaultLanguage) + res, ref, pp := r.ResourceTranslationParts() + out = append(out, NewResourceTranslation(systemTypes.FromLocale(rr), res, ref, pp...)) +{{ if .Locale.Extended }} + tmp, err := r.encodeTranslations() + return append(out, tmp...), err +{{ else }} + return out, nil +{{- end }} +} +{{- end }} diff --git a/codegen/assets/templates/gocode/envoy/resource-resource_translation_parse.go.tpl- b/codegen/assets/templates/gocode/envoy/resource-resource_translation_parse.go.tpl- new file mode 100644 index 000000000..a630a7aeb --- /dev/null +++ b/codegen/assets/templates/gocode/envoy/resource-resource_translation_parse.go.tpl- @@ -0,0 +1,73 @@ +package {{ .Package }} + +{{ template "header-gentext.tpl" }} +{{ template "header-definitions.tpl" . }} + +import ( + "fmt" + "strings" +{{- range .Imports }} + {{ . }} +{{- end }} +) + + +// Parse generates resource setting logic for each resource +// +// Resources with "envoy: false" are skipped +// +// This function is auto-generated +func ParseResourceTranslation(res string) (string, *Ref, []*Ref, error) { + if res == "" { + return "", nil, nil, fmt.Errorf("empty resource") + } + + sp := "/" + + if strings.Index(res, "corteza::") == 0 { + res = res[9:] + } + + res = strings.TrimSpace(res) + res = strings.TrimRight(res, sp) + rr := strings.Split(res, sp) + + // only service defined (corteza::system, corteza::compose, ...) + if len(rr) == 1 { + return "", nil, nil, fmt.Errorf("only service defined: %s", res) + } + + // full thing + resourceType, path := rr[0], rr[1:] + for p := 1; p < len(path); p++ { + if path[p] == "*" { + return "", nil, nil, fmt.Errorf("path wildcard not allowed for locale resources: '%s'", res) + } + } + + // make the resource provide the slice of parent resources we should nest under + switch resourceType { + {{- range .Def }} + case {{ unexport .Component "types" }}.{{ export .Resource }}ResourceTranslationType: + if len(path) != {{ len .Locale.Resource.References }} { + return "", nil, nil, fmt.Errorf("expecting {{ len .Locale.Resource.References }} reference components in path, got %d", len(path)) + } + {{- if gt (len .Locale.Resource.References) 0 }} + ref, pp, err := {{ export .Component .Resource }}ResourceTranslationReferences( + {{- range $i, $r := .Locale.Resource.References }} + // {{ unexport $r.Resource }} + path[{{ $i }}], + {{ end }} + ) + return {{ unexport .Component "types" }}.{{ export .Resource }}ResourceTranslationType, ref, pp, err + {{ else }} + + // Component resource, no path + return {{ unexport .Component "types" }}.{{ export .Resource }}ResourceTranslationType, nil, nil, nil + {{- end }} + {{- end}} + } + + // return unhandled resource as-is + return resourceType, nil, nil, nil +} diff --git a/codegen/assets/templates/gocode/envoy/resource-resource_translation_references.go.tpl- b/codegen/assets/templates/gocode/envoy/resource-resource_translation_references.go.tpl- new file mode 100644 index 000000000..065516b5b --- /dev/null +++ b/codegen/assets/templates/gocode/envoy/resource-resource_translation_references.go.tpl- @@ -0,0 +1,33 @@ +package {{ .Package }} + +{{ template "header-gentext.tpl" }} +{{ template "header-definitions.tpl" . }} + +import ( +{{- range .Imports }} + {{ . }} +{{- end }} +) + +{{- range .Def }} +{{- if .Locale }} +{{- if gt (len .Locale.Resource.References) 0 }} +// {{ export .Component .Resource }}ResourceTranslationReferences generates Locale references +// +// Resources with "envoy: false" are skipped +// +// This function is auto-generated +func {{ export .Component .Resource }}ResourceTranslationReferences({{- range .Locale.Resource.References }}{{ unexport .Resource }} string, {{- end }}) (res *Ref, pp []*Ref, err error) { + {{- range .Locale.Resource.References }} + {{- if eq .Field "ID" }} + res = &Ref{ResourceType: types.{{ export .Resource }}ResourceType, Identifiers: MakeIdentifiers({{ unexport .Resource }})} + {{- else }} + pp = append(pp, &Ref{ResourceType: types.{{ export .Resource }}ResourceType, Identifiers: MakeIdentifiers({{ unexport .Resource }})}) + {{- end }} + {{- end }} + + return +} +{{- end }} +{{- end }} +{{- end }} diff --git a/codegen/envoy-rbac.cue b/codegen/envoy-rbac.cue new file mode 100644 index 000000000..132d3937e --- /dev/null +++ b/codegen/envoy-rbac.cue @@ -0,0 +1,72 @@ +package codegen + +import ( + "github.com/cortezaproject/corteza-server/app" + "github.com/cortezaproject/corteza-server/codegen/schema" + // "strings" +) + +envoyRBAC: + [...schema.#codegen] & + [ + for cmp in app.corteza.components { + template: "gocode/envoy/rbac-references.go.tpl" + output: "pkg/envoy/resource/rbac_references_\(cmp.ident).gen.go" + payload: { + package: "resource" + imports: [ + "\"github.com/cortezaproject/corteza-server/\(cmp.ident)/types\"", + ] + + // cmpIdent: cmp.ident + // Operation/resource validators, grouped by resource + resources: [ + for res in cmp.resources { + rbacRefFunc: "\(cmp.expIdent)\(res.expIdent)RbacReferences" + references: [ + for p in res.parents {p}, + {param: res.ident, refField: "ID", expIdent: res.expIdent}, + ] + }, + ] + } + }, + ]+ + [ + { + template: "gocode/envoy/rbac-rules-parse.go.tpl" + output: "pkg/envoy/resource/rbac_rules_parse.gen.go" + payload: { + package: "resource" + imports: [ + for cmp in app.corteza.components { + "\(cmp.ident)Types \"github.com/cortezaproject/corteza-server/\(cmp.ident)/types\"" + }, + ] + + // cmpIdent: cmp.ident + // Operation/resource validators, grouped by resource + resources: [ + for cmp in app.corteza.components for res in cmp.resources { + importAlias: "\(cmp.ident)Types" + expIdent: res.expIdent + + typeConst: "\(importAlias).\(expIdent)ResourceType" + rbacRefFunc: "\(cmp.expIdent)\(res.expIdent)RbacReferences" + references: [ + for p in res.parents {p}, + {param: res.ident, refField: "ID", expIdent: res.expIdent}, + ] + }, + + for cmp in app.corteza.components { + importAlias: "\(cmp.ident)Types" + expIdent: cmp.expIdent + + typeConst: "\(importAlias).ComponentResourceType" + references: [] + }, + ] + } + }, + ] diff --git a/codegen/locale-service.cue b/codegen/locale-service.cue index 2807d4597..00bd0bd93 100644 --- a/codegen/locale-service.cue +++ b/codegen/locale-service.cue @@ -32,7 +32,7 @@ localeService: keys: [ for key in res.locale.keys if key.handlerFunc == _|_ { struct: key.struct - extended: extended + "extended": extended customHandler: key.customHandler if key.serviceFunc != _|_ {serviceFunc: key.serviceFunc} }] diff --git a/compose/service/access_control.gen.go b/compose/service/access_control.gen.go index 70eac31ea..ae387c225 100644 --- a/compose/service/access_control.gen.go +++ b/compose/service/access_control.gen.go @@ -9,12 +9,11 @@ package service import ( "context" "fmt" - "strings" - "github.com/cortezaproject/corteza-server/compose/types" "github.com/cortezaproject/corteza-server/pkg/actionlog" "github.com/cortezaproject/corteza-server/pkg/rbac" "github.com/spf13/cast" + "strings" ) type ( diff --git a/pkg/envoy/resource/rbac_references_compose.gen.go b/pkg/envoy/resource/rbac_references_compose.gen.go index 9b72bfccc..34c706985 100644 --- a/pkg/envoy/resource/rbac_references_compose.gen.go +++ b/pkg/envoy/resource/rbac_references_compose.gen.go @@ -6,15 +6,6 @@ package resource // the code is regenerated. // -// Definitions file that controls how this file is generated: -// - compose.chart.yaml -// - compose.module-field.yaml -// - compose.module.yaml -// - compose.namespace.yaml -// - compose.page.yaml -// - compose.record.yaml -// - compose.yaml - import ( "github.com/cortezaproject/corteza-server/compose/types" ) @@ -24,9 +15,9 @@ import ( // Resources with "envoy: false" are skipped // // This function is auto-generated -func ComposeChartRbacReferences(namespace string, chart string) (res *Ref, pp []*Ref, err error) { - if namespace != "*" { - pp = append(pp, &Ref{ResourceType: types.NamespaceResourceType, Identifiers: MakeIdentifiers(namespace)}) +func ComposeChartRbacReferences(namespaceID string, chart string) (res *Ref, pp []*Ref, err error) { + if namespaceID != "*" { + pp = append(pp, &Ref{ResourceType: types.NamespaceResourceType, Identifiers: MakeIdentifiers(namespaceID)}) } if chart != "*" { res = &Ref{ResourceType: types.ChartResourceType, Identifiers: MakeIdentifiers(chart)} @@ -35,33 +26,14 @@ func ComposeChartRbacReferences(namespace string, chart string) (res *Ref, pp [] return } -// ComposeModuleFieldRbacReferences generates RBAC references -// -// Resources with "envoy: false" are skipped -// -// This function is auto-generated -func ComposeModuleFieldRbacReferences(namespace string, module string, moduleField string) (res *Ref, pp []*Ref, err error) { - if namespace != "*" { - pp = append(pp, &Ref{ResourceType: types.NamespaceResourceType, Identifiers: MakeIdentifiers(namespace)}) - } - if module != "*" { - pp = append(pp, &Ref{ResourceType: types.ModuleResourceType, Identifiers: MakeIdentifiers(module)}) - } - if moduleField != "*" { - res = &Ref{ResourceType: types.ModuleFieldResourceType, Identifiers: MakeIdentifiers(moduleField)} - } - - return -} - // ComposeModuleRbacReferences generates RBAC references // // Resources with "envoy: false" are skipped // // This function is auto-generated -func ComposeModuleRbacReferences(namespace string, module string) (res *Ref, pp []*Ref, err error) { - if namespace != "*" { - pp = append(pp, &Ref{ResourceType: types.NamespaceResourceType, Identifiers: MakeIdentifiers(namespace)}) +func ComposeModuleRbacReferences(namespaceID string, module string) (res *Ref, pp []*Ref, err error) { + if namespaceID != "*" { + pp = append(pp, &Ref{ResourceType: types.NamespaceResourceType, Identifiers: MakeIdentifiers(namespaceID)}) } if module != "*" { res = &Ref{ResourceType: types.ModuleResourceType, Identifiers: MakeIdentifiers(module)} @@ -70,6 +42,25 @@ func ComposeModuleRbacReferences(namespace string, module string) (res *Ref, pp return } +// ComposeModuleFieldRbacReferences generates RBAC references +// +// Resources with "envoy: false" are skipped +// +// This function is auto-generated +func ComposeModuleFieldRbacReferences(namespaceID string, moduleID string, moduleField string) (res *Ref, pp []*Ref, err error) { + if namespaceID != "*" { + pp = append(pp, &Ref{ResourceType: types.NamespaceResourceType, Identifiers: MakeIdentifiers(namespaceID)}) + } + if moduleID != "*" { + pp = append(pp, &Ref{ResourceType: types.ModuleResourceType, Identifiers: MakeIdentifiers(moduleID)}) + } + if moduleField != "*" { + res = &Ref{ResourceType: types.ModuleFieldResourceType, Identifiers: MakeIdentifiers(moduleField)} + } + + return +} + // ComposeNamespaceRbacReferences generates RBAC references // // Resources with "envoy: false" are skipped @@ -88,9 +79,9 @@ func ComposeNamespaceRbacReferences(namespace string) (res *Ref, pp []*Ref, err // Resources with "envoy: false" are skipped // // This function is auto-generated -func ComposePageRbacReferences(namespace string, page string) (res *Ref, pp []*Ref, err error) { - if namespace != "*" { - pp = append(pp, &Ref{ResourceType: types.NamespaceResourceType, Identifiers: MakeIdentifiers(namespace)}) +func ComposePageRbacReferences(namespaceID string, page string) (res *Ref, pp []*Ref, err error) { + if namespaceID != "*" { + pp = append(pp, &Ref{ResourceType: types.NamespaceResourceType, Identifiers: MakeIdentifiers(namespaceID)}) } if page != "*" { res = &Ref{ResourceType: types.PageResourceType, Identifiers: MakeIdentifiers(page)} @@ -104,12 +95,12 @@ func ComposePageRbacReferences(namespace string, page string) (res *Ref, pp []*R // Resources with "envoy: false" are skipped // // This function is auto-generated -func ComposeRecordRbacReferences(namespace string, module string, record string) (res *Ref, pp []*Ref, err error) { - if namespace != "*" { - pp = append(pp, &Ref{ResourceType: types.NamespaceResourceType, Identifiers: MakeIdentifiers(namespace)}) +func ComposeRecordRbacReferences(namespaceID string, moduleID string, record string) (res *Ref, pp []*Ref, err error) { + if namespaceID != "*" { + pp = append(pp, &Ref{ResourceType: types.NamespaceResourceType, Identifiers: MakeIdentifiers(namespaceID)}) } - if module != "*" { - pp = append(pp, &Ref{ResourceType: types.ModuleResourceType, Identifiers: MakeIdentifiers(module)}) + if moduleID != "*" { + pp = append(pp, &Ref{ResourceType: types.ModuleResourceType, Identifiers: MakeIdentifiers(moduleID)}) } if record != "*" { res = &Ref{ResourceType: types.RecordResourceType, Identifiers: MakeIdentifiers(record)} diff --git a/pkg/envoy/resource/rbac_references_system.gen.go b/pkg/envoy/resource/rbac_references_system.gen.go index 4e953ee6d..4fb241d91 100644 --- a/pkg/envoy/resource/rbac_references_system.gen.go +++ b/pkg/envoy/resource/rbac_references_system.gen.go @@ -6,17 +6,6 @@ package resource // the code is regenerated. // -// Definitions file that controls how this file is generated: -// - system.apigw-route.yaml -// - system.application.yaml -// - system.auth-client.yaml -// - system.queue.yaml -// - system.report.yaml -// - system.role.yaml -// - system.template.yaml -// - system.user.yaml -// - system.yaml - import ( "github.com/cortezaproject/corteza-server/system/types" ) diff --git a/pkg/envoy/resource/rbac_rules_parse.gen.go b/pkg/envoy/resource/rbac_rules_parse.gen.go index 98423de17..09e5bdbbd 100644 --- a/pkg/envoy/resource/rbac_rules_parse.gen.go +++ b/pkg/envoy/resource/rbac_rules_parse.gen.go @@ -6,32 +6,12 @@ package resource // the code is regenerated. // -// Definitions file that controls how this file is generated: -// - automation.workflow.yaml -// - automation.yaml -// - compose.chart.yaml -// - compose.module-field.yaml -// - compose.module.yaml -// - compose.namespace.yaml -// - compose.page.yaml -// - compose.record.yaml -// - compose.yaml -// - system.apigw-route.yaml -// - system.application.yaml -// - system.auth-client.yaml -// - system.queue.yaml -// - system.report.yaml -// - system.role.yaml -// - system.template.yaml -// - system.user.yaml -// - system.yaml - import ( "fmt" - automationTypes "github.com/cortezaproject/corteza-server/automation/types" + "strings" + composeTypes "github.com/cortezaproject/corteza-server/compose/types" systemTypes "github.com/cortezaproject/corteza-server/system/types" - "strings" ) // Parse generates resource setting logic for each resource @@ -66,190 +46,138 @@ func ParseRule(res string) (string, *Ref, []*Ref, error) { // make the resource provide the slice of parent resources we should nest under switch resourceType { - case automationTypes.WorkflowResourceType: - if len(path) != 1 { - return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path)) - } - ref, pp, err := AutomationWorkflowRbacReferences( - // workflow - path[0], - ) - return automationTypes.WorkflowResourceType, ref, pp, err - - case automationTypes.ComponentResourceType: - if len(path) != 0 { - return "", nil, nil, fmt.Errorf("expecting 0 reference components in path, got %d", len(path)) - } - - // Component resource, no path - return automationTypes.ComponentResourceType, nil, nil, nil - case composeTypes.ChartResourceType: - if len(path) != 2 { - return "", nil, nil, fmt.Errorf("expecting 2 reference components in path, got %d", len(path)) - } - ref, pp, err := ComposeChartRbacReferences( - // namespace - path[0], - - // chart - path[1], - ) - return composeTypes.ChartResourceType, ref, pp, err - - case composeTypes.ModuleFieldResourceType: - if len(path) != 3 { - return "", nil, nil, fmt.Errorf("expecting 3 reference components in path, got %d", len(path)) - } - ref, pp, err := ComposeModuleFieldRbacReferences( - // namespace - path[0], - - // module - path[1], - - // moduleField - path[2], - ) - return composeTypes.ModuleFieldResourceType, ref, pp, err - - case composeTypes.ModuleResourceType: - if len(path) != 2 { - return "", nil, nil, fmt.Errorf("expecting 2 reference components in path, got %d", len(path)) - } - ref, pp, err := ComposeModuleRbacReferences( - // namespace - path[0], - - // module - path[1], - ) - return composeTypes.ModuleResourceType, ref, pp, err - - case composeTypes.NamespaceResourceType: - if len(path) != 1 { - return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path)) - } - ref, pp, err := ComposeNamespaceRbacReferences( - // namespace - path[0], - ) - return composeTypes.NamespaceResourceType, ref, pp, err - - case composeTypes.PageResourceType: - if len(path) != 2 { - return "", nil, nil, fmt.Errorf("expecting 2 reference components in path, got %d", len(path)) - } - ref, pp, err := ComposePageRbacReferences( - // namespace - path[0], - - // page - path[1], - ) - return composeTypes.PageResourceType, ref, pp, err - - case composeTypes.RecordResourceType: - if len(path) != 3 { - return "", nil, nil, fmt.Errorf("expecting 3 reference components in path, got %d", len(path)) - } - ref, pp, err := ComposeRecordRbacReferences( - // namespace - path[0], - - // module - path[1], - - // record - path[2], - ) - return composeTypes.RecordResourceType, ref, pp, err - - case composeTypes.ComponentResourceType: - if len(path) != 0 { - return "", nil, nil, fmt.Errorf("expecting 0 reference components in path, got %d", len(path)) - } - - // Component resource, no path - return composeTypes.ComponentResourceType, nil, nil, nil case systemTypes.ApigwRouteResourceType: if len(path) != 1 { return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path)) } ref, pp, err := SystemApigwRouteRbacReferences( - // apigwRoute path[0], ) - return systemTypes.ApigwRouteResourceType, ref, pp, err + return resourceType, ref, pp, err case systemTypes.ApplicationResourceType: if len(path) != 1 { return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path)) } ref, pp, err := SystemApplicationRbacReferences( - // application path[0], ) - return systemTypes.ApplicationResourceType, ref, pp, err + return resourceType, ref, pp, err case systemTypes.AuthClientResourceType: if len(path) != 1 { return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path)) } ref, pp, err := SystemAuthClientRbacReferences( - // authClient path[0], ) - return systemTypes.AuthClientResourceType, ref, pp, err + 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)) } ref, pp, err := SystemQueueRbacReferences( - // queue path[0], ) - return systemTypes.QueueResourceType, ref, pp, err + 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)) } ref, pp, err := SystemReportRbacReferences( - // report path[0], ) - return systemTypes.ReportResourceType, ref, pp, err + return resourceType, ref, pp, err case systemTypes.RoleResourceType: if len(path) != 1 { return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path)) } ref, pp, err := SystemRoleRbacReferences( - // role path[0], ) - return systemTypes.RoleResourceType, ref, pp, err + return resourceType, ref, pp, err case systemTypes.TemplateResourceType: if len(path) != 1 { return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path)) } ref, pp, err := SystemTemplateRbacReferences( - // template path[0], ) - return systemTypes.TemplateResourceType, ref, pp, err + return resourceType, ref, pp, err case systemTypes.UserResourceType: if len(path) != 1 { return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path)) } ref, pp, err := SystemUserRbacReferences( - // user path[0], ) - return systemTypes.UserResourceType, ref, pp, err + 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)) + } + ref, pp, err := ComposeChartRbacReferences( + path[0], + path[1], + ) + return resourceType, ref, pp, err + + case composeTypes.ModuleResourceType: + if len(path) != 2 { + return "", nil, nil, fmt.Errorf("expecting 2 reference components in path, got %d", len(path)) + } + ref, pp, err := ComposeModuleRbacReferences( + path[0], + path[1], + ) + return resourceType, ref, pp, err + + case composeTypes.ModuleFieldResourceType: + if len(path) != 3 { + return "", nil, nil, fmt.Errorf("expecting 3 reference components in path, got %d", len(path)) + } + ref, pp, err := ComposeModuleFieldRbacReferences( + path[0], + path[1], + path[2], + ) + return resourceType, ref, pp, err + + case composeTypes.NamespaceResourceType: + if len(path) != 1 { + return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path)) + } + ref, pp, err := ComposeNamespaceRbacReferences( + path[0], + ) + return resourceType, ref, pp, err + + case composeTypes.PageResourceType: + if len(path) != 2 { + return "", nil, nil, fmt.Errorf("expecting 2 reference components in path, got %d", len(path)) + } + ref, pp, err := ComposePageRbacReferences( + path[0], + path[1], + ) + return resourceType, ref, pp, err + + case composeTypes.RecordResourceType: + if len(path) != 3 { + return "", nil, nil, fmt.Errorf("expecting 3 reference components in path, got %d", len(path)) + } + ref, pp, err := ComposeRecordRbacReferences( + path[0], + path[1], + path[2], + ) + return resourceType, ref, pp, err case systemTypes.ComponentResourceType: if len(path) != 0 { @@ -257,7 +185,14 @@ func ParseRule(res string) (string, *Ref, []*Ref, error) { } // Component resource, no path - return systemTypes.ComponentResourceType, nil, nil, nil + return resourceType, nil, nil, nil + case composeTypes.ComponentResourceType: + if len(path) != 0 { + return "", nil, nil, fmt.Errorf("expecting 0 reference components in path, got %d", len(path)) + } + + // Component resource, no path + return resourceType, nil, nil, nil } // return unhandled resource as-is