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