Outputs the content of all the files inside the pack. Handles requests: GET /packs/views/files/
(self, ref_or_id, requester_user)
| 99 | self.get_one_db_method = self._get_by_ref_or_id |
| 100 | |
| 101 | def get_one(self, ref_or_id, requester_user): |
| 102 | """ |
| 103 | Outputs the content of all the files inside the pack. |
| 104 | |
| 105 | Handles requests: |
| 106 | GET /packs/views/files/<pack_ref_or_id> |
| 107 | """ |
| 108 | pack_db = self._get_by_ref_or_id(ref_or_id=ref_or_id) |
| 109 | |
| 110 | rbac_utils = get_rbac_backend().get_utils_class() |
| 111 | rbac_utils.assert_user_has_resource_db_permission( |
| 112 | user_db=requester_user, |
| 113 | resource_db=pack_db, |
| 114 | permission_type=PermissionType.PACK_VIEW, |
| 115 | ) |
| 116 | |
| 117 | if not pack_db: |
| 118 | msg = 'Pack with ref_or_id "%s" does not exist' % (ref_or_id) |
| 119 | raise StackStormDBObjectNotFoundError(msg) |
| 120 | |
| 121 | pack_ref = pack_db.ref |
| 122 | pack_files = pack_db.files |
| 123 | |
| 124 | result = [] |
| 125 | for file_path in pack_files: |
| 126 | normalized_file_path = get_pack_file_abs_path( |
| 127 | pack_ref=pack_ref, file_path=file_path |
| 128 | ) |
| 129 | if not normalized_file_path or not os.path.isfile(normalized_file_path): |
| 130 | # Ignore references to files which don't exist on disk |
| 131 | continue |
| 132 | |
| 133 | file_size = self._get_file_size(file_path=normalized_file_path) |
| 134 | if file_size is not None and file_size > MAX_FILE_SIZE: |
| 135 | LOG.debug( |
| 136 | 'Skipping file "%s" which size exceeds max file size (%s bytes)' |
| 137 | % (normalized_file_path, MAX_FILE_SIZE) |
| 138 | ) |
| 139 | continue |
| 140 | |
| 141 | content = self._get_file_content(file_path=normalized_file_path) |
| 142 | |
| 143 | include_file = self._include_file(file_path=file_path, content=content) |
| 144 | if not include_file: |
| 145 | LOG.debug('Skipping binary file "%s"' % (normalized_file_path)) |
| 146 | continue |
| 147 | |
| 148 | item = {"file_path": file_path, "content": content} |
| 149 | result.append(item) |
| 150 | return result |
| 151 | |
| 152 | def _include_file(self, file_path, content): |
| 153 | """ |
nothing calls this directly
no test coverage detected