Skip to content

Commit

Permalink
Merge pull request #1475 from eladperets/master
Browse files Browse the repository at this point in the history
Add new policy 'count' expressions
  • Loading branch information
anthony-c-martin authored Jan 22, 2021
2 parents 904daf3 + 04bef46 commit 0e1c9ba
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 19 deletions.
2 changes: 1 addition & 1 deletion schemas/2015-10-01-preview/policyDefinition.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "https://schema.management.azure.com/schemas/2015-10-01-preview/policyDefinition.json#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Policy Definition",
"description": "This schema defines Azure resource policy definition, please see https://azure.microsoft.com/en-us/documentation/articles/resource-manager-policy/ for more details.",
"description": "This schema defines Azure Policy definition policy rules. For more details, see https://docs.microsoft.com/azure/governance/policy/.",
"type": "object",
"properties": {
"if": {
Expand Down
2 changes: 1 addition & 1 deletion schemas/2016-12-01/policyDefinition.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "https://schema.management.azure.com/schemas/2016-12-01/policyDefinition.json#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Policy Definition",
"description": "This schema defines Azure resource policy definition, please see https://azure.microsoft.com/en-us/documentation/articles/resource-manager-policy/ for more details.",
"description": "This schema defines Azure Policy definition policy rules. For more details, see https://docs.microsoft.com/azure/governance/policy/.",
"type": "object",
"properties": {
"if": {
Expand Down
2 changes: 1 addition & 1 deletion schemas/2018-05-01/policyDefinition.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "https://schema.management.azure.com/schemas/2018-05-01/policyDefinition.json#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Policy Definition",
"description": "This schema defines Azure resource policy definition, please see https://azure.microsoft.com/en-us/documentation/articles/resource-manager-policy/ for more details.",
"description": "This schema defines Azure Policy definition policy rules. For more details, see https://docs.microsoft.com/azure/governance/policy/.",
"type": "object",
"properties": {
"if": {
Expand Down
2 changes: 1 addition & 1 deletion schemas/2019-01-01/policyDefinition.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "https://schema.management.azure.com/schemas/2019-01-01/policyDefinition.json#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Policy Definition",
"description": "This schema defines Azure resource policy definition, please see https://azure.microsoft.com/documentation/articles/resource-manager-policy/ for more details.",
"description": "This schema defines Azure Policy definition policy rules. For more details, see https://docs.microsoft.com/azure/governance/policy/.",
"type": "object",
"properties": {
"if": {
Expand Down
2 changes: 1 addition & 1 deletion schemas/2019-06-01/policyDefinition.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "https://schema.management.azure.com/schemas/2019-06-01/policyDefinition.json#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Policy Definition",
"description": "This schema defines Azure resource policy definition, please see https://azure.microsoft.com/documentation/articles/resource-manager-policy/ for more details.",
"description": "This schema defines Azure Policy definition policy rules. For more details, see https://docs.microsoft.com/azure/governance/policy/.",
"type": "object",
"properties": {
"if": {
Expand Down
50 changes: 37 additions & 13 deletions schemas/2019-09-01/policyDefinition.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,21 +348,45 @@
]
},
"countExpression": {
"properties": {
"field": {
"type": "string"
"oneOf": [
{
"properties": {
"field": {
"type": "string"
},
"where": {
"oneOf": [
{ "$ref": "#/definitions/condition" },
{ "$ref": "#/definitions/operatorNot" },
{ "$ref": "#/definitions/operatorAnyOf" },
{ "$ref": "#/definitions/operatorAllOf" }
]
}
},
"required": [ "field" ],
"additionalProperties": false
},
"where": {
"oneOf": [
{ "$ref": "#/definitions/condition" },
{ "$ref": "#/definitions/operatorNot" },
{ "$ref": "#/definitions/operatorAnyOf" },
{ "$ref": "#/definitions/operatorAllOf" }
]
{
"properties": {
"value": {
"type": [ "array", "string" ]
},
"name": {
"type": "string"
},
"where": {
"oneOf": [
{ "$ref": "#/definitions/condition" },
{ "$ref": "#/definitions/operatorNot" },
{ "$ref": "#/definitions/operatorAnyOf" },
{ "$ref": "#/definitions/operatorAllOf" }
]
}
},
"required": [ "value" ],
"additionalProperties": false
}
},
"required": [ "field" ],
"additionalProperties": false
]
},
"operatorNot": {
"properties": {
Expand Down
63 changes: 62 additions & 1 deletion tests/2019-09-01/policyDefinition.tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
}
},
{
"name": "PolicyDefinition tests - valid complex count condition",
"name": "PolicyDefinition tests - valid complex field count condition",
"definition": "https://schema.management.azure.com/schemas/2019-09-01/policyDefinition.json#",
"json": {
"if": {
Expand Down Expand Up @@ -93,6 +93,67 @@
}
}
},
{
"name": "PolicyDefinition tests - valid value count conditions",
"definition": "https://schema.management.azure.com/schemas/2019-09-01/policyDefinition.json#",
"json": {
"if": {
"allOf": [
{
"count": {
"value": []
},
"greater": 0
},
{
"count": {
"value": [],
"name": "currentValue"
},
"greater": 0
},
{
"count": {
"value": [],
"name": "currentValue",
"where": {
"value": "[current('currentValue')]",
"equals": 1
}
},
"greater": 0
},
{
"count": {
"value": "[parameters('arrayParam')]"
},
"greater": 0
},
{
"count": {
"value": "[parameters('arrayParam')]",
"name": "currentValue"
},
"greater": 0
},
{
"count": {
"value": "[parameters('arrayParam')]",
"name": "currentValue",
"where": {
"value": "[current('currentValue')]",
"equals": 1
}
},
"greater": 0
}
]
},
"then": {
"effect": "deny"
}
}
},
{
"name": "PolicyDefinition tests - valid append details",
"definition": "https://schema.management.azure.com/schemas/2019-09-01/policyDefinition.json#",
Expand Down

0 comments on commit 0e1c9ba

Please sign in to comment.