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

Method clone

st2api/st2api/controllers/v1/actions.py:293–431  ·  view source on GitHub ↗

Clone an action from source pack to destination pack. Handles requests: POST /actions/{ref_or_id}/clone

(self, dest_data, ref_or_id, requester_user)

Source from the content-addressed store, hash-verified

291 return Response(status=http_client.NO_CONTENT)
292
293 def clone(self, dest_data, ref_or_id, requester_user):
294 """
295 Clone an action from source pack to destination pack.
296 Handles requests:
297 POST /actions/{ref_or_id}/clone
298 """
299
300 source_action_db = self._get_by_ref_or_id(ref_or_id=ref_or_id)
301 if not source_action_db:
302 msg = "The requested source for cloning operation doesn't exists"
303 abort(http_client.BAD_REQUEST, six.text_type(msg))
304
305 extra = {"action_db": source_action_db}
306 LOG.audit(
307 "Source action found. Action.id=%s" % (source_action_db.id), extra=extra
308 )
309
310 try:
311 permission_type = PermissionType.ACTION_VIEW
312 rbac_utils = get_rbac_backend().get_utils_class()
313 rbac_utils.assert_user_has_resource_db_permission(
314 user_db=requester_user,
315 resource_db=source_action_db,
316 permission_type=permission_type,
317 )
318 except ResourceAccessDeniedError as e:
319 abort(http_client.UNAUTHORIZED, six.text_type(e))
320
321 cloned_dest_action_db = clone_action_db(
322 source_action_db=source_action_db,
323 dest_pack=dest_data.dest_pack,
324 dest_action=dest_data.dest_action,
325 )
326
327 cloned_action_api = ActionAPI.from_model(cloned_dest_action_db)
328
329 try:
330 permission_type = PermissionType.ACTION_CREATE
331 rbac_utils.assert_user_has_resource_api_permission(
332 user_db=requester_user,
333 resource_api=cloned_action_api,
334 permission_type=permission_type,
335 )
336 except ResourceAccessDeniedError as e:
337 abort(http_client.UNAUTHORIZED, six.text_type(e))
338
339 dest_pack_base_path = get_pack_base_path(pack_name=dest_data.dest_pack)
340
341 if not os.path.isdir(dest_pack_base_path):
342 msg = "Destination pack '%s' doesn't exist" % (dest_data.dest_pack)
343 abort(http_client.BAD_REQUEST, six.text_type(msg))
344
345 dest_pack_base_path = get_pack_base_path(pack_name=dest_data.dest_pack)
346 dest_ref = ".".join([dest_data.dest_pack, dest_data.dest_action])
347 dest_action_db = self._get_by_ref(resource_ref=dest_ref)
348
349 try:
350 validate_not_part_of_system_pack_by_name(dest_data.dest_pack)

Callers

nothing calls this directly

Calls 15

deleteMethod · 0.95
postMethod · 0.95
_restore_actionMethod · 0.95
abortFunction · 0.90
get_rbac_backendFunction · 0.90
clone_action_dbFunction · 0.90
get_pack_base_pathFunction · 0.90
GenericRequestParamClass · 0.90
temp_backup_action_filesFunction · 0.90
clone_action_filesFunction · 0.90
remove_temp_action_filesFunction · 0.90

Tested by

no test coverage detected