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

Method get_one

st2api/st2api/controllers/v1/pack_views.py:174–243  ·  view source on GitHub ↗

Outputs the content of a specific file in a pack. Handles requests: GET /packs/views/file/ /

(
        self,
        ref_or_id,
        file_path,
        requester_user,
        if_none_match=None,
        if_modified_since=None,
    )

Source from the content-addressed store, hash-verified

172 """
173
174 def get_one(
175 self,
176 ref_or_id,
177 file_path,
178 requester_user,
179 if_none_match=None,
180 if_modified_since=None,
181 ):
182 """
183 Outputs the content of a specific file in a pack.
184
185 Handles requests:
186 GET /packs/views/file/<pack_ref_or_id>/<file path>
187 """
188 pack_db = self._get_by_ref_or_id(ref_or_id=ref_or_id)
189
190 if not pack_db:
191 msg = 'Pack with ref_or_id "%s" does not exist' % (ref_or_id)
192 raise StackStormDBObjectNotFoundError(msg)
193
194 if not file_path:
195 raise ValueError("Missing file path")
196
197 pack_ref = pack_db.ref
198
199 # Note: Until list filtering is in place we don't require RBAC check for icon file
200 permission_type = PermissionType.PACK_VIEW
201 if file_path not in WHITELISTED_FILE_PATHS:
202 rbac_utils = get_rbac_backend().get_utils_class()
203 rbac_utils.assert_user_has_resource_db_permission(
204 user_db=requester_user,
205 resource_db=pack_db,
206 permission_type=permission_type,
207 )
208
209 normalized_file_path = get_pack_file_abs_path(
210 pack_ref=pack_ref, file_path=file_path
211 )
212 if not normalized_file_path or not os.path.isfile(normalized_file_path):
213 # Ignore references to files which don't exist on disk
214 raise StackStormDBObjectNotFoundError('File "%s" not found' % (file_path))
215
216 file_size, file_mtime = self._get_file_stats(file_path=normalized_file_path)
217
218 response = Response()
219
220 if not self._is_file_changed(
221 file_mtime, if_none_match=if_none_match, if_modified_since=if_modified_since
222 ):
223 response.status = http_client.NOT_MODIFIED
224 else:
225 if file_size is not None and file_size > MAX_FILE_SIZE:
226 msg = "File %s exceeds maximum allowed file size (%s bytes)" % (
227 file_path,
228 MAX_FILE_SIZE,
229 )
230 raise ValueError(msg)
231

Callers

nothing calls this directly

Calls 10

_is_file_changedMethod · 0.95
get_rbac_backendFunction · 0.90
get_pack_file_abs_pathFunction · 0.90
ResponseClass · 0.90
_get_file_statsMethod · 0.80
_get_file_contentMethod · 0.80
_get_by_ref_or_idMethod · 0.45
get_utils_classMethod · 0.45

Tested by

no test coverage detected