Add cue tooling & codegen to makefile
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
#component: #_base & {
|
||||
// copy field values from #_base
|
||||
handle: handle, ident: ident, expIdent: expIdent
|
||||
|
||||
label: strings.ToTitle(ident)
|
||||
platform: #baseHandle
|
||||
|
||||
resources: {
|
||||
[key=_]: {"handle": key, "component": handle, "platform": platform} & #resource
|
||||
}
|
||||
|
||||
fqrn: platform + "::" + handle
|
||||
|
||||
// All known RBAC operations for this component
|
||||
rbac: #rbacComponent & {
|
||||
operations: {
|
||||
grant: {
|
||||
description: "Manage \(handle) permissions"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"list"
|
||||
)
|
||||
|
||||
#locale: {
|
||||
resourceExpIdent: #expIdent
|
||||
|
||||
// @todo we need a better name here!
|
||||
skipSvc: bool | *false
|
||||
|
||||
extended: bool | *false
|
||||
|
||||
resource: {
|
||||
// @todo merge with RBAC res-ref and move 2 levels lower.
|
||||
references: [ ...string] | *["ID"]
|
||||
type: string
|
||||
const: string | *("\(resourceExpIdent)ResourceTranslationType")
|
||||
}
|
||||
|
||||
keys: {
|
||||
[key=_]: #localeKey & {
|
||||
name: key
|
||||
_resourceExpIdent: resourceExpIdent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#localeKey: {
|
||||
name: #handle
|
||||
_resourceExpIdent: #expIdent
|
||||
|
||||
path: [...(#ident | {part: #ident, var: bool | *false})] | *([name])
|
||||
|
||||
expandedPath: [ for p in path {
|
||||
if (p & {"p": #ident}) != _|_ {p, var: p.var}
|
||||
if (p & string) != _|_ {"part": p, var: false}
|
||||
}]
|
||||
|
||||
_suffix: strings.Join([ for p in expandedPath {strings.ToTitle(p.part)}], "")
|
||||
|
||||
struct: string | *("LocaleKey" + _resourceExpIdent + _suffix)
|
||||
|
||||
// As soon as we use vars in the path,
|
||||
// custom handler must be present
|
||||
_hasVars: list.Contains([ for p in path {p.var | false}], true)
|
||||
customHandler: bool | *_hasVars
|
||||
|
||||
if customHandler {
|
||||
decodeFunc: string | *("decodeTranslations" + _suffix)
|
||||
encodeFunc: string | *("encodeTranslations" + _suffix)
|
||||
serviceFunc: string | *("handle" + _resourceExpIdent + _suffix)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package schema
|
||||
|
||||
#platform: {
|
||||
ident: #baseHandle | *"corteza"
|
||||
|
||||
components: [...{platform: ident} & #component]
|
||||
|
||||
// env-var definitions
|
||||
// options: {}
|
||||
|
||||
//
|
||||
|
||||
// automation: {
|
||||
// types: ....
|
||||
// function ....
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
#rbacComponent: {
|
||||
resource: {
|
||||
type: string
|
||||
}
|
||||
|
||||
operations: {
|
||||
[key=_]: #rbacOperation & {
|
||||
handle: key
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#rbacResource: {
|
||||
resourceExpIdent: #expIdent
|
||||
|
||||
operations: {
|
||||
[key=_]: #rbacOperation & {
|
||||
handle: key
|
||||
_resourceExpIdent: resourceExpIdent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#rbacOperation: {
|
||||
handle: #handle
|
||||
description: string | *handle
|
||||
_resourceExpIdent?: string
|
||||
|
||||
// Some string manipulation that will result in
|
||||
// more pronouncable access-control check function name
|
||||
|
||||
// When check function name is not explicitly defined we try
|
||||
// to use resource and operation name and generate easy-to-read name
|
||||
//
|
||||
// <res> + <op> => Can<Op><Res>
|
||||
// <res> + <op:foo.bar.verb> => Can<Verb><Foo><Bar>On<Res>
|
||||
|
||||
_operation: strings.Replace(strings.Replace(handle, "-", " ", -1), "_", " ", -1)
|
||||
_opSplit: strings.Split(_operation, ".")
|
||||
_opFlip: [_opSplit[len(_opSplit)-1]] + _opSplit[0:len(_opSplit)-1]
|
||||
_opFinal: strings.Replace(strings.ToTitle(strings.Join(_opFlip, " ")), " ", "", -1)
|
||||
|
||||
if _resourceExpIdent == _|_ {
|
||||
checkFuncName: #expIdent | *("Can" + _opFinal)
|
||||
}
|
||||
|
||||
if _resourceExpIdent != _|_ {
|
||||
checkFuncName: #expIdent | *("Can" + _opFinal + _resourceExpIdent)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package schema
|
||||
|
||||
#resource: #_base & {
|
||||
// copy field values from #_base
|
||||
handle: handle, ident: ident, expIdent: expIdent
|
||||
|
||||
component: #baseHandle | *"component"
|
||||
platform: #baseHandle | *"corteza"
|
||||
|
||||
// Fully qualified resource name
|
||||
fqrn: string | *(platform + "::" + component + ":" + handle)
|
||||
|
||||
// fields: #Fields
|
||||
// operations: #Operations
|
||||
|
||||
// All parent resources
|
||||
parents: [... #_base & {
|
||||
// copy field values from #_base
|
||||
handle: handle, ident: ident, expIdent: expIdent
|
||||
|
||||
refField: #expIdent | *(expIdent + "ID")
|
||||
param: #ident | *(ident + "ID")
|
||||
}]
|
||||
|
||||
// All known RBAC operations for this resource
|
||||
rbac: #rbacResource & {
|
||||
resourceExpIdent: expIdent
|
||||
}
|
||||
|
||||
locale?: #locale & {
|
||||
resourceExpIdent: expIdent
|
||||
resource: {
|
||||
// @todo can we merge this with RBAC type (FQRN?)
|
||||
type: component + ":" + handle
|
||||
}
|
||||
}
|
||||
|
||||
// List of known keys for resource translation
|
||||
// locale?: {
|
||||
// [Name=_]: {
|
||||
// name: Name & #Handle
|
||||
// path: string
|
||||
// custom: bool | *false
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
//#fields: {
|
||||
// // Each field can be
|
||||
// [key=_]: #fields | *({name: key} & #field)
|
||||
//}
|
||||
//
|
||||
//#field: {
|
||||
// name: #expIdent
|
||||
// unique: bool | *false
|
||||
//
|
||||
// // Golang type (built-in or other)
|
||||
// type: string | *"string"
|
||||
//
|
||||
// // System fields,
|
||||
// system: bool | *false
|
||||
//
|
||||
// if name =~ "At$" {
|
||||
// type: string | *"*time.Time"
|
||||
// }
|
||||
//}
|
||||
|
||||
//#Operations: {
|
||||
// [Operation=_]: {operation: Operation} & #Operation
|
||||
//}
|
||||
|
||||
//#Operation: {
|
||||
// name: #ExpIdent
|
||||
// description: string
|
||||
// can: string | false | *"\(name)"
|
||||
//}
|
||||
|
||||
//idField: {
|
||||
// // Expecting ID field to allways have name ID
|
||||
// name: "ID"
|
||||
// unique: true
|
||||
//
|
||||
// // Service fields,
|
||||
// // @todo We might want to have a better name for this
|
||||
// // service: true
|
||||
//
|
||||
// // @todo someday we'll replace this with the "ID" type
|
||||
// type: "uint64"
|
||||
//}
|
||||
//
|
||||
//handleField: {
|
||||
// // Expecting ID field to allways have name ID
|
||||
// name: "handle"
|
||||
// unique: true
|
||||
//
|
||||
// // @todo someday we'll replace this with the "ID" type
|
||||
// type: "string" & #handle
|
||||
//}
|
||||
@@ -0,0 +1,32 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Identifier
|
||||
#ident: =~"^[a-z][a-zA-Z0-9_]*$"
|
||||
|
||||
// Exported identifier
|
||||
#expIdent: =~"^[A-Z][a-zA-Z0-9_]*$"
|
||||
|
||||
// More liberal then identifier, allows underscores and dots
|
||||
#handle: =~"^[A-Za-z][a-zA-Z0-9_\\-\\.]*[a-zA-Z0-9]+$"
|
||||
|
||||
// More liberal then identifier, allows underscores and dots
|
||||
#baseHandle: =~"^[a-z][a-z0-9-]*[a-z0-9]+$"
|
||||
|
||||
#_base: {
|
||||
// lowercase dash-separated words
|
||||
// used to build ident and exported identifiers
|
||||
handle: #baseHandle | *"base"
|
||||
_words: strings.Replace(strings.Replace(strings.Replace(handle, "-", " ", -1), "_", " ", -1), ".", " ", -1)
|
||||
|
||||
// lowercased (unexported, golang) identifier
|
||||
ident: #ident | *strings.ToCamel(strings.Replace(strings.ToTitle(_words), " ", "", -1))
|
||||
|
||||
// upercased (exported, golang) identifier
|
||||
expIdent: #expIdent | *strings.Replace(strings.ToTitle(_words), " ", "", -1)
|
||||
|
||||
...
|
||||
}
|
||||
Reference in New Issue
Block a user