Create a new action. Handles requests: POST /actions/
(self, action, requester_user)
| 109 | ) |
| 110 | |
| 111 | def post(self, action, requester_user): |
| 112 | """ |
| 113 | Create a new action. |
| 114 | |
| 115 | Handles requests: |
| 116 | POST /actions/ |
| 117 | """ |
| 118 | |
| 119 | permission_type = PermissionType.ACTION_CREATE |
| 120 | rbac_utils = get_rbac_backend().get_utils_class() |
| 121 | rbac_utils.assert_user_has_resource_api_permission( |
| 122 | user_db=requester_user, resource_api=action, permission_type=permission_type |
| 123 | ) |
| 124 | |
| 125 | try: |
| 126 | # Perform validation |
| 127 | validate_not_part_of_system_pack(action) |
| 128 | action_validator.validate_action(action) |
| 129 | except ( |
| 130 | ValidationError, |
| 131 | ValueError, |
| 132 | ValueValidationException, |
| 133 | InvalidActionParameterException, |
| 134 | ) as e: |
| 135 | LOG.exception("Unable to create action data=%s", action) |
| 136 | abort(http_client.BAD_REQUEST, six.text_type(e)) |
| 137 | return |
| 138 | |
| 139 | # Write pack data files to disk (if any are provided) |
| 140 | data_files = getattr(action, "data_files", []) |
| 141 | written_data_files = [] |
| 142 | if data_files: |
| 143 | written_data_files = self._handle_data_files( |
| 144 | pack_ref=action.pack, data_files=data_files |
| 145 | ) |
| 146 | |
| 147 | action_model = ActionAPI.to_model(action) |
| 148 | |
| 149 | LOG.debug("/actions/ POST verified ActionAPI object=%s", action) |
| 150 | action_db = Action.add_or_update(action_model) |
| 151 | LOG.debug("/actions/ POST saved ActionDB object=%s", action_db) |
| 152 | |
| 153 | # Dispatch an internal trigger for each written data file. This way user |
| 154 | # automate comitting this files to git using StackStorm rule |
| 155 | if written_data_files: |
| 156 | self._dispatch_trigger_for_written_data_files( |
| 157 | action_db=action_db, written_data_files=written_data_files |
| 158 | ) |
| 159 | |
| 160 | extra = {"acion_db": action_db} |
| 161 | LOG.audit("Action created. Action.id=%s" % (action_db.id), extra=extra) |
| 162 | action_api = ActionAPI.from_model(action_db) |
| 163 | |
| 164 | return Response(json=action_api, status=http_client.CREATED) |
| 165 | |
| 166 | def put(self, action, ref_or_id, requester_user): |
| 167 | action_db = self._get_by_ref_or_id(ref_or_id=ref_or_id) |
no test coverage detected