-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rtOpts so validator can reference custom functions (#48)
Add rtOpts so validator can reference custom functions
- Loading branch information
1 parent
756118d
commit 2ad8ac2
Showing
15 changed files
with
226 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
1 change: 1 addition & 0 deletions
1
test/testdata/validator_with_custom_function/instance.invalid_port.compile.err
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ERROR: ../../test/testdata/validator_with_custom_function/instance.invalid_port.yaml:-1:0: invalid port |
21 changes: 21 additions & 0 deletions
21
test/testdata/validator_with_custom_function/instance.invalid_port.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: policy.acme.co/v1 | ||
kind: validator_with_custom_function | ||
metadata: | ||
name: instance_with_port | ||
namespace: acme | ||
rule: | ||
port: "-1" |
21 changes: 21 additions & 0 deletions
21
test/testdata/validator_with_custom_function/instance.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: policy.acme.co/v1 | ||
kind: validator_with_custom_function | ||
metadata: | ||
name: instance_with_port | ||
namespace: acme | ||
rule: | ||
port: "22-60" |
Empty file.
6 changes: 6 additions & 0 deletions
6
test/testdata/validator_with_custom_function/template.invalid_function.compile.err
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ERROR: ../../test/testdata/validator_with_custom_function/template.invalid_function.yaml:30:23: undeclared reference to 'invalidFunc' (in container '') | ||
| - match: invalidFunc(rule.port) < 0 | ||
| ......................^ | ||
ERROR: ../../test/testdata/validator_with_custom_function/template.invalid_function.yaml:31:15: undeclared reference to 'invalidFunc' (in container '') | ||
| message: "invalidFunc" | ||
| ..............^ |
37 changes: 37 additions & 0 deletions
37
test/testdata/validator_with_custom_function/template.invalid_function.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: policy.acme.co/v1 | ||
kind: PolicyTemplate | ||
metadata: | ||
name: validator_with_custom_function | ||
schema: | ||
type: object | ||
description: Policy with validator referencing to custom function. | ||
properties: | ||
port: | ||
description: > | ||
port contains a string which could be a range ex : "22-44" or "22". | ||
It has to be a positive number and less than 65535 | ||
type: string | ||
validator: | ||
productions: | ||
- match: invalidFunc(rule.port) < 0 | ||
message: "invalidFunc" | ||
|
||
evaluator: | ||
productions: | ||
- match: rule.port != '' | ||
decision: policy.report | ||
output: rule.port |
41 changes: 41 additions & 0 deletions
41
test/testdata/validator_with_custom_function/template.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: policy.acme.co/v1 | ||
kind: PolicyTemplate | ||
metadata: | ||
name: validator_with_custom_function | ||
schema: | ||
type: object | ||
description: Policy with validator referencing to custom function. | ||
properties: | ||
port: | ||
description: > | ||
port contains a string which could be a range ex : "22-44" or "22". | ||
It has to be a positive number and less than 65535 | ||
type: string | ||
validator: | ||
productions: | ||
- match: > | ||
has(rule.port) && ( | ||
rangeLow(rule.port) < 0 | ||
|| rangeHigh(rule.port) > 65535 | ||
|| rangeLow(rule.port) > rangeHigh(rule.port)) | ||
message: "invalid port. allowed port range is [0, 65535]" | ||
evaluator: | ||
productions: | ||
- match: rule.port != '' | ||
decision: policy.report | ||
output: rule.port |