nautobot-app-firewall-models icon indicating copy to clipboard operation
nautobot-app-firewall-models copied to clipboard

Unable to set policy_rules when updating policy via API

Open bdd4329 opened this issue 1 year ago • 0 comments

Environment

  • Python version: 3.9
  • Nautobot version: 1.5.7
  • nautobot-plugin-firewall-model version: 1.1.3

I'm using the OpenAPI docs (i.e., http://localhost:8080/api/docs/#/), and I'm unable to add policy_rules via the /api/plugins/firewall/policy/ endpoint using PUT, PATCH, or POST. I've verified that the policy and the policy rule UUIDs are correct. The same operation works correctly via web interface.

PUT request body to /api/plugins/firewall/policy/:

[
  {
    "id": "5b729dd5-daeb-418c-ba43-51f4acc76fc3",
    "name": "ngen-poc-switch-177",
    "policy_rules": [
      "f03e3ee9-0a84-4609-917d-5af6ca0765c6"
    ]
  }
]

Expected Behavior

policy rules should be added

Observed Behavior

No policy rules are added. I get a 200 response as follows:

[
  {
    "id": "5b729dd5-daeb-418c-ba43-51f4acc76fc3",
    "display": "ngen-poc-switch-177",
    "tags": [],
    "status": {
      "value": "active",
      "label": "Active"
    },
    "relationships": {},
    "computed_fields": {},
    "custom_fields": {},
    "notes_url": "http://localhost:8080/api/plugins/firewall/policy/5b729dd5-daeb-418c-ba43-51f4acc76fc3/notes/",
    "url": "http://localhost:8080/api/plugins/firewall/policy/5b729dd5-daeb-418c-ba43-51f4acc76fc3/",
    "assigned_devices": [
      {
        "device": "828245e0-ea43-4860-a6b0-d32cc262470f",
        "weight": 100
      }
    ],
    "assigned_dynamic_groups": [],
    "created": "2023-01-08",
    "last_updated": "2023-01-08T23:09:10.969667Z",
    "_custom_field_data": {},
    "description": "",
    "name": "ngen-poc-switch-177",
    "tenant": null,
    "policy_rules": []
  }
]

The policy_rules field is always empty unless I add a policy rule via the web interface, which works properly.

Steps to Reproduce

  1. Create a policy rule
  2. Create a policy
  3. Assign a device to the policy
  4. Use an API PATCH, POST, or PUT operation to add a policy_rule to a policy.

bdd4329 avatar Jan 08 '23 23:01 bdd4329