Skip to content

Commit

Permalink
Merge branch 'main' into support/3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuch committed Dec 28, 2023
2 parents eb734cb + a3a74da commit 432aa30
Show file tree
Hide file tree
Showing 45 changed files with 2,484 additions and 460 deletions.
17 changes: 15 additions & 2 deletions code/zato-cli/src/zato/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class MS_SQL:
('pubsub_cleanup', 'zato.cli.pubsub.cleanup.Cleanup'),
('pubsub_create_endpoint', 'zato.cli.pubsub.endpoint.CreateEndpoint'),
('pubsub_create_topic', 'zato.cli.pubsub.topic.CreateTopic'),
('pubsub_create_test_topics', 'zato.cli.pubsub.topic.CreateTestTopics'),
('pubsub_delete_endpoint', 'zato.cli.pubsub.endpoint.DeleteEndpoint'),
('pubsub_delete_topic', 'zato.cli.pubsub.topic.DeleteTopics'),
('pubsub_delete_topics', 'zato.cli.pubsub.topic.DeleteTopics'),
Expand Down Expand Up @@ -308,6 +309,15 @@ def __init__(self, args):
# one, so we read it here and give other processes explicitly on input, if they need it.
self.stdin_data = read_stdin_data()

# ################################################################################################################################

def exit(self, exit_code:'int'=0) -> 'None':

# stdlib
import sys

_ = sys.exit(exit_code)

# ################################################################################################################################

def allow_empty_secrets(self):
Expand Down Expand Up @@ -1060,13 +1070,16 @@ def _invoke_service_and_log_response(
request:'anydict',
hook_func:'callnone'=None,
needs_stdout:'bool'=True
) -> 'None':
) -> 'any_':

# Invoke the service first ..
data = self._invoke_service(service, request, hook_func)

# .. and log its output now.
# .. log its output ..
self._log_response(data, needs_stdout)

# .. and return the output to our caller.
return data

# ################################################################################################################################
# ################################################################################################################################
172 changes: 172 additions & 0 deletions code/zato-cli/src/zato/cli/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# -*- coding: utf-8 -*-

"""
Copyright (C) 2023, Zato Source s.r.o. https://zato.io
Licensed under LGPLv3, see LICENSE.txt for terms and conditions.
"""

# Zato
from zato.cli import ServerAwareCommand
from zato.common.api import CommonObject, NotGiven

# ################################################################################################################################
# ################################################################################################################################

if 0:
from argparse import Namespace
from zato.common.typing_ import strdict, strdictnone, strlist, strnone
Namespace = Namespace

# ################################################################################################################################
# ################################################################################################################################

class DeleteCommon(ServerAwareCommand):
""" A base class for CLI commands that delete objects.
"""

# This will be populated by subclasses
object_type = CommonObject.Invalid

opts = [
{'name':'--id', 'help':'An exact ID of an object to delete', 'required':False},
{'name':'--id-list', 'help':'A list of object IDs to delete', 'required':False},
{'name':'--name', 'help':'An exact name of an object to delete', 'required':False},
{'name':'--name-list','help':'List of objects to delete', 'required':False},
{'name':'--pattern', 'help':'All objects with names that contain this pattern', 'required':False},
{'name':'--path', 'help':'Path to a Zato server', 'required':False},
]

# ################################################################################################################################

def execute(self, args:'Namespace'):

# stdlib
import sys

# This will be built based on the option provided by user
request = {
'object_type': self.object_type,
}

options = ['--id', '--id-list', '--name', '--name-list', '--pattern']
for name in options:
arg_attr = name.replace('--', '')
arg_attr = arg_attr.replace('-', '_')
value = getattr(args, arg_attr, None)
if value:
request[arg_attr] = value
break

if not request:
options = ', '.join(options)
self.logger.warn(f'Missing input. One of the following is expected: {options}')
sys.exit(self.SYS_ERROR.PARAMETER_MISSING)

# Our service to invoke
service = 'zato.common.delete-objects'

# Invoke the service and log the response it produced
self._invoke_service_and_log_response(service, request)

# ################################################################################################################################
# ################################################################################################################################

class CreateCommon(ServerAwareCommand):
""" A base class for CLI commands that create objects.
"""

# These will be populated by subclasses
object_type = CommonObject.Invalid
prefix = CommonObject.Prefix_Invalid

opts = [
{'name':'--count', 'help':'How many objects to create', 'required':False},
{'name':'--prefix', 'help':'Prefix that each of the topics to be created will have', 'required':False},
{'name':'--path', 'help':'Path to a Zato server', 'required':False},
{'name':'--endpoints-per-topic',
'help':'How many endpoints to create per each topic', 'required':False, 'default':3, 'type':int},
{'name':'--messages-per-pub',
'help':'How many messages to publish from each publisher', 'required':False, 'default':10, 'type':int},
{'name':'--msg-size',
'help':'How big, in kilobytes, each published message should be', 'required':False, 'default':3, 'type':int},
{'name':'--needs-stdout',
'help':'Whether to log default messages to stdout', 'required':False, 'default':NotGiven},
]

# ################################################################################################################################

def invoke_common(
self,
service:'str',
object_type: 'strnone',
name_list:'strlist',
*,
args:'Namespace | None'=None,
needs_stdout:'bool'=True,
initial_data:'strdictnone'=None,
) -> 'strdict':

# stdlib
from zato.common.util import as_bool

request:'strdict' = {
'object_type': object_type,
'name_list': name_list,
'initial_data': initial_data,
}

if args and (args_needs_stdout := args.needs_stdout):
args_needs_stdout = as_bool(args_needs_stdout)
needs_stdout = args_needs_stdout

# Invoke the service and log the response it produced
response = self._invoke_service_and_log_response(service, request, needs_stdout=needs_stdout)

return response

# ################################################################################################################################

def invoke_common_create(self,
object_type: 'strnone',
name_list:'strlist',
*,
args:'Namespace | None'=None,
needs_stdout:'bool'=True,
initial_data:'strdictnone'=None,
) -> 'strdict':

service = 'zato.common.create-objects'
response = self.invoke_common(
service, object_type, name_list, args=args, needs_stdout=needs_stdout, initial_data=initial_data)
return response

# ################################################################################################################################

def execute(self, args:'Namespace') -> 'strdict':

# Local variables
default_count = 1000

# Read the parameters from the command line or fall back on the defaults
count = int(args.count or default_count)
prefix = args.prefix or self.prefix

# Find out to how many digits we should fill tha names
digits = len(str(count))

# The list to create
name_list = []

for idx, _ in enumerate(range(count), 1):
idx = str(idx).zfill(digits)
topic_name = f'{prefix}{idx}'
name_list.append(topic_name)

# Invoke the service
response = self.invoke_common_create(self.object_type, name_list, args=args)

return response

# ################################################################################################################################
# ################################################################################################################################
2 changes: 1 addition & 1 deletion code/zato-cli/src/zato/cli/create_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@
inform_if_locked=True
inform_if_not_confirmed=True
inform_if_not_approved=True
inform_if_totp_missing=False
inform_if_totp_missing=True
[password_reset]
valid_for=1440 # In minutes = 1 day
Expand Down
Loading

0 comments on commit 432aa30

Please sign in to comment.