Description
client.zia.cloudappcontrol.list_rules(rule_type) fails for an entire rule type as soon as it encounters one rule that has a Cloud App Risk Profile assigned since it treats the cloudAppRiskProfile field as an array but Zscaler API returns a single json object. The call returns (None, response, error), where error is a bare KeyError(0).
Reproduction
In a ZIA tenant, create (or use an existing) Cloud App Control rule under the AI_ML category and attach a Cloud App Risk Profile to it.
Run:
python
from zscaler import ZscalerClient
config = {
"clientId": "...",
"clientSecret": "...",
"vanityDomain": "...",
}
with ZscalerClient(config) as client:
rules, response, error = client.zia.cloudappcontrol.list_rules("AI_ML")
print(rules, error)
Expected behavior
Returns the rules for that cloud app control rule type even if one of them has a cloud app risk profile with no error.
Root cause
webApplicationRules/{ruleType} returns cloudAppRiskProfile as a single JSON object, not an array, e.g.:
json
"cloudAppRiskProfile": {
"id": 2724,
"name": "Unsanctioned Risk 5"
}
But the model class treats this field as a list and runs it through ZscalerCollection.form_list():
python
zscaler/zia/models/cloudappcontrol.py
self.cloud_app_risk_profile = ZscalerCollection.form_list(
config["cloudAppRiskProfile"] if "cloudAppRiskProfile" in config else [], common_reference.ResourceReference
)
python
zscaler/oneapi_collection.py
@staticmethod
def form_list(collection: List[Any], data_type: Type[T]) -> List[T]:
if not collection:
return []
for index in range(len(collection)):
if not ZscalerCollection.is_formed(collection[index], data_type):
collection[index] = data_type(collection[index])
return collection
Since cloudAppRiskProfile is a dict with 2 keys (id, name), len(collection) evaluates to 2, and collection[0] indexes the dict with the integer 0 instead of a valid key, raising KeyError: 0.
Other Information
- OS: [windows]
- Version: [1.9.44]
Description
client.zia.cloudappcontrol.list_rules(rule_type) fails for an entire rule type as soon as it encounters one rule that has a Cloud App Risk Profile assigned since it treats the cloudAppRiskProfile field as an array but Zscaler API returns a single json object. The call returns (None, response, error), where error is a bare KeyError(0).
Reproduction
In a ZIA tenant, create (or use an existing) Cloud App Control rule under the AI_ML category and attach a Cloud App Risk Profile to it.
Run:
python
from zscaler import ZscalerClient
config = {
"clientId": "...",
"clientSecret": "...",
"vanityDomain": "...",
}
with ZscalerClient(config) as client:
rules, response, error = client.zia.cloudappcontrol.list_rules("AI_ML")
print(rules, error)
Expected behavior
Returns the rules for that cloud app control rule type even if one of them has a cloud app risk profile with no error.
Root cause
webApplicationRules/{ruleType} returns cloudAppRiskProfile as a single JSON object, not an array, e.g.:
json
"cloudAppRiskProfile": {
"id": 2724,
"name": "Unsanctioned Risk 5"
}
But the model class treats this field as a list and runs it through ZscalerCollection.form_list():
python
zscaler/zia/models/cloudappcontrol.py
self.cloud_app_risk_profile = ZscalerCollection.form_list(
config["cloudAppRiskProfile"] if "cloudAppRiskProfile" in config else [], common_reference.ResourceReference
)
python
zscaler/oneapi_collection.py
@staticmethod
def form_list(collection: List[Any], data_type: Type[T]) -> List[T]:
if not collection:
return []
for index in range(len(collection)):
if not ZscalerCollection.is_formed(collection[index], data_type):
collection[index] = data_type(collection[index])
return collection
Since cloudAppRiskProfile is a dict with 2 keys (id, name), len(collection) evaluates to 2, and collection[0] indexes the dict with the integer 0 instead of a valid key, raising KeyError: 0.
Other Information