Skip to content

Commit 3581c62

Browse files
committed
Fix GET detail route when id is array (single vs multi-id)
Use /endpoint/{id}/ only for scalar or one-element id; keep list endpoint and pass id as query params for multiple ids. Fixes 404 with stackstorm-netbox v3.4.x.
1 parent 69cb91a commit 3581c62

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

actions/run.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,37 @@ def run(self, endpoint_uri, http_verb, get_detail_route_eligible, fail_non_2xx,
1515
StackStorm action entry point.
1616
"""
1717
if http_verb == "get":
18-
if kwargs.get("id", False) and get_detail_route_eligible:
19-
# modify the `endpoint_uri` to use the detail route
20-
endpoint_uri = "{}{}/".format(endpoint_uri, str(kwargs.pop("id")))
21-
self.logger.debug(
22-
"endpoint_uri transformed to {} because id was passed".format(endpoint_uri)
23-
)
18+
if get_detail_route_eligible and "id" in kwargs:
19+
id_param = kwargs["id"]
20+
# Scalar or 1-elem list -> detail route; multi-elem list -> list filter
21+
if isinstance(id_param, (list, tuple)):
22+
if len(id_param) == 1:
23+
detail_id = id_param[0]
24+
kwargs.pop("id")
25+
endpoint_uri = "{}{}/".format(endpoint_uri, str(detail_id))
26+
self.logger.debug(
27+
"endpoint_uri transformed to {} (single id from list)".format(
28+
endpoint_uri
29+
)
30+
)
31+
# else: len > 1 -> keep id in kwargs for list filter, no endpoint change
32+
else:
33+
# scalar id -> detail route
34+
detail_id = kwargs.pop("id")
35+
endpoint_uri = "{}{}/".format(endpoint_uri, str(detail_id))
36+
self.logger.debug(
37+
"endpoint_uri transformed to {} because id was passed".format(
38+
endpoint_uri
39+
)
40+
)
2441

25-
if kwargs.get("save_in_key_store") and not kwargs.get("save_in_key_store_key_name"):
26-
return (False, "save_in_key_store_key_name MUST be used with save_in_key_store!")
42+
if kwargs.get("save_in_key_store") and not kwargs.get(
43+
"save_in_key_store_key_name"
44+
):
45+
return (
46+
False,
47+
"save_in_key_store_key_name MUST be used with save_in_key_store!",
48+
)
2749

2850
result = self.make_request(endpoint_uri, http_verb, **kwargs)
2951

@@ -38,7 +60,9 @@ def run(self, endpoint_uri, http_verb, get_detail_route_eligible, fail_non_2xx,
3860
key_name = kwargs["save_in_key_store_key_name"]
3961
client.keys.update(
4062
KeyValuePair(
41-
name=key_name, value=json.dumps(result), ttl=kwargs["save_in_key_store_ttl"]
63+
name=key_name,
64+
value=json.dumps(result),
65+
ttl=kwargs["save_in_key_store_ttl"],
4266
)
4367
)
4468

0 commit comments

Comments
 (0)