From ac7381b5a4494bd0035a4afb8915a7b70d620c0a Mon Sep 17 00:00:00 2001 From: Richelle Ahlvers Date: Thu, 4 Apr 2024 18:09:36 -0600 Subject: [PATCH] Editorial fixes; roll back changes removed by autogen PR --- .../redfish/MessageRegistryFile_api.py | 24 +++++++++++-------- api_emulator/utils.py | 5 ++-- emulator.py | 6 ++++- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/api_emulator/redfish/MessageRegistryFile_api.py b/api_emulator/redfish/MessageRegistryFile_api.py index 575d3d74..c4d003f5 100644 --- a/api_emulator/redfish/MessageRegistryFile_api.py +++ b/api_emulator/redfish/MessageRegistryFile_api.py @@ -31,22 +31,23 @@ # Program name - MessageRegistryFile_api.py import g -import json, os +import json +import os import traceback -import logging, random, requests, string, jwt +import logging -from flask import Flask, request, session +from flask import Flask, request from flask_restful import Resource from .constants import * -from api_emulator.utils import check_authentication, create_path, get_json_data, create_and_patch_object, delete_object, patch_object, put_object, delete_collection, create_collection +from api_emulator.utils import check_authentication, update_collections_json, create_path, get_json_data, create_and_patch_object, delete_object, patch_object, put_object, delete_collection, create_collection config = {} -members = [] -member_ids = [] INTERNAL_ERROR = 500 # MessageRegistryFile Collection API + + class MessageRegistryFileCollectionAPI(Resource): def __init__(self, **kwargs): logging.info('MessageRegistryFile Collection init called') @@ -98,8 +99,13 @@ def get(self, MessageRegistryFileId): msg, code = check_authentication(self.auth) if code == 200: - path = create_path(self.root, 'Registries/{0}', 'index.json').format(MessageRegistryFileId) - return get_json_data (path) + if '.json' not in MessageRegistryFileId: + path = create_path( + self.root, 'Registries/{0}', 'index.json').format(MessageRegistryFileId) + else: + path = create_path( + self.root, 'Registries/{0}').format(MessageRegistryFileId) + return get_json_data(path) else: return msg, code @@ -122,5 +128,3 @@ def patch(self, MessageRegistryFileId): def delete(self, MessageRegistryFileId): logging.info('MessageRegistryFile delete called') return 'DELETE is not a supported command for MessageRegistryFileAPI', 405 - - diff --git a/api_emulator/utils.py b/api_emulator/utils.py index 26701bfa..f8d0ffc2 100644 --- a/api_emulator/utils.py +++ b/api_emulator/utils.py @@ -341,8 +341,9 @@ def remove_json_object (config, property_id): # Iterate through the objects in the JSON and pop (remove) # the obj once we find it. - if property_id in config: - config.pop (property_id, None) + if isinstance(config, dict): + if property_id in config: + config.pop(property_id, None) return config def check_session_authentication(): diff --git a/emulator.py b/emulator.py index 31576729..5fd29aba 100644 --- a/emulator.py +++ b/emulator.py @@ -179,7 +179,11 @@ def output_json(data, code, headers=None): global location if 'UserName' not in data or 'Password' not in data: - resp = make_response(json.dumps(data, indent=4), code) + if code == 405: + # No data should be returned in the body - only return the code. + resp = make_response('', code) + if code != 405: + resp = make_response(json.dumps(data, indent=4), code) resp.headers.extend(headers or {}) #if session timed out then delete the cookie as well