| Nan Zhou | 313c1b7 | 2022-03-25 11:47:55 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 2 | import argparse | 
| Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 3 | import json | 
| Nan Zhou | 6eaf0bd | 2022-08-07 01:18:45 +0000 | [diff] [blame] | 4 | import os | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 5 | from collections import OrderedDict | 
| Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 6 |  | 
| Nan Zhou | 6eaf0bd | 2022-08-07 01:18:45 +0000 | [diff] [blame] | 7 | import requests | 
| Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 8 |  | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 9 | PRAGMA_ONCE = """#pragma once | 
|  | 10 | """ | 
| Nan Zhou | 043bec0 | 2022-09-20 18:12:13 +0000 | [diff] [blame] | 11 |  | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 12 | WARNING = """/**************************************************************** | 
| Ed Tanous | 1cf53df | 2022-02-17 09:09:25 -0800 | [diff] [blame] | 13 | *                 READ THIS WARNING FIRST | 
| Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 14 | * This is an auto-generated header which contains definitions | 
|  | 15 | * for Redfish DMTF defined messages. | 
| Ed Tanous | 1cf53df | 2022-02-17 09:09:25 -0800 | [diff] [blame] | 16 | * DO NOT modify this registry outside of running the | 
| Jason M. Bills | 0e2d069 | 2022-04-01 13:59:05 -0700 | [diff] [blame] | 17 | * parse_registries.py script.  The definitions contained within | 
| Ed Tanous | 1cf53df | 2022-02-17 09:09:25 -0800 | [diff] [blame] | 18 | * this file are owned by DMTF.  Any modifications to these files | 
|  | 19 | * should be first pushed to the relevant registry in the DMTF | 
|  | 20 | * github organization. | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 21 | ***************************************************************/""" | 
| Ed Tanous | 1cf53df | 2022-02-17 09:09:25 -0800 | [diff] [blame] | 22 |  | 
| Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 23 | COPYRIGHT = """// SPDX-License-Identifier: Apache-2.0 | 
|  | 24 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors | 
|  | 25 | """ | 
|  | 26 |  | 
|  | 27 | INCLUDES = """ | 
| Nan Zhou | 01c78a0 | 2022-09-20 18:17:20 +0000 | [diff] [blame] | 28 | #include "registries.hpp" | 
|  | 29 |  | 
|  | 30 | #include <array> | 
| Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 31 |  | 
| Ed Tanous | 4d99bbb | 2022-02-17 10:02:57 -0800 | [diff] [blame] | 32 | // clang-format off | 
|  | 33 |  | 
| Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 34 | namespace redfish::registries::{} | 
| Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 35 | {{ | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 36 | """ | 
| Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 37 |  | 
|  | 38 | REGISTRY_HEADER = f"{COPYRIGHT}{PRAGMA_ONCE}{WARNING}{INCLUDES}" | 
| Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 39 |  | 
|  | 40 | SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) | 
|  | 41 |  | 
| Igor Kanyuka | 557ab0d | 2025-02-18 15:20:38 +0000 | [diff] [blame] | 42 | INCLUDE_PATH = os.path.realpath( | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 43 | os.path.join(SCRIPT_DIR, "..", "redfish-core", "include", "registries") | 
|  | 44 | ) | 
| Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 45 |  | 
| Igor Kanyuka | 557ab0d | 2025-02-18 15:20:38 +0000 | [diff] [blame] | 46 | PROXIES = {"https": os.environ.get("https_proxy", None)} | 
| Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 47 |  | 
| Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 48 |  | 
| James Feist | e51c710 | 2020-03-17 10:38:18 -0700 | [diff] [blame] | 49 | def make_getter(dmtf_name, header_name, type_name): | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 50 | url = "https://redfish.dmtf.org/registries/{}".format(dmtf_name) | 
| Igor Kanyuka | 557ab0d | 2025-02-18 15:20:38 +0000 | [diff] [blame] | 51 | dmtf = requests.get(url, proxies=PROXIES) | 
| James Feist | e51c710 | 2020-03-17 10:38:18 -0700 | [diff] [blame] | 52 | dmtf.raise_for_status() | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 53 | json_file = json.loads(dmtf.text, object_pairs_hook=OrderedDict) | 
| Igor Kanyuka | 557ab0d | 2025-02-18 15:20:38 +0000 | [diff] [blame] | 54 | path = os.path.join(INCLUDE_PATH, header_name) | 
| James Feist | e51c710 | 2020-03-17 10:38:18 -0700 | [diff] [blame] | 55 | return (path, json_file, type_name, url) | 
|  | 56 |  | 
|  | 57 |  | 
| Ed Tanous | 3e5faba | 2023-08-16 15:11:29 -0700 | [diff] [blame] | 58 | def openbmc_local_getter(): | 
| Milton D. Miller II | 770362f | 2024-12-17 05:28:27 +0000 | [diff] [blame] | 59 | url = "https://raw.githubusercontent.com/openbmc/bmcweb/refs/heads/master/redfish-core/include/registries/openbmc.json" | 
| Ed Tanous | 3e5faba | 2023-08-16 15:11:29 -0700 | [diff] [blame] | 60 | with open( | 
|  | 61 | os.path.join( | 
|  | 62 | SCRIPT_DIR, | 
|  | 63 | "..", | 
|  | 64 | "redfish-core", | 
|  | 65 | "include", | 
|  | 66 | "registries", | 
|  | 67 | "openbmc.json", | 
|  | 68 | ), | 
|  | 69 | "rb", | 
| Igor Kanyuka | 557ab0d | 2025-02-18 15:20:38 +0000 | [diff] [blame] | 70 | ) as json_file_fd: | 
|  | 71 | json_file = json.load(json_file_fd) | 
| Ed Tanous | 3e5faba | 2023-08-16 15:11:29 -0700 | [diff] [blame] | 72 |  | 
| Igor Kanyuka | 557ab0d | 2025-02-18 15:20:38 +0000 | [diff] [blame] | 73 | path = os.path.join(INCLUDE_PATH, "openbmc_message_registry.hpp") | 
| Ed Tanous | 3e5faba | 2023-08-16 15:11:29 -0700 | [diff] [blame] | 74 | return (path, json_file, "openbmc", url) | 
|  | 75 |  | 
|  | 76 |  | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 77 | def update_registries(files): | 
|  | 78 | # Remove the old files | 
|  | 79 | for file, json_dict, namespace, url in files: | 
|  | 80 | try: | 
|  | 81 | os.remove(file) | 
|  | 82 | except BaseException: | 
|  | 83 | print("{} not found".format(file)) | 
| Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 84 |  | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 85 | with open(file, "w") as registry: | 
| Ed Tanous | 56b8199 | 2024-12-02 10:36:37 -0800 | [diff] [blame] | 86 |  | 
|  | 87 | version_split = json_dict["RegistryVersion"].split(".") | 
|  | 88 |  | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 89 | registry.write(REGISTRY_HEADER.format(namespace)) | 
|  | 90 | # Parse the Registry header info | 
| Ed Tanous | 5b9ef70 | 2022-02-17 12:19:32 -0800 | [diff] [blame] | 91 | registry.write( | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 92 | "const Header header = {{\n" | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 93 | '    "{json_dict[@Redfish.Copyright]}",\n' | 
|  | 94 | '    "{json_dict[@odata.type]}",\n' | 
| Ed Tanous | 56b8199 | 2024-12-02 10:36:37 -0800 | [diff] [blame] | 95 | "    {version_split[0]},\n" | 
|  | 96 | "    {version_split[1]},\n" | 
|  | 97 | "    {version_split[2]},\n" | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 98 | '    "{json_dict[Name]}",\n' | 
|  | 99 | '    "{json_dict[Language]}",\n' | 
|  | 100 | '    "{json_dict[Description]}",\n' | 
|  | 101 | '    "{json_dict[RegistryPrefix]}",\n' | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 102 | '    "{json_dict[OwningEntity]}",\n' | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 103 | "}};\n" | 
|  | 104 | "constexpr const char* url =\n" | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 105 | '    "{url}";\n' | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 106 | "\n" | 
|  | 107 | "constexpr std::array registry =\n" | 
|  | 108 | "{{\n".format( | 
|  | 109 | json_dict=json_dict, | 
|  | 110 | url=url, | 
| Ed Tanous | 56b8199 | 2024-12-02 10:36:37 -0800 | [diff] [blame] | 111 | version_split=version_split, | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 112 | ) | 
|  | 113 | ) | 
| Ed Tanous | 30a3c43 | 2022-02-07 09:37:21 -0800 | [diff] [blame] | 114 |  | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 115 | messages_sorted = sorted(json_dict["Messages"].items()) | 
|  | 116 | for messageId, message in messages_sorted: | 
|  | 117 | registry.write( | 
|  | 118 | "    MessageEntry{{\n" | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 119 | '        "{messageId}",\n' | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 120 | "        {{\n" | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 121 | '            "{message[Description]}",\n' | 
|  | 122 | '            "{message[Message]}",\n' | 
|  | 123 | '            "{message[MessageSeverity]}",\n' | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 124 | "            {message[NumberOfArgs]},\n" | 
|  | 125 | "            {{".format( | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 126 | messageId=messageId, message=message | 
|  | 127 | ) | 
|  | 128 | ) | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 129 | paramTypes = message.get("ParamTypes") | 
|  | 130 | if paramTypes: | 
|  | 131 | for paramType in paramTypes: | 
|  | 132 | registry.write( | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 133 | '\n                "{}",'.format(paramType) | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 134 | ) | 
|  | 135 | registry.write("\n            },\n") | 
|  | 136 | else: | 
|  | 137 | registry.write("},\n") | 
|  | 138 | registry.write( | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 139 | '            "{message[Resolution]}",\n' | 
|  | 140 | "        }}}},\n".format(message=message) | 
|  | 141 | ) | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 142 |  | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 143 | registry.write("\n};\n\nenum class Index\n{\n") | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 144 | for index, (messageId, message) in enumerate(messages_sorted): | 
|  | 145 | messageId = messageId[0].lower() + messageId[1:] | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 146 | registry.write("    {} = {},\n".format(messageId, index)) | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 147 | registry.write( | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 148 | "}};\n}} // namespace redfish::registries::{}\n".format( | 
|  | 149 | namespace | 
|  | 150 | ) | 
|  | 151 | ) | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 152 |  | 
|  | 153 |  | 
|  | 154 | def get_privilege_string_from_list(privilege_list): | 
|  | 155 | privilege_string = "{{\n" | 
|  | 156 | for privilege_json in privilege_list: | 
|  | 157 | privileges = privilege_json["Privilege"] | 
|  | 158 | privilege_string += "    {" | 
|  | 159 | for privilege in privileges: | 
|  | 160 | if privilege == "NoAuth": | 
|  | 161 | continue | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 162 | privilege_string += '"' | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 163 | privilege_string += privilege | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 164 | privilege_string += '",\n' | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 165 | if privilege != "NoAuth": | 
|  | 166 | privilege_string = privilege_string[:-2] | 
|  | 167 | privilege_string += "}" | 
|  | 168 | privilege_string += ",\n" | 
|  | 169 | privilege_string = privilege_string[:-2] | 
|  | 170 | privilege_string += "\n}}" | 
|  | 171 | return privilege_string | 
|  | 172 |  | 
| Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 173 |  | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 174 | def get_variable_name_for_privilege_set(privilege_list): | 
|  | 175 | names = [] | 
|  | 176 | for privilege_json in privilege_list: | 
|  | 177 | privileges = privilege_json["Privilege"] | 
|  | 178 | names.append("And".join(privileges)) | 
|  | 179 | return "Or".join(names) | 
|  | 180 |  | 
| Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 181 |  | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 182 | PRIVILEGE_HEADER = ( | 
| Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 183 | COPYRIGHT | 
|  | 184 | + PRAGMA_ONCE | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 185 | + WARNING | 
|  | 186 | + """ | 
| Nan Zhou | 01c78a0 | 2022-09-20 18:17:20 +0000 | [diff] [blame] | 187 | #include "privileges.hpp" | 
|  | 188 |  | 
|  | 189 | #include <array> | 
| Nan Zhou | 043bec0 | 2022-09-20 18:12:13 +0000 | [diff] [blame] | 190 |  | 
|  | 191 | // clang-format off | 
|  | 192 |  | 
|  | 193 | namespace redfish::privileges | 
|  | 194 | { | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 195 | """ | 
|  | 196 | ) | 
| Nan Zhou | 043bec0 | 2022-09-20 18:12:13 +0000 | [diff] [blame] | 197 |  | 
|  | 198 |  | 
| Igor Kanyuka | 557ab0d | 2025-02-18 15:20:38 +0000 | [diff] [blame] | 199 | def get_response_code(entry_id): | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 200 | codes = { | 
|  | 201 | "InternalError": "internal_server_error", | 
|  | 202 | "OperationTimeout": "internal_server_error", | 
|  | 203 | "PropertyValueResourceConflict": "conflict", | 
|  | 204 | "ResourceInUse": "service_unavailable", | 
|  | 205 | "ServiceTemporarilyUnavailable": "service_unavailable", | 
|  | 206 | "ResourceCannotBeDeleted": "method_not_allowed", | 
|  | 207 | "PropertyValueModified": "ok", | 
|  | 208 | "InsufficientPrivilege": "forbidden", | 
|  | 209 | "AccountForSessionNoLongerExists": "forbidden", | 
|  | 210 | "ServiceDisabled": "service_unavailable", | 
|  | 211 | "ServiceInUnknownState": "service_unavailable", | 
|  | 212 | "EventSubscriptionLimitExceeded": "service_unavailable", | 
|  | 213 | "ResourceAtUriUnauthorized": "unauthorized", | 
|  | 214 | "SessionTerminated": "ok", | 
|  | 215 | "SubscriptionTerminated": "ok", | 
|  | 216 | "PropertyNotWritable": "forbidden", | 
|  | 217 | "MaximumErrorsExceeded": "internal_server_error", | 
|  | 218 | "GeneralError": "internal_server_error", | 
|  | 219 | "PreconditionFailed": "precondition_failed", | 
|  | 220 | "OperationFailed": "bad_gateway", | 
|  | 221 | "ServiceShuttingDown": "service_unavailable", | 
|  | 222 | "AccountRemoved": "ok", | 
|  | 223 | "PropertyValueExternalConflict": "conflict", | 
|  | 224 | "InsufficientStorage": "insufficient_storage", | 
|  | 225 | "OperationNotAllowed": "method_not_allowed", | 
|  | 226 | "ResourceNotFound": "not_found", | 
|  | 227 | "CouldNotEstablishConnection": "not_found", | 
|  | 228 | "AccessDenied": "forbidden", | 
|  | 229 | "Success": None, | 
|  | 230 | "Created": "created", | 
|  | 231 | "NoValidSession": "forbidden", | 
|  | 232 | "SessionLimitExceeded": "service_unavailable", | 
|  | 233 | "ResourceExhaustion": "service_unavailable", | 
|  | 234 | "AccountModified": "ok", | 
|  | 235 | "PasswordChangeRequired": None, | 
|  | 236 | "ResourceInStandby": "service_unavailable", | 
|  | 237 | "GenerateSecretKeyRequired": "forbidden", | 
|  | 238 | } | 
|  | 239 |  | 
| Igor Kanyuka | 557ab0d | 2025-02-18 15:20:38 +0000 | [diff] [blame] | 240 | return codes.get(entry_id, "bad_request") | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 241 |  | 
|  | 242 |  | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 243 | def make_error_function( | 
|  | 244 | entry_id, entry, is_header, registry_name, namespace_name | 
|  | 245 | ): | 
| Ed Tanous | 644cdcb | 2024-11-17 11:12:41 -0800 | [diff] [blame] | 246 | arg_nonstring_types = { | 
|  | 247 | "const boost::urls::url_view_base&": { | 
|  | 248 | "AccessDenied": [1], | 
|  | 249 | "CouldNotEstablishConnection": [1], | 
|  | 250 | "GenerateSecretKeyRequired": [1], | 
|  | 251 | "InvalidObject": [1], | 
|  | 252 | "PasswordChangeRequired": [1], | 
|  | 253 | "PropertyValueResourceConflict": [3], | 
|  | 254 | "ResetRequired": [1], | 
|  | 255 | "ResourceAtUriInUnknownFormat": [1], | 
|  | 256 | "ResourceAtUriUnauthorized": [1], | 
|  | 257 | "ResourceCreationConflict": [1], | 
|  | 258 | "ResourceMissingAtURI": [1], | 
|  | 259 | "SourceDoesNotSupportProtocol": [1], | 
|  | 260 | }, | 
|  | 261 | "const nlohmann::json&": { | 
|  | 262 | "ActionParameterValueError": [1], | 
|  | 263 | "ActionParameterValueFormatError": [1], | 
|  | 264 | "ActionParameterValueTypeError": [1], | 
|  | 265 | "PropertyValueExternalConflict": [2], | 
|  | 266 | "PropertyValueFormatError": [1], | 
|  | 267 | "PropertyValueIncorrect": [2], | 
|  | 268 | "PropertyValueModified": [2], | 
|  | 269 | "PropertyValueNotInList": [1], | 
|  | 270 | "PropertyValueOutOfRange": [1], | 
|  | 271 | "PropertyValueResourceConflict": [2], | 
|  | 272 | "PropertyValueTypeError": [1], | 
|  | 273 | "QueryParameterValueFormatError": [1], | 
|  | 274 | "QueryParameterValueTypeError": [1], | 
|  | 275 | }, | 
|  | 276 | "uint64_t": { | 
|  | 277 | "ArraySizeTooLong": [2], | 
|  | 278 | "InvalidIndex": [1], | 
|  | 279 | "StringValueTooLong": [2], | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 280 | "TaskProgressChanged": [2], | 
| Ed Tanous | 644cdcb | 2024-11-17 11:12:41 -0800 | [diff] [blame] | 281 | }, | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 282 | } | 
|  | 283 |  | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 284 | out = "" | 
|  | 285 | args = [] | 
|  | 286 | argtypes = [] | 
|  | 287 | for arg_index, arg in enumerate(entry.get("ParamTypes", [])): | 
|  | 288 | arg_index += 1 | 
| Ed Tanous | 644cdcb | 2024-11-17 11:12:41 -0800 | [diff] [blame] | 289 | typename = "std::string_view" | 
|  | 290 | for typestring, entries in arg_nonstring_types.items(): | 
|  | 291 | if arg_index in entries.get(entry_id, []): | 
|  | 292 | typename = typestring | 
|  | 293 |  | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 294 | argtypes.append(typename) | 
|  | 295 | args.append(f"{typename} arg{arg_index}") | 
|  | 296 | function_name = entry_id[0].lower() + entry_id[1:] | 
|  | 297 | arg = ", ".join(args) | 
|  | 298 | out += f"nlohmann::json {function_name}({arg})" | 
|  | 299 |  | 
|  | 300 | if is_header: | 
|  | 301 | out += ";\n\n" | 
|  | 302 | else: | 
|  | 303 | out += "\n{\n" | 
|  | 304 | to_array_type = "" | 
|  | 305 | if argtypes: | 
|  | 306 | outargs = [] | 
|  | 307 | for index, typename in enumerate(argtypes): | 
|  | 308 | index += 1 | 
|  | 309 | if typename == "const nlohmann::json&": | 
|  | 310 | out += f"std::string arg{index}Str = arg{index}.dump(-1, ' ', true, nlohmann::json::error_handler_t::replace);\n" | 
| Ed Tanous | 644cdcb | 2024-11-17 11:12:41 -0800 | [diff] [blame] | 311 | elif typename == "uint64_t": | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 312 | out += f"std::string arg{index}Str = std::to_string(arg{index});\n" | 
|  | 313 |  | 
|  | 314 | for index, typename in enumerate(argtypes): | 
|  | 315 | index += 1 | 
|  | 316 | if typename == "const boost::urls::url_view_base&": | 
|  | 317 | outargs.append(f"arg{index}.buffer()") | 
|  | 318 | to_array_type = "<std::string_view>" | 
|  | 319 | elif typename == "const nlohmann::json&": | 
|  | 320 | outargs.append(f"arg{index}Str") | 
|  | 321 | to_array_type = "<std::string_view>" | 
| Ed Tanous | 644cdcb | 2024-11-17 11:12:41 -0800 | [diff] [blame] | 322 | elif typename == "uint64_t": | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 323 | outargs.append(f"arg{index}Str") | 
|  | 324 | to_array_type = "<std::string_view>" | 
|  | 325 | else: | 
|  | 326 | outargs.append(f"arg{index}") | 
|  | 327 | argstring = ", ".join(outargs) | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 328 |  | 
|  | 329 | if argtypes: | 
|  | 330 | arg_param = f"std::to_array{to_array_type}({{{argstring}}})" | 
|  | 331 | else: | 
|  | 332 | arg_param = "{}" | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 333 | out += f"    return getLog(redfish::registries::{namespace_name}::Index::{function_name}, {arg_param});" | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 334 | out += "\n}\n\n" | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 335 | if registry_name == "Base": | 
|  | 336 | args.insert(0, "crow::Response& res") | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 337 | if entry_id == "InternalError": | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 338 | if is_header: | 
|  | 339 | args.append( | 
|  | 340 | "std::source_location location = std::source_location::current()" | 
|  | 341 | ) | 
|  | 342 | else: | 
|  | 343 | args.append("const std::source_location location") | 
|  | 344 | arg = ", ".join(args) | 
|  | 345 | out += f"void {function_name}({arg})" | 
|  | 346 | if is_header: | 
|  | 347 | out += ";\n" | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 348 | else: | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 349 | out += "\n{\n" | 
|  | 350 | if entry_id == "InternalError": | 
|  | 351 | out += """BMCWEB_LOG_CRITICAL("Internal Error {}({}:{}) `{}`: ", location.file_name(), | 
|  | 352 | location.line(), location.column(), | 
|  | 353 | location.function_name());\n""" | 
|  | 354 |  | 
|  | 355 | if entry_id == "ServiceTemporarilyUnavailable": | 
|  | 356 | out += "res.addHeader(boost::beast::http::field::retry_after, arg1);" | 
|  | 357 |  | 
| Igor Kanyuka | 557ab0d | 2025-02-18 15:20:38 +0000 | [diff] [blame] | 358 | res = get_response_code(entry_id) | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 359 | if res: | 
|  | 360 | out += f"    res.result(boost::beast::http::status::{res});\n" | 
|  | 361 | args_out = ", ".join([f"arg{x+1}" for x in range(len(argtypes))]) | 
|  | 362 |  | 
|  | 363 | addMessageToJson = { | 
|  | 364 | "PropertyDuplicate": 1, | 
|  | 365 | "ResourceAlreadyExists": 2, | 
|  | 366 | "CreateFailedMissingReqProperties": 1, | 
|  | 367 | "PropertyValueFormatError": 2, | 
|  | 368 | "PropertyValueNotInList": 2, | 
|  | 369 | "PropertyValueTypeError": 2, | 
|  | 370 | "PropertyValueError": 1, | 
|  | 371 | "PropertyNotWritable": 1, | 
|  | 372 | "PropertyValueModified": 1, | 
|  | 373 | "PropertyMissing": 1, | 
|  | 374 | } | 
|  | 375 |  | 
|  | 376 | addMessageToRoot = [ | 
|  | 377 | "SessionTerminated", | 
|  | 378 | "SubscriptionTerminated", | 
|  | 379 | "AccountRemoved", | 
|  | 380 | "Created", | 
|  | 381 | "Success", | 
|  | 382 | "PasswordChangeRequired", | 
|  | 383 | ] | 
|  | 384 |  | 
|  | 385 | if entry_id in addMessageToJson: | 
|  | 386 | out += f"    addMessageToJson(res.jsonValue, {function_name}({args_out}), arg{addMessageToJson[entry_id]});\n" | 
|  | 387 | elif entry_id in addMessageToRoot: | 
|  | 388 | out += f"    addMessageToJsonRoot(res.jsonValue, {function_name}({args_out}));\n" | 
|  | 389 | else: | 
|  | 390 | out += f"    addMessageToErrorJson(res.jsonValue, {function_name}({args_out}));\n" | 
|  | 391 | out += "}\n" | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 392 | out += "\n" | 
|  | 393 | return out | 
|  | 394 |  | 
|  | 395 |  | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 396 | def create_error_registry( | 
|  | 397 | entry, registry_version, registry_name, namespace_name, filename | 
|  | 398 | ): | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 399 | file, json_dict, namespace, url = entry | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 400 | base_filename = filename + "_messages" | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 401 |  | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 402 | error_messages_hpp = os.path.join( | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 403 | SCRIPT_DIR, "..", "redfish-core", "include", f"{base_filename}.hpp" | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 404 | ) | 
| Ed Tanous | f8cca87 | 2024-11-16 22:47:34 -0800 | [diff] [blame] | 405 | messages = json_dict["Messages"] | 
|  | 406 |  | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 407 | with open( | 
|  | 408 | error_messages_hpp, | 
|  | 409 | "w", | 
|  | 410 | ) as out: | 
|  | 411 | out.write(PRAGMA_ONCE) | 
|  | 412 | out.write(WARNING) | 
|  | 413 | out.write( | 
|  | 414 | """ | 
| Ed Tanous | 4aad6ed | 2025-01-30 09:35:06 -0800 | [diff] [blame] | 415 | // These generated headers are a superset of what is needed. | 
|  | 416 | // clang sees them as an error, so ignore | 
|  | 417 | // NOLINTBEGIN(misc-include-cleaner) | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 418 | #include "http_response.hpp" | 
|  | 419 |  | 
|  | 420 | #include <boost/url/url_view_base.hpp> | 
|  | 421 | #include <nlohmann/json.hpp> | 
|  | 422 |  | 
| Ed Tanous | 4aad6ed | 2025-01-30 09:35:06 -0800 | [diff] [blame] | 423 | #include <cstdint> | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 424 | #include <source_location> | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 425 | #include <string_view> | 
| Ed Tanous | 4aad6ed | 2025-01-30 09:35:06 -0800 | [diff] [blame] | 426 | // NOLINTEND(misc-include-cleaner) | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 427 |  | 
|  | 428 | namespace redfish | 
|  | 429 | { | 
|  | 430 |  | 
|  | 431 | namespace messages | 
|  | 432 | { | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 433 | """ | 
|  | 434 | ) | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 435 | for entry_id, entry in messages.items(): | 
|  | 436 | message = entry["Message"] | 
|  | 437 | for index in range(1, 10): | 
|  | 438 | message = message.replace(f"'%{index}'", f"<arg{index}>") | 
|  | 439 | message = message.replace(f"%{index}", f"<arg{index}>") | 
|  | 440 |  | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 441 | if registry_name == "Base": | 
|  | 442 | out.write("/**\n") | 
|  | 443 | out.write(f"* @brief Formats {entry_id} message into JSON\n") | 
|  | 444 | out.write(f'* Message body: "{message}"\n') | 
|  | 445 | out.write("*\n") | 
|  | 446 | arg_index = 0 | 
|  | 447 | for arg_index, arg in enumerate(entry.get("ParamTypes", [])): | 
|  | 448 | arg_index += 1 | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 449 |  | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 450 | out.write( | 
|  | 451 | f"* @param[in] arg{arg_index} Parameter of message that will replace %{arg_index} in its body.\n" | 
|  | 452 | ) | 
|  | 453 | out.write("*\n") | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 454 | out.write( | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 455 | f"* @returns Message {entry_id} formatted to JSON */\n" | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 456 | ) | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 457 |  | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 458 | out.write( | 
|  | 459 | make_error_function( | 
|  | 460 | entry_id, entry, True, registry_name, namespace_name | 
|  | 461 | ) | 
|  | 462 | ) | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 463 | out.write("    }\n") | 
|  | 464 | out.write("}\n") | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 465 |  | 
|  | 466 | error_messages_cpp = os.path.join( | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 467 | SCRIPT_DIR, "..", "redfish-core", "src", f"{base_filename}.cpp" | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 468 | ) | 
|  | 469 | with open( | 
|  | 470 | error_messages_cpp, | 
|  | 471 | "w", | 
|  | 472 | ) as out: | 
|  | 473 | out.write(WARNING) | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 474 | out.write(f'\n#include "{base_filename}.hpp"\n') | 
| Ed Tanous | 847deee | 2024-12-02 15:28:10 -0800 | [diff] [blame] | 475 | headers = [] | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 476 |  | 
| Ed Tanous | 847deee | 2024-12-02 15:28:10 -0800 | [diff] [blame] | 477 | headers.append('"registries.hpp"') | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 478 | if registry_name == "Base": | 
|  | 479 | reg_name_lower = "base" | 
| Ed Tanous | 6c038f2 | 2025-01-14 09:46:04 -0800 | [diff] [blame] | 480 | headers.append('"error_message_utils.hpp"') | 
| Ed Tanous | 847deee | 2024-12-02 15:28:10 -0800 | [diff] [blame] | 481 | headers.append('"http_response.hpp"') | 
|  | 482 | headers.append('"logging.hpp"') | 
|  | 483 | headers.append("<boost/beast/http/field.hpp>") | 
|  | 484 | headers.append("<boost/beast/http/status.hpp>") | 
|  | 485 | headers.append("<boost/url/url_view_base.hpp>") | 
|  | 486 | headers.append("<source_location>") | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 487 | else: | 
|  | 488 | reg_name_lower = namespace_name.lower() | 
| Ed Tanous | 847deee | 2024-12-02 15:28:10 -0800 | [diff] [blame] | 489 | headers.append(f'"registries/{reg_name_lower}_message_registry.hpp"') | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 490 |  | 
| Ed Tanous | 847deee | 2024-12-02 15:28:10 -0800 | [diff] [blame] | 491 | headers.append("<nlohmann/json.hpp>") | 
|  | 492 | headers.append("<array>") | 
|  | 493 | headers.append("<cstddef>") | 
|  | 494 | headers.append("<span>") | 
|  | 495 |  | 
| Ed Tanous | a8a5bc1 | 2024-12-02 15:43:16 -0800 | [diff] [blame] | 496 | if registry_name not in ("ResourceEvent", "HeartbeatEvent"): | 
| Ed Tanous | 847deee | 2024-12-02 15:28:10 -0800 | [diff] [blame] | 497 | headers.append("<cstdint>") | 
|  | 498 | headers.append("<string>") | 
|  | 499 | headers.append("<string_view>") | 
|  | 500 |  | 
|  | 501 | for header in headers: | 
|  | 502 | out.write(f"#include {header}\n") | 
|  | 503 |  | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 504 | out.write( | 
|  | 505 | """ | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 506 | // Clang can't seem to decide whether this header needs to be included or not, | 
|  | 507 | // and is inconsistent.  Include it for now | 
|  | 508 | // NOLINTNEXTLINE(misc-include-cleaner) | 
|  | 509 | #include <utility> | 
|  | 510 |  | 
|  | 511 | namespace redfish | 
|  | 512 | { | 
|  | 513 |  | 
|  | 514 | namespace messages | 
|  | 515 | { | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 516 | """ | 
|  | 517 | ) | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 518 | out.write( | 
|  | 519 | """ | 
|  | 520 | static nlohmann::json getLog(redfish::registries::{namespace_name}::Index name, | 
|  | 521 | std::span<const std::string_view> args) | 
|  | 522 | {{ | 
|  | 523 | size_t index = static_cast<size_t>(name); | 
|  | 524 | if (index >= redfish::registries::{namespace_name}::registry.size()) | 
|  | 525 | {{ | 
|  | 526 | return {{}}; | 
|  | 527 | }} | 
|  | 528 | return getLogFromRegistry(redfish::registries::{namespace_name}::header, | 
|  | 529 | redfish::registries::{namespace_name}::registry, index, args); | 
|  | 530 | }} | 
|  | 531 |  | 
|  | 532 | """.format( | 
|  | 533 | namespace_name=namespace_name | 
|  | 534 | ) | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 535 | ) | 
|  | 536 | for entry_id, entry in messages.items(): | 
|  | 537 | out.write( | 
|  | 538 | f"""/** | 
|  | 539 | * @internal | 
|  | 540 | * @brief Formats {entry_id} message into JSON | 
|  | 541 | * | 
|  | 542 | * See header file for more information | 
|  | 543 | * @endinternal | 
|  | 544 | */ | 
|  | 545 | """ | 
|  | 546 | ) | 
|  | 547 | message = entry["Message"] | 
| Ed Tanous | f175c28 | 2024-12-02 15:12:50 -0800 | [diff] [blame] | 548 | out.write( | 
|  | 549 | make_error_function( | 
|  | 550 | entry_id, entry, False, registry_name, namespace_name | 
|  | 551 | ) | 
|  | 552 | ) | 
| Ed Tanous | 7ccfe68 | 2024-11-16 14:36:16 -0800 | [diff] [blame] | 553 |  | 
|  | 554 | out.write("    }\n") | 
|  | 555 | out.write("}\n") | 
|  | 556 | os.system(f"clang-format -i {error_messages_hpp} {error_messages_cpp}") | 
| Ed Tanous | 42079ec | 2024-11-16 13:32:29 -0800 | [diff] [blame] | 557 |  | 
|  | 558 |  | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 559 | def make_privilege_registry(): | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 560 | path, json_file, type_name, url = make_getter( | 
| Gunnar Mills | 5910d94 | 2024-04-16 12:07:17 -0500 | [diff] [blame] | 561 | "Redfish_1.5.0_PrivilegeRegistry.json", | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 562 | "privilege_registry.hpp", | 
|  | 563 | "privilege", | 
|  | 564 | ) | 
|  | 565 | with open(path, "w") as registry: | 
| Nan Zhou | 043bec0 | 2022-09-20 18:12:13 +0000 | [diff] [blame] | 566 | registry.write(PRIVILEGE_HEADER) | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 567 |  | 
|  | 568 | privilege_dict = {} | 
|  | 569 | for mapping in json_file["Mappings"]: | 
|  | 570 | # first pass, identify all the unique privilege sets | 
|  | 571 | for operation, privilege_list in mapping["OperationMap"].items(): | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 572 | privilege_dict[ | 
|  | 573 | get_privilege_string_from_list(privilege_list) | 
|  | 574 | ] = (privilege_list,) | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 575 | for index, key in enumerate(privilege_dict): | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 576 | (privilege_list,) = privilege_dict[key] | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 577 | name = get_variable_name_for_privilege_set(privilege_list) | 
| Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 578 | registry.write( | 
| Ed Tanous | 5b9ef70 | 2022-02-17 12:19:32 -0800 | [diff] [blame] | 579 | "const std::array<Privileges, {length}> " | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 580 | "privilegeSet{name} = {key};\n".format( | 
|  | 581 | length=len(privilege_list), name=name, key=key | 
|  | 582 | ) | 
| Ed Tanous | 5b9ef70 | 2022-02-17 12:19:32 -0800 | [diff] [blame] | 583 | ) | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 584 | privilege_dict[key] = (privilege_list, name) | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 585 |  | 
|  | 586 | for mapping in json_file["Mappings"]: | 
|  | 587 | entity = mapping["Entity"] | 
| Ed Tanous | 4d99bbb | 2022-02-17 10:02:57 -0800 | [diff] [blame] | 588 | registry.write("// {}\n".format(entity)) | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 589 | for operation, privilege_list in mapping["OperationMap"].items(): | 
|  | 590 | privilege_string = get_privilege_string_from_list( | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 591 | privilege_list | 
|  | 592 | ) | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 593 | operation = operation.lower() | 
|  | 594 |  | 
| Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 595 | registry.write( | 
|  | 596 | "const static auto& {}{} = privilegeSet{};\n".format( | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 597 | operation, entity, privilege_dict[privilege_string][1] | 
|  | 598 | ) | 
|  | 599 | ) | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 600 | registry.write("\n") | 
| Ed Tanous | 5b9ef70 | 2022-02-17 12:19:32 -0800 | [diff] [blame] | 601 | registry.write( | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 602 | "} // namespace redfish::privileges\n// clang-format on\n" | 
|  | 603 | ) | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 604 |  | 
|  | 605 |  | 
| Gunnar Mills | 665e760 | 2024-04-10 13:14:41 -0500 | [diff] [blame] | 606 | def to_pascal_case(text): | 
|  | 607 | s = text.replace("_", " ") | 
|  | 608 | s = s.split() | 
|  | 609 | if len(text) == 0: | 
|  | 610 | return text | 
|  | 611 | return "".join(i.capitalize() for i in s[0:]) | 
|  | 612 |  | 
|  | 613 |  | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 614 | def main(): | 
| Ed Tanous | c8895b0 | 2025-01-03 11:44:08 -0800 | [diff] [blame] | 615 | dmtf_registries = OrderedDict( | 
|  | 616 | [ | 
|  | 617 | ("base", "1.19.0"), | 
|  | 618 | ("composition", "1.1.2"), | 
| Igor Kanyuka | 0bce6a9 | 2025-02-21 12:40:12 +0000 | [diff] [blame^] | 619 | ("environmental", "1.1.0"), | 
| Ed Tanous | c8895b0 | 2025-01-03 11:44:08 -0800 | [diff] [blame] | 620 | ("ethernet_fabric", "1.0.1"), | 
|  | 621 | ("fabric", "1.0.2"), | 
|  | 622 | ("heartbeat_event", "1.0.1"), | 
|  | 623 | ("job_event", "1.0.1"), | 
|  | 624 | ("license", "1.0.3"), | 
|  | 625 | ("log_service", "1.0.1"), | 
|  | 626 | ("network_device", "1.0.3"), | 
|  | 627 | ("platform", "1.0.1"), | 
|  | 628 | ("power", "1.0.1"), | 
|  | 629 | ("resource_event", "1.3.0"), | 
|  | 630 | ("sensor_event", "1.0.1"), | 
|  | 631 | ("storage_device", "1.2.1"), | 
|  | 632 | ("task_event", "1.0.3"), | 
|  | 633 | ("telemetry", "1.0.0"), | 
|  | 634 | ("update", "1.0.2"), | 
|  | 635 | ] | 
|  | 636 | ) | 
| Gunnar Mills | 665e760 | 2024-04-10 13:14:41 -0500 | [diff] [blame] | 637 |  | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 638 | parser = argparse.ArgumentParser() | 
|  | 639 | parser.add_argument( | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 640 | "--registries", | 
|  | 641 | type=str, | 
| Gunnar Mills | 665e760 | 2024-04-10 13:14:41 -0500 | [diff] [blame] | 642 | default="privilege,openbmc," | 
| Tam Nguyen | 7e6d032 | 2024-12-27 09:47:38 +0700 | [diff] [blame] | 643 | + ",".join([dmtf for dmtf in dmtf_registries]), | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 644 | help="Comma delimited list of registries to update", | 
|  | 645 | ) | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 646 |  | 
|  | 647 | args = parser.parse_args() | 
|  | 648 |  | 
|  | 649 | registries = set(args.registries.split(",")) | 
| Tam Nguyen | 7e6d032 | 2024-12-27 09:47:38 +0700 | [diff] [blame] | 650 | registries_map = OrderedDict() | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 651 |  | 
| Tam Nguyen | 7e6d032 | 2024-12-27 09:47:38 +0700 | [diff] [blame] | 652 | for registry, version in dmtf_registries.items(): | 
| Gunnar Mills | 665e760 | 2024-04-10 13:14:41 -0500 | [diff] [blame] | 653 | if registry in registries: | 
|  | 654 | registry_pascal_case = to_pascal_case(registry) | 
| Igor Kanyuka | 557ab0d | 2025-02-18 15:20:38 +0000 | [diff] [blame] | 655 | registries_map[registry] = make_getter( | 
|  | 656 | f"{registry_pascal_case}.{version}.json", | 
|  | 657 | f"{registry}_message_registry.hpp", | 
|  | 658 | registry, | 
| Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 659 | ) | 
| Ed Tanous | 3e5faba | 2023-08-16 15:11:29 -0700 | [diff] [blame] | 660 | if "openbmc" in registries: | 
| Igor Kanyuka | 557ab0d | 2025-02-18 15:20:38 +0000 | [diff] [blame] | 661 | registries_map["openbmc"] = openbmc_local_getter() | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 662 |  | 
| Igor Kanyuka | 557ab0d | 2025-02-18 15:20:38 +0000 | [diff] [blame] | 663 | update_registries(registries_map.values()) | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 664 |  | 
| Tam Nguyen | 7e6d032 | 2024-12-27 09:47:38 +0700 | [diff] [blame] | 665 | if "base" in registries_map: | 
|  | 666 | create_error_registry( | 
| Ed Tanous | c8895b0 | 2025-01-03 11:44:08 -0800 | [diff] [blame] | 667 | registries_map["base"], | 
|  | 668 | dmtf_registries["base"], | 
|  | 669 | "Base", | 
|  | 670 | "base", | 
|  | 671 | "error", | 
| Tam Nguyen | 7e6d032 | 2024-12-27 09:47:38 +0700 | [diff] [blame] | 672 | ) | 
|  | 673 | if "heartbeat_event" in registries_map: | 
|  | 674 | create_error_registry( | 
|  | 675 | registries_map["heartbeat_event"], | 
|  | 676 | dmtf_registries["heartbeat_event"], | 
|  | 677 | "HeartbeatEvent", | 
|  | 678 | "heartbeat_event", | 
|  | 679 | "heartbeat", | 
|  | 680 | ) | 
|  | 681 | if "resource_event" in registries_map: | 
|  | 682 | create_error_registry( | 
|  | 683 | registries_map["resource_event"], | 
|  | 684 | dmtf_registries["resource_event"], | 
|  | 685 | "ResourceEvent", | 
|  | 686 | "resource_event", | 
|  | 687 | "resource", | 
|  | 688 | ) | 
|  | 689 | if "task_event" in registries_map: | 
|  | 690 | create_error_registry( | 
| Ed Tanous | c8895b0 | 2025-01-03 11:44:08 -0800 | [diff] [blame] | 691 | registries_map["task_event"], | 
|  | 692 | dmtf_registries["task_event"], | 
|  | 693 | "TaskEvent", | 
|  | 694 | "task_event", | 
|  | 695 | "task", | 
| Tam Nguyen | 7e6d032 | 2024-12-27 09:47:38 +0700 | [diff] [blame] | 696 | ) | 
|  | 697 |  | 
| Nan Zhou | 49aa131f | 2022-09-20 18:41:37 +0000 | [diff] [blame] | 698 | if "privilege" in registries: | 
|  | 699 | make_privilege_registry() | 
|  | 700 |  | 
|  | 701 |  | 
|  | 702 | if __name__ == "__main__": | 
|  | 703 | main() |