75824ff5ac
1st command: list the stream mapping
77 lines
1.6 KiB
Python
Executable File
77 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# coding: utf8
|
|
|
|
"""A basic opensearch.org client.
|
|
|
|
All start here.
|
|
|
|
Author: frederic zind 2022-08-02
|
|
Licenses: GNU AGPL v3: http://www.gnu.org/licenses/
|
|
"""
|
|
|
|
|
|
import argparse
|
|
import sys
|
|
|
|
from pprint import pprint as pp
|
|
|
|
from client import LDP_ALIAS, opnsrch_clt
|
|
|
|
|
|
class CustomFormatter(
|
|
argparse.RawDescriptionHelpFormatter, argparse.ArgumentDefaultsHelpFormatter
|
|
):
|
|
"""This convert file docstring into help text."""
|
|
|
|
pass
|
|
|
|
|
|
def parse_args(args=sys.argv[1:]):
|
|
"""Argument parser.
|
|
|
|
Put values & describe parameters here not in your code
|
|
Ease usage with help & docs
|
|
"""
|
|
parser = argparse.ArgumentParser(
|
|
description=sys.modules[__name__].__doc__, formatter_class=CustomFormatter
|
|
)
|
|
|
|
parser.add_argument(
|
|
"-m",
|
|
"--mapping",
|
|
action="store_true",
|
|
help="Show the stream mapping",
|
|
)
|
|
|
|
return parser.parse_args(args)
|
|
|
|
|
|
def get_map_props():
|
|
"""Get stream mapping.
|
|
|
|
LDP indices are rolling and LDP do not implement the call
|
|
to get indices related to an alias.
|
|
"""
|
|
indices = list(opnsrch_clt.indices.get_alias("*"))
|
|
mapping = opnsrch_clt.indices.get_mapping(LDP_ALIAS)[indices[0]]["mappings"]
|
|
map_props = sorted(list(mapping["properties"]))
|
|
|
|
return map_props
|
|
|
|
|
|
def main(options):
|
|
"""Execute as a script. Functions related to the arguments passed."""
|
|
if options.mapping:
|
|
response = get_map_props()
|
|
else:
|
|
raise RuntimeError
|
|
|
|
return response
|
|
|
|
|
|
if __name__ == "__main__":
|
|
pargs = parse_args()
|
|
result = main(pargs)
|
|
|
|
pp(result)
|