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

Method delete

st2api/st2api/controllers/v1/actions.py:218–291  ·  view source on GitHub ↗

Delete an action. Handles requests: POST /actions/1?_method=delete DELETE /actions/1 DELETE /actions/mypack.myaction

(self, options, ref_or_id, requester_user)

Source from the content-addressed store, hash-verified

216 return action_api
217
218 def delete(self, options, ref_or_id, requester_user):
219 """
220 Delete an action.
221
222 Handles requests:
223 POST /actions/1?_method=delete
224 DELETE /actions/1
225 DELETE /actions/mypack.myaction
226 """
227 action_db = self._get_by_ref_or_id(ref_or_id=ref_or_id)
228 action_id = action_db.id
229
230 permission_type = PermissionType.ACTION_DELETE
231 rbac_utils = get_rbac_backend().get_utils_class()
232 rbac_utils.assert_user_has_resource_db_permission(
233 user_db=requester_user,
234 resource_db=action_db,
235 permission_type=permission_type,
236 )
237
238 try:
239 validate_not_part_of_system_pack(action_db)
240 except ValueValidationException as e:
241 abort(http_client.BAD_REQUEST, six.text_type(e))
242
243 LOG.debug(
244 "DELETE /actions/ lookup with ref_or_id=%s found object: %s",
245 ref_or_id,
246 action_db,
247 )
248
249 pack_name = action_db["pack"]
250 entry_point = action_db["entry_point"]
251 metadata_file = action_db["metadata_file"]
252
253 try:
254 Action.delete(action_db)
255 except Exception as e:
256 LOG.error(
257 'Database delete encountered exception during delete of id="%s". '
258 "Exception was %s",
259 action_id,
260 e,
261 )
262 abort(http_client.INTERNAL_SERVER_ERROR, six.text_type(e))
263 return
264
265 if options.remove_files:
266 try:
267 delete_action_files_from_pack(
268 pack_name=pack_name,
269 entry_point=entry_point,
270 metadata_file=metadata_file,
271 )
272 except PermissionError as e:
273 LOG.error("No permission to delete resource files from disk.")
274 action_db.id = None
275 Action.add_or_update(action_db)

Callers 1

cloneMethod · 0.95

Calls 9

get_rbac_backendFunction · 0.90
abortFunction · 0.90
ResponseClass · 0.90
_get_by_ref_or_idMethod · 0.45
get_utils_classMethod · 0.45
add_or_updateMethod · 0.45

Tested by

no test coverage detected