From aaa74b01f235a29acd5d777aac664980845aa32d Mon Sep 17 00:00:00 2001 From: Clemens Vasters Date: Sat, 2 Nov 2024 12:23:36 +0100 Subject: [PATCH 1/3] baseline API client Signed-off-by: Clemens Vasters --- .vscode/launch.json | 47 +- xregistry/cli.py | 8 + xregistry/commands/catalog.py | 1599 +++++++++++++++++++++++++++------ 3 files changed, 1359 insertions(+), 295 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 3b48eb1..e521ad7 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -16,11 +16,12 @@ // "args": "generate --style dashboard --language ts --definitions C:\\git\\cedisco-codegen\\samples\\message-definitions\\inkjet.xreg.json --projectname inkjet_dash --output c:\\temp\\inkjet_dash", //"args": "generate --definitions c:\\git\\cedisco-codegen\\samples\\message-definitions\\compact\\cloudevent-avro-embedded.json --projectname Sample --language cs --style ehproducer --output c:\\temp\\outp\\cs12" //"args": "generate --definitions c:\\git\\cedisco-codegen\\samples\\message-definitions\\fabrikam-motorsports.xreg.json --projectname Sample --language cs --style ehconsumer --output c:\\temp\\outp\\cs13" - "args": "generate --projectname ContosoErp --definitions C:\\git\\cedisco-codegen\\test\\xreg\\contoso-erp.xreg.json --output c:\\temp\\contoso\\ehazfn --style ehazfn --language cs" + //"args": "generate --projectname ContosoErp --definitions C:\\git\\cedisco-codegen\\test\\xreg\\contoso-erp.xreg.json --output c:\\temp\\contoso\\ehazfn --style ehazfn --language cs" //"args": "generate generate --style kafkaproducer --language py --definitions c:\\git\\real-time-sources\\gtfs\\xreg\\gtfs.xreg.json --projectname gtfs_rt_producer --output c:\\temp\\gtfs_rt_producer" //"args": "generate --definitions c:\\git\\cedisco-codegen\\samples\\message-definitions\\separate-schema\\cloudevent-avro-separate.json --projectname Sample --language cs --style amqpproducer --output c:\\temp\\outp\\cs1" //"args": "generate --style ehproducer --language cs --definitions C:\\temp\\kusto\\avro-avsc.xreg.json --projectname Test --output c:\\temp\\outp\\SoccerTest" //"args": "generate --style kafkaproducer --language py --definitions c:\\git\\cedisco-codegen\\samples\\message-definitions\\lightbulb.xreg.json --projectname lightbulb-py-producer --output c:\\temp\\lightbulb-py-prod" + "args": "catalog" }, { "name": "Python: Manifest", @@ -42,7 +43,7 @@ }, { "name": "Python: Current File", - "type": "python", + "type": "debugpy", "request": "launch", "program": "${file}", "console": "integratedTerminal", @@ -51,7 +52,7 @@ }, { "name": "Python: Code Generator EventHubs", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", @@ -60,7 +61,7 @@ }, { "name": "Python: Code Generator C# SB", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", @@ -69,7 +70,7 @@ }, { "name": "Python: Code Generator C# HTTP", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", @@ -78,7 +79,7 @@ }, { "name": "Python: Code Generator C# Consumer", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", @@ -87,7 +88,7 @@ }, { "name": "Python: Code Generator openAPI Producer", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", @@ -96,7 +97,7 @@ }, { "name": "Python: Code Generator openAPI Subscriber", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", @@ -105,7 +106,7 @@ }, { "name": "Python: Code Generator Java producer", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", @@ -114,7 +115,7 @@ }, { "name": "Python: Code Generator Java producer Proto", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", @@ -123,7 +124,7 @@ }, { "name": "Python: Code Generator Java producer Avro", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", @@ -133,7 +134,7 @@ { "name": "Python: Code Generator Java consumer", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", @@ -142,7 +143,7 @@ }, { "name": "Python: Code Generator Java consumer Proto", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", @@ -151,7 +152,7 @@ }, { "name": "Python: Code Generator Java consumer Avro", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", @@ -160,7 +161,7 @@ }, { "name": "Python: Code Generator Fropp", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", @@ -169,7 +170,7 @@ }, { "name": "Python: Code Generator Help", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", @@ -178,7 +179,7 @@ }, { "name": "Python: List JSON", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", @@ -187,22 +188,12 @@ }, { "name": "Python: Validate", - "type": "python", + "type": "debugpy", "request": "launch", "program": "-m xregistry", "console": "integratedTerminal", "justMyCode": true, "args": "validate --definitions c:\\git\\cedisco-codegen\\samples\\message-definitions\\Microsoft.Storage.json" - }, - { - "name": "Debug test", - "type": "python", - "request": "attach", - "console": "externalTerminal", - "justMyCode": false, - "stopOnEntry": false, - "envFile": "${workspaceFolder}/.env.test", - "purpose": ["debug-test"] } ] } diff --git a/xregistry/cli.py b/xregistry/cli.py index 7f84fa7..bcbc301 100644 --- a/xregistry/cli.py +++ b/xregistry/cli.py @@ -6,6 +6,9 @@ import logging import sys +from xregistry.commands import catalog +from xregistry.commands.catalog import CatalogSubcommands + logging.basicConfig(level=logging.DEBUG if sys.gettrace() is not None else logging.ERROR, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) @@ -38,6 +41,8 @@ def main(): ManifestSubcommands.add_parsers(manifest_parser) manifest_parser.add_argument("filename", help="The manifest file to use") subparsers_parser.required = True + catalog_parser = subparsers_parser.add_parser("catalog", help="Manage the catalog") + CatalogSubcommands.add_parsers(catalog_parser) # Specify the arguments for the generate command generate_parser.add_argument("--projectname", dest="project_name", required=True, help="The project name (namespace name) for the output") @@ -63,6 +68,9 @@ def main(): # Parse the command line arguments args = parser.parse_args() + if not 'func' in args: + parser.print_help() + return 1 try: args.func(args) return 0 diff --git a/xregistry/commands/catalog.py b/xregistry/commands/catalog.py index b6462c0..e9e66b5 100644 --- a/xregistry/commands/catalog.py +++ b/xregistry/commands/catalog.py @@ -1,11 +1,15 @@ """This module contains the CatalogSubcommands class, which provides methods to handle catalog subcommands.""" +from email import message import json import datetime import argparse +import re from typing import List, Dict, Any, Optional import requests +PROPERTY_TYPES = ["string", "int", "timestamp", "uritemplate"] + def current_time_iso() -> str: """Returns the current time in ISO format.""" return datetime.datetime.now().isoformat() @@ -13,37 +17,21 @@ def current_time_iso() -> str: class CatalogSubcommands: """Class containing methods to handle catalog subcommands.""" - def __init__(self): - self.base_url = "" - - def set_base_url(self, uri: str) -> None: - """Sets the base URL for the API.""" - self.base_url = uri - - def init_catalog(self, uri: str) -> None: - """Initializes a new catalog by sending a POST request to the API.""" - self.set_base_url(uri) - data = { - "endpoints": {}, - "messagegroups": {}, - "schemagroups": {} - } - response = requests.post(self.base_url, json=data) - if response.status_code != 200: - raise ValueError(f"Failed to initialize catalog: {response.text}") + def __init__(self, base_url: str) -> None: + self.base_url = base_url - def add_endpoint(self, uri: str, endpointid: str, usage: str, protocol: str, endpoints: Optional[List[str]] = None, + def add_endpoint(self, endpointid: str, usage: str, protocol: str, endpoints: Optional[List[str]] = None, options: Optional[Dict[str, Any]] = None, messagegroups: Optional[List[str]] = None, deployed: bool = False, documentation: Optional[str] = None, description: Optional[str] = None, labels: Optional[Dict[str, str]] = None, - name: Optional[str] = None) -> None: + name: Optional[str] = None, channel: Optional[str] = None, deprecated: Optional[bool] = None) -> None: """Adds an endpoint to the catalog.""" - self.set_base_url(uri) + endpoint = { "endpointid": endpointid, "usage": usage, "protocol": protocol, - "createdon": current_time_iso(), - "modifiedon": current_time_iso(), + "createdat": current_time_iso(), + "modifiedat": current_time_iso(), "epoch": 0 } if endpoints: @@ -62,23 +50,35 @@ def add_endpoint(self, uri: str, endpointid: str, usage: str, protocol: str, end endpoint["labels"] = labels if name: endpoint["name"] = name + if channel: + endpoint["channel"] = channel + if deprecated: + endpoint["deprecated"] = deprecated response = requests.put(f"{self.base_url}/endpoints/{endpointid}", json=endpoint) if response.status_code != 200: raise ValueError(f"Failed to add endpoint: {response.text}") - def remove_endpoint(self, uri: str, endpointid: str, epoch: int) -> None: + def remove_endpoint(self, endpointid: str) -> None: """Removes an endpoint from the catalog.""" - self.set_base_url(uri) + + # Fetch the current endpoint to get the epoch + response = requests.get(f"{self.base_url}/endpoints/{endpointid}") + if response.status_code != 200: + raise ValueError(f"Endpoint with id {endpointid} does not exist: {response.text}") + endpoint = response.json() + epoch = endpoint.get("epoch", 0) + + # Delete the endpoint response = requests.delete(f"{self.base_url}/endpoints/{endpointid}", params={"epoch": epoch}) if response.status_code != 204: raise ValueError(f"Failed to remove endpoint: {response.text}") - def edit_endpoint(self, uri: str, endpointid: str, usage: Optional[str] = None, protocol: Optional[str] = None, endpoints: Optional[List[str]] = None, + def edit_endpoint(self, endpointid: str, usage: Optional[str] = None, protocol: Optional[str] = None, endpoints: Optional[List[str]] = None, options: Optional[Dict[str, Any]] = None, messagegroups: Optional[List[str]] = None, deployed: bool|None = None, documentation: Optional[str] = None, description: Optional[str] = None, labels: Optional[Dict[str, str]] = None, - name: Optional[str] = None) -> None: + name: Optional[str] = None, channel: Optional[str] = None, deprecated: Optional[bool] = None) -> None: """Edits an existing endpoint in the catalog.""" - self.set_base_url(uri) + response = requests.get(f"{self.base_url}/endpoints/{endpointid}") if response.status_code != 200: raise ValueError(f"Endpoint with id {endpointid} does not exist: {response.text}") @@ -103,43 +103,47 @@ def edit_endpoint(self, uri: str, endpointid: str, usage: Optional[str] = None, endpoint["labels"] = labels if name: endpoint["name"] = name - endpoint["modifiedon"] = current_time_iso() + if channel: + endpoint["channel"] = channel + if deprecated: + endpoint["deprecated"] = deprecated + endpoint["modifiedat"] = current_time_iso() endpoint["epoch"] += 1 response = requests.put(f"{self.base_url}/endpoints/{endpointid}", json=endpoint) if response.status_code != 200: raise ValueError(f"Failed to edit endpoint: {response.text}") - def show_endpoint(self, uri: str, endpointid: str) -> None: + def show_endpoint(self, endpointid: str) -> None: """Shows an endpoint from the catalog.""" - self.set_base_url(uri) + response = requests.get(f"{self.base_url}/endpoints/{endpointid}") if response.status_code != 200: raise ValueError(f"Endpoint with id {endpointid} does not exist: {response.text}") print(json.dumps(response.json(), indent=2)) - def apply_endpoint(self, uri: str, file: str) -> None: + def apply_endpoint(self, file: str) -> None: """Applies an endpoint from a file.""" - self.set_base_url(uri) + with open(file, 'r', encoding='utf-8') as ef: endpoint = json.load(ef) endpointid = endpoint["endpointid"] response = requests.get(f"{self.base_url}/endpoints/{endpointid}") if response.status_code == 200: - self.edit_endpoint(uri, endpointid, **endpoint) + self.edit_endpoint(endpointid, **endpoint) else: - self.add_endpoint(uri, **endpoint) + self.add_endpoint(**endpoint) - def add_messagegroup(self, uri: str, messagegroupid: str, format: str, binding: str, messages: Optional[Dict[str, Any]] = None, + def add_messagegroup(self, messagegroupid: str, format: str, binding: str, messages: Optional[Dict[str, Any]] = None, description: Optional[str] = None, documentation: Optional[str] = None, labels: Optional[Dict[str, str]] = None, name: Optional[str] = None) -> None: """Adds a messagegroup to the catalog.""" - self.set_base_url(uri) + messagegroup = { "messagegroupid": messagegroupid, "format": format, "binding": binding, - "createdon": current_time_iso(), - "modifiedon": current_time_iso(), + "createdat": current_time_iso(), + "modifiedat": current_time_iso(), "epoch": 0 } if messages: @@ -156,18 +160,26 @@ def add_messagegroup(self, uri: str, messagegroupid: str, format: str, binding: if response.status_code != 200: raise ValueError(f"Failed to add messagegroup: {response.text}") - def remove_messagegroup(self, uri: str, messagegroupid: str, epoch: int) -> None: + def remove_messagegroup(self, messagegroupid: str) -> None: """Removes a messagegroup from the catalog.""" - self.set_base_url(uri) + + # Fetch the current messagegroup to get the epoch + response = requests.get(f"{self.base_url}/messagegroups/{messagegroupid}") + if response.status_code != 200: + raise ValueError(f"Messagegroup with id {messagegroupid} does not exist: {response.text}") + messagegroup = response.json() + epoch = messagegroup.get("epoch", 0) + + # Delete the messagegroup response = requests.delete(f"{self.base_url}/messagegroups/{messagegroupid}", params={"epoch": epoch}) if response.status_code != 204: raise ValueError(f"Failed to remove messagegroup: {response.text}") - def edit_messagegroup(self, uri: str, messagegroupid: str, format: Optional[str] = None, binding: Optional[str] = None, messages: Optional[Dict[str, Any]] = None, + def edit_messagegroup(self, messagegroupid: str, format: Optional[str] = None, binding: Optional[str] = None, messages: Optional[Dict[str, Any]] = None, description: Optional[str] = None, documentation: Optional[str] = None, labels: Optional[Dict[str, str]] = None, name: Optional[str] = None) -> None: """Edits an existing messagegroup in the catalog.""" - self.set_base_url(uri) + response = requests.get(f"{self.base_url}/messagegroups/{messagegroupid}") if response.status_code != 200: raise ValueError(f"Messagegroup with id {messagegroupid} does not exist: {response.text}") @@ -186,42 +198,42 @@ def edit_messagegroup(self, uri: str, messagegroupid: str, format: Optional[str] messagegroup["labels"] = labels if name: messagegroup["name"] = name - messagegroup["modifiedon"] = current_time_iso() + messagegroup["modifiedat"] = current_time_iso() messagegroup["epoch"] += 1 response = requests.put(f"{self.base_url}/messagegroups/{messagegroupid}", json=messagegroup) if response.status_code != 200: raise ValueError(f"Failed to edit messagegroup: {response.text}") - def show_messagegroup(self, uri: str, messagegroupid: str) -> None: + def show_messagegroup(self, messagegroupid: str) -> None: """Shows a messagegroup from the catalog.""" - self.set_base_url(uri) + response = requests.get(f"{self.base_url}/messagegroups/{messagegroupid}") if response.status_code != 200: raise ValueError(f"Messagegroup with id {messagegroupid} does not exist: {response.text}") print(json.dumps(response.json(), indent=2)) - def apply_messagegroup(self, uri: str, file: str) -> None: + def apply_messagegroup(self, file: str) -> None: """Applies a messagegroup from a file.""" - self.set_base_url(uri) + with open(file, 'r', encoding='utf-8') as ef: messagegroup = json.load(ef) messagegroupid = messagegroup["messagegroupid"] response = requests.get(f"{self.base_url}/messagegroups/{messagegroupid}") if response.status_code == 200: - self.edit_messagegroup(uri, messagegroupid, **messagegroup) + self.edit_messagegroup(messagegroupid, **messagegroup) else: - self.add_messagegroup(uri, **messagegroup) + self.add_messagegroup(**messagegroup) - def add_schemagroup(self, uri: str, schemagroupid: str, format: str, schemas: Optional[Dict[str, Any]] = None, + def add_schemagroup(self, schemagroupid: str, format: str, schemas: Optional[Dict[str, Any]] = None, description: Optional[str] = None, documentation: Optional[str] = None, labels: Optional[Dict[str, str]] = None, name: Optional[str] = None) -> None: """Adds a schemagroup to the catalog.""" - self.set_base_url(uri) + schemagroup = { "schemagroupid": schemagroupid, "format": format, - "createdon": current_time_iso(), - "modifiedon": current_time_iso(), + "createdat": current_time_iso(), + "modifiedat": current_time_iso(), "epoch": 0 } if schemas: @@ -238,18 +250,26 @@ def add_schemagroup(self, uri: str, schemagroupid: str, format: str, schemas: Op if response.status_code != 200: raise ValueError(f"Failed to add schemagroup: {response.text}") - def remove_schemagroup(self, uri: str, schemagroupid: str, epoch: int) -> None: + def remove_schemagroup(self, schemagroupid: str) -> None: """Removes a schemagroup from the catalog.""" - self.set_base_url(uri) + + # Fetch the current schemagroup to get the epoch + response = requests.get(f"{self.base_url}/schemagroups/{schemagroupid}") + if response.status_code != 200: + raise ValueError(f"Schemagroup with id {schemagroupid} does not exist: {response.text}") + schemagroup = response.json() + epoch = schemagroup.get("epoch", 0) + + # Delete the schemagroup response = requests.delete(f"{self.base_url}/schemagroups/{schemagroupid}", params={"epoch": epoch}) if response.status_code != 204: raise ValueError(f"Failed to remove schemagroup: {response.text}") - def edit_schemagroup(self, uri: str, schemagroupid: str, format: Optional[str] = None, schemas: Optional[Dict[str, Any]] = None, + def edit_schemagroup(self, schemagroupid: str, format: Optional[str] = None, schemas: Optional[Dict[str, Any]] = None, description: Optional[str] = None, documentation: Optional[str] = None, labels: Optional[Dict[str, str]] = None, name: Optional[str] = None) -> None: """Edits an existing schemagroup in the catalog.""" - self.set_base_url(uri) + response = requests.get(f"{self.base_url}/schemagroups/{schemagroupid}") if response.status_code != 200: raise ValueError(f"Schemagroup with id {schemagroupid} does not exist: {response.text}") @@ -266,47 +286,531 @@ def edit_schemagroup(self, uri: str, schemagroupid: str, format: Optional[str] = schemagroup["labels"] = labels if name: schemagroup["name"] = name - schemagroup["modifiedon"] = current_time_iso() + schemagroup["modifiedat"] = current_time_iso() schemagroup["epoch"] += 1 response = requests.put(f"{self.base_url}/schemagroups/{schemagroupid}", json=schemagroup) if response.status_code != 200: raise ValueError(f"Failed to edit schemagroup: {response.text}") - def show_schemagroup(self, uri: str, schemagroupid: str) -> None: + def show_schemagroup(self, schemagroupid: str) -> None: """Shows a schemagroup from the catalog.""" - self.set_base_url(uri) + response = requests.get(f"{self.base_url}/schemagroups/{schemagroupid}") if response.status_code != 200: raise ValueError(f"Schemagroup with id {schemagroupid} does not exist: {response.text}") print(json.dumps(response.json(), indent=2)) - def apply_schemagroup(self, uri: str, file: str) -> None: + def apply_schemagroup(self, file: str) -> None: """Applies a schemagroup from a file.""" - self.set_base_url(uri) + with open(file, 'r', encoding='utf-8') as ef: schemagroup = json.load(ef) schemagroupid = schemagroup["schemagroupid"] response = requests.get(f"{self.base_url}/schemagroups/{schemagroupid}") if response.status_code == 200: - self.edit_schemagroup(uri, schemagroupid, **schemagroup) + self.edit_schemagroup(schemagroupid, **schemagroup) + else: + self.add_schemagroup(**schemagroup) + + def add_message(self, groupid: str, messageid: str, format: str, protocol: str, schemaformat: Optional[str] = None, + schemagroup: Optional[str] = None, schemaid: Optional[str] = None, schemaurl: Optional[str] = None, + documentation: Optional[str] = None, description: Optional[str] = None, labels: Optional[Dict[str, str]] = None, + name: Optional[str] = None) -> None: + """Adds a message to a message group in the catalog.""" + + message = { + "messageid": messageid, + "format": format, + "protocol": protocol, + "createdat": current_time_iso(), + "modifiedat": current_time_iso(), + "epoch": 0 + } + if schemaformat: + message["schemaformat"] = schemaformat + if schemagroup: + message["schemagroup"] = schemagroup + if schemaid: + message["schemaid"] = schemaid + if schemaurl: + message["schemaurl"] = schemaurl + if documentation: + message["documentation"] = documentation + if description: + message["description"] = description + if labels: + message["labels"] = labels + if name: + message["name"] = name + + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to add message: {response.text}") + + def remove_message(self, groupid: str, messageid: str) -> None: + """Removes a message from a message group in the catalog.""" + + # Fetch the current message to get the epoch + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Message with id {messageid} does not exist: {response.text}") + message = response.json() + epoch = message.get("epoch", 0) + + # Delete the message + response = requests.delete(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", params={"epoch": epoch}) + if response.status_code != 204: + raise ValueError(f"Failed to remove message: {response.text}") + + def edit_message(self, groupid: str, messageid: str, format: Optional[str] = None, protocol: Optional[str] = None, schemaformat: Optional[str] = None, + schemagroup: Optional[str] = None, schemaid: Optional[str] = None, schemaurl: Optional[str] = None, + documentation: Optional[str] = None, description: Optional[str] = None, labels: Optional[Dict[str, str]] = None, + name: Optional[str] = None) -> None: + """Edits an existing message in a message group in the catalog.""" + + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Message with id {messageid} does not exist: {response.text}") + message = response.json() + if format: + message["format"] = format + if protocol: + message["protocol"] = protocol + if schemaformat: + message["schemaformat"] = schemaformat + if schemagroup: + message["schemagroup"] = schemagroup + if schemaid: + message["schemaid"] = schemaid + if schemaurl: + message["schemaurl"] = schemaurl + if documentation: + message["documentation"] = documentation + if description: + message["description"] = description + if labels: + message["labels"] = labels + if name: + message["name"] = name + message["modifiedat"] = current_time_iso() + message["epoch"] += 1 + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to edit message: {response.text}") + + def remove_protocol_option(self, messageid: str, message: Any, section: str|None, name: str) -> None: + """Removes a protocol option from a message in the catalog.""" + # Remove the metadata entry + if "protocoloptions" in message: + obj = message["protocoloptions"] + if section: + if section in obj: + obj = message["protocoloptions"][section] + else: + raise ValueError(f"Section {section} not found in message {messageid}") + if name in obj: + del obj[name] else: - self.add_schemagroup(uri, **schemagroup) + raise ValueError(f"Metadata entry {name} not found in message {messageid}") + else: + raise ValueError(f"No protocoloptions found for message {messageid}") + + def set_protocol_option(self, message:Any, section: str|None, name: str, type: str, value: str|None, description: str, required: bool) -> None: + """Adds a protocol option to a message.""" + + if "protocoloptions" not in message: + obj = message["protocoloptions"] = {} + if section not in message["protocoloptions"]: + obj = message["protocoloptions"][section] = {} + obj[name] = {} + if type: + obj[name]["type"] = type + if value: + obj[name]["value"] = value + if description: + obj[name]["description"] = description + if required: + obj[name]["required"] = required + + + def remove_amqp_message_metadata(self, groupid: str, messageid: str, section: str|None, name: str) -> None: + """Removes AMQP message metadata from a message in a message group in the catalog.""" + + # Fetch the current message + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Failed to fetch message: {response.text}") + message = response.json() + + if "protocol" not in message or message["protocol"] != "AMQP/1.0": + raise ValueError(f"Message {messageid} is not an AMQP message") + + self.remove_protocol_option(messageid, message, section, name) + # Increment the epoch + message["epoch"] += 1 + + # Update the message with a PUT request + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to remove AMQP message metadata: {response.text}") + + def add_amqp_message_metadata(self, groupid: str, messageid: str, section: str|None, name: str, type: str, value: str|None, description: str, required: bool) -> None: + """Adds AMQP message metadata to a message in a message group in the catalog.""" + + # Fetch the current message + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Failed to fetch message: {response.text}") + message = response.json() + + if "protocol" not in message or message["protocol"] != "AMQP/1.0": + raise ValueError(f"Message {messageid} is not an AMQP message") + + self.set_protocol_option(message, section, name, type, value, description, required) + + # Increment the epoch + message["epoch"] += 1 + + # Update the message with a PUT request + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to add AMQP message metadata: {response.text}") + + def edit_amqp_message_metadata(self, groupid: str, messageid: str, section: str|None, name: str, type: str, value: str, description: str, required: bool) -> None: + """Edits AMQP message metadata for a message in a message group in the catalog.""" + + # Fetch the current message + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Failed to fetch message: {response.text}") + message = response.json() + + if "protocol" not in message or message["protocol"] != "AMQP/1.0": + raise ValueError(f"Message {messageid} is not an AMQP message") + + # Update the metadata entry + self.set_protocol_option(message, section, name, type, value, description, required) + + # Increment the epoch + message["epoch"] += 1 + + # Update the message with a PUT request + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to edit AMQP message metadata: {response.text}") + + def add_mqtt_message_metadata(self, groupid: str, messageid: str, mqtt_version: str, name: str, type: str, value: str, description: str, required: bool) -> None: + """Adds MQTT message metadata to a message in a message group in the catalog.""" + + # Fetch the current message + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Failed to fetch message: {response.text}") + message = response.json() + + if "protocol" not in message or message["protocol"] != "MQTT/5.0" and message["protocol"] != "MQTT/3.1.1": + raise ValueError(f"Message {messageid} is not an MQTT message") + + self.set_protocol_option(message, None, name, type, value, description, required) + + # Increment the epoch + message["epoch"] += 1 + + # Update the message with a PUT request + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to add MQTT message metadata: {response.text}") + + def remove_mqtt_message_metadata(self, groupid: str, messageid: str, section:str|None, name: str) -> None: + """Removes MQTT message metadata from a message in a message group in the catalog.""" + + # Fetch the current message + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Failed to fetch message: {response.text}") + message = response.json() + + if "protocol" not in message or message["protocol"] != "MQTT/5.0" and message["protocol"] != "MQTT/3.1.1": + raise ValueError(f"Message {messageid} is not an MQTT message") + + self.remove_protocol_option(messageid, message, section, name) + + # Increment the epoch + message["epoch"] += 1 + + # Update the message with a PUT request + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to remove MQTT message metadata: {response.text}") + + def edit_mqtt_message_metadata(self, groupid: str, messageid: str, name: str, type: str, value: str, description: str, required: bool) -> None: + """Edits MQTT message metadata for a message in a message group in the catalog.""" + + # Fetch the current message + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Failed to fetch message: {response.text}") + message = response.json() + + if "protocol" not in message or message["protocol"] != "MQTT/5.0" and message["protocol"] != "MQTT/3.1.1": + raise ValueError(f"Message {messageid} is not an MQTT message") + + self.set_protocol_option(message, None, name, type, value, description, required) + + # Increment the epoch + message["epoch"] += 1 + + # Update the message with a PUT request + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to edit MQTT message metadata: {response.text}") + + def add_kafka_message_metadata(self, groupid: str, messageid: str, section: Optional[str], name: str, type: str, value: str, description: str, required: bool) -> None: + """Adds Kafka message metadata to a message in a message group in the catalog.""" + + # Fetch the current message + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Failed to fetch message: {response.text}") + message = response.json() + + if "protocol" not in message or message["protocol"] != "Kafka": + raise ValueError(f"Message {messageid} is not a Kafka message") + + self.set_protocol_option(message, section, name, type, value, description, required) + + # Increment the epoch + message["epoch"] += 1 + + # Update the message with a PUT request + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to add Kafka message metadata: {response.text}") + + def remove_kafka_message_metadata(self, groupid: str, messageid: str, section: Optional[str], name: str) -> None: + """Removes Kafka message metadata from a message in a message group in the catalog.""" + + # Fetch the current message + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Failed to fetch message: {response.text}") + message = response.json() + + if "protocol" not in message or message["protocol"] != "Kafka": + raise ValueError(f"Message {messageid} is not a Kafka message") + + self.remove_protocol_option(messageid, message, section, name) + + # Increment the epoch + message["epoch"] += 1 + + # Update the message with a PUT request + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to remove Kafka message metadata: {response.text}") + + def edit_kafka_message_metadata(self, groupid: str, messageid: str, section: Optional[str], name: str, type: str, value: str, description: str, required: bool) -> None: + """Edits Kafka message metadata for a message in a message group in the catalog.""" + + # Fetch the current message + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Failed to fetch message: {response.text}") + message = response.json() + + if "protocol" not in message or message["protocol"] != "Kafka": + raise ValueError(f"Message {messageid} is not a Kafka message") + + self.set_protocol_option(message, section, name, type, value, description, required) + + # Increment the epoch + message["epoch"] += 1 + + # Update the message with a PUT request + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to edit Kafka message metadata: {response.text}") + + def add_http_message_metadata(self, groupid: str, messageid: str, section: str | None, name: str, type: str, value: str, description: str, required: bool) -> None: + """Adds HTTP message metadata to a message in a message group in the catalog.""" + + # Fetch the current message + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Failed to fetch message: {response.text}") + message = response.json() + + if "protocol" not in message or message["protocol"] != "HTTP/1.1": + raise ValueError(f"Message {messageid} is not an HTTP message") + + self.set_protocol_option(message, section, name, type, value, description, required) + + # Increment the epoch + message["epoch"] += 1 + + # Update the message with a PUT request + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to add HTTP message metadata: {response.text}") + + def remove_http_message_metadata(self, groupid: str, messageid: str, section: str | None, name: str) -> None: + """Removes HTTP message metadata from a message in a message group in the catalog.""" + + # Fetch the current message + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Failed to fetch message: {response.text}") + message = response.json() + + if "protocol" not in message or message["protocol"] != "HTTP/1.1": + raise ValueError(f"Message {messageid} is not an HTTP message") + + self.remove_protocol_option(messageid, message, section, name) + + # Increment the epoch + message["epoch"] += 1 + + # Update the message with a PUT request + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to remove HTTP message metadata: {response.text}") + + def edit_http_message_metadata(self, groupid: str, messageid: str, section: str | None, name: str, type: str, value: str, description: str, required: bool) -> None: + """Edits HTTP message metadata for a message in a message group in the catalog.""" + + # Fetch the current message + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Failed to fetch message: {response.text}") + message = response.json() + + if "protocol" not in message or message["protocol"] != "HTTP/1.1": + raise ValueError(f"Message {messageid} is not an HTTP message") + + self.set_protocol_option(message, section, name, type, value, description, required) + + # Increment the epoch + message["epoch"] += 1 + + # Update the message with a PUT request + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to edit HTTP message metadata: {response.text}") + + def set_envelope_metadata(self, message:Any,name: str, type: str, value: str, description: str, required: bool) -> None: + """Sets envelope metadata for a message.""" + + if "envelopemetadata" not in message: + obj = message["envelopemetadata"] = {} + else: + obj = message["envelopemetadata"] + obj[name] = {} + if type: + obj[name]["type"] = type + if value: + obj[name]["value"] = value + if description: + obj[name]["description"] = description + if required: + obj[name]["required"] = required + + def remove_envelope_metadata(self, messageid: str, message: Any,name: str) -> None: + """Removes envelope metadata from a message in the catalog.""" + + # Remove the metadata entry + if "envelopemetadata" in message: + obj = message["envelopemetadata"] + if name in obj: + del obj[name] + else: + raise ValueError(f"Metadata entry {name} not found in message {messageid}") + else: + raise ValueError(f"No envelopemetadata found for message {messageid}") + + + def add_cloudevents_message_metadata(self, groupid: str, messageid: str, attribute: str, type: str, description: str, value: str, required: bool) -> None: + """Adds CloudEvents message metadata to a message in a message group in the catalog.""" + + # Fetch the current message + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Failed to fetch message: {response.text}") + message = response.json() + + if "envelope" not in message or message["envelope"] != "CloudEvents/1.0": + raise ValueError(f"Message {messageid} is not a CloudEvents message") + + self.set_envelope_metadata(message, attribute, type, value, description, required) + + # Increment the epoch + message["epoch"] += 1 + + # Update the message with a PUT request + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to add CloudEvents message metadata: {response.text}") + + def edit_cloudevents_message_metadata(self, groupid: str, messageid: str, attribute: str, type: str, description: str, value: str, required: bool) -> None: + """Edits CloudEvents message metadata for a message in a message group in the catalog.""" + + # Fetch the current message + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Failed to fetch message: {response.text}") + message = response.json() + + if "envelope" not in message or message["envelope"] != "CloudEvents/1.0": + raise ValueError(f"Message {messageid} is not a CloudEvents message") + + self.remove_envelope_metadata(messageid, message, attribute) + + # Increment the epoch + message["epoch"] += 1 + + # Update the message with a PUT request + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to edit CloudEvents message metadata: {response.text}") + + def remove_cloudevents_message_metadata(self, groupid: str, messageid: str, attribute: str) -> None: + """Removes CloudEvents message metadata from a message in a message group in the catalog.""" + + # Fetch the current message + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Failed to fetch message: {response.text}") + message = response.json() + + # Remove the metadata entry + if "metadata" in message: + message["metadata"] = [m for m in message["metadata"] if m["attribute"] != attribute] + + # Increment the epoch + message["epoch"] += 1 + + # Update the message with a PUT request + response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + if response.status_code != 200: + raise ValueError(f"Failed to remove CloudEvents message metadata: {response.text}") - def add_schema(self, uri: str, groupid: str, schemaid: str, format: str, versionid: str = "1", schema: Optional[str] = None, + def add_schema(self, groupid: str, schemaid: str, format: str, versionid: str = "1", schema: Optional[str] = None, schemaimport: Optional[str] = None, schemaurl: Optional[str] = None, description: Optional[str] = None, documentation: Optional[str] = None, labels: Optional[Dict[str, str]] = None, name: Optional[str] = None) -> None: """Adds a schema to a schemagroup in the catalog.""" - self.set_base_url(uri) + response = requests.get(f"{self.base_url}/schemagroups/{groupid}") if response.status_code != 200: raise ValueError(f"Schemagroup with id {groupid} does not exist: {response.text}") schemagroup = response.json() + if not format: + raise ValueError("Schema format is required") + schema_obj = { "schemaid": schemaid, "format": format, - "createdon": current_time_iso(), - "modifiedon": current_time_iso(), + "createdat": current_time_iso(), + "modifiedat": current_time_iso(), "epoch": 0 } if schema: @@ -342,9 +846,136 @@ def add_schema(self, uri: str, groupid: str, schemaid: str, format: str, version if response.status_code != 200: raise ValueError(f"Failed to add schema: {response.text}") - def remove_schema(self, uri: str, groupid: str, schemaid: str, versionid: Optional[str] = None) -> None: + def add_schemaversion(self, groupid: str, schemaid: str, format: str, versionid: str = "1", schema: Optional[str] = None, + schemaimport: Optional[str] = None, schemaurl: Optional[str] = None, description: Optional[str] = None, documentation: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, name: Optional[str] = None) -> None: + """Adds a schema version to a schemagroup in the catalog.""" + + response = requests.get(f"{self.base_url}/schemagroups/{groupid}") + if response.status_code != 200: + raise ValueError(f"Schemagroup with id {groupid} does not exist: {response.text}") + schemagroup = response.json() + + schema_obj = { + "schemaid": schemaid, + "format": format, + "versionid": versionid, + "createdat": current_time_iso(), + "modifiedat": current_time_iso(), + "epoch": 0 + } + if schema: + try: + json.loads(schema) + schema_obj["schema"] = schema + except json.JSONDecodeError: + schema_obj["schemabase64"] = schema.encode("utf-8").hex() + elif schemaimport: + with open(schemaimport, 'r', encoding='utf-8') as sf: + schema_content = sf.read() + try: + json.loads(schema_content) + schema_obj["schema"] = schema_content + except json.JSONDecodeError: + schema_obj["schemabase64"] = schema_content.encode("utf-8").hex() + elif schemaurl: + schema_obj["schemaurl"] = schemaurl + if description: + schema_obj["description"] = description + if documentation: + schema_obj["documentation"] = documentation + if labels: + schema_obj["labels"] = labels + if name: + schema_obj["name"] = name + + if "schemas" not in schemagroup: + schemagroup["schemas"] = {} + if schemaid not in schemagroup["schemas"]: + schemagroup["schemas"][schemaid] = {"versions": {}} + schemagroup["schemas"][schemaid]["versions"][versionid] = schema_obj + + response = requests.put(f"{self.base_url}/schemagroups/{groupid}", json=schemagroup) + if response.status_code != 200: + raise ValueError(f"Failed to add schema version: {response.text}") + + def edit_schemaversion(self, groupid: str, schemaid: str, versionid: str, format: Optional[str] = None, schema: Optional[str] = None, + schemaimport: Optional[str] = None, schemaurl: Optional[str] = None, description: Optional[str] = None, documentation: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, name: Optional[str] = None) -> None: + """Edits an existing schema version in a schemagroup in the catalog.""" + + response = requests.get(f"{self.base_url}/schemagroups/{groupid}") + if response.status_code != 200: + raise ValueError(f"Schemagroup with id {groupid} does not exist: {response.text}") + schemagroup = response.json() + + if "schemas" not in schemagroup or schemaid not in schemagroup["schemas"]: + raise ValueError(f"Schema with id {schemaid} does not exist in schemagroup {groupid}") + + if "versions" not in schemagroup["schemas"][schemaid] or versionid not in schemagroup["schemas"][schemaid]["versions"]: + raise ValueError(f"Version with id {versionid} does not exist for schema {schemaid}") + + schema_obj = schemagroup["schemas"][schemaid]["versions"][versionid] + if format: + schema_obj["format"] = format + if schema: + try: + json.loads(schema) + schema_obj["schema"] = schema + except json.JSONDecodeError: + schema_obj["schemabase64"] = schema.encode("utf-8").hex() + elif schemaimport: + with open(schemaimport, 'r', encoding='utf-8') as sf: + schema_content = sf.read() + try: + json.loads(schema_content) + schema_obj["schema"] = schema_content + except json.JSONDecodeError: + schema_obj["schemabase64"] = schema_content.encode("utf-8").hex() + elif schemaurl: + schema_obj["schemaurl"] = schemaurl + if description: + schema_obj["description"] = description + if documentation: + schema_obj["documentation"] = documentation + if labels: + schema_obj["labels"] = labels + if name: + schema_obj["name"] = name + + schema_obj["modifiedat"] = current_time_iso() + schema_obj["epoch"] += 1 + + response = requests.put(f"{self.base_url}/schemagroups/{groupid}", json=schemagroup) + if response.status_code != 200: + raise ValueError(f"Failed to edit schema version: {response.text}") + + def remove_schemaversion(self, groupid: str, schemaid: str, versionid: str) -> None: + """Removes a schema version from a schemagroup in the catalog.""" + + response = requests.get(f"{self.base_url}/schemagroups/{groupid}") + if response.status_code != 200: + raise ValueError(f"Schemagroup with id {groupid} does not exist: {response.text}") + schemagroup = response.json() + + if "schemas" not in schemagroup or schemaid not in schemagroup["schemas"]: + raise ValueError(f"Schema with id {schemaid} does not exist in schemagroup {groupid}") + + if "versions" not in schemagroup["schemas"][schemaid] or versionid not in schemagroup["schemas"][schemaid]["versions"]: + raise ValueError(f"Version with id {versionid} does not exist for schema {schemaid}") + + del schemagroup["schemas"][schemaid]["versions"][versionid] + if not schemagroup["schemas"][schemaid]["versions"]: + del schemagroup["schemas"][schemaid] + + response = requests.put(f"{self.base_url}/schemagroups/{groupid}", json=schemagroup) + if response.status_code != 200: + raise ValueError(f"Failed to remove schema version: {response.text}") + + + def remove_schema(self, groupid: str, schemaid: str, versionid: Optional[str] = None) -> None: """Removes a schema from a schemagroup in the catalog.""" - self.set_base_url(uri) + response = requests.get(f"{self.base_url}/schemagroups/{groupid}") if response.status_code != 200: raise ValueError(f"Schemagroup with id {groupid} does not exist: {response.text}") @@ -371,11 +1002,11 @@ def remove_schema(self, uri: str, groupid: str, schemaid: str, versionid: Option if response.status_code != 200: raise ValueError(f"Failed to remove schema: {response.text}") - def edit_schema(self, uri: str, groupid: str, schemaid: str, format: Optional[str] = None, versionid: str = "1", schema: Optional[str] = None, + def edit_schema(self, groupid: str, schemaid: str, format: Optional[str] = None, versionid: str = "1", schema: Optional[str] = None, schemaimport: Optional[str] = None, schemaurl: Optional[str] = None, description: Optional[str] = None, documentation: Optional[str] = None, labels: Optional[Dict[str, str]] = None, name: Optional[str] = None) -> None: """Edits an existing schema in a schemagroup in the catalog.""" - self.set_base_url(uri) + response = requests.get(f"{self.base_url}/schemagroups/{groupid}") if response.status_code != 200: raise ValueError(f"Schemagroup with id {groupid} does not exist: {response.text}") @@ -412,16 +1043,16 @@ def edit_schema(self, uri: str, groupid: str, schemaid: str, format: Optional[st if name: schema_obj["name"] = name - schema_obj["modifiedon"] = current_time_iso() + schema_obj["modifiedat"] = current_time_iso() schema_obj["epoch"] += 1 response = requests.put(f"{self.base_url}/schemagroups/{groupid}", json=schemagroup) if response.status_code != 200: raise ValueError(f"Failed to edit schema: {response.text}") - def show_schema(self, uri: str, groupid: str, schemaid: str) -> None: + def show_schema(self, groupid: str, schemaid: str) -> None: """Shows a schema from a schemagroup in the catalog.""" - self.set_base_url(uri) + response = requests.get(f"{self.base_url}/schemagroups/{groupid}") if response.status_code != 200: raise ValueError(f"Schemagroup with id {groupid} does not exist: {response.text}") @@ -432,202 +1063,636 @@ def show_schema(self, uri: str, groupid: str, schemaid: str) -> None: print(json.dumps(schemagroup["schemas"][schemaid], indent=2)) - def apply_schema(self, uri: str, file: str) -> None: + def show_message(self, groupid: str, messageid: str) -> None: + """Shows a message from a message group in the catalog.""" + + response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + if response.status_code != 200: + raise ValueError(f"Message with id {messageid} does not exist in message group {groupid}") + message = response.json() + + print(json.dumps(message, indent=2)) + + def apply_schema(self, file: str) -> None: """Applies a schema from a file.""" - self.set_base_url(uri) + with open(file, 'r', encoding='utf-8') as sf: schema = json.load(sf) groupid = schema["schemagroupid"] schemaid = schema["schemaid"] response = requests.get(f"{self.base_url}/schemagroups/{groupid}") if response.status_code == 200: - self.edit_schema(uri, groupid, schemaid, **schema) + self.edit_schema(groupid, schemaid, **schema) else: - self.add_schema(uri, groupid, schemaid, **schema) - - def add_catalog_parsers(self, subparsers: argparse._SubParsersAction[argparse.ArgumentParser]): - catalog_parser = subparsers.add_parser('catalog', help="Operate on catalog via webservice") - catalog_subparsers = catalog_parser.add_subparsers(dest="catalog_command", help="Catalog command to execute") - - # Endpoint commands - add_endpoint_parser = catalog_subparsers.add_parser('endpoint_add', help="Add an endpoint") - add_endpoint_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - add_endpoint_parser.add_argument('id', type=str, help="ID of the endpoint") - add_endpoint_parser.add_argument('usage', type=str, help="Usage of the endpoint") - add_endpoint_parser.add_argument('protocol', type=str, choices=["HTTP", "AMQP", "MQTT", "Kafka", "NATS"], help="Protocol of the endpoint") - add_endpoint_parser.set_defaults(func=CatalogSubcommands().add_endpoint) - - remove_endpoint_parser = catalog_subparsers.add_parser('endpoint_remove', help="Remove an endpoint") - remove_endpoint_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - remove_endpoint_parser.add_argument('id', type=str, help="ID of the endpoint") - remove_endpoint_parser.add_argument('epoch', type=int, help="Epoch of the endpoint") - remove_endpoint_parser.set_defaults(func=CatalogSubcommands().remove_endpoint) - - edit_endpoint_parser = catalog_subparsers.add_parser('endpoint_edit', help="Edit an endpoint") - edit_endpoint_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - edit_endpoint_parser.add_argument('id', type=str, help="ID of the endpoint") - edit_endpoint_parser.add_argument('--usage', type=str, help="Usage of the endpoint") - edit_endpoint_parser.add_argument('--protocol', type=str, choices=["HTTP", "AMQP", "MQTT", "Kafka", "NATS"], help="Protocol of the endpoint") - edit_endpoint_parser.set_defaults(func=CatalogSubcommands().edit_endpoint) - - show_endpoint_parser = catalog_subparsers.add_parser('endpoint_show', help="Show an endpoint") - show_endpoint_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - show_endpoint_parser.add_argument('id', type=str, help="ID of the endpoint") - show_endpoint_parser.set_defaults(func=CatalogSubcommands().show_endpoint) - - apply_endpoint_parser = catalog_subparsers.add_parser('endpoint_apply', help="Apply an endpoint from a file") - apply_endpoint_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - apply_endpoint_parser.add_argument('file', type=str, help="File containing the endpoint definition") - apply_endpoint_parser.set_defaults(func=CatalogSubcommands().apply_endpoint) - - # MessageGroup commands - add_messagegroup_parser = catalog_subparsers.add_parser('messagegroup_add', help="Add a messagegroup") - add_messagegroup_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - add_messagegroup_parser.add_argument('id', type=str, help="ID of the messagegroup") - add_messagegroup_parser.add_argument('--format', type=str, choices=["CloudEvents", "None"], help="Format of the messagegroup") - add_messagegroup_parser.set_defaults(func=CatalogSubcommands().add_messagegroup) - - remove_messagegroup_parser = catalog_subparsers.add_parser('messagegroup_remove', help="Remove a messagegroup") - remove_messagegroup_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - remove_messagegroup_parser.add_argument('id', type=str, help="ID of the messagegroup") - remove_messagegroup_parser.add_argument('epoch', type=int, help="Epoch of the messagegroup") - remove_messagegroup_parser.set_defaults(func=CatalogSubcommands().remove_messagegroup) - - edit_messagegroup_parser = catalog_subparsers.add_parser('messagegroup_edit', help="Edit a messagegroup") - edit_messagegroup_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - edit_messagegroup_parser.add_argument('id', type=str, help="ID of the messagegroup") - edit_messagegroup_parser.add_argument('--format', type=str, choices=["CloudEvents", "None"], help="Format of the messagegroup") - edit_messagegroup_parser.set_defaults(func=CatalogSubcommands().edit_messagegroup) - - show_messagegroup_parser = catalog_subparsers.add_parser('messagegroup_show', help="Show a messagegroup") - show_messagegroup_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - show_messagegroup_parser.add_argument('id', type=str, help="ID of the messagegroup") - show_messagegroup_parser.set_defaults(func=CatalogSubcommands().show_messagegroup) - - apply_messagegroup_parser = catalog_subparsers.add_parser('messagegroup_apply', help="Apply a messagegroup from a file") - apply_messagegroup_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - apply_messagegroup_parser.add_argument('file', type=str, help="File containing the messagegroup definition") - apply_messagegroup_parser.set_defaults(func=CatalogSubcommands().apply_messagegroup) - - # SchemaGroup commands - add_schemagroup_parser = catalog_subparsers.add_parser('schemagroup_add', help="Add a schemagroup") - add_schemagroup_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - add_schemagroup_parser.add_argument('id', type=str, help="ID of the schemagroup") - add_schemagroup_parser.add_argument('--format', type=str, help="Format of the schemagroup") - add_schemagroup_parser.set_defaults(func=CatalogSubcommands().add_schemagroup) - - remove_schemagroup_parser = catalog_subparsers.add_parser('schemagroup_remove', help="Remove a schemagroup") - remove_schemagroup_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - remove_schemagroup_parser.add_argument('id', type=str, help="ID of the schemagroup") - remove_schemagroup_parser.add_argument('epoch', type=int, help="Epoch of the schemagroup") - remove_schemagroup_parser.set_defaults(func=CatalogSubcommands().remove_schemagroup) - - edit_schemagroup_parser = catalog_subparsers.add_parser('schemagroup_edit', help="Edit a schemagroup") - edit_schemagroup_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - edit_schemagroup_parser.add_argument('id', type=str, help="ID of the schemagroup") - edit_schemagroup_parser.add_argument('--format', type=str, help="Format of the schemagroup") - edit_schemagroup_parser.set_defaults(func=CatalogSubcommands().edit_schemagroup) - - show_schemagroup_parser = catalog_subparsers.add_parser('schemagroup_show', help="Show a schemagroup") - show_schemagroup_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - show_schemagroup_parser.add_argument('id', type=str, help="ID of the schemagroup") - show_schemagroup_parser.set_defaults(func=CatalogSubcommands().show_schemagroup) - - apply_schemagroup_parser = catalog_subparsers.add_parser('schemagroup_apply', help="Apply a schemagroup from a file") - apply_schemagroup_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - apply_schemagroup_parser.add_argument('file', type=str, help="File containing the schemagroup definition") - apply_schemagroup_parser.set_defaults(func=CatalogSubcommands().apply_schemagroup) - - # Schema commands - add_schema_parser = catalog_subparsers.add_parser('schema_add', help="Add a schema to a schemagroup") - add_schema_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - add_schema_parser.add_argument('groupid', type=str, help="ID of the schemagroup") - add_schema_parser.add_argument('id', type=str, help="ID of the schema") - add_schema_parser.add_argument('format', type=str, help="Format of the schema") - add_schema_parser.add_argument('--versionid', type=str, default="1", help="Version ID of the schema") - add_schema_parser.add_argument('--schema', type=str, help="Literal schema content") - add_schema_parser.add_argument('--schemaimport', type=str, help="File to import schema content from") - add_schema_parser.add_argument('--schemaurl', type=str, help="URL of the schema content") - add_schema_parser.set_defaults(func=CatalogSubcommands().add_schema) - - remove_schema_parser = catalog_subparsers.add_parser('schema_remove', help="Remove a schema from a schemagroup") - remove_schema_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - remove_schema_parser.add_argument('groupid', type=str, help="ID of the schemagroup") - remove_schema_parser.add_argument('id', type=str, help="ID of the schema") - remove_schema_parser.add_argument('--versionid', type=str, help="Version ID of the schema") - remove_schema_parser.set_defaults(func=CatalogSubcommands().remove_schema) - - edit_schema_parser = catalog_subparsers.add_parser('schema_edit', help="Edit a schema in a schemagroup") - edit_schema_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - edit_schema_parser.add_argument('groupid', type=str, help="ID of the schemagroup") - edit_schema_parser.add_argument('id', type=str, help="ID of the schema") - edit_schema_parser.add_argument('format', type=str, help="Format of the schema") - edit_schema_parser.add_argument('--versionid', type=str, default="1", help="Version ID of the schema") - edit_schema_parser.add_argument('--schema', type=str, help="Literal schema content") - edit_schema_parser.add_argument('--schemaimport', type=str, help="File to import schema content from") - edit_schema_parser.add_argument('--schemaurl', type=str, help="URL of the schema content") - edit_schema_parser.set_defaults(func=CatalogSubcommands().edit_schema) - - show_schema_parser = catalog_subparsers.add_parser('schema_show', help="Show a schema in a schemagroup") - show_schema_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - show_schema_parser.add_argument('groupid', type=str, help="ID of the schemagroup") - show_schema_parser.add_argument('id', type=str, help="ID of the schema") - show_schema_parser.set_defaults(func=CatalogSubcommands().show_schema) - - apply_schema_parser = catalog_subparsers.add_parser('schema_apply', help="Apply a schema to a schemagroup from a file") - apply_schema_parser.add_argument('uri', type=str, help="Base URI for the catalog API") - apply_schema_parser.add_argument('file', type=str, help="File containing the schema definition") - apply_schema_parser.set_defaults(func=CatalogSubcommands().apply_schema) - - def process_catalog_command(self, args): - command = args.catalog_command - catalog_subcommands = CatalogSubcommands() - - if command == 'endpoint_add': - catalog_subcommands.add_endpoint(args.uri, args.id, args.usage, args.protocol) - elif command == 'endpoint_remove': - catalog_subcommands.remove_endpoint(args.uri, args.id, args.epoch) - elif command == 'endpoint_edit': - catalog_subcommands.edit_endpoint(args.uri, args.id, args.usage, args.protocol) - elif command == 'endpoint_show': - catalog_subcommands.show_endpoint(args.uri, args.id) - elif command == 'endpoint_apply': - catalog_subcommands.apply_endpoint(args.uri, args.file) - - elif command == 'messagegroup_add': - catalog_subcommands.add_messagegroup(args.uri, args.id, args.format, args.binding) - elif command == 'messagegroup_remove': - catalog_subcommands.remove_messagegroup(args.uri, args.id, args.epoch) - elif command == 'messagegroup_edit': - catalog_subcommands.edit_messagegroup(args.uri, args.id, args.format) - elif command == 'messagegroup_show': - catalog_subcommands.show_messagegroup(args.uri, args.id) - elif command == 'messagegroup_apply': - catalog_subcommands.apply_messagegroup(args.uri, args.file) - - elif command == 'schemagroup_add': - catalog_subcommands.add_schemagroup(args.uri, args.id, args.format) - elif command == 'schemagroup_remove': - catalog_subcommands.remove_schemagroup(args.uri, args.id, args.epoch) - elif command == 'schemagroup_edit': - catalog_subcommands.edit_schemagroup(args.uri, args.id, args.format) - elif command == 'schemagroup_show': - catalog_subcommands.show_schemagroup(args.uri, args.id) - elif command == 'schemagroup_apply': - catalog_subcommands.apply_schemagroup(args.uri, args.file) - - elif command == 'schema_add': - catalog_subcommands.add_schema(args.uri, args.groupid, args.id, args.format, args.versionid, args.schema, args.schemaimport, args.schemaurl) - elif command == 'schema_remove': - catalog_subcommands.remove_schema(args.uri, args.groupid, args.id, args.versionid) - elif command == 'schema_edit': - catalog_subcommands.edit_schema(args.uri, args.groupid, args.id, args.format, args.versionid, args.schema, args.schemaimport, args.schemaurl) - elif command == 'schema_show': - catalog_subcommands.show_schema(args.uri, args.groupid, args.id) - elif command == 'schema_apply': - catalog_subcommands.apply_schema(args.uri, args.file) - - -# Example usage: -# catalog = CatalogSubcommands() -# catalog.add_endpoint("http://example.com/api", "endpoint1", "usage1", "protocol1") + self.add_schema(groupid, schemaid, **schema) + + @classmethod + @classmethod + def add_parsers(cls, manifest_parser: argparse.ArgumentParser): + """ + Add subparsers for the manifest commands. + + Args: + subparsers (Any): The subparsers object to add the subcommands to. + """ + + manifest_subparsers = manifest_parser.add_subparsers(help="Manifest commands") + + def add_common_arguments(parser): + """ + Add common arguments to the parser. + + Args: + parser (ArgumentParser): The parser to add arguments to. + """ + parser.add_argument("--description", help="Description string") + parser.add_argument("--documentation", help="Documentation URL") + parser.add_argument("--labels", nargs='*', + help="Labels as key=value pairs") + parser.add_argument("--name", help="Human-readable name") + + endpoint_subparsers = manifest_subparsers.add_parser("endpoint", help="Manage endpoints").add_subparsers( + dest="endpoint_command", help="Endpoint commands") + + endpoint_add = endpoint_subparsers.add_parser("add", help="Add a new endpoint") + endpoint_add.add_argument("--id", required=True, help="Endpoint ID") + endpoint_add.add_argument("--usage", required=True, + choices=["subscriber", "producer", "consumer"], help="Usage type") + endpoint_add.add_argument("--protocol", choices=["HTTP", "AMQP", "MQTT", "Kafka", "NATS"], help="Protocol") + endpoint_add.add_argument("--deployed", type=bool, help="Deployed status") + endpoint_add.add_argument("--endpoints", nargs='+', help="Endpoint URIs") + endpoint_add.add_argument("--options", nargs='*', help="Endpoint options") + endpoint_add.add_argument("--messagegroups", nargs='*', help="Message group IDs") + endpoint_add.add_argument("--channel", help="Channel identifier") + endpoint_add.add_argument("--deprecated", help="Deprecation information") + add_common_arguments(endpoint_add) + endpoint_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_endpoint(args.id, args.usage, args.protocol, args.deployed, args.endpoints, args.options, + args.messagegroups, args.documentation, args.description, args.labels, args.name, + args.channel, args.deprecated + )) + + endpoint_remove = endpoint_subparsers.add_parser("remove", help="Remove an endpoint") + endpoint_remove.add_argument("--id", required=True, help="Endpoint ID") + endpoint_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_endpoint(args.id)) + + endpoint_edit = endpoint_subparsers.add_parser("edit", help="Edit an endpoint") + endpoint_edit.add_argument("--id", required=True, help="Endpoint ID") + endpoint_edit.add_argument("--usage", choices=["subscriber", "producer", "consumer"], help="Usage type") + endpoint_edit.add_argument("--protocol", choices=["HTTP", "AMQP", "MQTT", "Kafka", "NATS"], help="Protocol") + endpoint_edit.add_argument("--deployed", type=bool, help="Deployed status") + endpoint_edit.add_argument("--endpoints", nargs='+', help="Endpoint URIs") + endpoint_edit.add_argument("--options", nargs='*', help="Endpoint options") + endpoint_edit.add_argument("--messagegroups", nargs='*', help="Message group IDs") + endpoint_edit.add_argument("--channel", help="Channel identifier") + endpoint_edit.add_argument("--deprecated", help="Deprecation information") + add_common_arguments(endpoint_edit) + endpoint_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_endpoint(args.id, args.usage, args.protocol, args.deployed, args.endpoints, args.options, + args.messagegroups, args.documentation, args.description, args.labels, args.name, + args.channel, args.deprecated + )) + + endpoint_show = endpoint_subparsers.add_parser("show", help="Show an endpoint") + endpoint_show.add_argument("--id", required=True, help="Endpoint ID") + endpoint_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_endpoint(args.id)) + + endpoint_apply = endpoint_subparsers.add_parser("apply", help="Apply an endpoint JSON") + endpoint_apply.add_argument("-f", "--file", required=True, help="JSON file containing endpoint data") + endpoint_apply.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).apply_endpoint(args.file)) + + messagegroup_subparsers = manifest_subparsers.add_parser("messagegroup", help="Manage message groups").add_subparsers( + dest="messagegroup_command", help="Message group commands") + + messagegroup_add = messagegroup_subparsers.add_parser("add", help="Add a new message group") + messagegroup_add.add_argument("--id", required=True, help="Message group ID") + messagegroup_add.add_argument("--format", choices=["CloudEvents", "None"], help="Message group format") + messagegroup_add.add_argument("--protocol", help="protocol identifier") + add_common_arguments(messagegroup_add) + messagegroup_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_messagegroup(args.id, args.format, args.documentation, args.description, args.labels, args.name, + args.protocol + )) + + messagegroup_remove = messagegroup_subparsers.add_parser("remove", help="Remove a message group") + messagegroup_remove.add_argument("--id", required=True, help="Message group ID") + messagegroup_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_messagegroup(args.id)) + + messagegroup_edit = messagegroup_subparsers.add_parser("edit", help="Edit a message group") + messagegroup_edit.add_argument("--id", required=True, help="Message group ID") + messagegroup_edit.add_argument("--format", choices=["CloudEvents", "None"], help="Message group format") + messagegroup_edit.add_argument("--protocol", help="protocol identifier") + add_common_arguments(messagegroup_edit) + messagegroup_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_messagegroup(args.id, args.format, args.documentation, args.description, args.labels, args.name, + args.protocol + )) + + messagegroup_show = messagegroup_subparsers.add_parser("show", help="Show a message group") + messagegroup_show.add_argument("--id", required=True, help="Message group ID") + messagegroup_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_messagegroup(args.id)) + + messagegroup_apply = messagegroup_subparsers.add_parser("apply", help="Apply a message group JSON") + messagegroup_apply.add_argument("-f", "--file", required=True, help="JSON file containing message group data") + messagegroup_apply.set_defaults(func=lambda args: CatalogSubcommands( + args.catalog).apply_messagegroup(args.file)) + + message_subparsers = manifest_subparsers.add_parser( + "message", help="Manage messages").add_subparsers(dest="message_command", help="Message commands") + + message_add = message_subparsers.add_parser("add", help="Add a new message") + message_add.add_argument("--groupid", required=True, help="Message group ID") + message_add.add_argument("--id", required=True, help="Message ID") + message_add.add_argument("--format", choices=["CloudEvents", "None"], + help="Message format", default="CloudEvents") + message_add.add_argument("--protocol", choices=["AMQP", "MQTT", "NATS", + "HTTP", "Kafka", "None"], help="Message protocol", default="None") + message_add.add_argument("--schemaformat", help="Schema format") + message_add.add_argument("--schemagroup", help="Schema group ID") + message_add.add_argument("--schemaid", help="Schema ID") + message_add.add_argument("--schemaurl", help="Schema URL") + add_common_arguments(message_add) + message_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_message(args.groupid, args.id, args.format, args.protocol, args.schemaformat, args.schemagroup, args.schemaid, + args.schemaurl, args.documentation, args.description, args.labels, args.name + )) + + message_remove = message_subparsers.add_parser("remove", help="Remove a message") + message_remove.add_argument("--groupid", required=True, help="Message group ID") + message_remove.add_argument("--id", required=True, help="Message ID") + message_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_message(args.groupid, args.id)) + + message_edit = message_subparsers.add_parser("edit", help="Edit a message") + message_edit.add_argument("--groupid", required=True, help="Message group ID") + message_edit.add_argument("--id", required=True, help="Message ID") + message_edit.add_argument("--format", choices=["CloudEvents", "None"], help="Message format") + message_edit.add_argument("--protocol", choices=["AMQP", "MQTT", + "NATS", "HTTP", "Kafka", "None"], help="Message protocol") + message_edit.add_argument("--schemaformat", help="Schema format") + message_edit.add_argument("--schemagroup", help="Schema group ID") + message_edit.add_argument("--schemaid", help="Schema ID") + message_edit.add_argument("--schemaurl", help="Schema URL") + add_common_arguments(message_edit) + message_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message(args.groupid, args.id, args.format, args.protocol, args.schemaformat, args.schemagroup, args.schemaid, + args.schemaurl, args.documentation, args.description, args.labels, args.name)) + + message_cloudevent_subparsers = manifest_subparsers.add_parser( + "cloudevent", help="Manage CloudEvents").add_subparsers(dest="cloudevents_command", help="CloudEvents commands") + message_cloudevent_add = message_cloudevent_subparsers.add_parser("add", help="Add a new CloudEvent") + message_cloudevent_add.add_argument("--groupid", required=True, help="Message group ID") + message_cloudevent_add.add_argument("--id", required=True, help="Message ID and CloudEvents type") + message_cloudevent_add.add_argument("--schemaformat", help="Schema format") + message_cloudevent_add.add_argument("--schemagroup", help="Schema group ID") + message_cloudevent_add.add_argument("--schemaid", help="Schema ID") + message_cloudevent_add.add_argument("--schemaurl", help="Schema URL") + add_common_arguments(message_cloudevent_add) + + def _add_cloudevent(args): + sc = CatalogSubcommands(args.catalog) + sc.add_message( + args.groupid, args.id, "CloudEvents/1.0", "None", args.schemaformat, args.schemagroup, args.schemaid, + args.schemaurl, args.documentation, args.description, args.labels, args.name) + sc.add_cloudevents_message_metadata(args.groupid, args.id, "specversion", + "string", "CloudEvents version", "1.0", True) + sc.add_cloudevents_message_metadata(args.groupid, args.id, "type", "string", "Event type", args.id, True) + sc.add_cloudevents_message_metadata(args.groupid, args.id, "source", + "string", "Event source", "{source}", True) + return + message_cloudevent_add.set_defaults(func=_add_cloudevent) + + message_cloudevent_edit = message_cloudevent_subparsers.add_parser("edit", help="Edit a CloudEvent") + message_cloudevent_edit.add_argument("--groupid", required=True, help="Message group ID") + message_cloudevent_edit.add_argument("--id", required=True, help="Message ID and CloudEvents type") + message_cloudevent_edit.add_argument("--schemaformat", help="Schema format") + message_cloudevent_edit.add_argument("--schemagroup", help="Schema group ID") + message_cloudevent_edit.add_argument("--schemaid", help="Schema ID") + message_cloudevent_edit.add_argument("--schemaurl", help="Schema URL") + add_common_arguments(message_cloudevent_edit) + message_cloudevent_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( + args.groupid, args.id, "CloudEvents/1.0", "None", args.schemaformat, args.schemagroup, args.schemaid, + args.schemaurl, args.documentation, args.description, args.labels, args.name)) + + message_cloudevent_remove = message_cloudevent_subparsers.add_parser("remove", help="Remove a CloudEvent") + message_cloudevent_remove.add_argument("--groupid", required=True, help="Message group ID", type=str) + message_cloudevent_remove.add_argument("--id", required=True, help="Message ID and CloudEvents type", type=str) + message_cloudevent_remove.add_argument("--epoch", required=True, type=int, help="Epoch number") + message_cloudevent_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_message(args.groupid, args.id)) + + message_cloudevent_metadata_subparsers = message_cloudevent_subparsers.add_parser( + "metadata", help="Manage message metadata").add_subparsers(dest="metadata_command", help="Metadata commands") + message_cloudevent_metadata_add = message_cloudevent_metadata_subparsers.add_parser( + "add", help="Add a new metadata field") + message_cloudevent_metadata_add.add_argument("--groupid", required=True, help="Message group ID") + message_cloudevent_metadata_add.add_argument("--id", required=True, help="Message ID") + message_cloudevent_metadata_add.add_argument("--attribute", required=True, help="Attribute name") + message_cloudevent_metadata_add.add_argument( + "--type", choices=PROPERTY_TYPES, help="Metadata type", default="string") + message_cloudevent_metadata_add.add_argument("--description", help="Metadata description") + message_cloudevent_metadata_add.add_argument( + "--value", help="Attribute value, may contain template expressions if the type is 'uritemplate'") + message_cloudevent_metadata_add.add_argument("--required", type=bool, help="Metadata required status") + message_cloudevent_metadata_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_cloudevents_message_metadata( + args.groupid, args.id, args.attribute, args.type, args.description, args.value, args.required)) + + message_cloudevent_metadata_edit = message_cloudevent_metadata_subparsers.add_parser( + "edit", help="Edit a metadata field") + message_cloudevent_metadata_edit.add_argument("--groupid", required=True, help="Message group ID") + message_cloudevent_metadata_edit.add_argument("--id", required=True, help="Message ID") + message_cloudevent_metadata_edit.add_argument("--attribute", required=True, help="Attribute name") + message_cloudevent_metadata_edit.add_argument("--type", choices=PROPERTY_TYPES, help="Attribute type") + message_cloudevent_metadata_edit.add_argument("--description", help="Attribute description") + message_cloudevent_metadata_edit.add_argument( + "--value", help="Attribute value, may contain template expressions if the type is 'uritemplate'") + message_cloudevent_metadata_edit.add_argument("--required", type=bool, help="Metadata required status") + message_cloudevent_metadata_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_cloudevents_message_metadata( + args.groupid, args.id, args.attribute, args.type, args.description, args.value, args.required)) + + message_cloudevent_metadata_remove = message_cloudevent_metadata_subparsers.add_parser( + "remove", help="Remove a metadata field") + message_cloudevent_metadata_remove.add_argument("--groupid", required=True, help="Message group ID") + message_cloudevent_metadata_remove.add_argument("--id", required=True, help="Message ID") + message_cloudevent_metadata_remove.add_argument("--attribute", required=True, help="CloudEvents attribute") + message_cloudevent_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands( + args.catalog).remove_cloudevents_message_metadata(args.groupid, args.id, args.key)) + + message_amqp_subparsers = manifest_subparsers.add_parser( + "amqp", help="Manage AMQP").add_subparsers(dest="amqp_command", help="AMQP commands") + message_amqp_metadata_subparsers = message_amqp_subparsers.add_parser( + "metadata", help="Manage message metadata").add_subparsers(dest="metadata_command", help="Metadata commands") + + def _add_amqp_message(args): + sc = CatalogSubcommands(args.catalog) + sc.add_message(args.groupid, args.id, "None", "AMQP/1.0", args.schemaformat, args.schemagroup, + args.schemaid, args.schemaurl, args.documentation, args.description, args.labels, args.name) + sc.add_amqp_message_metadata(args.groupid, args.id, "properties", + "subject", "string", None, "Subject", True) + + message_amqp_add = message_amqp_subparsers.add_parser("add", help="Add a new message") + message_amqp_add.add_argument("--groupid", required=True, help="Message group ID") + message_amqp_add.add_argument("--id", required=True, help="Message ID") + message_amqp_add.add_argument("--schemaformat", help="Schema format") + message_amqp_add.add_argument("--schemagroup", help="Schema group ID") + message_amqp_add.add_argument("--schemaid", help="Schema ID") + message_amqp_add.add_argument("--schemaurl", help="Schema URL") + message_amqp_add.set_defaults(func=_add_amqp_message) + + message_amqp_edit = message_amqp_subparsers.add_parser("edit", help="Edit a message") + message_amqp_edit.add_argument("--groupid", required=True, help="Message group ID") + message_amqp_edit.add_argument("--id", required=True, help="Message ID") + message_amqp_edit.add_argument("--schemaformat", help="Schema format") + message_amqp_edit.add_argument("--schemagroup", help="Schema group ID") + message_amqp_edit.add_argument("--schemaid", help="Schema ID") + message_amqp_edit.add_argument("--schemaurl", help="Schema URL") + add_common_arguments(message_amqp_edit) + message_amqp_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( + args.groupid, args.id, "None", "AMQP/1.0", args.schemaformat, args.schemagroup, args.schemaid, + args.schemaurl, args.documentation, args.description, args.labels, args.name)) + + message_amqp_remove = message_amqp_subparsers.add_parser("remove", help="Remove a message") + message_amqp_remove.add_argument("--groupid", required=True, help="Message group ID") + message_amqp_remove.add_argument("--id", required=True, help="Message ID") + message_amqp_remove.set_defaults(func=lambda args: CatalogSubcommands( + args.catalog).remove_message(args.groupid, args.id)) + + message_amqp_metadata_add = message_amqp_metadata_subparsers.add_parser("add", help="Add a new metadata field") + message_amqp_metadata_add.add_argument("--groupid", required=True, help="Message group ID") + message_amqp_metadata_add.add_argument("--id", required=True, help="Message ID") + message_amqp_metadata_add.add_argument("--section", required=True, choices=[ + "properties", "application-properties"], help="Metadata section") + message_amqp_metadata_add.add_argument("--name", required=True, help="Metadata name") + message_amqp_metadata_add.add_argument("--type", required=True, choices=PROPERTY_TYPES, help="Metadata type") + message_amqp_metadata_add.add_argument("--value", required=False, help="Metadata value") + message_amqp_metadata_add.add_argument("--description", help="Metadata description") + message_amqp_metadata_add.add_argument("--required", type=bool, help="Metadata required status") + message_amqp_metadata_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_amqp_message_metadata( + args.groupid, args.id, args.section, args.name, args.type, args.value, args.description, args.required)) + + message_amqp_metadata_edit = message_amqp_metadata_subparsers.add_parser("edit", help="Edit a metadata field") + message_amqp_metadata_edit.add_argument("--groupid", required=True, help="Message group ID") + message_amqp_metadata_edit.add_argument("--id", required=True, help="Message ID") + message_amqp_metadata_edit.add_argument("--section", required=True, choices=[ + "properties", "application-properties"], help="Metadata section") + message_amqp_metadata_edit.add_argument("--name", help="Metadata name") + message_amqp_metadata_edit.add_argument("--type", choices=PROPERTY_TYPES, help="Metadata type") + message_amqp_metadata_edit.add_argument("--value", required=False, help="Metadata value") + message_amqp_metadata_edit.add_argument("--description", help="Metadata description") + message_amqp_metadata_edit.add_argument("--required", type=bool, help="Metadata required status") + message_amqp_metadata_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_amqp_message_metadata( + args.groupid, args.id, args.section, args.name, args.type, args.value, args.description, args.required)) + + message_amqp_metadata_remove = message_amqp_metadata_subparsers.add_parser( + "remove", help="Remove a metadata field") + message_amqp_metadata_remove.add_argument("--groupid", required=True, help="Message group ID") + message_amqp_metadata_remove.add_argument("--id", required=True, help="Message ID") + message_amqp_metadata_remove.add_argument("--section", required=True, choices=[ + "properties", "application-properties"], help="Metadata section") + message_amqp_metadata_remove.add_argument("--name", required=True, help="Metadata name") + message_amqp_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands( + args.catalog).remove_amqp_message_metadata(args.groupid, args.id, args.name, args.section)) + + message_mqtt_subparsers = manifest_subparsers.add_parser( + "mqtt", help="Manage MQTT").add_subparsers(dest="mqtt_command", help="MQTT commands") + message_mqtt_metadata_subparsers = message_mqtt_subparsers.add_parser( + "metadata", help="Manage message metadata").add_subparsers(dest="metadata_command", help="Metadata commands") + + def _add_mqtt_message(args): + sc = CatalogSubcommands(args.catalog) + sc.add_message( + args.groupid, args.id, "None", "MQTT/" + args.mqtt_version, args.schemaformat, args.schemagroup, args.schemaid, + args.schemaurl, args.documentation, args.description, args.labels, args.name) + sc.add_mqtt_message_metadata(args.groupid, args.id, args.mqtt_version, "topic", + "string", "{topic}/"+args.id, "MQTT topic", True) + + message_mqtt_add = message_mqtt_subparsers.add_parser("add", help="Add a new message") + message_mqtt_add.add_argument("--groupid", required=True, help="Message group ID") + message_mqtt_add.add_argument("--id", required=True, help="Message ID") + message_mqtt_add.add_argument("--mqtt_version", required=True, + choices=["3", "5", "3.1.1", "5.0"], help="MQTT version") + message_mqtt_add.add_argument("--schemaformat", help="Schema format") + message_mqtt_add.add_argument("--schemagroup", help="Schema group ID") + message_mqtt_add.add_argument("--schemaid", help="Schema ID") + message_mqtt_add.add_argument("--schemaurl", help="Schema URL") + add_common_arguments(message_mqtt_add) + message_mqtt_add.set_defaults(func=_add_amqp_message) + + message_mqtt_edit = message_mqtt_subparsers.add_parser("edit", help="Edit a message") + message_mqtt_edit.add_argument("--groupid", required=True, help="Message group ID") + message_mqtt_edit.add_argument("--id", required=True, help="Message ID") + message_mqtt_edit.add_argument("--schemaformat", help="Schema format") + message_mqtt_edit.add_argument("--schemagroup", help="Schema group ID") + message_mqtt_edit.add_argument("--schemaid", help="Schema ID") + message_mqtt_edit.add_argument("--schemaurl", help="Schema URL") + add_common_arguments(message_mqtt_edit) + message_mqtt_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( + args.groupid, args.id, "None", "MQTT/" + args.mqtt_version, args.schemaformat, args.schemagroup, args.schemaid, + args.schemaurl, args.documentation, args.description, args.labels, args.name)) + + message_mqtt_remove = message_mqtt_subparsers.add_parser("remove", help="Remove a message") + message_mqtt_remove.add_argument("--groupid", required=True, help="Message group ID") + message_mqtt_remove.add_argument("--id", required=True, help="Message ID") + message_mqtt_remove.set_defaults(func=lambda args: CatalogSubcommands( + args.catalog).remove_message(args.groupid, args.id)) + + message_mqtt_metadata_add = message_mqtt_metadata_subparsers.add_parser("add", help="Add a new metadata field") + message_mqtt_metadata_add.add_argument("--groupid", required=True, help="Message group ID") + message_mqtt_metadata_add.add_argument("--id", required=True, help="Message ID") + message_mqtt_metadata_add.add_argument("--mqtt_version", required=True, + choices=["3", "5", "3.1.1", "5.0"], help="MQTT version") + message_mqtt_metadata_add.add_argument("--name", required=True, help="Metadata name") + message_mqtt_metadata_add.add_argument("--type", required=True, choices=PROPERTY_TYPES, help="Metadata type") + message_mqtt_metadata_add.add_argument("--value", required=True, help="Metadata value") + message_mqtt_metadata_add.add_argument("--description", help="Metadata description") + message_mqtt_metadata_add.add_argument("--required", type=bool, help="Metadata required status") + message_mqtt_metadata_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_mqtt_message_metadata( + args.groupid, args.id, args.mqtt_version, args.name, args.type, args.value, args.description, args.required)) + + message_mqtt_metadata_edit = message_mqtt_metadata_subparsers.add_parser("edit", help="Edit a metadata field") + message_mqtt_metadata_edit.add_argument("--groupid", required=True, help="Message group ID") + message_mqtt_metadata_edit.add_argument("--id", required=True, help="Message ID") + message_mqtt_metadata_edit.add_argument("--mqtt_version", required=True, + choices=["3", "5", "3.1.1", "5.0"], help="MQTT version") + message_mqtt_metadata_edit.add_argument("--name", help="Metadata name") + message_mqtt_metadata_edit.add_argument("--type", choices=PROPERTY_TYPES, help="Metadata type") + message_mqtt_metadata_edit.add_argument("--value", help="Metadata value") + message_mqtt_metadata_edit.add_argument("--description", help="Metadata description") + message_mqtt_metadata_edit.add_argument("--required", type=bool, help="Metadata required status") + message_mqtt_metadata_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_mqtt_message_metadata( + args.groupid, args.id, args.name, args.type, args.value, args.description, args.required)) + + message_mqtt_metadata_remove = message_mqtt_metadata_subparsers.add_parser( + "remove", help="Remove a metadata field") + message_mqtt_metadata_remove.add_argument("--groupid", required=True, help="Message group ID") + message_mqtt_metadata_remove.add_argument("--id", required=True, help="Message ID") + message_mqtt_metadata_remove.add_argument("--section", required=False, choices=["properties", "topic"], help="Metadata section") + message_mqtt_metadata_remove.add_argument("--name", required=True, help="Metadata name") + message_mqtt_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands( + args.catalog).remove_mqtt_message_metadata(args.groupid, args.id, args.section, args.name)) + + message_kafka_subparsers = manifest_subparsers.add_parser( + "kafka", help="Manage Kafka").add_subparsers(dest="kafka_command", help="Kafka commands") + message_kafka_metadata_subparsers = message_kafka_subparsers.add_parser( + "metadata", help="Manage message metadata").add_subparsers(dest="metadata_command", help="Metadata commands") + + def _add_kafka_message(args): + sc = CatalogSubcommands(args.catalog) + sc.add_message(args.groupid, args.id, "None", "Kafka", args.schemaformat, args.schemagroup, args.schemaid, + args.schemaurl, args.documentation, args.description, args.labels, args.name) + sc.add_kafka_message_metadata(args.groupid, args.id, "headers", "message_type", + "string", args.id, "Message ID", True) + sc.add_kafka_message_metadata(args.groupid, args.id, None, "key", "string", "{key}", "Message key", False) + + message_kafka_add = message_kafka_subparsers.add_parser("add", help="Add a new message") + message_kafka_add.add_argument("--groupid", required=True, help="Message group ID") + message_kafka_add.add_argument("--id", required=True, help="Message ID") + message_kafka_add.add_argument("--schemaformat", help="Schema format") + message_kafka_add.add_argument("--schemagroup", help="Schema group ID") + message_kafka_add.add_argument("--schemaid", help="Schema ID") + message_kafka_add.add_argument("--schemaurl", help="Schema URL") + add_common_arguments(message_kafka_add) + message_kafka_add.set_defaults(func=_add_kafka_message) + + message_kafka_edit = message_kafka_subparsers.add_parser("edit", help="Edit a message") + message_kafka_edit.add_argument("--groupid", required=True, help="Message group ID") + message_kafka_edit.add_argument("--id", required=True, help="Message ID") + message_kafka_edit.add_argument("--schemaformat", help="Schema format") + message_kafka_edit.add_argument("--schemagroup", help="Schema group ID") + message_kafka_edit.add_argument("--schemaid", help="Schema ID") + message_kafka_edit.add_argument("--schemaurl", help="Schema URL") + add_common_arguments(message_kafka_edit) + message_kafka_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( + args.groupid, args.id, "None", "Kafka", args.schemaformat, args.schemagroup, args.schemaid, + args.schemaurl, args.documentation, args.description, args.labels, args.name)) + + message_kafka_remove = message_kafka_subparsers.add_parser("remove", help="Remove a message") + message_kafka_remove.add_argument("--groupid", required=True, help="Message group ID") + message_kafka_remove.add_argument("--id", required=True, help="Message ID") + message_kafka_remove.set_defaults(func=lambda args: CatalogSubcommands( + args.catalog).remove_message(args.groupid, args.id)) + + message_kafka_metadata_add = message_kafka_metadata_subparsers.add_parser( + "add", help="Add a new metadata field") + message_kafka_metadata_add.add_argument("--groupid", required=True, help="Message group ID") + message_kafka_metadata_add.add_argument("--id", required=True, help="Message ID") + message_kafka_metadata_add.add_argument("--section", required=True, choices=["headers"], help="Metadata section") + message_kafka_metadata_add.add_argument("--name", required=True, help="Metadata name") + message_kafka_metadata_add.add_argument("--type", required=True, choices=PROPERTY_TYPES, help="Metadata type") + message_kafka_metadata_add.add_argument("--value", required=True, help="Metadata value") + message_kafka_metadata_add.add_argument("--description", help="Metadata description") + message_kafka_metadata_add.add_argument("--required", type=bool, help="Metadata required status") + message_kafka_metadata_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_kafka_message_metadata( + args.groupid, args.id, args.section, args.name, args.type, args.value, args.description, args.required)) + + message_kafka_metadata_edit = message_kafka_metadata_subparsers.add_parser("edit", help="Edit a metadata field") + message_kafka_metadata_edit.add_argument("--groupid", required=True, help="Message group ID") + message_kafka_metadata_edit.add_argument("--id", required=True, help="Message ID") + message_kafka_metadata_edit.add_argument("--section", required=True, choices=["headers"], help="Metadata section") + message_kafka_metadata_edit.add_argument("--name", help="Metadata name") + message_kafka_metadata_edit.add_argument("--type", choices=PROPERTY_TYPES, help="Metadata type") + message_kafka_metadata_edit.add_argument("--value", help="Metadata value") + message_kafka_metadata_edit.add_argument("--description", help="Metadata description") + message_kafka_metadata_edit.add_argument("--required", type=bool, help="Metadata required status") + message_kafka_metadata_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_kafka_message_metadata( + args.groupid, args.id, args.section, args.name, args.type, args.value, args.description, args.required)) + + message_kafka_metadata_remove = message_kafka_metadata_subparsers.add_parser( + "remove", help="Remove a metadata field") + message_kafka_metadata_remove.add_argument("--groupid", required=True, help="Message group ID") + message_kafka_metadata_remove.add_argument("--id", required=True, help="Message ID") + message_kafka_metadata_remove.add_argument("--name", required=True, help="Metadata name") + message_kafka_metadata_remove.add_argument( + "--section", required=True, choices=["headers"], help="Metadata section") + message_kafka_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands( + args.catalog).remove_kafka_message_metadata(args.groupid, args.id, args.section, args.name)) + + message_http_subparsers = manifest_subparsers.add_parser( + "http", help="Manage HTTP").add_subparsers(dest="http_command", help="HTTP commands") + message_http_metadata_subparsers = message_http_subparsers.add_parser( + "metadata", help="Manage message metadata").add_subparsers(dest="metadata_command", help="Metadata commands") + + def _add_http_message(args): + sc = CatalogSubcommands(args.catalog) + sc.add_message(args.groupid, args.id, "None", "HTTP", args.schemaformat, args.schemagroup, args.schemaid, + args.schemaurl, args.documentation, args.description, args.labels, args.name) + sc.add_http_message_metadata(args.groupid, args.id, "headers", "content-type", + "string", "application/json", "Content type", True) + sc.add_http_message_metadata(args.groupid, args.id, None, "method", "string", "POST", "HTTP method", True) + + message_http_add = message_http_subparsers.add_parser("add", help="Add a new message") + message_http_add.add_argument("--groupid", required=True, help="Message group ID") + message_http_add.add_argument("--id", required=True, help="Message ID") + message_http_add.add_argument("--schemaformat", help="Schema format") + message_http_add.add_argument("--schemagroup", help="Schema group ID") + message_http_add.add_argument("--schemaid", help="Schema ID") + message_http_add.add_argument("--schemaurl", help="Schema URL") + add_common_arguments(message_http_add) + message_http_add.set_defaults(func=_add_http_message) + + message_http_edit = message_http_subparsers.add_parser("edit", help="Edit a message") + message_http_edit.add_argument("--groupid", required=True, help="Message group ID") + message_http_edit.add_argument("--id", required=True, help="Message ID") + message_http_edit.add_argument("--schemaformat", help="Schema format") + message_http_edit.add_argument("--schemagroup", help="Schema group ID") + message_http_edit.add_argument("--schemaid", help="Schema ID") + message_http_edit.add_argument("--schemaurl", help="Schema URL") + add_common_arguments(message_http_edit) + message_http_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( + args.groupid, args.id, "None", "HTTP", args.schemaformat, args.schemagroup, args.schemaid, + args.schemaurl, args.documentation, args.description, args.labels, args.name)) + + message_http_remove = message_http_subparsers.add_parser("remove", help="Remove a message") + message_http_remove.add_argument("--groupid", required=True, help="Message group ID") + message_http_remove.add_argument("--id", required=True, help="Message ID") + message_http_remove.set_defaults(func=lambda args: CatalogSubcommands( + args.catalog).remove_message(args.groupid, args.id)) + + message_http_metadata_add = message_http_metadata_subparsers.add_parser("add", help="Add a new metadata field") + message_http_metadata_add.add_argument("--groupid", required=True, help="Message group ID") + message_http_metadata_add.add_argument("--id", required=True, help="Message ID") + message_http_metadata_add.add_argument("--key", required=True, help="Metadata key") + message_http_metadata_add.add_argument("--section", required=False, + choices=["headers", "query"], help="Metadata section") + message_http_metadata_add.add_argument("--name", required=True, help="Metadata name") + message_http_metadata_add.add_argument("--type", required=True, choices=PROPERTY_TYPES, help="Metadata type") + message_http_metadata_add.add_argument("--value", required=True, help="Metadata value") + message_http_metadata_add.add_argument("--description", help="Metadata description") + message_http_metadata_add.add_argument("--required", type=bool, help="Metadata required status") + message_http_metadata_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_http_message_metadata( + args.groupid, args.id, args.section, args.name, args.type, args.value, args.description, args.required)) + + message_http_metadata_edit = message_http_metadata_subparsers.add_parser("edit", help="Edit a metadata field") + message_http_metadata_edit.add_argument("--groupid", required=True, help="Message group ID") + message_http_metadata_edit.add_argument("--id", required=True, help="Message ID") + message_http_metadata_edit.add_argument("--key", required=True, help="Metadata key") + message_http_metadata_edit.add_argument("--section", required=False, + choices=["headers", "query"], help="Metadata section") + message_http_metadata_edit.add_argument("--name", help="Metadata name") + message_http_metadata_edit.add_argument("--type", choices=PROPERTY_TYPES, help="Metadata type") + message_http_metadata_edit.add_argument("--value", help="Metadata value") + message_http_metadata_edit.add_argument("--description", help="Metadata description") + message_http_metadata_edit.add_argument("--required", type=bool, help="Metadata required status") + message_http_metadata_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_http_message_metadata( + args.groupid, args.id, args.section, args.name, args.type, args.value, args.description, args.required)) + + message_http_metadata_remove = message_http_metadata_subparsers.add_parser( + "remove", help="Remove a metadata field") + message_http_metadata_remove.add_argument("--groupid", required=True, help="Message group ID") + message_http_metadata_remove.add_argument("--id", required=True, help="Message ID") + message_http_metadata_remove.add_argument("--name", required=True, help="Metadata key") + message_http_metadata_remove.add_argument( + "--section", required=False, choices=["headers", "query"], help="Metadata section") + message_http_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands( + args.catalog).remove_http_message_metadata(args.groupid, args.id, args.section, args.name)) + + message_show = message_subparsers.add_parser("show", help="Show a message") + message_show.add_argument("--groupid", required=True, help="Message group ID") + message_show.add_argument("--id", required=True, help="Message ID") + message_show.set_defaults(func=lambda args: CatalogSubcommands( + args.catalog).show_message(args.groupid, args.id)) + + schemagroup_subparsers = manifest_subparsers.add_parser("schemagroup", help="Manage schema groups").add_subparsers( + dest="schemagroup_command", help="Schema group commands") + + schemagroup_add = schemagroup_subparsers.add_parser("add", help="Add a new schema group") + schemagroup_add.add_argument("--id", required=True, help="Schema group ID") + add_common_arguments(schemagroup_add) + schemagroup_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_schemagroup( + args.id, args.documentation, args.description, args.labels, args.name)) + + schemagroup_remove = schemagroup_subparsers.add_parser("remove", help="Remove a schema group") + schemagroup_remove.add_argument("--id", required=True, help="Schema group ID") + schemagroup_remove.set_defaults(func=lambda args: CatalogSubcommands( + args.catalog).remove_schemagroup(args.id)) + + schemagroup_edit = schemagroup_subparsers.add_parser("edit", help="Edit a schema group") + schemagroup_edit.add_argument("--id", required=True, help="Schema group ID") + add_common_arguments(schemagroup_edit) + schemagroup_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_schemagroup(args.id, args.documentation, args.description, args.labels, args.name )) + + schemagroup_show = schemagroup_subparsers.add_parser("show", help="Show a schema group") + schemagroup_show.add_argument("--id", required=True, help="Schema group ID") + schemagroup_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_schemagroup(args.id)) + + schemagroup_apply = schemagroup_subparsers.add_parser("apply", help="Apply a schema group JSON") + schemagroup_apply.add_argument("-f", "--file", required=True, help="JSON file containing schema group data") + schemagroup_apply.set_defaults(func=lambda args: CatalogSubcommands( + args.catalog).apply_schemagroup(args.file)) + + schema_subparsers = manifest_subparsers.add_parser( + "schemaversion", help="Manage schema versions").add_subparsers(dest="schema_command", help="Schema commands") + + schema_add = schema_subparsers.add_parser("add", help="Add a new schema version") + schema_add.add_argument("--groupid", required=True, help="Schema group ID") + schema_add.add_argument("--id", required=True, help="Schema ID") + schema_add.add_argument("--format", required=True, help="Schema format") + schema_add.add_argument("--versionid", help="Schema version ID") + schema_add.add_argument("--schema", help="Inline schema") + schema_add.add_argument("--schemaimport", help="Schema import file location or URL") + schema_add.add_argument("--schemaurl", help="Schema URL") + add_common_arguments(schema_add) + schema_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_schemaversion(args.groupid, args.id, args.format, args.versionid, args.schema, args.schemaimport, + args.schemaurl, args.documentation, args.description, args.labels, args.name + )) + + schema_remove = schema_subparsers.add_parser("remove", help="Remove a schema or schema version") + schema_remove.add_argument("--groupid", required=True, help="Schema group ID") + schema_remove.add_argument("--id", required=True, help="Schema ID") + schema_remove.add_argument("--versionid", required=True, help="Schema version ID") + schema_remove.set_defaults(func=lambda args: CatalogSubcommands( + args.catalog).remove_schema(args.groupid, args.id, args.versionid)) + + schema_edit = schema_subparsers.add_parser("edit", help="Edit a schema or schema version") + schema_edit.add_argument("--groupid", required=True, help="Schema group ID") + schema_edit.add_argument("--id", required=True, help="Schema ID") + schema_edit.add_argument("--format", help="Schema format") + schema_edit.add_argument("--versionid", required=True, help="Schema version ID") + schema_edit.add_argument("--schema", help="Inline schema") + schema_edit.add_argument("--schemaimport", help="Schema import file location or URL") + schema_edit.add_argument("--schemaurl", help="Schema URL") + add_common_arguments(schema_edit) + schema_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_schemaversion(args.groupid, args.id, args.versionid, args.format, args.schema, args.schemaimport, + args.schemaurl, args.documentation, args.description, args.labels, args.name + )) + + schema_show = schema_subparsers.add_parser("show", help="Show a schema") + schema_show.add_argument("--groupid", required=True, help="Schema group ID") + schema_show.add_argument("--id", required=True, help="Schema ID") + schema_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_schema(args.groupid, args.id)) + + schema_apply = schema_subparsers.add_parser("apply", help="Apply a schema JSON") + schema_apply.add_argument("-f", "--file", required=True, help="JSON file containing schema data") + schema_apply.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).apply_schema(args.file)) \ No newline at end of file From 96e1b7d18d1b5221ee0b3491a600b4cf9721d0f9 Mon Sep 17 00:00:00 2001 From: Clemens Vasters Date: Mon, 4 Nov 2024 15:08:27 -0700 Subject: [PATCH 2/3] interim state save --- test/catalog/test_catalog.py | 382 ++++++++++++++++ xregistry/commands/catalog.py | 826 +++++++++++++++++++++------------- 2 files changed, 895 insertions(+), 313 deletions(-) create mode 100644 test/catalog/test_catalog.py diff --git a/test/catalog/test_catalog.py b/test/catalog/test_catalog.py new file mode 100644 index 0000000..3078cd4 --- /dev/null +++ b/test/catalog/test_catalog.py @@ -0,0 +1,382 @@ +import os +import sys +import pytest +import json +import requests + +project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')) +sys.path.append(os.path.join(project_root)) + +from xregistry.commands.catalog import CatalogSubcommands +from testcontainers.core.container import DockerContainer +from testcontainers.core.waiting_utils import wait_for_logs +import logging +import os +import sys +import pytest +import requests +from unittest.mock import patch +from xregistry.cli import main as cli + +# Enable HTTP request tracing +logging.basicConfig(level=logging.DEBUG) +http_client_logger = logging.getLogger("http.client") +http_client_logger.setLevel(logging.DEBUG) +http_client_logger.propagate = True +# log to the console +console_handler = logging.StreamHandler() +console_handler.setLevel(logging.DEBUG) +formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +console_handler.setFormatter(formatter) +logging.getLogger().addHandler(console_handler) + + +@pytest.fixture(scope="module") +def catalog_container(): + with DockerContainer("duglin/xreg-server-all") \ + .with_bind_ports(8080, 8080) as container: + wait_for_logs(container, "Listening on 8080") + yield container + +""" this file tests the catalog subcommands in #file: """ + +@pytest.mark.usefixtures("catalog_container") +def test_catalog_endpoint_operations(): + catalog = CatalogSubcommands("http://localhost:8080") + + # Add endpoint + catalog.add_endpoint( + "test-endpoint", + "producer", + "AMQP/1.0", + endpoints=["amqp://localhost:5672"], + options={"key": "value"}, + messagegroups=["test-group"], + description="Test endpoint", + documentation="http://docs", + labels={"env": "test"}, + name="Test Endpoint" + ) + + # Verify endpoint was added + response = requests.get("http://localhost:8080/endpoints/test-endpoint") + assert response.status_code == 200 + endpoint = response.json() + assert endpoint["endpointid"] == "test-endpoint" + assert endpoint["usage"] == "producer" + assert endpoint["protocol"] == "AMQP/1.0" + + # Edit endpoint + catalog.edit_endpoint( + "test-endpoint", + description="Updated endpoint", + labels={"env": "prod"} + ) + + # Verify endpoint was updated + response = requests.get("http://localhost:8080/endpoints/test-endpoint") + assert response.status_code == 200 + endpoint = response.json() + assert endpoint["description"] == "Updated endpoint" + assert endpoint["labels"]["env"] == "prod" + + # Add message group + catalog.add_messagegroup( + "test-group", + "CloudEvents/1.0", + "amqp", + description="Test message group", + documentation="http://docs", + labels={"env": "test"}, + name="Test Group" + ) + + # Verify message group was added + response = requests.get("http://localhost:8080/messagegroups/test-group") + assert response.status_code == 200 + group = response.json() + assert group["messagegroupid"] == "test-group" + assert group["envelope"] == "CloudEvents/1.0" + + # Add message to group + catalog.add_message( + "test-group", + "test-message", + "CloudEvents/1.0", + "AMQP/1.0", + description="Test message", + documentation="http://docs", + labels={"type": "event"}, + name="Test Message" + ) + + # Verify message was added + response = requests.get("http://localhost:8080/messagegroups/test-group/messages/test-message") + assert response.status_code == 200 + message = response.json() + assert message["messageid"] == "test-message" + assert message["envelope"] == "CloudEvents/1.0" + + # Add schema group + catalog.add_schemagroup( + "test-schemas", + "avro", + description="Test schema group", + documentation="http://docs", + labels={"type": "schemas"}, + name="Test Schemas" + ) + + # Verify schema group was added + response = requests.get("http://localhost:8080/schemagroups/test-schemas") + assert response.status_code == 200 + schemas = response.json() + assert schemas["schemagroupid"] == "test-schemas" + + # Add schema version + catalog.add_schemaversion( + "test-schemas", + "test-schema", + "avro", + schema='{"type": "string"}', + versionid="1.0", + description="Test schema", + documentation="http://docs", + labels={"type": "schema"}, + name="Test Schema" + ) + + # Verify schema was added + response = requests.get("http://localhost:8080/schemagroups/test-schemas?inline=schemas,schemas.versions,schemas.versions.schema") + assert response.status_code == 200 + schemas = response.json() + assert "test-schema" in schemas["schemas"] + assert schemas["schemas"]["test-schema"]["versions"]["1.0"]["schema"]["type"] == "string" + + # Clean up + catalog.remove_schemagroup("test-schemas") + catalog.remove_messagegroup("test-group") + catalog.remove_endpoint("test-endpoint") + + # Verify cleanup + response = requests.get("http://localhost:8080/endpoints/test-endpoint") + assert response.status_code == 404 + response = requests.get("http://localhost:8080/messagegroups/test-group") + assert response.status_code == 404 + response = requests.get("http://localhost:8080/schemagroups/test-schemas") + assert response.status_code == 404 + project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')) + sys.path.append(os.path.join(project_root)) + + +@pytest.mark.usefixtures("catalog_container") +def test_cli_add_endpoint(): + test_args = [ + 'xregistry', + 'catalog', + 'endpoint', + 'add', + '--catalog', 'http://localhost:8080', + '--endpointid', 'cli-endpoint', + '--usage', 'producer', + '--protocol', 'AMQP/1.0', + '--endpoints', 'amqp://localhost:5672', + '--description', '"CLI Test endpoint"', + ] + with patch.object(sys, 'argv', test_args): + result = cli() + assert result == 0 + + response = requests.get('http://localhost:8080/endpoints/cli-endpoint') + assert response.status_code == 200 + endpoint = response.json() + assert endpoint['endpointid'] == 'cli-endpoint' + assert endpoint['usage'] == 'producer' + assert endpoint['protocol'] == 'AMQP/1.0' + + test_args = [ + 'xregistry', + 'catalog', + 'endpoint', + 'remove', + '--catalog', 'http://localhost:8080', + '--endpointid', 'cli-endpoint', + ] + with patch.object(sys, 'argv', test_args): + result = cli() + assert result == 0 + + response = requests.get('http://localhost:8080/endpoints/cli-endpoint') + assert response.status_code == 404 + +@pytest.mark.usefixtures("catalog_container") +def test_cli_add_messagegroup(): + test_args = [ + 'xregistry', + 'catalog', + 'messagegroup', + 'add', + '--catalog', 'http://localhost:8080', + '--messagegroupid', 'cli-messagegroup', + '--envelope', 'CloudEvents/1.0', + '--protocol', 'AMQP/1.0', + '--description', '"CLI Test message group"', + ] + with patch.object(sys, 'argv', test_args): + result = cli() + assert result == 0 + + response = requests.get('http://localhost:8080/messagegroups/cli-messagegroup') + assert response.status_code == 200 + group = response.json() + assert group['messagegroupid'] == 'cli-messagegroup' + assert group['envelope'] == 'CloudEvents/1.0' + + test_args = [ + 'xregistry', + 'catalog', + 'messagegroup', + 'remove', + '--catalog', 'http://localhost:8080', + '--messagegroupid', 'cli-messagegroup', + ] + with patch.object(sys, 'argv', test_args): + result = cli() + assert result == 0 + + response = requests.get('http://localhost:8080/messagegroups/cli-messagegroup') + assert response.status_code == 404 + +@pytest.mark.usefixtures("catalog_container") +def test_cli_add_message(): + test_args = [ + 'xregistry', + 'catalog', + 'messagegroup', + 'add', + '--catalog', 'http://localhost:8080', + '--messagegroupid', 'cli-messagegroup', + '--envelope', 'CloudEvents/1.0', + '--protocol', 'AMQP/1.0', + ] + with patch.object(sys, 'argv', test_args): + cli() + + test_args = [ + 'xregistry', + 'catalog', + 'message', + 'add', + '--catalog', 'http://localhost:8080', + '--messagegroupid', 'cli-messagegroup', + '--messageid', 'cli-message', + '--envelope', 'CloudEvents/1.0', + '--protocol', 'AMQP/1.0', + '--description', '"CLI Test message"', + ] + with patch.object(sys, 'argv', test_args): + result = cli() + assert result == 0 + + response = requests.get('http://localhost:8080/messagegroups/cli-messagegroup/messages/cli-message') + assert response.status_code == 200 + message = response.json() + assert message['messageid'] == 'cli-message' + assert message['envelope'] == 'CloudEvents/1.0' + + test_args = [ + 'xregistry', + 'catalog', + 'message', + 'remove', + '--catalog', 'http://localhost:8080', + '--messagegroupid', 'cli-messagegroup', + '--messageid', 'cli-message', + ] + with patch.object(sys, 'argv', test_args): + cli() + + test_args = [ + 'xregistry', + 'catalog', + 'messagegroup', + 'remove', + '--catalog', 'http://localhost:8080', + '--messagegroupid', 'cli-messagegroup', + ] + with patch.object(sys, 'argv', test_args): + cli() + + response = requests.get('http://localhost:8080/messagegroups/cli-messagegroup') + assert response.status_code == 404 + +@pytest.mark.usefixtures("catalog_container") +def test_cli_add_schemagroup_and_schema(): + test_args = [ + 'xregistry', + 'catalog', + 'schemagroup', + 'add', + '--catalog', 'http://localhost:8080', + '--schemagroupid', 'cli-schemagroup', + '--format', 'avro', + '--description', '"CLI Test schema group"', + ] + with patch.object(sys, 'argv', test_args): + result = cli() + assert result == 0 + + response = requests.get('http://localhost:8080/schemagroups/cli-schemagroup') + assert response.status_code == 200 + schemagroup = response.json() + assert schemagroup['schemagroupid'] == 'cli-schemagroup' + + test_args = [ + 'xregistry', + 'catalog', + 'schema', + 'add', + '--catalog', 'http://localhost:8080', + '--schemagroupid', 'cli-schemagroup', + '--schemaid', 'cli-schema', + '--format', 'avro', + '--versionid', '1.0', + '--schema', '{"type": "string"}', + '--description', 'CLI Test schema', + ] + with patch.object(sys, 'argv', test_args): + result = cli() + assert result == 0 + + response = requests.get('http://localhost:8080/schemagroups/cli-schemagroup?inline=schemas,schemas.versions,schemas.versions.schema') + assert response.status_code == 200 + schemas = response.json() + assert 'cli-schema' in schemas['schemas'] + assert schemas['schemas']['cli-schema']['versions']['1.0']['schema']['type'] == 'string' + + test_args = [ + 'xregistry', + 'catalog', + 'schema', + 'remove', + '--catalog', 'http://localhost:8080', + '--schemagroupid', 'cli-schemagroup', + '--schemaid', 'cli-schema', + '--versionid', '1.0', + ] + with patch.object(sys, 'argv', test_args): + cli() + + test_args = [ + 'xregistry', + 'catalog', + 'schemagroup', + 'remove', + '--catalog', 'http://localhost:8080', + '--schemagroupid', 'cli-schemagroup', + ] + with patch.object(sys, 'argv', test_args): + cli() + + response = requests.get('http://localhost:8080/schemagroups/cli-schemagroup') + assert response.status_code == 404 diff --git a/xregistry/commands/catalog.py b/xregistry/commands/catalog.py index e9e66b5..b1a4a74 100644 --- a/xregistry/commands/catalog.py +++ b/xregistry/commands/catalog.py @@ -12,7 +12,7 @@ def current_time_iso() -> str: """Returns the current time in ISO format.""" - return datetime.datetime.now().isoformat() + return datetime.datetime.now(tz=datetime.UTC).isoformat() class CatalogSubcommands: """Class containing methods to handle catalog subcommands.""" @@ -55,7 +55,7 @@ def add_endpoint(self, endpointid: str, usage: str, protocol: str, endpoints: Op if deprecated: endpoint["deprecated"] = deprecated response = requests.put(f"{self.base_url}/endpoints/{endpointid}", json=endpoint) - if response.status_code != 200: + if response.status_code != 201 and response.status_code != 200: raise ValueError(f"Failed to add endpoint: {response.text}") def remove_endpoint(self, endpointid: str) -> None: @@ -108,7 +108,6 @@ def edit_endpoint(self, endpointid: str, usage: Optional[str] = None, protocol: if deprecated: endpoint["deprecated"] = deprecated endpoint["modifiedat"] = current_time_iso() - endpoint["epoch"] += 1 response = requests.put(f"{self.base_url}/endpoints/{endpointid}", json=endpoint) if response.status_code != 200: raise ValueError(f"Failed to edit endpoint: {response.text}") @@ -133,15 +132,15 @@ def apply_endpoint(self, file: str) -> None: else: self.add_endpoint(**endpoint) - def add_messagegroup(self, messagegroupid: str, format: str, binding: str, messages: Optional[Dict[str, Any]] = None, + def add_messagegroup(self, messagegroupid: str, envelope: str, protocol: str, messages: Optional[Dict[str, Any]] = None, description: Optional[str] = None, documentation: Optional[str] = None, labels: Optional[Dict[str, str]] = None, name: Optional[str] = None) -> None: """Adds a messagegroup to the catalog.""" messagegroup = { "messagegroupid": messagegroupid, - "format": format, - "binding": binding, + "envelope": envelope, + "protocol": protocol, "createdat": current_time_iso(), "modifiedat": current_time_iso(), "epoch": 0 @@ -157,7 +156,7 @@ def add_messagegroup(self, messagegroupid: str, format: str, binding: str, messa if name: messagegroup["name"] = name response = requests.put(f"{self.base_url}/messagegroups/{messagegroupid}", json=messagegroup) - if response.status_code != 200: + if response.status_code != 200 and response.status_code != 201: raise ValueError(f"Failed to add messagegroup: {response.text}") def remove_messagegroup(self, messagegroupid: str) -> None: @@ -175,7 +174,7 @@ def remove_messagegroup(self, messagegroupid: str) -> None: if response.status_code != 204: raise ValueError(f"Failed to remove messagegroup: {response.text}") - def edit_messagegroup(self, messagegroupid: str, format: Optional[str] = None, binding: Optional[str] = None, messages: Optional[Dict[str, Any]] = None, + def edit_messagegroup(self, messagegroupid: str, envelope: Optional[str] = None, protocol: Optional[str] = None, messages: Optional[Dict[str, Any]] = None, description: Optional[str] = None, documentation: Optional[str] = None, labels: Optional[Dict[str, str]] = None, name: Optional[str] = None) -> None: """Edits an existing messagegroup in the catalog.""" @@ -184,10 +183,10 @@ def edit_messagegroup(self, messagegroupid: str, format: Optional[str] = None, b if response.status_code != 200: raise ValueError(f"Messagegroup with id {messagegroupid} does not exist: {response.text}") messagegroup = response.json() - if format: - messagegroup["format"] = format - if binding: - messagegroup["binding"] = binding + if envelope: + messagegroup["envelope"] = envelope + if protocol: + messagegroup["protocol"] = protocol if messages: messagegroup["messages"] = messages if description: @@ -199,7 +198,6 @@ def edit_messagegroup(self, messagegroupid: str, format: Optional[str] = None, b if name: messagegroup["name"] = name messagegroup["modifiedat"] = current_time_iso() - messagegroup["epoch"] += 1 response = requests.put(f"{self.base_url}/messagegroups/{messagegroupid}", json=messagegroup) if response.status_code != 200: raise ValueError(f"Failed to edit messagegroup: {response.text}") @@ -236,8 +234,7 @@ def add_schemagroup(self, schemagroupid: str, format: str, schemas: Optional[Dic "modifiedat": current_time_iso(), "epoch": 0 } - if schemas: - schemagroup["schemas"] = schemas + schemagroup["schemas"] = schemas if schemas else {} if description: schemagroup["description"] = description if documentation: @@ -247,7 +244,7 @@ def add_schemagroup(self, schemagroupid: str, format: str, schemas: Optional[Dic if name: schemagroup["name"] = name response = requests.put(f"{self.base_url}/schemagroups/{schemagroupid}", json=schemagroup) - if response.status_code != 200: + if response.status_code != 200 and response.status_code != 201: raise ValueError(f"Failed to add schemagroup: {response.text}") def remove_schemagroup(self, schemagroupid: str) -> None: @@ -287,7 +284,6 @@ def edit_schemagroup(self, schemagroupid: str, format: Optional[str] = None, sch if name: schemagroup["name"] = name schemagroup["modifiedat"] = current_time_iso() - schemagroup["epoch"] += 1 response = requests.put(f"{self.base_url}/schemagroups/{schemagroupid}", json=schemagroup) if response.status_code != 200: raise ValueError(f"Failed to edit schemagroup: {response.text}") @@ -312,7 +308,7 @@ def apply_schemagroup(self, file: str) -> None: else: self.add_schemagroup(**schemagroup) - def add_message(self, groupid: str, messageid: str, format: str, protocol: str, schemaformat: Optional[str] = None, + def add_message(self, messagegroupid: str, messageid: str, envelope: str, protocol: str, schemaformat: Optional[str] = None, schemagroup: Optional[str] = None, schemaid: Optional[str] = None, schemaurl: Optional[str] = None, documentation: Optional[str] = None, description: Optional[str] = None, labels: Optional[Dict[str, str]] = None, name: Optional[str] = None) -> None: @@ -320,7 +316,7 @@ def add_message(self, groupid: str, messageid: str, format: str, protocol: str, message = { "messageid": messageid, - "format": format, + "envelope": envelope, "protocol": protocol, "createdat": current_time_iso(), "modifiedat": current_time_iso(), @@ -343,8 +339,8 @@ def add_message(self, groupid: str, messageid: str, format: str, protocol: str, if name: message["name"] = name - response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) - if response.status_code != 200: + response = requests.put(f"{self.base_url}/messagegroups/{messagegroupid}/messages/{messageid}", json=message) + if response.status_code != 200 and response.status_code != 201: raise ValueError(f"Failed to add message: {response.text}") def remove_message(self, groupid: str, messageid: str) -> None: @@ -362,18 +358,18 @@ def remove_message(self, groupid: str, messageid: str) -> None: if response.status_code != 204: raise ValueError(f"Failed to remove message: {response.text}") - def edit_message(self, groupid: str, messageid: str, format: Optional[str] = None, protocol: Optional[str] = None, schemaformat: Optional[str] = None, + def edit_message(self, messagegroupid: str, messageid: str, envelope: Optional[str] = None, protocol: Optional[str] = None, schemaformat: Optional[str] = None, schemagroup: Optional[str] = None, schemaid: Optional[str] = None, schemaurl: Optional[str] = None, documentation: Optional[str] = None, description: Optional[str] = None, labels: Optional[Dict[str, str]] = None, name: Optional[str] = None) -> None: """Edits an existing message in a message group in the catalog.""" - response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + response = requests.get(f"{self.base_url}/messagegroups/{messagegroupid}/messages/{messageid}") if response.status_code != 200: raise ValueError(f"Message with id {messageid} does not exist: {response.text}") message = response.json() - if format: - message["format"] = format + if envelope: + message["envelope"] = envelope if protocol: message["protocol"] = protocol if schemaformat: @@ -393,8 +389,7 @@ def edit_message(self, groupid: str, messageid: str, format: Optional[str] = Non if name: message["name"] = name message["modifiedat"] = current_time_iso() - message["epoch"] += 1 - response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + response = requests.put(f"{self.base_url}/messagegroups/{messagegroupid}/messages/{messageid}", json=message) if response.status_code != 200: raise ValueError(f"Failed to edit message: {response.text}") @@ -446,19 +441,17 @@ def remove_amqp_message_metadata(self, groupid: str, messageid: str, section: st raise ValueError(f"Message {messageid} is not an AMQP message") self.remove_protocol_option(messageid, message, section, name) - # Increment the epoch - message["epoch"] += 1 # Update the message with a PUT request response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) if response.status_code != 200: raise ValueError(f"Failed to remove AMQP message metadata: {response.text}") - def add_amqp_message_metadata(self, groupid: str, messageid: str, section: str|None, name: str, type: str, value: str|None, description: str, required: bool) -> None: + def add_amqp_message_metadata(self, messagegroupid: str, messageid: str, section: str|None, name: str, type: str, value: str|None, description: str, required: bool) -> None: """Adds AMQP message metadata to a message in a message group in the catalog.""" # Fetch the current message - response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + response = requests.get(f"{self.base_url}/messagegroups/{messagegroupid}/messages/{messageid}") if response.status_code != 200: raise ValueError(f"Failed to fetch message: {response.text}") message = response.json() @@ -468,11 +461,8 @@ def add_amqp_message_metadata(self, groupid: str, messageid: str, section: str|N self.set_protocol_option(message, section, name, type, value, description, required) - # Increment the epoch - message["epoch"] += 1 - # Update the message with a PUT request - response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + response = requests.put(f"{self.base_url}/messagegroups/{messagegroupid}/messages/{messageid}", json=message) if response.status_code != 200: raise ValueError(f"Failed to add AMQP message metadata: {response.text}") @@ -491,9 +481,6 @@ def edit_amqp_message_metadata(self, groupid: str, messageid: str, section: str| # Update the metadata entry self.set_protocol_option(message, section, name, type, value, description, required) - # Increment the epoch - message["epoch"] += 1 - # Update the message with a PUT request response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) if response.status_code != 200: @@ -513,9 +500,6 @@ def add_mqtt_message_metadata(self, groupid: str, messageid: str, mqtt_version: self.set_protocol_option(message, None, name, type, value, description, required) - # Increment the epoch - message["epoch"] += 1 - # Update the message with a PUT request response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) if response.status_code != 200: @@ -535,9 +519,6 @@ def remove_mqtt_message_metadata(self, groupid: str, messageid: str, section:str self.remove_protocol_option(messageid, message, section, name) - # Increment the epoch - message["epoch"] += 1 - # Update the message with a PUT request response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) if response.status_code != 200: @@ -557,9 +538,6 @@ def edit_mqtt_message_metadata(self, groupid: str, messageid: str, name: str, ty self.set_protocol_option(message, None, name, type, value, description, required) - # Increment the epoch - message["epoch"] += 1 - # Update the message with a PUT request response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) if response.status_code != 200: @@ -574,14 +552,11 @@ def add_kafka_message_metadata(self, groupid: str, messageid: str, section: Opti raise ValueError(f"Failed to fetch message: {response.text}") message = response.json() - if "protocol" not in message or message["protocol"] != "Kafka": + if "protocol" not in message or message["protocol"] != "KAFKA": raise ValueError(f"Message {messageid} is not a Kafka message") self.set_protocol_option(message, section, name, type, value, description, required) - # Increment the epoch - message["epoch"] += 1 - # Update the message with a PUT request response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) if response.status_code != 200: @@ -596,13 +571,10 @@ def remove_kafka_message_metadata(self, groupid: str, messageid: str, section: O raise ValueError(f"Failed to fetch message: {response.text}") message = response.json() - if "protocol" not in message or message["protocol"] != "Kafka": + if "protocol" not in message or message["protocol"] != "KAFKA": raise ValueError(f"Message {messageid} is not a Kafka message") self.remove_protocol_option(messageid, message, section, name) - - # Increment the epoch - message["epoch"] += 1 # Update the message with a PUT request response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) @@ -618,14 +590,11 @@ def edit_kafka_message_metadata(self, groupid: str, messageid: str, section: Opt raise ValueError(f"Failed to fetch message: {response.text}") message = response.json() - if "protocol" not in message or message["protocol"] != "Kafka": + if "protocol" not in message or message["protocol"] != "KAFKA": raise ValueError(f"Message {messageid} is not a Kafka message") self.set_protocol_option(message, section, name, type, value, description, required) - # Increment the epoch - message["epoch"] += 1 - # Update the message with a PUT request response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) if response.status_code != 200: @@ -645,19 +614,16 @@ def add_http_message_metadata(self, groupid: str, messageid: str, section: str | self.set_protocol_option(message, section, name, type, value, description, required) - # Increment the epoch - message["epoch"] += 1 - # Update the message with a PUT request response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) if response.status_code != 200: raise ValueError(f"Failed to add HTTP message metadata: {response.text}") - def remove_http_message_metadata(self, groupid: str, messageid: str, section: str | None, name: str) -> None: + def remove_http_message_metadata(self, messagegroupid: str, messageid: str, section: str | None, name: str) -> None: """Removes HTTP message metadata from a message in a message group in the catalog.""" # Fetch the current message - response = requests.get(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}") + response = requests.get(f"{self.base_url}/messagegroups/{messagegroupid}/messages/{messageid}") if response.status_code != 200: raise ValueError(f"Failed to fetch message: {response.text}") message = response.json() @@ -667,11 +633,8 @@ def remove_http_message_metadata(self, groupid: str, messageid: str, section: st self.remove_protocol_option(messageid, message, section, name) - # Increment the epoch - message["epoch"] += 1 - # Update the message with a PUT request - response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) + response = requests.put(f"{self.base_url}/messagegroups/{messagegroupid}/messages/{messageid}", json=message) if response.status_code != 200: raise ValueError(f"Failed to remove HTTP message metadata: {response.text}") @@ -689,9 +652,6 @@ def edit_http_message_metadata(self, groupid: str, messageid: str, section: str self.set_protocol_option(message, section, name, type, value, description, required) - # Increment the epoch - message["epoch"] += 1 - # Update the message with a PUT request response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) if response.status_code != 200: @@ -742,9 +702,6 @@ def add_cloudevents_message_metadata(self, groupid: str, messageid: str, attribu self.set_envelope_metadata(message, attribute, type, value, description, required) - # Increment the epoch - message["epoch"] += 1 - # Update the message with a PUT request response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) if response.status_code != 200: @@ -764,9 +721,6 @@ def edit_cloudevents_message_metadata(self, groupid: str, messageid: str, attrib self.remove_envelope_metadata(messageid, message, attribute) - # Increment the epoch - message["epoch"] += 1 - # Update the message with a PUT request response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) if response.status_code != 200: @@ -785,9 +739,6 @@ def remove_cloudevents_message_metadata(self, groupid: str, messageid: str, attr if "metadata" in message: message["metadata"] = [m for m in message["metadata"] if m["attribute"] != attribute] - # Increment the epoch - message["epoch"] += 1 - # Update the message with a PUT request response = requests.put(f"{self.base_url}/messagegroups/{groupid}/messages/{messageid}", json=message) if response.status_code != 200: @@ -843,20 +794,20 @@ def add_schema(self, groupid: str, schemaid: str, format: str, versionid: str = schemagroup["schemas"][schemaid] = schema_obj response = requests.put(f"{self.base_url}/schemagroups/{groupid}", json=schemagroup) - if response.status_code != 200: + if response.status_code != 200 and response.status_code != 201: raise ValueError(f"Failed to add schema: {response.text}") - def add_schemaversion(self, groupid: str, schemaid: str, format: str, versionid: str = "1", schema: Optional[str] = None, + def add_schemaversion(self, schemagroupid: str, schemaid: str, format: str, versionid: str = "1", schema: Optional[str] = None, schemaimport: Optional[str] = None, schemaurl: Optional[str] = None, description: Optional[str] = None, documentation: Optional[str] = None, - labels: Optional[Dict[str, str]] = None, name: Optional[str] = None) -> None: + labels: Optional[Dict[str, str]] = None, name: Optional[str] = None) -> Any: """Adds a schema version to a schemagroup in the catalog.""" - response = requests.get(f"{self.base_url}/schemagroups/{groupid}") + response = requests.get(f"{self.base_url}/schemagroups/{schemagroupid}") if response.status_code != 200: - raise ValueError(f"Schemagroup with id {groupid} does not exist: {response.text}") + raise ValueError(f"Schemagroup with id {schemagroupid} does not exist: {response.text}") schemagroup = response.json() - schema_obj = { + schema_version = { "schemaid": schemaid, "format": format, "versionid": versionid, @@ -867,50 +818,45 @@ def add_schemaversion(self, groupid: str, schemaid: str, format: str, versionid: if schema: try: json.loads(schema) - schema_obj["schema"] = schema + schema_version["schema"] = schema except json.JSONDecodeError: - schema_obj["schemabase64"] = schema.encode("utf-8").hex() + schema_version["schemabase64"] = schema.encode("utf-8").hex() elif schemaimport: with open(schemaimport, 'r', encoding='utf-8') as sf: schema_content = sf.read() try: json.loads(schema_content) - schema_obj["schema"] = schema_content + schema_version["schema"] = schema_content except json.JSONDecodeError: - schema_obj["schemabase64"] = schema_content.encode("utf-8").hex() + schema_version["schemabase64"] = schema_content.encode("utf-8").hex() elif schemaurl: - schema_obj["schemaurl"] = schemaurl + schema_version["schemaurl"] = schemaurl if description: - schema_obj["description"] = description + schema_version["description"] = description if documentation: - schema_obj["documentation"] = documentation + schema_version["documentation"] = documentation if labels: - schema_obj["labels"] = labels + schema_version["labels"] = labels if name: - schema_obj["name"] = name - - if "schemas" not in schemagroup: - schemagroup["schemas"] = {} - if schemaid not in schemagroup["schemas"]: - schemagroup["schemas"][schemaid] = {"versions": {}} - schemagroup["schemas"][schemaid]["versions"][versionid] = schema_obj + schema_version["name"] = name - response = requests.put(f"{self.base_url}/schemagroups/{groupid}", json=schemagroup) - if response.status_code != 200: + response = requests.put(f"{self.base_url}/schemagroups/{schemagroupid}/schemas/{schemaid}/versions/{versionid}$meta", json=schema_version) + if response.status_code != 200 and response.status_code != 201: raise ValueError(f"Failed to add schema version: {response.text}") + return response.json() - def edit_schemaversion(self, groupid: str, schemaid: str, versionid: str, format: Optional[str] = None, schema: Optional[str] = None, + def edit_schemaversion(self, schemagroupid: str, schemaid: str, versionid: str, format: Optional[str] = None, schema: Optional[str] = None, schemaimport: Optional[str] = None, schemaurl: Optional[str] = None, description: Optional[str] = None, documentation: Optional[str] = None, labels: Optional[Dict[str, str]] = None, name: Optional[str] = None) -> None: """Edits an existing schema version in a schemagroup in the catalog.""" - response = requests.get(f"{self.base_url}/schemagroups/{groupid}") + response = requests.get(f"{self.base_url}/schemagroups/{schemagroupid}") if response.status_code != 200: - raise ValueError(f"Schemagroup with id {groupid} does not exist: {response.text}") + raise ValueError(f"Schemagroup with id {schemagroupid} does not exist: {response.text}") schemagroup = response.json() if "schemas" not in schemagroup or schemaid not in schemagroup["schemas"]: - raise ValueError(f"Schema with id {schemaid} does not exist in schemagroup {groupid}") + raise ValueError(f"Schema with id {schemaid} does not exist in schemagroup {schemagroupid}") if "versions" not in schemagroup["schemas"][schemaid] or versionid not in schemagroup["schemas"][schemaid]["versions"]: raise ValueError(f"Version with id {versionid} does not exist for schema {schemaid}") @@ -944,9 +890,8 @@ def edit_schemaversion(self, groupid: str, schemaid: str, versionid: str, format schema_obj["name"] = name schema_obj["modifiedat"] = current_time_iso() - schema_obj["epoch"] += 1 - - response = requests.put(f"{self.base_url}/schemagroups/{groupid}", json=schemagroup) + + response = requests.put(f"{self.base_url}/schemagroups/{schemagroupid}", json=schemagroup) if response.status_code != 200: raise ValueError(f"Failed to edit schema version: {response.text}") @@ -973,16 +918,16 @@ def remove_schemaversion(self, groupid: str, schemaid: str, versionid: str) -> N raise ValueError(f"Failed to remove schema version: {response.text}") - def remove_schema(self, groupid: str, schemaid: str, versionid: Optional[str] = None) -> None: + def remove_schema(self, schemagroupid: str, schemaid: str, versionid: Optional[str] = None) -> None: """Removes a schema from a schemagroup in the catalog.""" - response = requests.get(f"{self.base_url}/schemagroups/{groupid}") + response = requests.get(f"{self.base_url}/schemagroups/{schemagroupid}") if response.status_code != 200: - raise ValueError(f"Schemagroup with id {groupid} does not exist: {response.text}") + raise ValueError(f"Schemagroup with id {schemagroupid} does not exist: {response.text}") schemagroup = response.json() if "schemas" not in schemagroup or schemaid not in schemagroup["schemas"]: - raise ValueError(f"Schema with id {schemaid} does not exist in schemagroup {groupid}") + raise ValueError(f"Schema with id {schemaid} does not exist in schemagroup {schemagroupid}") if versionid: if "versions" in schemagroup["schemas"][schemaid]: @@ -998,7 +943,7 @@ def remove_schema(self, groupid: str, schemaid: str, versionid: Optional[str] = else: del schemagroup["schemas"][schemaid] - response = requests.put(f"{self.base_url}/schemagroups/{groupid}", json=schemagroup) + response = requests.put(f"{self.base_url}/schemagroups/{schemagroupid}", json=schemagroup) if response.status_code != 200: raise ValueError(f"Failed to remove schema: {response.text}") @@ -1044,22 +989,21 @@ def edit_schema(self, groupid: str, schemaid: str, format: Optional[str] = None, schema_obj["name"] = name schema_obj["modifiedat"] = current_time_iso() - schema_obj["epoch"] += 1 - + response = requests.put(f"{self.base_url}/schemagroups/{groupid}", json=schemagroup) if response.status_code != 200: raise ValueError(f"Failed to edit schema: {response.text}") - def show_schema(self, groupid: str, schemaid: str) -> None: + def show_schema(self, schemagroupid: str, schemaid: str) -> None: """Shows a schema from a schemagroup in the catalog.""" - response = requests.get(f"{self.base_url}/schemagroups/{groupid}") + response = requests.get(f"{self.base_url}/schemagroups/{schemagroupid}") if response.status_code != 200: - raise ValueError(f"Schemagroup with id {groupid} does not exist: {response.text}") + raise ValueError(f"Schemagroup with id {schemagroupid} does not exist: {response.text}") schemagroup = response.json() if "schemas" not in schemagroup or schemaid not in schemagroup["schemas"]: - raise ValueError(f"Schema with id {schemaid} does not exist in schemagroup {groupid}") + raise ValueError(f"Schema with id {schemaid} does not exist in schemagroup {schemagroupid}") print(json.dumps(schemagroup["schemas"][schemaid], indent=2)) @@ -1105,20 +1049,24 @@ def add_common_arguments(parser): Args: parser (ArgumentParser): The parser to add arguments to. """ - parser.add_argument("--description", help="Description string") - parser.add_argument("--documentation", help="Documentation URL") - parser.add_argument("--labels", nargs='*', - help="Labels as key=value pairs") - parser.add_argument("--name", help="Human-readable name") - + parser.add_argument("--catalog", required=True, help="Catalog URL") + parser.add_argument("--authmode", choices=["none", "basic", "bearer"], help="Authentication mode") + parser.add_argument("--username", help="Username") + parser.add_argument("--password", help="Password") + parser.add_argument("--token", help="Bearer token") + endpoint_subparsers = manifest_subparsers.add_parser("endpoint", help="Manage endpoints").add_subparsers( dest="endpoint_command", help="Endpoint commands") endpoint_add = endpoint_subparsers.add_parser("add", help="Add a new endpoint") - endpoint_add.add_argument("--id", required=True, help="Endpoint ID") + endpoint_add.add_argument("--endpointid", required=True, help="Endpoint ID") + endpoint_add.add_argument("--description", help="Endpoint description") + endpoint_add.add_argument("--documentation", help="Endpoint documentation URL") + endpoint_add.add_argument("--name", help="Endpoint name") + endpoint_add.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Endpoint labels (key=value pairs)") endpoint_add.add_argument("--usage", required=True, choices=["subscriber", "producer", "consumer"], help="Usage type") - endpoint_add.add_argument("--protocol", choices=["HTTP", "AMQP", "MQTT", "Kafka", "NATS"], help="Protocol") + endpoint_add.add_argument("--protocol", choices=["HTTP", "AMQP/1.0", "MQTT/3.1.1", "MQTT/5.0", "KAFKA", "NATS"], help="Protocol") endpoint_add.add_argument("--deployed", type=bool, help="Deployed status") endpoint_add.add_argument("--endpoints", nargs='+', help="Endpoint URIs") endpoint_add.add_argument("--options", nargs='*', help="Endpoint options") @@ -1126,19 +1074,23 @@ def add_common_arguments(parser): endpoint_add.add_argument("--channel", help="Channel identifier") endpoint_add.add_argument("--deprecated", help="Deprecation information") add_common_arguments(endpoint_add) - endpoint_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_endpoint(args.id, args.usage, args.protocol, args.deployed, args.endpoints, args.options, + endpoint_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_endpoint(args.endpointid, args.usage, args.protocol, args.deployed, args.endpoints, args.options, args.messagegroups, args.documentation, args.description, args.labels, args.name, args.channel, args.deprecated )) endpoint_remove = endpoint_subparsers.add_parser("remove", help="Remove an endpoint") - endpoint_remove.add_argument("--id", required=True, help="Endpoint ID") - endpoint_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_endpoint(args.id)) - + endpoint_remove.add_argument("--endpointid", required=True, help="Endpoint ID") + add_common_arguments(endpoint_remove) + endpoint_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_endpoint(args.endpointid)) + endpoint_edit = endpoint_subparsers.add_parser("edit", help="Edit an endpoint") - endpoint_edit.add_argument("--id", required=True, help="Endpoint ID") + endpoint_edit.add_argument("--endpointid", required=True, help="Endpoint ID") + endpoint_edit.add_argument("--description", help="Endpoint description") + endpoint_edit.add_argument("--documentation", help="Endpoint documentation URL") + endpoint_edit.add_argument("--name", help="Endpoint name") endpoint_edit.add_argument("--usage", choices=["subscriber", "producer", "consumer"], help="Usage type") - endpoint_edit.add_argument("--protocol", choices=["HTTP", "AMQP", "MQTT", "Kafka", "NATS"], help="Protocol") + endpoint_edit.add_argument("--protocol", choices=["HTTP", "AMQP/1.0", "MQTT/3.1.1", "MQTT/5.0", "KAFKA", "NATS"], help="Protocol") endpoint_edit.add_argument("--deployed", type=bool, help="Deployed status") endpoint_edit.add_argument("--endpoints", nargs='+', help="Endpoint URIs") endpoint_edit.add_argument("--options", nargs='*', help="Endpoint options") @@ -1146,50 +1098,75 @@ def add_common_arguments(parser): endpoint_edit.add_argument("--channel", help="Channel identifier") endpoint_edit.add_argument("--deprecated", help="Deprecation information") add_common_arguments(endpoint_edit) - endpoint_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_endpoint(args.id, args.usage, args.protocol, args.deployed, args.endpoints, args.options, + endpoint_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_endpoint(args.endpointid, args.usage, args.protocol, args.deployed, args.endpoints, args.options, args.messagegroups, args.documentation, args.description, args.labels, args.name, args.channel, args.deprecated )) endpoint_show = endpoint_subparsers.add_parser("show", help="Show an endpoint") - endpoint_show.add_argument("--id", required=True, help="Endpoint ID") - endpoint_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_endpoint(args.id)) + endpoint_show.add_argument("--endpointid", required=True, help="Endpoint ID") + add_common_arguments(endpoint_show) + endpoint_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_endpoint(args.endpointid)) endpoint_apply = endpoint_subparsers.add_parser("apply", help="Apply an endpoint JSON") endpoint_apply.add_argument("-f", "--file", required=True, help="JSON file containing endpoint data") + add_common_arguments(endpoint_apply) endpoint_apply.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).apply_endpoint(args.file)) messagegroup_subparsers = manifest_subparsers.add_parser("messagegroup", help="Manage message groups").add_subparsers( dest="messagegroup_command", help="Message group commands") messagegroup_add = messagegroup_subparsers.add_parser("add", help="Add a new message group") - messagegroup_add.add_argument("--id", required=True, help="Message group ID") - messagegroup_add.add_argument("--format", choices=["CloudEvents", "None"], help="Message group format") + messagegroup_add.add_argument("--messagegroupid", required=True, help="Message group ID") + messagegroup_add.add_argument("--description", help="Message group description") + messagegroup_add.add_argument("--documentation", help="Message group documentation URL") + messagegroup_add.add_argument("--name", help="Message group name") + messagegroup_add.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message group labels (key=value pairs)") + messagegroup_add.add_argument("--envelope", choices=["CloudEvents/1.0", "None"], help="Message group envelope") messagegroup_add.add_argument("--protocol", help="protocol identifier") add_common_arguments(messagegroup_add) - messagegroup_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_messagegroup(args.id, args.format, args.documentation, args.description, args.labels, args.name, - args.protocol - )) - + messagegroup_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_messagegroup( + messagegroupid=args.messagegroupid, + envelope=args.envelope, + protocol=args.protocol, + documentation=args.documentation, + description=args.description, + labels=args.labels, + name=args.name + )) + messagegroup_remove = messagegroup_subparsers.add_parser("remove", help="Remove a message group") - messagegroup_remove.add_argument("--id", required=True, help="Message group ID") - messagegroup_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_messagegroup(args.id)) + messagegroup_remove.add_argument("--messagegroupid", required=True, help="Message group ID") + add_common_arguments(messagegroup_remove) + messagegroup_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_messagegroup(args.messagegroupid)) messagegroup_edit = messagegroup_subparsers.add_parser("edit", help="Edit a message group") - messagegroup_edit.add_argument("--id", required=True, help="Message group ID") - messagegroup_edit.add_argument("--format", choices=["CloudEvents", "None"], help="Message group format") + messagegroup_edit.add_argument("--messagegroupid", required=True, help="Message group ID") + messagegroup_edit.add_argument("--description", help="Message group description") + messagegroup_edit.add_argument("--documentation", help="Message group documentation URL") + messagegroup_edit.add_argument("--name", help="Message group name") + messagegroup_edit.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message group labels (key=value pairs)") + messagegroup_edit.add_argument("--envelope", choices=["CloudEvents/1.0", "None"], help="Message group envelope") messagegroup_edit.add_argument("--protocol", help="protocol identifier") add_common_arguments(messagegroup_edit) - messagegroup_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_messagegroup(args.id, args.format, args.documentation, args.description, args.labels, args.name, - args.protocol - )) + messagegroup_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_messagegroup( + messagegroupid=args.messagegroupid, + envelope=args.envelope, + protocol=args.protocol, + documentation=args.documentation, + description=args.description, + labels=args.labels, + name=args.name + )) messagegroup_show = messagegroup_subparsers.add_parser("show", help="Show a message group") - messagegroup_show.add_argument("--id", required=True, help="Message group ID") - messagegroup_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_messagegroup(args.id)) + messagegroup_show.add_argument("--messagegroupid", required=True, help="Message group ID") + add_common_arguments(messagegroup_show) + messagegroup_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_messagegroup(args.messagegroupid)) messagegroup_apply = messagegroup_subparsers.add_parser("apply", help="Apply a message group JSON") messagegroup_apply.add_argument("-f", "--file", required=True, help="JSON file containing message group data") + add_common_arguments(messagegroup_apply) messagegroup_apply.set_defaults(func=lambda args: CatalogSubcommands( args.catalog).apply_messagegroup(args.file)) @@ -1197,45 +1174,80 @@ def add_common_arguments(parser): "message", help="Manage messages").add_subparsers(dest="message_command", help="Message commands") message_add = message_subparsers.add_parser("add", help="Add a new message") - message_add.add_argument("--groupid", required=True, help="Message group ID") - message_add.add_argument("--id", required=True, help="Message ID") - message_add.add_argument("--format", choices=["CloudEvents", "None"], - help="Message format", default="CloudEvents") - message_add.add_argument("--protocol", choices=["AMQP", "MQTT", "NATS", - "HTTP", "Kafka", "None"], help="Message protocol", default="None") + message_add.add_argument("--messagegroupid", required=True, help="Message group ID") + message_add.add_argument("--messageid", required=True, help="Message ID") + message_add.add_argument("--description", help="Message description") + message_add.add_argument("--documentation", help="Message documentation URL") + message_add.add_argument("--name", help="Message name") + message_add.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message labels (key=value pairs)") + message_add.add_argument("--envelope", choices=["CloudEvents/1.0", "None"], + help="Message envelope", default="CloudEvents/1.0") + message_add.add_argument("--protocol", choices=["AMQP/1.0", "MQTT/3.1.1", "MQTT/5.0", "NATS", + "HTTP", "KAFKA", "None"], help="Message protocol", default="None") message_add.add_argument("--schemaformat", help="Schema format") message_add.add_argument("--schemagroup", help="Schema group ID") message_add.add_argument("--schemaid", help="Schema ID") message_add.add_argument("--schemaurl", help="Schema URL") add_common_arguments(message_add) - message_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_message(args.groupid, args.id, args.format, args.protocol, args.schemaformat, args.schemagroup, args.schemaid, - args.schemaurl, args.documentation, args.description, args.labels, args.name - )) - + message_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_message( + messagegroupid=args.messagegroupid, + messageid=args.messageid, + envelope=args.envelope, + protocol=args.protocol, + schemaformat=args.schemaformat, + schemagroup=args.schemagroup, + schemaid=args.schemaid, + schemaurl=args.schemaurl, + documentation=args.documentation, + description=args.description, + labels=args.labels, + name=args.name + )) + message_remove = message_subparsers.add_parser("remove", help="Remove a message") - message_remove.add_argument("--groupid", required=True, help="Message group ID") - message_remove.add_argument("--id", required=True, help="Message ID") - message_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_message(args.groupid, args.id)) + message_remove.add_argument("--messagegroupid", required=True, help="Message group ID") + message_remove.add_argument("--messageid", required=True, help="Message ID") + add_common_arguments(message_remove) + message_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_message(args.messagegroupid, args.messageid)) message_edit = message_subparsers.add_parser("edit", help="Edit a message") - message_edit.add_argument("--groupid", required=True, help="Message group ID") - message_edit.add_argument("--id", required=True, help="Message ID") - message_edit.add_argument("--format", choices=["CloudEvents", "None"], help="Message format") - message_edit.add_argument("--protocol", choices=["AMQP", "MQTT", - "NATS", "HTTP", "Kafka", "None"], help="Message protocol") + message_edit.add_argument("--messagegroupid", required=True, help="Message group ID") + message_edit.add_argument("--messageid", required=True, help="Message ID") + message_edit.add_argument("--description", help="Message description") + message_edit.add_argument("--documentation", help="Message documentation URL") + message_edit.add_argument("--name", help="Message name") + message_edit.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message labels (key=value pairs)") + message_edit.add_argument("--envelope", choices=["CloudEvents/1.0", "None"], help="Message envelope") + message_edit.add_argument("--protocol", choices=["AMQP/1.0", "MQTT/3.1.1", "MQTT/5.0", + "NATS", "HTTP", "KAFKA", "None"], help="Message protocol") message_edit.add_argument("--schemaformat", help="Schema format") message_edit.add_argument("--schemagroup", help="Schema group ID") message_edit.add_argument("--schemaid", help="Schema ID") message_edit.add_argument("--schemaurl", help="Schema URL") add_common_arguments(message_edit) - message_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message(args.groupid, args.id, args.format, args.protocol, args.schemaformat, args.schemagroup, args.schemaid, - args.schemaurl, args.documentation, args.description, args.labels, args.name)) + message_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( + messagegroupid=args.messagegroupid, + messageid=args.messageid, + envelope=args.envelope, + protocol=args.protocol, + schemaformat=args.schemaformat, + schemagroup=args.schemagroup, + schemaid=args.schemaid, + schemaurl=args.schemaurl, + documentation=args.documentation, + description=args.description, + labels=args.labels, + name=args.name)) message_cloudevent_subparsers = manifest_subparsers.add_parser( "cloudevent", help="Manage CloudEvents").add_subparsers(dest="cloudevents_command", help="CloudEvents commands") message_cloudevent_add = message_cloudevent_subparsers.add_parser("add", help="Add a new CloudEvent") - message_cloudevent_add.add_argument("--groupid", required=True, help="Message group ID") - message_cloudevent_add.add_argument("--id", required=True, help="Message ID and CloudEvents type") + message_cloudevent_add.add_argument("--messagegroupid", required=True, help="Message group ID") + message_cloudevent_add.add_argument("--messageid", required=True, help="Message ID and CloudEvents type") + message_cloudevent_add.add_argument("--description", help="Message description") + message_cloudevent_add.add_argument("--documentation", help="Message documentation URL") + message_cloudevent_add.add_argument("--name", help="Message name") + message_cloudevent_add.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message labels (key=value pairs)") message_cloudevent_add.add_argument("--schemaformat", help="Schema format") message_cloudevent_add.add_argument("--schemagroup", help="Schema group ID") message_cloudevent_add.add_argument("--schemaid", help="Schema ID") @@ -1245,40 +1257,44 @@ def add_common_arguments(parser): def _add_cloudevent(args): sc = CatalogSubcommands(args.catalog) sc.add_message( - args.groupid, args.id, "CloudEvents/1.0", "None", args.schemaformat, args.schemagroup, args.schemaid, + args.messagegroupid, args.messageid, "CloudEvents/1.0", "None", args.schemaformat, args.schemagroup, args.schemaid, args.schemaurl, args.documentation, args.description, args.labels, args.name) - sc.add_cloudevents_message_metadata(args.groupid, args.id, "specversion", + sc.add_cloudevents_message_metadata(args.messagegroupid, args.messageid, "specversion", "string", "CloudEvents version", "1.0", True) - sc.add_cloudevents_message_metadata(args.groupid, args.id, "type", "string", "Event type", args.id, True) - sc.add_cloudevents_message_metadata(args.groupid, args.id, "source", + sc.add_cloudevents_message_metadata(args.messagegroupid, args.messageid, "type", "string", "Event type", args.messageid, True) + sc.add_cloudevents_message_metadata(args.messagegroupid, args.messageid, "source", "string", "Event source", "{source}", True) return message_cloudevent_add.set_defaults(func=_add_cloudevent) message_cloudevent_edit = message_cloudevent_subparsers.add_parser("edit", help="Edit a CloudEvent") - message_cloudevent_edit.add_argument("--groupid", required=True, help="Message group ID") - message_cloudevent_edit.add_argument("--id", required=True, help="Message ID and CloudEvents type") + message_cloudevent_edit.add_argument("--messagegroupid", required=True, help="Message group ID") + message_cloudevent_edit.add_argument("--messageid", required=True, help="Message ID and CloudEvents type") + message_cloudevent_edit.add_argument("--description", help="Message description") + message_cloudevent_edit.add_argument("--documentation", help="Message documentation URL") + message_cloudevent_edit.add_argument("--name", help="Message name") + message_cloudevent_edit.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message labels (key=value pairs)") message_cloudevent_edit.add_argument("--schemaformat", help="Schema format") message_cloudevent_edit.add_argument("--schemagroup", help="Schema group ID") message_cloudevent_edit.add_argument("--schemaid", help="Schema ID") message_cloudevent_edit.add_argument("--schemaurl", help="Schema URL") add_common_arguments(message_cloudevent_edit) message_cloudevent_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( - args.groupid, args.id, "CloudEvents/1.0", "None", args.schemaformat, args.schemagroup, args.schemaid, + args.messagegroupid, args.messageid, "CloudEvents/1.0", "None", args.schemaformat, args.schemagroup, args.schemaid, args.schemaurl, args.documentation, args.description, args.labels, args.name)) message_cloudevent_remove = message_cloudevent_subparsers.add_parser("remove", help="Remove a CloudEvent") - message_cloudevent_remove.add_argument("--groupid", required=True, help="Message group ID", type=str) - message_cloudevent_remove.add_argument("--id", required=True, help="Message ID and CloudEvents type", type=str) - message_cloudevent_remove.add_argument("--epoch", required=True, type=int, help="Epoch number") - message_cloudevent_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_message(args.groupid, args.id)) + message_cloudevent_remove.add_argument("--messagegroupid", required=True, help="Message group ID", type=str) + message_cloudevent_remove.add_argument("--messageid", required=True, help="Message ID and CloudEvents type", type=str) + add_common_arguments(message_cloudevent_remove) + message_cloudevent_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_message(args.messagegroupid, args.messageid)) message_cloudevent_metadata_subparsers = message_cloudevent_subparsers.add_parser( "metadata", help="Manage message metadata").add_subparsers(dest="metadata_command", help="Metadata commands") message_cloudevent_metadata_add = message_cloudevent_metadata_subparsers.add_parser( "add", help="Add a new metadata field") - message_cloudevent_metadata_add.add_argument("--groupid", required=True, help="Message group ID") - message_cloudevent_metadata_add.add_argument("--id", required=True, help="Message ID") + message_cloudevent_metadata_add.add_argument("--messagegroupid", required=True, help="Message group ID") + message_cloudevent_metadata_add.add_argument("--messageid", required=True, help="Message ID") message_cloudevent_metadata_add.add_argument("--attribute", required=True, help="Attribute name") message_cloudevent_metadata_add.add_argument( "--type", choices=PROPERTY_TYPES, help="Metadata type", default="string") @@ -1286,72 +1302,104 @@ def _add_cloudevent(args): message_cloudevent_metadata_add.add_argument( "--value", help="Attribute value, may contain template expressions if the type is 'uritemplate'") message_cloudevent_metadata_add.add_argument("--required", type=bool, help="Metadata required status") + add_common_arguments(message_cloudevent_metadata_add) message_cloudevent_metadata_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_cloudevents_message_metadata( - args.groupid, args.id, args.attribute, args.type, args.description, args.value, args.required)) + args.messagegroupid, args.messageid, args.attribute, args.type, args.description, args.value, args.required)) message_cloudevent_metadata_edit = message_cloudevent_metadata_subparsers.add_parser( "edit", help="Edit a metadata field") - message_cloudevent_metadata_edit.add_argument("--groupid", required=True, help="Message group ID") - message_cloudevent_metadata_edit.add_argument("--id", required=True, help="Message ID") + message_cloudevent_metadata_edit.add_argument("--messagegroupid", required=True, help="Message group ID") + message_cloudevent_metadata_edit.add_argument("--messageid", required=True, help="Message ID") message_cloudevent_metadata_edit.add_argument("--attribute", required=True, help="Attribute name") message_cloudevent_metadata_edit.add_argument("--type", choices=PROPERTY_TYPES, help="Attribute type") message_cloudevent_metadata_edit.add_argument("--description", help="Attribute description") message_cloudevent_metadata_edit.add_argument( "--value", help="Attribute value, may contain template expressions if the type is 'uritemplate'") message_cloudevent_metadata_edit.add_argument("--required", type=bool, help="Metadata required status") + add_common_arguments(message_cloudevent_metadata_edit) message_cloudevent_metadata_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_cloudevents_message_metadata( - args.groupid, args.id, args.attribute, args.type, args.description, args.value, args.required)) + args.messagegroupid, args.messageid, args.attribute, args.type, args.description, args.value, args.required)) message_cloudevent_metadata_remove = message_cloudevent_metadata_subparsers.add_parser( "remove", help="Remove a metadata field") - message_cloudevent_metadata_remove.add_argument("--groupid", required=True, help="Message group ID") - message_cloudevent_metadata_remove.add_argument("--id", required=True, help="Message ID") + message_cloudevent_metadata_remove.add_argument("--messagegroupid", required=True, help="Message group ID") + message_cloudevent_metadata_remove.add_argument("--messageid", required=True, help="Message ID") message_cloudevent_metadata_remove.add_argument("--attribute", required=True, help="CloudEvents attribute") + add_common_arguments(message_cloudevent_metadata_remove) message_cloudevent_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands( - args.catalog).remove_cloudevents_message_metadata(args.groupid, args.id, args.key)) + args.catalog).remove_cloudevents_message_metadata(args.messagegroupid, args.messageid, args.key)) message_amqp_subparsers = manifest_subparsers.add_parser( - "amqp", help="Manage AMQP").add_subparsers(dest="amqp_command", help="AMQP commands") + "AMQP/1.0", help="Manage AMQP").add_subparsers(dest="amqp_command", help="AMQP commands") message_amqp_metadata_subparsers = message_amqp_subparsers.add_parser( "metadata", help="Manage message metadata").add_subparsers(dest="metadata_command", help="Metadata commands") def _add_amqp_message(args): sc = CatalogSubcommands(args.catalog) - sc.add_message(args.groupid, args.id, "None", "AMQP/1.0", args.schemaformat, args.schemagroup, + sc.add_message(args.messagegroupid, args.messageid, "None", "AMQP/1.0", args.schemaformat, args.schemagroup, args.schemaid, args.schemaurl, args.documentation, args.description, args.labels, args.name) - sc.add_amqp_message_metadata(args.groupid, args.id, "properties", - "subject", "string", None, "Subject", True) + sc.add_amqp_message_metadata( + messagegroupid=args.messagegroupid, + messageid=args.messageid, + section="properties", + name="subject", + type="string", + value=None, + description="Subject", + required=True + ) message_amqp_add = message_amqp_subparsers.add_parser("add", help="Add a new message") - message_amqp_add.add_argument("--groupid", required=True, help="Message group ID") - message_amqp_add.add_argument("--id", required=True, help="Message ID") + message_amqp_add.add_argument("--messagegroupid", required=True, help="Message group ID") + message_amqp_add.add_argument("--messageid", required=True, help="Message ID") + message_amqp_add.add_argument("--description", help="Message description") + message_amqp_add.add_argument("--documentation", help="Message documentation URL") + message_amqp_add.add_argument("--name", help="Message name") + message_amqp_add.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message labels (key=value pairs)") message_amqp_add.add_argument("--schemaformat", help="Schema format") message_amqp_add.add_argument("--schemagroup", help="Schema group ID") message_amqp_add.add_argument("--schemaid", help="Schema ID") message_amqp_add.add_argument("--schemaurl", help="Schema URL") + add_common_arguments(message_amqp_add) message_amqp_add.set_defaults(func=_add_amqp_message) message_amqp_edit = message_amqp_subparsers.add_parser("edit", help="Edit a message") - message_amqp_edit.add_argument("--groupid", required=True, help="Message group ID") - message_amqp_edit.add_argument("--id", required=True, help="Message ID") + message_amqp_edit.add_argument("--messagegroupid", required=True, help="Message group ID") + message_amqp_edit.add_argument("--messageid", required=True, help="Message ID") + message_amqp_edit.add_argument("--description", help="Message description") + message_amqp_edit.add_argument("--documentation", help="Message documentation URL") + message_amqp_edit.add_argument("--name", help="Message name") + message_amqp_edit.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message labels (key=value pairs)") message_amqp_edit.add_argument("--schemaformat", help="Schema format") message_amqp_edit.add_argument("--schemagroup", help="Schema group ID") message_amqp_edit.add_argument("--schemaid", help="Schema ID") message_amqp_edit.add_argument("--schemaurl", help="Schema URL") add_common_arguments(message_amqp_edit) message_amqp_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( - args.groupid, args.id, "None", "AMQP/1.0", args.schemaformat, args.schemagroup, args.schemaid, - args.schemaurl, args.documentation, args.description, args.labels, args.name)) + groupid=args.messagegroupid, + messageid=args.messageid, + envelope="None", + protocol="AMQP/1.0", + schemaformat=args.schemaformat, + schemagroup=args.schemagroup, + schemaid=args.schemaid, + schemaurl=args.schemaurl, + documentation=args.documentation, + description=args.description, + labels=args.labels, + name=args.name + )) message_amqp_remove = message_amqp_subparsers.add_parser("remove", help="Remove a message") - message_amqp_remove.add_argument("--groupid", required=True, help="Message group ID") - message_amqp_remove.add_argument("--id", required=True, help="Message ID") + message_amqp_remove.add_argument("--messagegroupid", required=True, help="Message group ID") + message_amqp_remove.add_argument("--messageid", required=True, help="Message ID") + add_common_arguments(message_amqp_remove) message_amqp_remove.set_defaults(func=lambda args: CatalogSubcommands( - args.catalog).remove_message(args.groupid, args.id)) + args.catalog).remove_message(args.messagegroupid, args.messageid)) message_amqp_metadata_add = message_amqp_metadata_subparsers.add_parser("add", help="Add a new metadata field") - message_amqp_metadata_add.add_argument("--groupid", required=True, help="Message group ID") - message_amqp_metadata_add.add_argument("--id", required=True, help="Message ID") + message_amqp_metadata_add.add_argument("--messagegroupid", required=True, help="Message group ID") + message_amqp_metadata_add.add_argument("--messageid", required=True, help="Message ID") message_amqp_metadata_add.add_argument("--section", required=True, choices=[ "properties", "application-properties"], help="Metadata section") message_amqp_metadata_add.add_argument("--name", required=True, help="Metadata name") @@ -1359,12 +1407,13 @@ def _add_amqp_message(args): message_amqp_metadata_add.add_argument("--value", required=False, help="Metadata value") message_amqp_metadata_add.add_argument("--description", help="Metadata description") message_amqp_metadata_add.add_argument("--required", type=bool, help="Metadata required status") + add_common_arguments(message_amqp_metadata_add) message_amqp_metadata_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_amqp_message_metadata( - args.groupid, args.id, args.section, args.name, args.type, args.value, args.description, args.required)) + messagegroupid=args.messagegroupid, messageid=args.messageid, section=args.section, name=args.name, type=args.type, value=args.value, description=args.description, required=args.required)) message_amqp_metadata_edit = message_amqp_metadata_subparsers.add_parser("edit", help="Edit a metadata field") - message_amqp_metadata_edit.add_argument("--groupid", required=True, help="Message group ID") - message_amqp_metadata_edit.add_argument("--id", required=True, help="Message ID") + message_amqp_metadata_edit.add_argument("--messagegroupid", required=True, help="Message group ID") + message_amqp_metadata_edit.add_argument("--messageid", required=True, help="Message ID") message_amqp_metadata_edit.add_argument("--section", required=True, choices=[ "properties", "application-properties"], help="Metadata section") message_amqp_metadata_edit.add_argument("--name", help="Metadata name") @@ -1372,35 +1421,40 @@ def _add_amqp_message(args): message_amqp_metadata_edit.add_argument("--value", required=False, help="Metadata value") message_amqp_metadata_edit.add_argument("--description", help="Metadata description") message_amqp_metadata_edit.add_argument("--required", type=bool, help="Metadata required status") + add_common_arguments(message_amqp_metadata_edit) message_amqp_metadata_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_amqp_message_metadata( - args.groupid, args.id, args.section, args.name, args.type, args.value, args.description, args.required)) + args.messagegroupid, args.messageid, args.section, args.name, args.type, args.value, args.description, args.required)) message_amqp_metadata_remove = message_amqp_metadata_subparsers.add_parser( "remove", help="Remove a metadata field") - message_amqp_metadata_remove.add_argument("--groupid", required=True, help="Message group ID") - message_amqp_metadata_remove.add_argument("--id", required=True, help="Message ID") + message_amqp_metadata_remove.add_argument("--messagegroupid", required=True, help="Message group ID") + message_amqp_metadata_remove.add_argument("--messageid", required=True, help="Message ID") message_amqp_metadata_remove.add_argument("--section", required=True, choices=[ "properties", "application-properties"], help="Metadata section") message_amqp_metadata_remove.add_argument("--name", required=True, help="Metadata name") + add_common_arguments(message_amqp_metadata_remove) message_amqp_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands( - args.catalog).remove_amqp_message_metadata(args.groupid, args.id, args.name, args.section)) + args.catalog).remove_amqp_message_metadata(args.messagegroupid, args.messageid, args.name, args.section)) - message_mqtt_subparsers = manifest_subparsers.add_parser( - "mqtt", help="Manage MQTT").add_subparsers(dest="mqtt_command", help="MQTT commands") + message_mqtt_subparsers = manifest_subparsers.add_parser("mqtt", help="Manage MQTT").add_subparsers(dest="mqtt_command", help="MQTT commands") message_mqtt_metadata_subparsers = message_mqtt_subparsers.add_parser( "metadata", help="Manage message metadata").add_subparsers(dest="metadata_command", help="Metadata commands") def _add_mqtt_message(args): sc = CatalogSubcommands(args.catalog) sc.add_message( - args.groupid, args.id, "None", "MQTT/" + args.mqtt_version, args.schemaformat, args.schemagroup, args.schemaid, + args.messagegroupid, args.messageid, "None", "MQTT/" + args.mqtt_version, args.schemaformat, args.schemagroup, args.schemaid, args.schemaurl, args.documentation, args.description, args.labels, args.name) - sc.add_mqtt_message_metadata(args.groupid, args.id, args.mqtt_version, "topic", - "string", "{topic}/"+args.id, "MQTT topic", True) + sc.add_mqtt_message_metadata(args.messagegroupid, args.messageid, args.mqtt_version, "topic", + "string", "{topic}/"+args.messageid, "MQTT topic", True) message_mqtt_add = message_mqtt_subparsers.add_parser("add", help="Add a new message") - message_mqtt_add.add_argument("--groupid", required=True, help="Message group ID") - message_mqtt_add.add_argument("--id", required=True, help="Message ID") + message_mqtt_add.add_argument("--messagegroupid", required=True, help="Message group ID") + message_mqtt_add.add_argument("--messageid", required=True, help="Message ID") + message_mqtt_add.add_argument("--description", help="Message description") + message_mqtt_add.add_argument("--documentation", help="Message documentation URL") + message_mqtt_add.add_argument("--name", help="Message name") + message_mqtt_add.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message labels (key=value pairs)") message_mqtt_add.add_argument("--mqtt_version", required=True, choices=["3", "5", "3.1.1", "5.0"], help="MQTT version") message_mqtt_add.add_argument("--schemaformat", help="Schema format") @@ -1411,26 +1465,31 @@ def _add_mqtt_message(args): message_mqtt_add.set_defaults(func=_add_amqp_message) message_mqtt_edit = message_mqtt_subparsers.add_parser("edit", help="Edit a message") - message_mqtt_edit.add_argument("--groupid", required=True, help="Message group ID") - message_mqtt_edit.add_argument("--id", required=True, help="Message ID") + message_mqtt_edit.add_argument("--messagegroupid", required=True, help="Message group ID") + message_mqtt_edit.add_argument("--messageid", required=True, help="Message ID") + message_mqtt_edit.add_argument("--description", help="Message description") + message_mqtt_edit.add_argument("--documentation", help="Message documentation URL") + message_mqtt_edit.add_argument("--name", help="Message name") + message_mqtt_edit.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message labels (key=value pairs)") message_mqtt_edit.add_argument("--schemaformat", help="Schema format") message_mqtt_edit.add_argument("--schemagroup", help="Schema group ID") message_mqtt_edit.add_argument("--schemaid", help="Schema ID") message_mqtt_edit.add_argument("--schemaurl", help="Schema URL") add_common_arguments(message_mqtt_edit) message_mqtt_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( - args.groupid, args.id, "None", "MQTT/" + args.mqtt_version, args.schemaformat, args.schemagroup, args.schemaid, + args.messagegroupid, args.messageid, "None", "MQTT/" + args.mqtt_version, args.schemaformat, args.schemagroup, args.schemaid, args.schemaurl, args.documentation, args.description, args.labels, args.name)) message_mqtt_remove = message_mqtt_subparsers.add_parser("remove", help="Remove a message") - message_mqtt_remove.add_argument("--groupid", required=True, help="Message group ID") - message_mqtt_remove.add_argument("--id", required=True, help="Message ID") + message_mqtt_remove.add_argument("--messagegroupid", required=True, help="Message group ID") + message_mqtt_remove.add_argument("--messageid", required=True, help="Message ID") + add_common_arguments(message_mqtt_remove) message_mqtt_remove.set_defaults(func=lambda args: CatalogSubcommands( - args.catalog).remove_message(args.groupid, args.id)) + args.catalog).remove_message(args.messagegroupid, args.messageid)) message_mqtt_metadata_add = message_mqtt_metadata_subparsers.add_parser("add", help="Add a new metadata field") - message_mqtt_metadata_add.add_argument("--groupid", required=True, help="Message group ID") - message_mqtt_metadata_add.add_argument("--id", required=True, help="Message ID") + message_mqtt_metadata_add.add_argument("--messagegroupid", required=True, help="Message group ID") + message_mqtt_metadata_add.add_argument("--messageid", required=True, help="Message ID") message_mqtt_metadata_add.add_argument("--mqtt_version", required=True, choices=["3", "5", "3.1.1", "5.0"], help="MQTT version") message_mqtt_metadata_add.add_argument("--name", required=True, help="Metadata name") @@ -1438,12 +1497,13 @@ def _add_mqtt_message(args): message_mqtt_metadata_add.add_argument("--value", required=True, help="Metadata value") message_mqtt_metadata_add.add_argument("--description", help="Metadata description") message_mqtt_metadata_add.add_argument("--required", type=bool, help="Metadata required status") + add_common_arguments(message_mqtt_metadata_add) message_mqtt_metadata_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_mqtt_message_metadata( - args.groupid, args.id, args.mqtt_version, args.name, args.type, args.value, args.description, args.required)) + args.messagegroupid, args.messageid, args.mqtt_version, args.name, args.type, args.value, args.description, args.required)) message_mqtt_metadata_edit = message_mqtt_metadata_subparsers.add_parser("edit", help="Edit a metadata field") - message_mqtt_metadata_edit.add_argument("--groupid", required=True, help="Message group ID") - message_mqtt_metadata_edit.add_argument("--id", required=True, help="Message ID") + message_mqtt_metadata_edit.add_argument("--messagegroupid", required=True, help="Message group ID") + message_mqtt_metadata_edit.add_argument("--messageid", required=True, help="Message ID") message_mqtt_metadata_edit.add_argument("--mqtt_version", required=True, choices=["3", "5", "3.1.1", "5.0"], help="MQTT version") message_mqtt_metadata_edit.add_argument("--name", help="Metadata name") @@ -1451,34 +1511,40 @@ def _add_mqtt_message(args): message_mqtt_metadata_edit.add_argument("--value", help="Metadata value") message_mqtt_metadata_edit.add_argument("--description", help="Metadata description") message_mqtt_metadata_edit.add_argument("--required", type=bool, help="Metadata required status") + add_common_arguments(message_mqtt_metadata_edit) message_mqtt_metadata_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_mqtt_message_metadata( - args.groupid, args.id, args.name, args.type, args.value, args.description, args.required)) + args.messagegroupid, args.messageid, args.name, args.type, args.value, args.description, args.required)) message_mqtt_metadata_remove = message_mqtt_metadata_subparsers.add_parser( "remove", help="Remove a metadata field") - message_mqtt_metadata_remove.add_argument("--groupid", required=True, help="Message group ID") - message_mqtt_metadata_remove.add_argument("--id", required=True, help="Message ID") + message_mqtt_metadata_remove.add_argument("--messagegroupid", required=True, help="Message group ID") + message_mqtt_metadata_remove.add_argument("--messageid", required=True, help="Message ID") message_mqtt_metadata_remove.add_argument("--section", required=False, choices=["properties", "topic"], help="Metadata section") message_mqtt_metadata_remove.add_argument("--name", required=True, help="Metadata name") + add_common_arguments(message_mqtt_metadata_remove) message_mqtt_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands( - args.catalog).remove_mqtt_message_metadata(args.groupid, args.id, args.section, args.name)) + args.catalog).remove_mqtt_message_metadata(args.messagegroupid, args.messageid, args.section, args.name)) message_kafka_subparsers = manifest_subparsers.add_parser( - "kafka", help="Manage Kafka").add_subparsers(dest="kafka_command", help="Kafka commands") + "KAFKA", help="Manage Kafka").add_subparsers(dest="kafka_command", help="Kafka commands") message_kafka_metadata_subparsers = message_kafka_subparsers.add_parser( "metadata", help="Manage message metadata").add_subparsers(dest="metadata_command", help="Metadata commands") def _add_kafka_message(args): sc = CatalogSubcommands(args.catalog) - sc.add_message(args.groupid, args.id, "None", "Kafka", args.schemaformat, args.schemagroup, args.schemaid, + sc.add_message(args.messagegroupid, args.messageid, "None", "KAFKA", args.schemaformat, args.schemagroup, args.schemaid, args.schemaurl, args.documentation, args.description, args.labels, args.name) - sc.add_kafka_message_metadata(args.groupid, args.id, "headers", "message_type", - "string", args.id, "Message ID", True) - sc.add_kafka_message_metadata(args.groupid, args.id, None, "key", "string", "{key}", "Message key", False) + sc.add_kafka_message_metadata(args.messagegroupid, args.messageid, "headers", "message_type", + "string", args.messageid, "Message ID", True) + sc.add_kafka_message_metadata(args.messagegroupid, args.messageid, None, "key", "string", "{key}", "Message key", False) message_kafka_add = message_kafka_subparsers.add_parser("add", help="Add a new message") - message_kafka_add.add_argument("--groupid", required=True, help="Message group ID") - message_kafka_add.add_argument("--id", required=True, help="Message ID") + message_kafka_add.add_argument("--messagegroupid", required=True, help="Message group ID") + message_kafka_add.add_argument("--messageid", required=True, help="Message ID") + message_kafka_add.add_argument("--description", help="Message description") + message_kafka_add.add_argument("--documentation", help="Message documentation URL") + message_kafka_add.add_argument("--name", help="Message name") + message_kafka_add.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message labels (key=value pairs)") message_kafka_add.add_argument("--schemaformat", help="Schema format") message_kafka_add.add_argument("--schemagroup", help="Schema group ID") message_kafka_add.add_argument("--schemaid", help="Schema ID") @@ -1487,57 +1553,65 @@ def _add_kafka_message(args): message_kafka_add.set_defaults(func=_add_kafka_message) message_kafka_edit = message_kafka_subparsers.add_parser("edit", help="Edit a message") - message_kafka_edit.add_argument("--groupid", required=True, help="Message group ID") - message_kafka_edit.add_argument("--id", required=True, help="Message ID") + message_kafka_edit.add_argument("--messagegroupid", required=True, help="Message group ID") + message_kafka_edit.add_argument("--messageid", required=True, help="Message ID") + message_kafka_edit.add_argument("--description", help="Message description") + message_kafka_edit.add_argument("--documentation", help="Message documentation URL") + message_kafka_edit.add_argument("--name", help="Message name") + message_kafka_edit.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message labels (key=value pairs)") message_kafka_edit.add_argument("--schemaformat", help="Schema format") message_kafka_edit.add_argument("--schemagroup", help="Schema group ID") message_kafka_edit.add_argument("--schemaid", help="Schema ID") message_kafka_edit.add_argument("--schemaurl", help="Schema URL") add_common_arguments(message_kafka_edit) message_kafka_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( - args.groupid, args.id, "None", "Kafka", args.schemaformat, args.schemagroup, args.schemaid, + args.messagegroupid, args.messageid, "None", "KAFKA", args.schemaformat, args.schemagroup, args.schemaid, args.schemaurl, args.documentation, args.description, args.labels, args.name)) message_kafka_remove = message_kafka_subparsers.add_parser("remove", help="Remove a message") - message_kafka_remove.add_argument("--groupid", required=True, help="Message group ID") - message_kafka_remove.add_argument("--id", required=True, help="Message ID") + message_kafka_remove.add_argument("--messagegroupid", required=True, help="Message group ID") + message_kafka_remove.add_argument("--messageid", required=True, help="Message ID") + add_common_arguments(message_kafka_remove) message_kafka_remove.set_defaults(func=lambda args: CatalogSubcommands( - args.catalog).remove_message(args.groupid, args.id)) + args.catalog).remove_message(args.messagegroupid, args.messageid)) message_kafka_metadata_add = message_kafka_metadata_subparsers.add_parser( "add", help="Add a new metadata field") - message_kafka_metadata_add.add_argument("--groupid", required=True, help="Message group ID") - message_kafka_metadata_add.add_argument("--id", required=True, help="Message ID") + message_kafka_metadata_add.add_argument("--messagegroupid", required=True, help="Message group ID") + message_kafka_metadata_add.add_argument("--messageid", required=True, help="Message ID") message_kafka_metadata_add.add_argument("--section", required=True, choices=["headers"], help="Metadata section") message_kafka_metadata_add.add_argument("--name", required=True, help="Metadata name") message_kafka_metadata_add.add_argument("--type", required=True, choices=PROPERTY_TYPES, help="Metadata type") message_kafka_metadata_add.add_argument("--value", required=True, help="Metadata value") message_kafka_metadata_add.add_argument("--description", help="Metadata description") message_kafka_metadata_add.add_argument("--required", type=bool, help="Metadata required status") + add_common_arguments(message_kafka_metadata_add) message_kafka_metadata_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_kafka_message_metadata( - args.groupid, args.id, args.section, args.name, args.type, args.value, args.description, args.required)) + args.messagegroupid, args.messageid, args.section, args.name, args.type, args.value, args.description, args.required)) message_kafka_metadata_edit = message_kafka_metadata_subparsers.add_parser("edit", help="Edit a metadata field") - message_kafka_metadata_edit.add_argument("--groupid", required=True, help="Message group ID") - message_kafka_metadata_edit.add_argument("--id", required=True, help="Message ID") + message_kafka_metadata_edit.add_argument("--messagegroupid", required=True, help="Message group ID") + message_kafka_metadata_edit.add_argument("--messageid", required=True, help="Message ID") message_kafka_metadata_edit.add_argument("--section", required=True, choices=["headers"], help="Metadata section") message_kafka_metadata_edit.add_argument("--name", help="Metadata name") message_kafka_metadata_edit.add_argument("--type", choices=PROPERTY_TYPES, help="Metadata type") message_kafka_metadata_edit.add_argument("--value", help="Metadata value") message_kafka_metadata_edit.add_argument("--description", help="Metadata description") message_kafka_metadata_edit.add_argument("--required", type=bool, help="Metadata required status") + add_common_arguments(message_kafka_metadata_edit) message_kafka_metadata_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_kafka_message_metadata( - args.groupid, args.id, args.section, args.name, args.type, args.value, args.description, args.required)) + args.messagegroupid, args.messageid, args.section, args.name, args.type, args.value, args.description, args.required)) message_kafka_metadata_remove = message_kafka_metadata_subparsers.add_parser( "remove", help="Remove a metadata field") - message_kafka_metadata_remove.add_argument("--groupid", required=True, help="Message group ID") - message_kafka_metadata_remove.add_argument("--id", required=True, help="Message ID") + message_kafka_metadata_remove.add_argument("--messagegroupid", required=True, help="Message group ID") + message_kafka_metadata_remove.add_argument("--messageid", required=True, help="Message ID") message_kafka_metadata_remove.add_argument("--name", required=True, help="Metadata name") message_kafka_metadata_remove.add_argument( "--section", required=True, choices=["headers"], help="Metadata section") + add_common_arguments(message_kafka_metadata_remove) message_kafka_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands( - args.catalog).remove_kafka_message_metadata(args.groupid, args.id, args.section, args.name)) + args.catalog).remove_kafka_message_metadata(args.messagegroupid, args.messageid, args.section, args.name)) message_http_subparsers = manifest_subparsers.add_parser( "http", help="Manage HTTP").add_subparsers(dest="http_command", help="HTTP commands") @@ -1546,15 +1620,48 @@ def _add_kafka_message(args): def _add_http_message(args): sc = CatalogSubcommands(args.catalog) - sc.add_message(args.groupid, args.id, "None", "HTTP", args.schemaformat, args.schemagroup, args.schemaid, - args.schemaurl, args.documentation, args.description, args.labels, args.name) - sc.add_http_message_metadata(args.groupid, args.id, "headers", "content-type", - "string", "application/json", "Content type", True) - sc.add_http_message_metadata(args.groupid, args.id, None, "method", "string", "POST", "HTTP method", True) + sc.add_message( + messagegroupid=args.messagegroupid, + messageid=args.messageid, + envelope="None", + protocol="HTTP", + schemaformat=args.schemaformat, + schemagroup=args.schemagroup, + schemaid=args.schemaid, + schemaurl=args.schemaurl, + documentation=args.documentation, + description=args.description, + labels=args.labels, + name=args.name + ) + sc.add_http_message_metadata( + groupid=args.messagegroupid, + messageid=args.messageid, + section="headers", + name="content-type", + type="string", + value="application/json", + description="Content type", + required=True + ) + sc.add_http_message_metadata( + groupid=args.messagegroupid, + messageid=args.messageid, + section=None, + name="method", + type="string", + value="POST", + description="HTTP method", + required=True + ) message_http_add = message_http_subparsers.add_parser("add", help="Add a new message") - message_http_add.add_argument("--groupid", required=True, help="Message group ID") - message_http_add.add_argument("--id", required=True, help="Message ID") + message_http_add.add_argument("--messagegroupid", required=True, help="Message group ID") + message_http_add.add_argument("--messageid", required=True, help="Message ID") + message_http_add.add_argument("--description", help="Message description") + message_http_add.add_argument("--documentation", help="Message documentation URL") + message_http_add.add_argument("--name", help="Message name") + message_http_add.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message labels (key=value pairs)") message_http_add.add_argument("--schemaformat", help="Schema format") message_http_add.add_argument("--schemagroup", help="Schema group ID") message_http_add.add_argument("--schemaid", help="Schema ID") @@ -1563,26 +1670,42 @@ def _add_http_message(args): message_http_add.set_defaults(func=_add_http_message) message_http_edit = message_http_subparsers.add_parser("edit", help="Edit a message") - message_http_edit.add_argument("--groupid", required=True, help="Message group ID") - message_http_edit.add_argument("--id", required=True, help="Message ID") + message_http_edit.add_argument("--messagegroupid", required=True, help="Message group ID") + message_http_edit.add_argument("--messageid", required=True, help="Message ID") + message_http_edit.add_argument("--description", help="Message description") + message_http_edit.add_argument("--documentation", help="Message documentation URL") + message_http_edit.add_argument("--name", help="Message name") + message_http_edit.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message labels (key=value pairs)") message_http_edit.add_argument("--schemaformat", help="Schema format") message_http_edit.add_argument("--schemagroup", help="Schema group ID") message_http_edit.add_argument("--schemaid", help="Schema ID") message_http_edit.add_argument("--schemaurl", help="Schema URL") add_common_arguments(message_http_edit) message_http_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( - args.groupid, args.id, "None", "HTTP", args.schemaformat, args.schemagroup, args.schemaid, - args.schemaurl, args.documentation, args.description, args.labels, args.name)) + messagegroupid=args.messagegroupid, + messageid=args.messageid, + envelope="None", + protocol="HTTP", + schemaformat=args.schemaformat, + schemagroup=args.schemagroup, + schemaid=args.schemaid, + schemaurl=args.schemaurl, + documentation=args.documentation, + description=args.description, + labels=args.labels, + name=args.name + )) message_http_remove = message_http_subparsers.add_parser("remove", help="Remove a message") - message_http_remove.add_argument("--groupid", required=True, help="Message group ID") - message_http_remove.add_argument("--id", required=True, help="Message ID") + message_http_remove.add_argument("--messagegroupid", required=True, help="Message group ID") + message_http_remove.add_argument("--messageid", required=True, help="Message ID") + add_common_arguments(message_http_remove) message_http_remove.set_defaults(func=lambda args: CatalogSubcommands( - args.catalog).remove_message(args.groupid, args.id)) + args.catalog).remove_message(args.messagegroupid, args.messageid)) message_http_metadata_add = message_http_metadata_subparsers.add_parser("add", help="Add a new metadata field") - message_http_metadata_add.add_argument("--groupid", required=True, help="Message group ID") - message_http_metadata_add.add_argument("--id", required=True, help="Message ID") + message_http_metadata_add.add_argument("--messagegroupid", required=True, help="Message group ID") + message_http_metadata_add.add_argument("--messageid", required=True, help="Message ID") message_http_metadata_add.add_argument("--key", required=True, help="Metadata key") message_http_metadata_add.add_argument("--section", required=False, choices=["headers", "query"], help="Metadata section") @@ -1591,12 +1714,21 @@ def _add_http_message(args): message_http_metadata_add.add_argument("--value", required=True, help="Metadata value") message_http_metadata_add.add_argument("--description", help="Metadata description") message_http_metadata_add.add_argument("--required", type=bool, help="Metadata required status") + add_common_arguments(message_http_metadata_add) message_http_metadata_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_http_message_metadata( - args.groupid, args.id, args.section, args.name, args.type, args.value, args.description, args.required)) + groupid=args.messagegroupid, + messageid=args.messageid, + section=args.section, + name=args.name, + type=args.type, + value=args.value, + description=args.description, + required=args.required + )) message_http_metadata_edit = message_http_metadata_subparsers.add_parser("edit", help="Edit a metadata field") - message_http_metadata_edit.add_argument("--groupid", required=True, help="Message group ID") - message_http_metadata_edit.add_argument("--id", required=True, help="Message ID") + message_http_metadata_edit.add_argument("--messagegroupid", required=True, help="Message group ID") + message_http_metadata_edit.add_argument("--messageid", required=True, help="Message ID") message_http_metadata_edit.add_argument("--key", required=True, help="Metadata key") message_http_metadata_edit.add_argument("--section", required=False, choices=["headers", "query"], help="Metadata section") @@ -1605,50 +1737,81 @@ def _add_http_message(args): message_http_metadata_edit.add_argument("--value", help="Metadata value") message_http_metadata_edit.add_argument("--description", help="Metadata description") message_http_metadata_edit.add_argument("--required", type=bool, help="Metadata required status") + add_common_arguments(message_http_metadata_edit) message_http_metadata_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_http_message_metadata( - args.groupid, args.id, args.section, args.name, args.type, args.value, args.description, args.required)) + groupid=args.messagegroupid, + messageid=args.messageid, + section=args.section, + name=args.name, + type=args.type, + value=args.value, + description=args.description, + required=args.required + )) message_http_metadata_remove = message_http_metadata_subparsers.add_parser( "remove", help="Remove a metadata field") - message_http_metadata_remove.add_argument("--groupid", required=True, help="Message group ID") - message_http_metadata_remove.add_argument("--id", required=True, help="Message ID") + message_http_metadata_remove.add_argument("--messagegroupid", required=True, help="Message group ID") + message_http_metadata_remove.add_argument("--messageid", required=True, help="Message ID") message_http_metadata_remove.add_argument("--name", required=True, help="Metadata key") message_http_metadata_remove.add_argument( "--section", required=False, choices=["headers", "query"], help="Metadata section") - message_http_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands( - args.catalog).remove_http_message_metadata(args.groupid, args.id, args.section, args.name)) + add_common_arguments(message_http_metadata_remove) + message_http_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_http_message_metadata( + messagegroupid=args.messagegroupid, + messageid=args.messageid, + section=args.section, + name=args.name + )) message_show = message_subparsers.add_parser("show", help="Show a message") - message_show.add_argument("--groupid", required=True, help="Message group ID") - message_show.add_argument("--id", required=True, help="Message ID") + message_show.add_argument("--messagegroupid", required=True, help="Message group ID") + message_show.add_argument("--messageid", required=True, help="Message ID") + + add_common_arguments(message_show) message_show.set_defaults(func=lambda args: CatalogSubcommands( - args.catalog).show_message(args.groupid, args.id)) + args.catalog).show_message(args.messagegroupid, args.messageid)) schemagroup_subparsers = manifest_subparsers.add_parser("schemagroup", help="Manage schema groups").add_subparsers( dest="schemagroup_command", help="Schema group commands") schemagroup_add = schemagroup_subparsers.add_parser("add", help="Add a new schema group") - schemagroup_add.add_argument("--id", required=True, help="Schema group ID") + schemagroup_add.add_argument("--schemagroupid", required=True, help="Schema group ID") add_common_arguments(schemagroup_add) schemagroup_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_schemagroup( - args.id, args.documentation, args.description, args.labels, args.name)) + schemagroupid=args.schemagroupid, + description=args.description, + documentation=args.documentation, + format=args.format, + labels=args.labels, + name=args.name, + schemas=args.schemas)) schemagroup_remove = schemagroup_subparsers.add_parser("remove", help="Remove a schema group") - schemagroup_remove.add_argument("--id", required=True, help="Schema group ID") + schemagroup_remove.add_argument("--schemagroupid", required=True, help="Schema group ID") + add_common_arguments(schemagroup_remove) schemagroup_remove.set_defaults(func=lambda args: CatalogSubcommands( - args.catalog).remove_schemagroup(args.id)) + args.catalog).remove_schemagroup(args.schemagroupid)) schemagroup_edit = schemagroup_subparsers.add_parser("edit", help="Edit a schema group") - schemagroup_edit.add_argument("--id", required=True, help="Schema group ID") + schemagroup_edit.add_argument("--schemagroupid", required=True, help="Schema group ID") add_common_arguments(schemagroup_edit) - schemagroup_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_schemagroup(args.id, args.documentation, args.description, args.labels, args.name )) + schemagroup_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_schemagroup( + schemagroupid=args.schemagroupid, + documentation=args.documentation, + description=args.description, + labels=args.labels, + name=args.name + )) schemagroup_show = schemagroup_subparsers.add_parser("show", help="Show a schema group") - schemagroup_show.add_argument("--id", required=True, help="Schema group ID") - schemagroup_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_schemagroup(args.id)) + schemagroup_show.add_argument("--schemagroupid", required=True, help="Schema group ID") + add_common_arguments(schemagroup_show) + schemagroup_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_schemagroup(args.schemagroupid)) schemagroup_apply = schemagroup_subparsers.add_parser("apply", help="Apply a schema group JSON") schemagroup_apply.add_argument("-f", "--file", required=True, help="JSON file containing schema group data") + add_common_arguments(schemagroup_apply) schemagroup_apply.set_defaults(func=lambda args: CatalogSubcommands( args.catalog).apply_schemagroup(args.file)) @@ -1656,43 +1819,80 @@ def _add_http_message(args): "schemaversion", help="Manage schema versions").add_subparsers(dest="schema_command", help="Schema commands") schema_add = schema_subparsers.add_parser("add", help="Add a new schema version") - schema_add.add_argument("--groupid", required=True, help="Schema group ID") - schema_add.add_argument("--id", required=True, help="Schema ID") + schema_add.add_argument("--schemagroupid", required=True, help="Schema group ID") + schema_add.add_argument("--schemaid", required=True, help="Schema ID") + schema_add.add_argument("--description", help="Schema description") + schema_add.add_argument("--documentation", help="Schema documentation URL") + schema_add.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Schema labels (key=value pairs)") + schema_add.add_argument("--name", help="Schema name") schema_add.add_argument("--format", required=True, help="Schema format") schema_add.add_argument("--versionid", help="Schema version ID") schema_add.add_argument("--schema", help="Inline schema") schema_add.add_argument("--schemaimport", help="Schema import file location or URL") schema_add.add_argument("--schemaurl", help="Schema URL") add_common_arguments(schema_add) - schema_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_schemaversion(args.groupid, args.id, args.format, args.versionid, args.schema, args.schemaimport, - args.schemaurl, args.documentation, args.description, args.labels, args.name - )) + schema_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_schemaversion( + schemagroupid=args.schemagroupid, + schemaid=args.schemaid, + format=args.format, + versionid=args.versionid, + schema=args.schema, + schemaimport=args.schemaimport, + schemaurl=args.schemaurl, + description=args.description, + documentation=args.documentation, + labels=args.labels, + name=args.name + )) schema_remove = schema_subparsers.add_parser("remove", help="Remove a schema or schema version") - schema_remove.add_argument("--groupid", required=True, help="Schema group ID") - schema_remove.add_argument("--id", required=True, help="Schema ID") + schema_remove.add_argument("--schemagroupid", required=True, help="Schema group ID") + schema_remove.add_argument("--schemaid", required=True, help="Schema ID") schema_remove.add_argument("--versionid", required=True, help="Schema version ID") - schema_remove.set_defaults(func=lambda args: CatalogSubcommands( - args.catalog).remove_schema(args.groupid, args.id, args.versionid)) + add_common_arguments(schema_remove) + schema_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_schema( + schemagroupid=args.schemagroupid, + schemaid=args.schemaid, + versionid=args.versionid + )) schema_edit = schema_subparsers.add_parser("edit", help="Edit a schema or schema version") - schema_edit.add_argument("--groupid", required=True, help="Schema group ID") - schema_edit.add_argument("--id", required=True, help="Schema ID") + schema_edit.add_argument("--schemagroupid", required=True, help="Schema group ID") + schema_edit.add_argument("--schemaid", required=True, help="Schema ID") + schema_edit.add_argument("--description", help="Schema description") + schema_edit.add_argument("--documentation", help="Schema documentation URL") + schema_edit.add_argument("--name", help="Schema name") + schema_edit.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Schema labels (key=value pairs)") schema_edit.add_argument("--format", help="Schema format") schema_edit.add_argument("--versionid", required=True, help="Schema version ID") schema_edit.add_argument("--schema", help="Inline schema") schema_edit.add_argument("--schemaimport", help="Schema import file location or URL") schema_edit.add_argument("--schemaurl", help="Schema URL") add_common_arguments(schema_edit) - schema_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_schemaversion(args.groupid, args.id, args.versionid, args.format, args.schema, args.schemaimport, - args.schemaurl, args.documentation, args.description, args.labels, args.name - )) + schema_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_schemaversion( + schemagroupid=args.schemagroupid, + schemaid=args.schemaid, + versionid=args.versionid, + format=args.format, + schema=args.schema, + schemaimport=args.schemaimport, + schemaurl=args.schemaurl, + documentation=args.documentation, + description=args.description, + labels=args.labels, + name=args.name + )) schema_show = schema_subparsers.add_parser("show", help="Show a schema") - schema_show.add_argument("--groupid", required=True, help="Schema group ID") - schema_show.add_argument("--id", required=True, help="Schema ID") - schema_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_schema(args.groupid, args.id)) + schema_show.add_argument("--schemagroupid", required=True, help="Schema group ID") + schema_show.add_argument("--schemaid", required=True, help="Schema ID") + add_common_arguments(schema_show) + schema_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_schema( + schemagroupid=args.schemagroupid, + schemaid=args.schemaid + )) schema_apply = schema_subparsers.add_parser("apply", help="Apply a schema JSON") schema_apply.add_argument("-f", "--file", required=True, help="JSON file containing schema data") + add_common_arguments(schema_apply) schema_apply.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).apply_schema(args.file)) \ No newline at end of file From e803d82cef87363b25adb9510d7e91939e4946a2 Mon Sep 17 00:00:00 2001 From: Clemens Vasters Date: Tue, 5 Nov 2024 08:48:08 -0700 Subject: [PATCH 3/3] initial set of tests --- test/catalog/test_catalog.py | 7 +- xregistry/commands/catalog.py | 129 ++++++++++++++++++---------------- 2 files changed, 74 insertions(+), 62 deletions(-) diff --git a/test/catalog/test_catalog.py b/test/catalog/test_catalog.py index 3078cd4..937a85d 100644 --- a/test/catalog/test_catalog.py +++ b/test/catalog/test_catalog.py @@ -8,8 +8,11 @@ sys.path.append(os.path.join(project_root)) from xregistry.commands.catalog import CatalogSubcommands +# pylint: disable=import-error +# mypy: ignore-errors from testcontainers.core.container import DockerContainer from testcontainers.core.waiting_utils import wait_for_logs +# pylint: enable=import-error import logging import os import sys @@ -334,7 +337,7 @@ def test_cli_add_schemagroup_and_schema(): test_args = [ 'xregistry', 'catalog', - 'schema', + 'schemaversion', 'add', '--catalog', 'http://localhost:8080', '--schemagroupid', 'cli-schemagroup', @@ -357,7 +360,7 @@ def test_cli_add_schemagroup_and_schema(): test_args = [ 'xregistry', 'catalog', - 'schema', + 'schemaversion', 'remove', '--catalog', 'http://localhost:8080', '--schemagroupid', 'cli-schemagroup', diff --git a/xregistry/commands/catalog.py b/xregistry/commands/catalog.py index b1a4a74..a226834 100644 --- a/xregistry/commands/catalog.py +++ b/xregistry/commands/catalog.py @@ -291,7 +291,7 @@ def edit_schemagroup(self, schemagroupid: str, format: Optional[str] = None, sch def show_schemagroup(self, schemagroupid: str) -> None: """Shows a schemagroup from the catalog.""" - response = requests.get(f"{self.base_url}/schemagroups/{schemagroupid}") + response = requests.get(f"{self.base_url}/schemagroups/{schemagroupid}?inline=*") if response.status_code != 200: raise ValueError(f"Schemagroup with id {schemagroupid} does not exist: {response.text}") print(json.dumps(response.json(), indent=2)) @@ -412,7 +412,7 @@ def remove_protocol_option(self, messageid: str, message: Any, section: str|None def set_protocol_option(self, message:Any, section: str|None, name: str, type: str, value: str|None, description: str, required: bool) -> None: """Adds a protocol option to a message.""" - + obj: Any = {} if "protocoloptions" not in message: obj = message["protocoloptions"] = {} if section not in message["protocoloptions"]: @@ -1042,7 +1042,7 @@ def add_parsers(cls, manifest_parser: argparse.ArgumentParser): manifest_subparsers = manifest_parser.add_subparsers(help="Manifest commands") - def add_common_arguments(parser): + def add_authentication_arguments(parser): """ Add common arguments to the parser. @@ -1073,7 +1073,7 @@ def add_common_arguments(parser): endpoint_add.add_argument("--messagegroups", nargs='*', help="Message group IDs") endpoint_add.add_argument("--channel", help="Channel identifier") endpoint_add.add_argument("--deprecated", help="Deprecation information") - add_common_arguments(endpoint_add) + add_authentication_arguments(endpoint_add) endpoint_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_endpoint(args.endpointid, args.usage, args.protocol, args.deployed, args.endpoints, args.options, args.messagegroups, args.documentation, args.description, args.labels, args.name, args.channel, args.deprecated @@ -1081,7 +1081,7 @@ def add_common_arguments(parser): endpoint_remove = endpoint_subparsers.add_parser("remove", help="Remove an endpoint") endpoint_remove.add_argument("--endpointid", required=True, help="Endpoint ID") - add_common_arguments(endpoint_remove) + add_authentication_arguments(endpoint_remove) endpoint_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_endpoint(args.endpointid)) endpoint_edit = endpoint_subparsers.add_parser("edit", help="Edit an endpoint") @@ -1097,7 +1097,7 @@ def add_common_arguments(parser): endpoint_edit.add_argument("--messagegroups", nargs='*', help="Message group IDs") endpoint_edit.add_argument("--channel", help="Channel identifier") endpoint_edit.add_argument("--deprecated", help="Deprecation information") - add_common_arguments(endpoint_edit) + add_authentication_arguments(endpoint_edit) endpoint_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_endpoint(args.endpointid, args.usage, args.protocol, args.deployed, args.endpoints, args.options, args.messagegroups, args.documentation, args.description, args.labels, args.name, args.channel, args.deprecated @@ -1105,12 +1105,12 @@ def add_common_arguments(parser): endpoint_show = endpoint_subparsers.add_parser("show", help="Show an endpoint") endpoint_show.add_argument("--endpointid", required=True, help="Endpoint ID") - add_common_arguments(endpoint_show) + add_authentication_arguments(endpoint_show) endpoint_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_endpoint(args.endpointid)) endpoint_apply = endpoint_subparsers.add_parser("apply", help="Apply an endpoint JSON") endpoint_apply.add_argument("-f", "--file", required=True, help="JSON file containing endpoint data") - add_common_arguments(endpoint_apply) + add_authentication_arguments(endpoint_apply) endpoint_apply.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).apply_endpoint(args.file)) messagegroup_subparsers = manifest_subparsers.add_parser("messagegroup", help="Manage message groups").add_subparsers( @@ -1124,7 +1124,7 @@ def add_common_arguments(parser): messagegroup_add.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message group labels (key=value pairs)") messagegroup_add.add_argument("--envelope", choices=["CloudEvents/1.0", "None"], help="Message group envelope") messagegroup_add.add_argument("--protocol", help="protocol identifier") - add_common_arguments(messagegroup_add) + add_authentication_arguments(messagegroup_add) messagegroup_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_messagegroup( messagegroupid=args.messagegroupid, envelope=args.envelope, @@ -1137,7 +1137,7 @@ def add_common_arguments(parser): messagegroup_remove = messagegroup_subparsers.add_parser("remove", help="Remove a message group") messagegroup_remove.add_argument("--messagegroupid", required=True, help="Message group ID") - add_common_arguments(messagegroup_remove) + add_authentication_arguments(messagegroup_remove) messagegroup_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_messagegroup(args.messagegroupid)) messagegroup_edit = messagegroup_subparsers.add_parser("edit", help="Edit a message group") @@ -1148,7 +1148,7 @@ def add_common_arguments(parser): messagegroup_edit.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Message group labels (key=value pairs)") messagegroup_edit.add_argument("--envelope", choices=["CloudEvents/1.0", "None"], help="Message group envelope") messagegroup_edit.add_argument("--protocol", help="protocol identifier") - add_common_arguments(messagegroup_edit) + add_authentication_arguments(messagegroup_edit) messagegroup_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_messagegroup( messagegroupid=args.messagegroupid, envelope=args.envelope, @@ -1161,12 +1161,12 @@ def add_common_arguments(parser): messagegroup_show = messagegroup_subparsers.add_parser("show", help="Show a message group") messagegroup_show.add_argument("--messagegroupid", required=True, help="Message group ID") - add_common_arguments(messagegroup_show) + add_authentication_arguments(messagegroup_show) messagegroup_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_messagegroup(args.messagegroupid)) messagegroup_apply = messagegroup_subparsers.add_parser("apply", help="Apply a message group JSON") messagegroup_apply.add_argument("-f", "--file", required=True, help="JSON file containing message group data") - add_common_arguments(messagegroup_apply) + add_authentication_arguments(messagegroup_apply) messagegroup_apply.set_defaults(func=lambda args: CatalogSubcommands( args.catalog).apply_messagegroup(args.file)) @@ -1188,7 +1188,7 @@ def add_common_arguments(parser): message_add.add_argument("--schemagroup", help="Schema group ID") message_add.add_argument("--schemaid", help="Schema ID") message_add.add_argument("--schemaurl", help="Schema URL") - add_common_arguments(message_add) + add_authentication_arguments(message_add) message_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_message( messagegroupid=args.messagegroupid, messageid=args.messageid, @@ -1207,7 +1207,7 @@ def add_common_arguments(parser): message_remove = message_subparsers.add_parser("remove", help="Remove a message") message_remove.add_argument("--messagegroupid", required=True, help="Message group ID") message_remove.add_argument("--messageid", required=True, help="Message ID") - add_common_arguments(message_remove) + add_authentication_arguments(message_remove) message_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_message(args.messagegroupid, args.messageid)) message_edit = message_subparsers.add_parser("edit", help="Edit a message") @@ -1224,7 +1224,7 @@ def add_common_arguments(parser): message_edit.add_argument("--schemagroup", help="Schema group ID") message_edit.add_argument("--schemaid", help="Schema ID") message_edit.add_argument("--schemaurl", help="Schema URL") - add_common_arguments(message_edit) + add_authentication_arguments(message_edit) message_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( messagegroupid=args.messagegroupid, messageid=args.messageid, @@ -1252,7 +1252,7 @@ def add_common_arguments(parser): message_cloudevent_add.add_argument("--schemagroup", help="Schema group ID") message_cloudevent_add.add_argument("--schemaid", help="Schema ID") message_cloudevent_add.add_argument("--schemaurl", help="Schema URL") - add_common_arguments(message_cloudevent_add) + add_authentication_arguments(message_cloudevent_add) def _add_cloudevent(args): sc = CatalogSubcommands(args.catalog) @@ -1278,7 +1278,7 @@ def _add_cloudevent(args): message_cloudevent_edit.add_argument("--schemagroup", help="Schema group ID") message_cloudevent_edit.add_argument("--schemaid", help="Schema ID") message_cloudevent_edit.add_argument("--schemaurl", help="Schema URL") - add_common_arguments(message_cloudevent_edit) + add_authentication_arguments(message_cloudevent_edit) message_cloudevent_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( args.messagegroupid, args.messageid, "CloudEvents/1.0", "None", args.schemaformat, args.schemagroup, args.schemaid, args.schemaurl, args.documentation, args.description, args.labels, args.name)) @@ -1286,7 +1286,7 @@ def _add_cloudevent(args): message_cloudevent_remove = message_cloudevent_subparsers.add_parser("remove", help="Remove a CloudEvent") message_cloudevent_remove.add_argument("--messagegroupid", required=True, help="Message group ID", type=str) message_cloudevent_remove.add_argument("--messageid", required=True, help="Message ID and CloudEvents type", type=str) - add_common_arguments(message_cloudevent_remove) + add_authentication_arguments(message_cloudevent_remove) message_cloudevent_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_message(args.messagegroupid, args.messageid)) message_cloudevent_metadata_subparsers = message_cloudevent_subparsers.add_parser( @@ -1302,7 +1302,7 @@ def _add_cloudevent(args): message_cloudevent_metadata_add.add_argument( "--value", help="Attribute value, may contain template expressions if the type is 'uritemplate'") message_cloudevent_metadata_add.add_argument("--required", type=bool, help="Metadata required status") - add_common_arguments(message_cloudevent_metadata_add) + add_authentication_arguments(message_cloudevent_metadata_add) message_cloudevent_metadata_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_cloudevents_message_metadata( args.messagegroupid, args.messageid, args.attribute, args.type, args.description, args.value, args.required)) @@ -1316,7 +1316,7 @@ def _add_cloudevent(args): message_cloudevent_metadata_edit.add_argument( "--value", help="Attribute value, may contain template expressions if the type is 'uritemplate'") message_cloudevent_metadata_edit.add_argument("--required", type=bool, help="Metadata required status") - add_common_arguments(message_cloudevent_metadata_edit) + add_authentication_arguments(message_cloudevent_metadata_edit) message_cloudevent_metadata_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_cloudevents_message_metadata( args.messagegroupid, args.messageid, args.attribute, args.type, args.description, args.value, args.required)) @@ -1325,7 +1325,7 @@ def _add_cloudevent(args): message_cloudevent_metadata_remove.add_argument("--messagegroupid", required=True, help="Message group ID") message_cloudevent_metadata_remove.add_argument("--messageid", required=True, help="Message ID") message_cloudevent_metadata_remove.add_argument("--attribute", required=True, help="CloudEvents attribute") - add_common_arguments(message_cloudevent_metadata_remove) + add_authentication_arguments(message_cloudevent_metadata_remove) message_cloudevent_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands( args.catalog).remove_cloudevents_message_metadata(args.messagegroupid, args.messageid, args.key)) @@ -1360,7 +1360,7 @@ def _add_amqp_message(args): message_amqp_add.add_argument("--schemagroup", help="Schema group ID") message_amqp_add.add_argument("--schemaid", help="Schema ID") message_amqp_add.add_argument("--schemaurl", help="Schema URL") - add_common_arguments(message_amqp_add) + add_authentication_arguments(message_amqp_add) message_amqp_add.set_defaults(func=_add_amqp_message) message_amqp_edit = message_amqp_subparsers.add_parser("edit", help="Edit a message") @@ -1374,9 +1374,9 @@ def _add_amqp_message(args): message_amqp_edit.add_argument("--schemagroup", help="Schema group ID") message_amqp_edit.add_argument("--schemaid", help="Schema ID") message_amqp_edit.add_argument("--schemaurl", help="Schema URL") - add_common_arguments(message_amqp_edit) + add_authentication_arguments(message_amqp_edit) message_amqp_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( - groupid=args.messagegroupid, + messagegroupid=args.messagegroupid, messageid=args.messageid, envelope="None", protocol="AMQP/1.0", @@ -1393,7 +1393,7 @@ def _add_amqp_message(args): message_amqp_remove = message_amqp_subparsers.add_parser("remove", help="Remove a message") message_amqp_remove.add_argument("--messagegroupid", required=True, help="Message group ID") message_amqp_remove.add_argument("--messageid", required=True, help="Message ID") - add_common_arguments(message_amqp_remove) + add_authentication_arguments(message_amqp_remove) message_amqp_remove.set_defaults(func=lambda args: CatalogSubcommands( args.catalog).remove_message(args.messagegroupid, args.messageid)) @@ -1407,7 +1407,7 @@ def _add_amqp_message(args): message_amqp_metadata_add.add_argument("--value", required=False, help="Metadata value") message_amqp_metadata_add.add_argument("--description", help="Metadata description") message_amqp_metadata_add.add_argument("--required", type=bool, help="Metadata required status") - add_common_arguments(message_amqp_metadata_add) + add_authentication_arguments(message_amqp_metadata_add) message_amqp_metadata_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_amqp_message_metadata( messagegroupid=args.messagegroupid, messageid=args.messageid, section=args.section, name=args.name, type=args.type, value=args.value, description=args.description, required=args.required)) @@ -1421,7 +1421,7 @@ def _add_amqp_message(args): message_amqp_metadata_edit.add_argument("--value", required=False, help="Metadata value") message_amqp_metadata_edit.add_argument("--description", help="Metadata description") message_amqp_metadata_edit.add_argument("--required", type=bool, help="Metadata required status") - add_common_arguments(message_amqp_metadata_edit) + add_authentication_arguments(message_amqp_metadata_edit) message_amqp_metadata_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_amqp_message_metadata( args.messagegroupid, args.messageid, args.section, args.name, args.type, args.value, args.description, args.required)) @@ -1432,7 +1432,7 @@ def _add_amqp_message(args): message_amqp_metadata_remove.add_argument("--section", required=True, choices=[ "properties", "application-properties"], help="Metadata section") message_amqp_metadata_remove.add_argument("--name", required=True, help="Metadata name") - add_common_arguments(message_amqp_metadata_remove) + add_authentication_arguments(message_amqp_metadata_remove) message_amqp_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands( args.catalog).remove_amqp_message_metadata(args.messagegroupid, args.messageid, args.name, args.section)) @@ -1461,7 +1461,7 @@ def _add_mqtt_message(args): message_mqtt_add.add_argument("--schemagroup", help="Schema group ID") message_mqtt_add.add_argument("--schemaid", help="Schema ID") message_mqtt_add.add_argument("--schemaurl", help="Schema URL") - add_common_arguments(message_mqtt_add) + add_authentication_arguments(message_mqtt_add) message_mqtt_add.set_defaults(func=_add_amqp_message) message_mqtt_edit = message_mqtt_subparsers.add_parser("edit", help="Edit a message") @@ -1475,7 +1475,7 @@ def _add_mqtt_message(args): message_mqtt_edit.add_argument("--schemagroup", help="Schema group ID") message_mqtt_edit.add_argument("--schemaid", help="Schema ID") message_mqtt_edit.add_argument("--schemaurl", help="Schema URL") - add_common_arguments(message_mqtt_edit) + add_authentication_arguments(message_mqtt_edit) message_mqtt_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( args.messagegroupid, args.messageid, "None", "MQTT/" + args.mqtt_version, args.schemaformat, args.schemagroup, args.schemaid, args.schemaurl, args.documentation, args.description, args.labels, args.name)) @@ -1483,7 +1483,7 @@ def _add_mqtt_message(args): message_mqtt_remove = message_mqtt_subparsers.add_parser("remove", help="Remove a message") message_mqtt_remove.add_argument("--messagegroupid", required=True, help="Message group ID") message_mqtt_remove.add_argument("--messageid", required=True, help="Message ID") - add_common_arguments(message_mqtt_remove) + add_authentication_arguments(message_mqtt_remove) message_mqtt_remove.set_defaults(func=lambda args: CatalogSubcommands( args.catalog).remove_message(args.messagegroupid, args.messageid)) @@ -1497,7 +1497,7 @@ def _add_mqtt_message(args): message_mqtt_metadata_add.add_argument("--value", required=True, help="Metadata value") message_mqtt_metadata_add.add_argument("--description", help="Metadata description") message_mqtt_metadata_add.add_argument("--required", type=bool, help="Metadata required status") - add_common_arguments(message_mqtt_metadata_add) + add_authentication_arguments(message_mqtt_metadata_add) message_mqtt_metadata_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_mqtt_message_metadata( args.messagegroupid, args.messageid, args.mqtt_version, args.name, args.type, args.value, args.description, args.required)) @@ -1511,7 +1511,7 @@ def _add_mqtt_message(args): message_mqtt_metadata_edit.add_argument("--value", help="Metadata value") message_mqtt_metadata_edit.add_argument("--description", help="Metadata description") message_mqtt_metadata_edit.add_argument("--required", type=bool, help="Metadata required status") - add_common_arguments(message_mqtt_metadata_edit) + add_authentication_arguments(message_mqtt_metadata_edit) message_mqtt_metadata_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_mqtt_message_metadata( args.messagegroupid, args.messageid, args.name, args.type, args.value, args.description, args.required)) @@ -1521,7 +1521,7 @@ def _add_mqtt_message(args): message_mqtt_metadata_remove.add_argument("--messageid", required=True, help="Message ID") message_mqtt_metadata_remove.add_argument("--section", required=False, choices=["properties", "topic"], help="Metadata section") message_mqtt_metadata_remove.add_argument("--name", required=True, help="Metadata name") - add_common_arguments(message_mqtt_metadata_remove) + add_authentication_arguments(message_mqtt_metadata_remove) message_mqtt_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands( args.catalog).remove_mqtt_message_metadata(args.messagegroupid, args.messageid, args.section, args.name)) @@ -1549,7 +1549,7 @@ def _add_kafka_message(args): message_kafka_add.add_argument("--schemagroup", help="Schema group ID") message_kafka_add.add_argument("--schemaid", help="Schema ID") message_kafka_add.add_argument("--schemaurl", help="Schema URL") - add_common_arguments(message_kafka_add) + add_authentication_arguments(message_kafka_add) message_kafka_add.set_defaults(func=_add_kafka_message) message_kafka_edit = message_kafka_subparsers.add_parser("edit", help="Edit a message") @@ -1563,7 +1563,7 @@ def _add_kafka_message(args): message_kafka_edit.add_argument("--schemagroup", help="Schema group ID") message_kafka_edit.add_argument("--schemaid", help="Schema ID") message_kafka_edit.add_argument("--schemaurl", help="Schema URL") - add_common_arguments(message_kafka_edit) + add_authentication_arguments(message_kafka_edit) message_kafka_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( args.messagegroupid, args.messageid, "None", "KAFKA", args.schemaformat, args.schemagroup, args.schemaid, args.schemaurl, args.documentation, args.description, args.labels, args.name)) @@ -1571,7 +1571,7 @@ def _add_kafka_message(args): message_kafka_remove = message_kafka_subparsers.add_parser("remove", help="Remove a message") message_kafka_remove.add_argument("--messagegroupid", required=True, help="Message group ID") message_kafka_remove.add_argument("--messageid", required=True, help="Message ID") - add_common_arguments(message_kafka_remove) + add_authentication_arguments(message_kafka_remove) message_kafka_remove.set_defaults(func=lambda args: CatalogSubcommands( args.catalog).remove_message(args.messagegroupid, args.messageid)) @@ -1585,7 +1585,7 @@ def _add_kafka_message(args): message_kafka_metadata_add.add_argument("--value", required=True, help="Metadata value") message_kafka_metadata_add.add_argument("--description", help="Metadata description") message_kafka_metadata_add.add_argument("--required", type=bool, help="Metadata required status") - add_common_arguments(message_kafka_metadata_add) + add_authentication_arguments(message_kafka_metadata_add) message_kafka_metadata_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_kafka_message_metadata( args.messagegroupid, args.messageid, args.section, args.name, args.type, args.value, args.description, args.required)) @@ -1598,7 +1598,7 @@ def _add_kafka_message(args): message_kafka_metadata_edit.add_argument("--value", help="Metadata value") message_kafka_metadata_edit.add_argument("--description", help="Metadata description") message_kafka_metadata_edit.add_argument("--required", type=bool, help="Metadata required status") - add_common_arguments(message_kafka_metadata_edit) + add_authentication_arguments(message_kafka_metadata_edit) message_kafka_metadata_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_kafka_message_metadata( args.messagegroupid, args.messageid, args.section, args.name, args.type, args.value, args.description, args.required)) @@ -1609,7 +1609,7 @@ def _add_kafka_message(args): message_kafka_metadata_remove.add_argument("--name", required=True, help="Metadata name") message_kafka_metadata_remove.add_argument( "--section", required=True, choices=["headers"], help="Metadata section") - add_common_arguments(message_kafka_metadata_remove) + add_authentication_arguments(message_kafka_metadata_remove) message_kafka_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands( args.catalog).remove_kafka_message_metadata(args.messagegroupid, args.messageid, args.section, args.name)) @@ -1666,7 +1666,7 @@ def _add_http_message(args): message_http_add.add_argument("--schemagroup", help="Schema group ID") message_http_add.add_argument("--schemaid", help="Schema ID") message_http_add.add_argument("--schemaurl", help="Schema URL") - add_common_arguments(message_http_add) + add_authentication_arguments(message_http_add) message_http_add.set_defaults(func=_add_http_message) message_http_edit = message_http_subparsers.add_parser("edit", help="Edit a message") @@ -1680,7 +1680,7 @@ def _add_http_message(args): message_http_edit.add_argument("--schemagroup", help="Schema group ID") message_http_edit.add_argument("--schemaid", help="Schema ID") message_http_edit.add_argument("--schemaurl", help="Schema URL") - add_common_arguments(message_http_edit) + add_authentication_arguments(message_http_edit) message_http_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_message( messagegroupid=args.messagegroupid, messageid=args.messageid, @@ -1699,7 +1699,7 @@ def _add_http_message(args): message_http_remove = message_http_subparsers.add_parser("remove", help="Remove a message") message_http_remove.add_argument("--messagegroupid", required=True, help="Message group ID") message_http_remove.add_argument("--messageid", required=True, help="Message ID") - add_common_arguments(message_http_remove) + add_authentication_arguments(message_http_remove) message_http_remove.set_defaults(func=lambda args: CatalogSubcommands( args.catalog).remove_message(args.messagegroupid, args.messageid)) @@ -1714,7 +1714,7 @@ def _add_http_message(args): message_http_metadata_add.add_argument("--value", required=True, help="Metadata value") message_http_metadata_add.add_argument("--description", help="Metadata description") message_http_metadata_add.add_argument("--required", type=bool, help="Metadata required status") - add_common_arguments(message_http_metadata_add) + add_authentication_arguments(message_http_metadata_add) message_http_metadata_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_http_message_metadata( groupid=args.messagegroupid, messageid=args.messageid, @@ -1737,7 +1737,7 @@ def _add_http_message(args): message_http_metadata_edit.add_argument("--value", help="Metadata value") message_http_metadata_edit.add_argument("--description", help="Metadata description") message_http_metadata_edit.add_argument("--required", type=bool, help="Metadata required status") - add_common_arguments(message_http_metadata_edit) + add_authentication_arguments(message_http_metadata_edit) message_http_metadata_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_http_message_metadata( groupid=args.messagegroupid, messageid=args.messageid, @@ -1756,7 +1756,7 @@ def _add_http_message(args): message_http_metadata_remove.add_argument("--name", required=True, help="Metadata key") message_http_metadata_remove.add_argument( "--section", required=False, choices=["headers", "query"], help="Metadata section") - add_common_arguments(message_http_metadata_remove) + add_authentication_arguments(message_http_metadata_remove) message_http_metadata_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_http_message_metadata( messagegroupid=args.messagegroupid, messageid=args.messageid, @@ -1768,7 +1768,7 @@ def _add_http_message(args): message_show.add_argument("--messagegroupid", required=True, help="Message group ID") message_show.add_argument("--messageid", required=True, help="Message ID") - add_common_arguments(message_show) + add_authentication_arguments(message_show) message_show.set_defaults(func=lambda args: CatalogSubcommands( args.catalog).show_message(args.messagegroupid, args.messageid)) @@ -1777,25 +1777,34 @@ def _add_http_message(args): schemagroup_add = schemagroup_subparsers.add_parser("add", help="Add a new schema group") schemagroup_add.add_argument("--schemagroupid", required=True, help="Schema group ID") - add_common_arguments(schemagroup_add) + schemagroup_add.add_argument("--description", help="Schema group description") + schemagroup_add.add_argument("--documentation", help="Schema group documentation URL") + schemagroup_add.add_argument("--format", required=True, help="Schema group format") + schemagroup_add.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Schema group labels (key=value pairs)") + schemagroup_add.add_argument("--name", help="Schema group name") + add_authentication_arguments(schemagroup_add) schemagroup_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_schemagroup( schemagroupid=args.schemagroupid, description=args.description, documentation=args.documentation, format=args.format, labels=args.labels, - name=args.name, - schemas=args.schemas)) + name=args.name)) schemagroup_remove = schemagroup_subparsers.add_parser("remove", help="Remove a schema group") schemagroup_remove.add_argument("--schemagroupid", required=True, help="Schema group ID") - add_common_arguments(schemagroup_remove) + add_authentication_arguments(schemagroup_remove) schemagroup_remove.set_defaults(func=lambda args: CatalogSubcommands( args.catalog).remove_schemagroup(args.schemagroupid)) schemagroup_edit = schemagroup_subparsers.add_parser("edit", help="Edit a schema group") schemagroup_edit.add_argument("--schemagroupid", required=True, help="Schema group ID") - add_common_arguments(schemagroup_edit) + schemagroup_edit.add_argument("--description", help="Schema group description") + schemagroup_edit.add_argument("--format", help="Schema group format ('None' to clear format)") + schemagroup_edit.add_argument("--documentation", help="Schema group documentation URL") + schemagroup_edit.add_argument("--labels", nargs='*', metavar='KEY=VALUE', help="Schema group labels (key=value pairs)") + schemagroup_edit.add_argument("--name", help="Schema group name") + add_authentication_arguments(schemagroup_edit) schemagroup_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_schemagroup( schemagroupid=args.schemagroupid, documentation=args.documentation, @@ -1806,12 +1815,12 @@ def _add_http_message(args): schemagroup_show = schemagroup_subparsers.add_parser("show", help="Show a schema group") schemagroup_show.add_argument("--schemagroupid", required=True, help="Schema group ID") - add_common_arguments(schemagroup_show) + add_authentication_arguments(schemagroup_show) schemagroup_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_schemagroup(args.schemagroupid)) schemagroup_apply = schemagroup_subparsers.add_parser("apply", help="Apply a schema group JSON") schemagroup_apply.add_argument("-f", "--file", required=True, help="JSON file containing schema group data") - add_common_arguments(schemagroup_apply) + add_authentication_arguments(schemagroup_apply) schemagroup_apply.set_defaults(func=lambda args: CatalogSubcommands( args.catalog).apply_schemagroup(args.file)) @@ -1830,7 +1839,7 @@ def _add_http_message(args): schema_add.add_argument("--schema", help="Inline schema") schema_add.add_argument("--schemaimport", help="Schema import file location or URL") schema_add.add_argument("--schemaurl", help="Schema URL") - add_common_arguments(schema_add) + add_authentication_arguments(schema_add) schema_add.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).add_schemaversion( schemagroupid=args.schemagroupid, schemaid=args.schemaid, @@ -1849,7 +1858,7 @@ def _add_http_message(args): schema_remove.add_argument("--schemagroupid", required=True, help="Schema group ID") schema_remove.add_argument("--schemaid", required=True, help="Schema ID") schema_remove.add_argument("--versionid", required=True, help="Schema version ID") - add_common_arguments(schema_remove) + add_authentication_arguments(schema_remove) schema_remove.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).remove_schema( schemagroupid=args.schemagroupid, schemaid=args.schemaid, @@ -1868,7 +1877,7 @@ def _add_http_message(args): schema_edit.add_argument("--schema", help="Inline schema") schema_edit.add_argument("--schemaimport", help="Schema import file location or URL") schema_edit.add_argument("--schemaurl", help="Schema URL") - add_common_arguments(schema_edit) + add_authentication_arguments(schema_edit) schema_edit.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).edit_schemaversion( schemagroupid=args.schemagroupid, schemaid=args.schemaid, @@ -1886,7 +1895,7 @@ def _add_http_message(args): schema_show = schema_subparsers.add_parser("show", help="Show a schema") schema_show.add_argument("--schemagroupid", required=True, help="Schema group ID") schema_show.add_argument("--schemaid", required=True, help="Schema ID") - add_common_arguments(schema_show) + add_authentication_arguments(schema_show) schema_show.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).show_schema( schemagroupid=args.schemagroupid, schemaid=args.schemaid @@ -1894,5 +1903,5 @@ def _add_http_message(args): schema_apply = schema_subparsers.add_parser("apply", help="Apply a schema JSON") schema_apply.add_argument("-f", "--file", required=True, help="JSON file containing schema data") - add_common_arguments(schema_apply) + add_authentication_arguments(schema_apply) schema_apply.set_defaults(func=lambda args: CatalogSubcommands(args.catalog).apply_schema(args.file)) \ No newline at end of file