Note that I think the obligations should be parsed in the front-end parser, but because the linearization (flattening of the nested contexts) is currently be done in the back-end compiler, the changes for obligations support is all in the back-end side. In a future enhancement, I think the linearization should be done in the front-end parser so that a flattened out AST is available to all back-end compilers.
$ make test
? github.com/infobloxopen/seal [no test files]
? github.com/infobloxopen/seal/cmd [no test files]
? github.com/infobloxopen/seal/pkg/ast [no test files]
? github.com/infobloxopen/seal/pkg/compiler [no test files]
? github.com/infobloxopen/seal/pkg/compiler/error [no test files]
=== RUN TestCompile
rego_test.go:180: validate policy: allow subject group foo to manage petstore.pet;
rego_test.go:181: rego language output generated:
package foo
default allow = false
default deny = false
base_verbs := {
}
allow {
seal_list_contains(seal_subject.groups, `foo`)
seal_list_contains(base_verbs[input.type][`manage`], input.verb)
re_match(`petstore.pet`, input.type)
}
obligations := [
]
# rego functions defined by seal
# Helper to get the token payload.
seal_subject = payload {
[header, payload, signature] := io.jwt.decode(input.jwt)
}
# seal_list_contains returns true if elem exists in list
seal_list_contains(list, elem) {
list[_] = elem
}
rego_test.go:180: validate policy: allow subject user foo to manage petstore.pet;
rego_test.go:181: rego language output generated:
package foo
default allow = false
default deny = false
base_verbs := {
}
allow {
seal_subject.sub == `foo`
seal_list_contains(base_verbs[input.type][`manage`], input.verb)
re_match(`petstore.pet`, input.type)
}
obligations := [
]
# rego functions defined by seal
# Helper to get the token payload.
seal_subject = payload {
[header, payload, signature] := io.jwt.decode(input.jwt)
}
# seal_list_contains returns true if elem exists in list
seal_list_contains(list, elem) {
list[_] = elem
}
--- PASS: TestCompile (0.00s)
PASS
ok github.com/infobloxopen/seal/pkg/compiler/rego (cached)
=== RUN TestCompiler
--- PASS: TestCompiler (0.00s)
=== RUN TestLanguages
compiler_test.go:86: validate list of languages - supported languages: []string{"rego"}
--- PASS: TestLanguages (0.00s)
=== RUN TestBackend
=== RUN TestBackend/invalid-nonwildcarded-resource-property-with-subject
=== RUN TestBackend/multiple-statements
=== RUN TestBackend/matches
=== RUN TestBackend/in-operator
=== RUN TestBackend/obligations-multi-oblig-in-single-stmt
=== RUN TestBackend/blank-swagger
=== RUN TestBackend/missing-verb-errors
=== RUN TestBackend/missing-resource-errors
=== RUN TestBackend/invalid-nonwildcarded-resource-property
=== RUN TestBackend/grouping-with-parens
=== RUN TestBackend/tags
=== RUN TestBackend/context-2
=== RUN TestBackend/grouping-with-not-and-parens
=== RUN TestBackend/context
=== RUN TestBackend/invalid-resource-format-without-using-family.type-errors
=== RUN TestBackend/statement-with-not
=== RUN TestBackend/obligations-simple
=== RUN TestBackend/obligations-multi-stmt-with-oblig
=== RUN TestBackend/missing-to-errors
=== RUN TestBackend/precedence-with-not
=== RUN TestBackend/blank-subject
=== RUN TestBackend/no-swagger-actions
=== RUN TestBackend/support-for-or-operator-simple
=== RUN TestBackend/support-for-or-operator-context
=== RUN TestBackend/company.personnel
=== RUN TestBackend/context-nested
=== RUN TestBackend/obligations-context
=== RUN TestBackend/invalid-resource-not-registered
=== RUN TestBackend/invalid-nonwildcarded-resource-property-in-context
=== RUN TestBackend/simplest-statement-with-subject
=== RUN TestBackend/statement-with-and
=== RUN TestBackend/not-in-operator
=== RUN TestBackend/obligations-wildcard
--- PASS: TestBackend (0.07s)
--- PASS: TestBackend/invalid-nonwildcarded-resource-property-with-subject (0.00s)
--- PASS: TestBackend/multiple-statements (0.00s)
--- PASS: TestBackend/matches (0.00s)
--- PASS: TestBackend/in-operator (0.00s)
--- PASS: TestBackend/obligations-multi-oblig-in-single-stmt (0.00s)
--- PASS: TestBackend/blank-swagger (0.00s)
--- PASS: TestBackend/missing-verb-errors (0.00s)
--- PASS: TestBackend/missing-resource-errors (0.00s)
--- PASS: TestBackend/invalid-nonwildcarded-resource-property (0.00s)
--- PASS: TestBackend/grouping-with-parens (0.00s)
--- PASS: TestBackend/tags (0.00s)
--- PASS: TestBackend/context-2 (0.00s)
--- PASS: TestBackend/grouping-with-not-and-parens (0.00s)
--- PASS: TestBackend/context (0.00s)
--- PASS: TestBackend/invalid-resource-format-without-using-family.type-errors (0.00s)
--- PASS: TestBackend/statement-with-not (0.00s)
--- PASS: TestBackend/obligations-simple (0.00s)
--- PASS: TestBackend/obligations-multi-stmt-with-oblig (0.00s)
--- PASS: TestBackend/missing-to-errors (0.00s)
--- PASS: TestBackend/precedence-with-not (0.00s)
--- PASS: TestBackend/blank-subject (0.00s)
--- PASS: TestBackend/no-swagger-actions (0.00s)
--- PASS: TestBackend/support-for-or-operator-simple (0.00s)
--- PASS: TestBackend/support-for-or-operator-context (0.00s)
--- PASS: TestBackend/company.personnel (0.00s)
--- PASS: TestBackend/context-nested (0.00s)
--- PASS: TestBackend/obligations-context (0.00s)
--- PASS: TestBackend/invalid-resource-not-registered (0.00s)
--- PASS: TestBackend/invalid-nonwildcarded-resource-property-in-context (0.00s)
--- PASS: TestBackend/simplest-statement-with-subject (0.00s)
--- PASS: TestBackend/statement-with-and (0.00s)
--- PASS: TestBackend/not-in-operator (0.00s)
--- PASS: TestBackend/obligations-wildcard (0.00s)
=== RUN TestManySwaggers
=== RUN TestManySwaggers/empty
=== RUN TestManySwaggers/global-sw1-sw2
=== RUN TestManySwaggers/global-sw2-sw1
=== RUN TestManySwaggers/sw1
=== RUN TestManySwaggers/sw2
=== RUN TestManySwaggers/global
--- PASS: TestManySwaggers (0.01s)
--- PASS: TestManySwaggers/empty (0.00s)
--- PASS: TestManySwaggers/global-sw1-sw2 (0.00s)
--- PASS: TestManySwaggers/global-sw2-sw1 (0.00s)
--- PASS: TestManySwaggers/sw1 (0.00s)
--- PASS: TestManySwaggers/sw2 (0.00s)
--- PASS: TestManySwaggers/global (0.00s)
PASS
ok github.com/infobloxopen/seal/pkg/compiler/test (cached)
=== RUN TestNextToken
--- PASS: TestNextToken (0.00s)
=== RUN TestContextToken
--- PASS: TestContextToken (0.00s)
=== RUN TestNextTokenComment
--- PASS: TestNextTokenComment (0.00s)
PASS
ok github.com/infobloxopen/seal/pkg/lexer (cached)
=== RUN TestWhereClause
=== RUN TestWhereClause/simple_user
=== RUN TestWhereClause/simple_group
=== RUN TestWhereClause/simple_where_clause_compare_equal
=== RUN TestWhereClause/simple_where_clause_compare_not_equal
=== RUN TestWhereClause/simple_where_clause_compare_int
=== RUN TestWhereClause/simple_where_clause_compare_bool
=== RUN TestWhereClause/single_where_clause_and
=== RUN TestWhereClause/left_associative_where_clause_and
=== RUN TestWhereClause/where_clause_grouped_conditions
=== RUN TestWhereClause/where_clause_multiple_grouped_conditions
--- PASS: TestWhereClause (0.00s)
--- PASS: TestWhereClause/simple_user (0.00s)
--- PASS: TestWhereClause/simple_group (0.00s)
--- PASS: TestWhereClause/simple_where_clause_compare_equal (0.00s)
--- PASS: TestWhereClause/simple_where_clause_compare_not_equal (0.00s)
--- PASS: TestWhereClause/simple_where_clause_compare_int (0.00s)
--- PASS: TestWhereClause/simple_where_clause_compare_bool (0.00s)
--- PASS: TestWhereClause/single_where_clause_and (0.00s)
--- PASS: TestWhereClause/left_associative_where_clause_and (0.00s)
--- PASS: TestWhereClause/where_clause_grouped_conditions (0.00s)
--- PASS: TestWhereClause/where_clause_multiple_grouped_conditions (0.00s)
=== RUN TestLetStatements
--- PASS: TestLetStatements (0.00s)
PASS
ok github.com/infobloxopen/seal/pkg/parser (cached)
=== RUN TestLookupOperator
=== RUN TestLookupOperator/invalid_empty
=== RUN TestLookupOperator/equal_to
=== RUN TestLookupOperator/not_equal
=== RUN TestLookupOperator/less_than
=== RUN TestLookupOperator/greater_than
=== RUN TestLookupOperator/less_than_or_equal_to
=== RUN TestLookupOperator/greater_than_or_equal_to
=== RUN TestLookupOperator/not
=== RUN TestLookupOperator/and
=== RUN TestLookupOperator/or
=== RUN TestLookupOperator/matches
--- PASS: TestLookupOperator (0.00s)
--- PASS: TestLookupOperator/invalid_empty (0.00s)
--- PASS: TestLookupOperator/equal_to (0.00s)
--- PASS: TestLookupOperator/not_equal (0.00s)
--- PASS: TestLookupOperator/less_than (0.00s)
--- PASS: TestLookupOperator/greater_than (0.00s)
--- PASS: TestLookupOperator/less_than_or_equal_to (0.00s)
--- PASS: TestLookupOperator/greater_than_or_equal_to (0.00s)
--- PASS: TestLookupOperator/not (0.00s)
--- PASS: TestLookupOperator/and (0.00s)
--- PASS: TestLookupOperator/or (0.00s)
--- PASS: TestLookupOperator/matches (0.00s)
PASS
ok github.com/infobloxopen/seal/pkg/token (cached)
=== RUN TestIsNilInterface
--- PASS: TestIsNilInterface (0.00s)
=== RUN TestNewTypeFromOpenAPIv3
types_test.go:17: got type: petstore.pet
types_test.go:19: got action: &types.swaggerAction{name:"allow", schema:(*openapi3.SchemaRef)(0xc00000efa0)}
types_test.go:23: TODO: get type schema for action
types_test.go:19: got action: &types.swaggerAction{name:"deny", schema:(*openapi3.SchemaRef)(nil)}
types_test.go:23: TODO: get type schema for action
--- PASS: TestNewTypeFromOpenAPIv3 (0.00s)
PASS
ok github.com/infobloxopen/seal/pkg/types (cached)
Note that I think the obligations should be parsed in the front-end parser, but because the linearization (flattening of the nested contexts) is currently be done in the back-end compiler, the changes for obligations support is all in the back-end side. In a future enhancement, I think the linearization should be done in the front-end parser so that a flattened out AST is available to all back-end compilers.