🔀 Merge branch '9-fix-mapping'

Resolve "Fix mapping for demo mode"

Closes #9

See merge request forga/tool/ovh/ldpy!1
This commit is contained in:
Freezed 2022-10-03 23:06:03 +00:00
commit 38507bbefe

21
ldpy.py
View File

@ -16,6 +16,8 @@ import os
from pprint import pformat as pf
import sys
from opensearchpy import AuthorizationException
import client # pylint: disable=import-error
# Ranqe for the request retrieving the last entries.
@ -113,25 +115,20 @@ def get_last_entries(entries_nb):
def get_map_props():
"""Get stream mapping.
'demo' stream did not have an LDP_ALIAS
LDP indices are rolling and LDP do not implement the call
to get indices related to an alias.
"""
map_props = []
if client.LDP_CRED_TYPE == "token":
try:
indices = list(client.opnsrch_clt.indices.get_alias("*"))
mapping = client.opnsrch_clt.indices.get_mapping(client.LDP_ALIAS)[indices[0]][
"mappings"
]
map_props = sorted(list(mapping["properties"]))
logger.debug("Found mapping!")
else:
logger.critical(
"Stream mapping unavailable with credential type: '%s'",
client.LDP_CRED_TYPE,
)
logger.debug("Mapping found for alias: '%s'", client.LDP_ALIAS)
except AuthorizationException:
map_props = None
logger.critical("AuthorizationException: check credentials")
return map_props
@ -187,5 +184,5 @@ if __name__ == "__main__":
setup_logging(pargs)
result = main(pargs)
if not pargs.debug:
if not pargs.debug and result:
print(result)