Serve event contraints via API
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -18,9 +18,10 @@ type (
|
||||
}
|
||||
|
||||
eventTypeDef struct {
|
||||
ResourceType string `json:"resourceType"`
|
||||
EventType string `json:"eventType"`
|
||||
Properties []eventTypePropertyDef `json:"properties"`
|
||||
ResourceType string `json:"resourceType"`
|
||||
EventType string `json:"eventType"`
|
||||
Properties []eventTypePropertyDef `json:"properties"`
|
||||
Constraints []eventTypeConstraintDef `json:"constraints"`
|
||||
}
|
||||
|
||||
eventTypePropertyDef struct {
|
||||
@@ -28,6 +29,10 @@ type (
|
||||
Type string `json:"type"`
|
||||
Immutable bool `json:"immutable"`
|
||||
}
|
||||
|
||||
eventTypeConstraintDef struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
)
|
||||
|
||||
func (EventTypes) New() *EventTypes {
|
||||
|
||||
@@ -10,6 +10,9 @@ compose:namespace:
|
||||
- name: 'oldNamespace'
|
||||
type: '*types.Namespace'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: namespace.handle
|
||||
- name: namespace.name
|
||||
|
||||
compose:page:
|
||||
on: ['manual']
|
||||
@@ -23,6 +26,11 @@ compose:page:
|
||||
- name: 'namespace'
|
||||
type: '*types.Namespace'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: namespace.handle
|
||||
- name: namespace.name
|
||||
- name: page.handle
|
||||
- name: page.name
|
||||
|
||||
compose:module:
|
||||
on: ['manual']
|
||||
@@ -36,6 +44,11 @@ compose:module:
|
||||
- name: 'namespace'
|
||||
type: '*types.Namespace'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: namespace.handle
|
||||
- name: namespace.name
|
||||
- name: module.handle
|
||||
- name: module.name
|
||||
|
||||
compose:record:
|
||||
on: ['manual', 'iteration']
|
||||
@@ -54,3 +67,13 @@ compose:record:
|
||||
immutable: true
|
||||
- name: 'recordValueErrors'
|
||||
type: '*types.RecordValueErrorSet'
|
||||
|
||||
constraints:
|
||||
- name: namespace.handle
|
||||
- name: namespace.name
|
||||
- name: module.handle
|
||||
- name: module.name
|
||||
- name: record.created-at
|
||||
- name: record.updated-at
|
||||
- name: record.deleted-at
|
||||
- name: record.values.*
|
||||
|
||||
@@ -13,7 +13,7 @@ func (res namespaceBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
// Handles namespace matchers
|
||||
func namespaceMatch(r *types.Namespace, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
case "namespace", "namespace.slug":
|
||||
case "namespace", "namespace.slug", "namespace.handle":
|
||||
return c.Match(r.Slug)
|
||||
case "namespace.name":
|
||||
return c.Match(r.Name)
|
||||
|
||||
@@ -22,11 +22,11 @@ func (res recordBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
|
||||
func recordMatch(r *types.Record, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
case "record.updatedAt":
|
||||
case "record.updatedAt", "record.updated-at":
|
||||
return c.Match(r.UpdatedAt.Format(time.RFC3339))
|
||||
case "record.createdAt":
|
||||
case "record.createdAt", "record.created-at":
|
||||
return c.Match(r.CreatedAt.Format(time.RFC3339))
|
||||
case "record.deletedAt":
|
||||
case "record.deletedAt", "record.deleted-at":
|
||||
return c.Match(r.DeletedAt.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
|
||||
@@ -4,14 +4,10 @@ package rest
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// {{ .Source }}
|
||||
|
||||
func getEventTypeDefinitions() []eventTypeDef {
|
||||
return []eventTypeDef{
|
||||
{{ range .Definitions }}
|
||||
// {{ printf "%#v" .Imports }}
|
||||
{{ range $r := .Resources }}
|
||||
{{ template "eventTypeDefinitions" dict "res" $r "type" "on" "types" .On }}
|
||||
{{ template "eventTypeDefinitions" dict "res" $r "type" "before" "types" .BeforeAfter }}
|
||||
@@ -37,6 +33,13 @@ func getEventTypeDefinitions() []eventTypeDef {
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
},
|
||||
Constraints: []eventTypeConstraintDef{
|
||||
{{ range $.res.Constraints }}
|
||||
{
|
||||
Name: {{ printf "%q" .Name }},
|
||||
},
|
||||
{{ end }}
|
||||
},
|
||||
},
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
@@ -38,10 +38,11 @@ type (
|
||||
// used for filename
|
||||
ResourceFile string
|
||||
|
||||
On []string `yaml:"on"`
|
||||
BeforeAfter []string `yaml:"ba"`
|
||||
Properties []*eventProps `yaml:"props"`
|
||||
Result string `yaml:"result"`
|
||||
On []string `yaml:"on"`
|
||||
BeforeAfter []string `yaml:"ba"`
|
||||
Properties []*eventProps `yaml:"props"`
|
||||
Constraints []*eventConstraint `yaml:"constraints"`
|
||||
Result string `yaml:"result"`
|
||||
}
|
||||
|
||||
eventProps struct {
|
||||
@@ -58,6 +59,10 @@ type (
|
||||
// Do not allow change of the variable through
|
||||
Immutable bool
|
||||
}
|
||||
|
||||
eventConstraint struct {
|
||||
Name string
|
||||
}
|
||||
)
|
||||
|
||||
func procEvents(mm ...string) (dd []*eventsDef, err error) {
|
||||
|
||||
@@ -2,18 +2,23 @@ package event
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza-server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
)
|
||||
|
||||
var _ = eventbus.ConstraintMaker
|
||||
|
||||
// Match returns false if given conditions do not match event & resource internals
|
||||
func (res authClientBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
// By default we match no mather what kind of constraints we receive
|
||||
//
|
||||
// Function will be called multiple times - once for every trigger constraint
|
||||
// All should match (return true):
|
||||
// constraint#1 AND constraint#2 AND constraint#3 ...
|
||||
//
|
||||
// When there are multiple values, Match() can decide how to treat them (OR, AND...)
|
||||
return true
|
||||
return authClientMatch(res.authClient, c)
|
||||
}
|
||||
|
||||
// Handles application matchers
|
||||
func authClientMatch(r *types.AuthClient, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
// not supported yet
|
||||
case "auth-client", "auth-client.handle":
|
||||
return c.Match(r.Handle)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -9,12 +9,30 @@ system:sink:
|
||||
- name: 'request'
|
||||
type: '*types.SinkRequest'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: request.host
|
||||
- name: request.remote-address
|
||||
- name: request.method
|
||||
- name: request.path
|
||||
- name: request.username
|
||||
- name: request.password
|
||||
- name: request.content-type
|
||||
- name: request.get.*
|
||||
- name: request.post.*
|
||||
- name: request.header.*
|
||||
|
||||
system:mail:
|
||||
on: ['manual', 'receive', 'send']
|
||||
props:
|
||||
- name: 'message'
|
||||
type: '*types.MailMessage'
|
||||
constraints:
|
||||
- name: message.header.subject
|
||||
- name: message.header.from
|
||||
- name: message.header.to
|
||||
- name: message.header.reply-to
|
||||
- name: message.header.cc
|
||||
- name: message.header.bcc
|
||||
|
||||
system:auth:
|
||||
ba: ['login', 'signup']
|
||||
@@ -23,6 +41,9 @@ system:auth:
|
||||
type: '*types.User'
|
||||
- name: 'provider'
|
||||
type: '*types.AuthProvider'
|
||||
constraints:
|
||||
- name: user.handle
|
||||
- name: user.email
|
||||
|
||||
system:auth-client:
|
||||
on: ['manual']
|
||||
@@ -33,6 +54,9 @@ system:auth-client:
|
||||
- name: 'oldAuthClient'
|
||||
type: '*types.AuthClient'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: auth-client.handle
|
||||
|
||||
|
||||
system:user:
|
||||
on: ['manual']
|
||||
@@ -43,6 +67,9 @@ system:user:
|
||||
- name: 'oldUser'
|
||||
type: '*types.User'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: user.handle
|
||||
- name: user.email
|
||||
|
||||
system:role:
|
||||
on: ['manual']
|
||||
@@ -53,6 +80,9 @@ system:role:
|
||||
- name: 'oldRole'
|
||||
type: '*types.Role'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: role.handle
|
||||
- name: role.name
|
||||
|
||||
system:role:member:
|
||||
ba: ['add', 'remove']
|
||||
@@ -61,6 +91,12 @@ system:role:member:
|
||||
type: '*types.User'
|
||||
- name: 'role'
|
||||
type: '*types.Role'
|
||||
constraints:
|
||||
- name: role.handle
|
||||
- name: role.name
|
||||
- name: user.handle
|
||||
- name: user.email
|
||||
|
||||
|
||||
system:application:
|
||||
on: ['manual']
|
||||
@@ -71,3 +107,5 @@ system:application:
|
||||
- name: 'oldApplication'
|
||||
type: '*types.Application'
|
||||
immutable: true
|
||||
constraints:
|
||||
- name: application.name
|
||||
|
||||
@@ -21,17 +21,17 @@ func (res mailBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
// Handles role matchers
|
||||
func mailMatch(r *types.MailMessage, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
case "mail.header.subject":
|
||||
case "message.header.subject", "mail.header.subject":
|
||||
return c.Match(r.Subject)
|
||||
case "mail.header.from":
|
||||
case "message.header.from", "mail.header.from":
|
||||
return mailMatchAnyAddress(c, r.Header.From...)
|
||||
case "mail.header.to":
|
||||
case "message.header.to", "mail.header.to":
|
||||
return mailMatchAnyAddress(c, r.Header.To...)
|
||||
case "mail.header.replyTo":
|
||||
case "message.header.reply-to", "mail.header.replyTo":
|
||||
return mailMatchAnyAddress(c, r.Header.ReplyTo...)
|
||||
case "mail.header.cc":
|
||||
case "message.header.cc", "mail.header.cc":
|
||||
return mailMatchAnyAddress(c, r.Header.CC...)
|
||||
case "mail.header.bcc":
|
||||
case "message.header.bcc", "mail.header.bcc":
|
||||
return mailMatchAnyAddress(c, r.Header.BCC...)
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@ func (res sinkBase) Match(c eventbus.ConstraintMatcher) bool {
|
||||
// Handles sink's URL matchers
|
||||
func sinkMatch(r *types.SinkRequest, c eventbus.ConstraintMatcher) bool {
|
||||
switch c.Name() {
|
||||
case "request.remoteAddress":
|
||||
case "request.host":
|
||||
return c.Match(r.Host)
|
||||
case "request.remoteAddress", "request.remote-address":
|
||||
return c.Match(r.RemoteAddr)
|
||||
case "request.method":
|
||||
return c.Match(r.Method)
|
||||
|
||||
Reference in New Issue
Block a user