Skip to content

Commit

Permalink
GH #755 - Adding more skip lists to enmasse.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuch committed Nov 20, 2023
1 parent 6c20006 commit a884c66
Showing 1 changed file with 103 additions and 11 deletions.
114 changes: 103 additions & 11 deletions code/zato-cli/src/zato/cli/enmasse.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
outconn_wsx = COMMON_GENERIC.CONNECTION.TYPE.OUTCONN_WSX
outconn_ldap = COMMON_GENERIC.CONNECTION.TYPE.OUTCONN_LDAP

_prefix_generic = 'zato_generic_connection'
_attr_outconn_wsx = f'{_prefix_generic}_{outconn_wsx}'
_attr_outconn_ldap = f'{_prefix_generic}_{outconn_ldap}'

# We need to have our own version because type "bearer_token" exists in enmasse only.
_All_Sec_Def_Types = All_Sec_Def_Types + ['bearer_token']

Expand Down Expand Up @@ -102,6 +106,15 @@ class Include_Type:
# Maps enmasse defintions types to their attributes that will be skipped during an export if they are empty
Enmasse_Attr_List_Skip_If_Empty = cast_('strlistdict', None)

# Maps enmasse defintions types to their attributes that will be skipped during an export if they are True
Enmasse_Attr_List_Skip_If_True = cast_('strlistdict', None)

# Maps enmasse defintions types to their attributes that will be skipped during an export if they are False
Enmasse_Attr_List_Skip_If_False = cast_('strlistdict', None)

# Maps enmasse defintions types to their attributes that will be skipped during an export if their value matches configuration
Enmasse_Attr_List_Skip_If_Value_Matches = cast_('strdictdict', None)

# Maps enmasse defintions types to their attributes that will be turned into multiline strings
Enmasse_Attr_List_As_Multiline = cast_('strlistdict', None)

Expand Down Expand Up @@ -155,7 +168,7 @@ class Include_Type:
'client_secret_field',
'grant_type',
'scopes',
'extra_fields'
'extra_fields',
],

# REST connections - Channels
Expand All @@ -182,15 +195,6 @@ class Include_Type:
'transport',
],

# LDAP outgoing connections
f'zato_generic_connection_{outconn_ldap}': [
'type_',
'name',
'username',
'auth_type',
'server_list',
],

# Scheduled tasks
'scheduler': [
'name',
Expand All @@ -206,6 +210,28 @@ class Include_Type:
'repeats',
'extra',
],

# LDAP outgoing connections
_attr_outconn_ldap: [
'type_',
'name',
'username',
'auth_type',
'server_list',
],

# Outgoing WSX connections
_attr_outconn_wsx: [
'name',
'address',
'data_format',
'has_auto_reconnect',
'on_connect_service_name',
'on_message_service_name',
'on_close_service_name',
'subscription_list',
],

}

# ################################################################################################################################
Expand All @@ -222,7 +248,7 @@ class Include_Type:
# REST connections - outgoing connections
'outconn_plain_http': [
'connection',
'transport'
'transport',
],

}
Expand Down Expand Up @@ -251,6 +277,31 @@ class Include_Type:

# Security definitions
'scheduler': ['weeks', 'days', 'hours', 'minutes', 'seconds', 'cron_definition', 'repeats', 'extra'],

# Outgoing WSX connections
_attr_outconn_wsx: ['data_format', 'subscription_list'],
}

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

ModuleCtx.Enmasse_Attr_List_Skip_If_True = {

# Outgoing WSX connections
_attr_outconn_wsx: ['has_auto_reconnect'],
}

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

ModuleCtx.Enmasse_Attr_List_Skip_If_False = {
# No such attributes yet
}

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

ModuleCtx.Enmasse_Attr_List_Skip_If_Value_Matches = {

# E-Mail IMAP
'email_imap': {'get_criteria':'UNSEEN', 'timeout':10},
}

# ################################################################################################################################
Expand Down Expand Up @@ -329,6 +380,18 @@ class Include_Type:
'repeats',
'extra',
],

# Outgoing WSX connections
f'zato_generic_connection_{outconn_wsx}': [
'name',
'address',
'data_format',
'has_auto_reconnect',
'on_connect_service_name',
'on_message_service_name',
'on_close_service_name',
'subscription_list',
]
}

# ################################################################################################################################
Expand Down Expand Up @@ -2584,6 +2647,15 @@ def _preprocess_item_attrs(
# .. as above, for attributes that should be skipped if they are empty ..
attr_list_skip_if_empty = ModuleCtx.Enmasse_Attr_List_Skip_If_Empty.get(attr_key) or []

# .. as above, for attributes that should be skipped if their value is True ..
attr_list_skip_if_true = ModuleCtx.Enmasse_Attr_List_Skip_If_True.get(attr_key) or []

# .. as above, for attributes that should be skipped if their value is False ..
attr_list_skip_if_false = ModuleCtx.Enmasse_Attr_List_Skip_If_False.get(attr_key) or []

# .. as above, for attributes that should be skipped if they have a specific value ..
attr_list_skip_if_value_matches = ModuleCtx.Enmasse_Attr_List_Skip_If_Value_Matches.get(attr_key) or {}

# .. to make sure the dictionary does not change during iteration ..
item_copy = deepcopy(item)

Expand Down Expand Up @@ -2632,6 +2704,26 @@ def _preprocess_item_attrs(
if value:
item[attr] = value

# .. optionally, skip True attributes ..
for attr in attr_list_skip_if_true:
if value := item.pop(attr, NotGiven):
if value is not True:
if value:
item[attr] = value

# .. optionally, skip False attributes ..
for attr in attr_list_skip_if_false:
if value := item.pop(attr, NotGiven):
if value is not False:
if value:
item[attr] = value

# .. optionally, skip attributes that match configuration ..
for pattern_key, pattern_value in attr_list_skip_if_value_matches.items():
if value := item.pop(pattern_key, NotGiven): # type: ignore
if value != pattern_value:
item[pattern_key] = value

# .. ID's are never returned ..
_ = item.pop('id', None)

Expand Down

0 comments on commit a884c66

Please sign in to comment.