MCPcopy Create free account
hub / github.com/StackStorm/st2 / get_pack_resource_file_abs_path

Function get_pack_resource_file_abs_path

st2common/st2common/content/utils.py:318–352  ·  view source on GitHub ↗

Retrieve full absolute path to the pack resource file. Note: This function also takes care of sanitizing ``file_name`` argument preventing directory traversal and similar attacks. :param pack_ref: Pack reference (needs to be the same as directory on disk). :type pack_ref

(pack_ref, resource_type, file_path)

Source from the content-addressed store, hash-verified

316
317
318def get_pack_resource_file_abs_path(pack_ref, resource_type, file_path):
319 """
320 Retrieve full absolute path to the pack resource file.
321
322 Note: This function also takes care of sanitizing ``file_name`` argument
323 preventing directory traversal and similar attacks.
324
325 :param pack_ref: Pack reference (needs to be the same as directory on disk).
326 :type pack_ref: ``str``
327
328 :param resource_type: Pack resource type (e.g. action, sensor, etc.).
329 :type resource_type: ``str``
330
331 :pack file_path: Resource file path relative to the pack directory (e.g. my_file.py or
332 directory/my_file.py)
333 :type file_path: ``str``
334
335 :rtype: ``str``
336 """
337 path_components = []
338 if resource_type == "action":
339 path_components.append("actions/")
340 elif resource_type == "sensor":
341 path_components.append("sensors/")
342 elif resource_type == "rule":
343 path_components.append("rules/")
344 else:
345 raise ValueError("Invalid resource type: %s" % (resource_type))
346
347 path_components.append(file_path)
348 file_path = os.path.join(*path_components) # pylint: disable=E1120
349 result = get_pack_file_abs_path(
350 pack_ref=pack_ref, file_path=file_path, resource_type=resource_type
351 )
352 return result
353
354
355def get_relative_path_to_pack_file(pack_ref, file_path, use_pack_cache=False):

Calls 1

get_pack_file_abs_pathFunction · 0.85

Tested by 1