Outputs the file associated with action entry_point Handles requests: GET /actions/views/entry_point/1
(self, ref_or_id, requester_user)
| 225 | return abort(404) |
| 226 | |
| 227 | def get_one(self, ref_or_id, requester_user): |
| 228 | """ |
| 229 | Outputs the file associated with action entry_point |
| 230 | |
| 231 | Handles requests: |
| 232 | GET /actions/views/entry_point/1 |
| 233 | """ |
| 234 | LOG.info("GET /actions/views/entry_point with ref_or_id=%s", ref_or_id) |
| 235 | action_db = self._get_by_ref_or_id(ref_or_id=ref_or_id) |
| 236 | |
| 237 | permission_type = PermissionType.ACTION_VIEW |
| 238 | rbac_utils = get_rbac_backend().get_utils_class() |
| 239 | rbac_utils.assert_user_has_resource_db_permission( |
| 240 | user_db=requester_user, |
| 241 | resource_db=action_db, |
| 242 | permission_type=permission_type, |
| 243 | ) |
| 244 | |
| 245 | pack = getattr(action_db, "pack", None) |
| 246 | entry_point = getattr(action_db, "entry_point", None) |
| 247 | |
| 248 | abs_path = utils.get_entry_point_abs_path(pack, entry_point) |
| 249 | |
| 250 | if not abs_path: |
| 251 | raise StackStormDBObjectNotFoundError( |
| 252 | "Action ref_or_id=%s has no entry_point to output" % ref_or_id |
| 253 | ) |
| 254 | |
| 255 | with codecs.open(abs_path, "r") as fp: |
| 256 | content = fp.read() |
| 257 | |
| 258 | # Ensure content is utf-8 |
| 259 | if isinstance(content, six.binary_type): |
| 260 | content = content.decode("utf-8") |
| 261 | |
| 262 | try: |
| 263 | content_type = mimetypes.guess_type(abs_path)[0] |
| 264 | except Exception: |
| 265 | content_type = None |
| 266 | |
| 267 | # Special case if /etc/mime.types doesn't contain entry for yaml, py |
| 268 | if not content_type: |
| 269 | _, extension = os.path.splitext(abs_path) |
| 270 | if extension in [".yaml", ".yml"]: |
| 271 | content_type = "application/x-yaml" |
| 272 | elif extension in [".py"]: |
| 273 | content_type = "application/x-python" |
| 274 | else: |
| 275 | content_type = "text/plain" |
| 276 | |
| 277 | response = Response() |
| 278 | response.headers["Content-Type"] = content_type |
| 279 | response.text = content |
| 280 | return response |
| 281 | |
| 282 | |
| 283 | class ActionViewsController(object): |
nothing calls this directly
no test coverage detected