From 4577589903be1bb377b50a753e7669e32bc6eebe Mon Sep 17 00:00:00 2001 From: Yaniv Eliash Date: Tue, 7 Mar 2023 09:35:58 +0200 Subject: [PATCH 1/5] ignore python venv Signed-off-by: Yaniv Eliash --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 74626e2b8..58f4101d8 100644 --- a/.gitignore +++ b/.gitignore @@ -323,3 +323,6 @@ local-test .local-* /artifacts/ + +# Python Virtual Env +**/venv \ No newline at end of file From 64f6c43c6ce4e595bf4362c8adbe99b984da8fc9 Mon Sep 17 00:00:00 2001 From: Yaniv Eliash Date: Tue, 7 Mar 2023 09:36:23 +0200 Subject: [PATCH 2/5] main cli tool Signed-off-by: Yaniv Eliash --- scripts/integrations/main.py | 89 ++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 scripts/integrations/main.py diff --git a/scripts/integrations/main.py b/scripts/integrations/main.py new file mode 100644 index 000000000..4c16d8ff8 --- /dev/null +++ b/scripts/integrations/main.py @@ -0,0 +1,89 @@ +import typer +import configparser +import json +import os +import sys +import shutil +from rich import print + +app = typer.Typer() +base_integration_path = "../integrations" +dirs = ["assets", "info", "samples", "schema", "test"] + + +def createIntegrationDirs(directory, force): + if os.path.isdir(directory): + if force: + force = typer.confirm(f"Are you sure you want to delete {directory}?") + if force: + shutil.rmtree(directory) + os.makedirs(directory) + for dir in dirs: + os.makedirs(directory + "/" + dir) + else: + print(f"[red]Directory {directory} already exists[/red]") + sys.exit(1) + else: + os.makedirs(directory) + for dir in dirs: + os.makedirs(directory + "/" + dir) + + +def populateDefaultVars(var_name): + config = configparser.ConfigParser() + config.read('config.ini') + return (config.get("DEFAULT", var_name)) + + +def generateJson(directory, integration_name, integration_desc, schema, license): + data = { + "name": integration_name, + "version": { + "integ": "0.1.0", + "schema": schema, + "resource": "^1.23.0", + "license": license + }, + "description": integration_desc, + "identification": "instrumentationScope.attributes.identification", + "categories": [], + "collection": [{}], + "repo": { + "github": "https://github.com/opensearch-project/observability/tree/main/integrarions/"+integration_name + }} + + with open(directory + '/config.json', 'w', encoding='utf-8') as f: + json.dump(data, f, ensure_ascii=False, indent=4) + + +def error(txt): + print(txt) + sys.exit(1) + + +def main( + integration_name: str = typer.Option("", "--name", "-n", help="Your new integration name"), + integration_desc: str = typer.Option("", "--description", "-d", help="Your new integration description"), + license: str = typer.Option(populateDefaultVars("LICENSE"), "--license", "-l", help="Opensource license (e.g. Apache, MIT)"), + data_source: str = typer.Option("", "--data-source", "-s", help="The data source to ingest from, as well as which version(s) to support."), + schema: str = typer.Option("", "--schema", "-s", help="Which schema, and at which version, to use. The data will be ingested with this schema."), + catalog: str = typer.Option("", "--catalog", "-c", help="The specific catalog to target, such as `observability` or `security`."), + force: bool = typer.Option(False, "--force", "-f", help="Force integration directoy removal and recreation") +): + + directory = integration_name.lower() + directory = base_integration_path + "/" + directory.replace("_", "-") + + createIntegrationDirs(directory, force) + + generateJson(directory, + integration_name, + integration_desc, + schema, license) + + +if __name__ == "__main__": + if len(sys.argv) <= 1: + typer.run(error("No options been provided\nIf unsure, run again with --help\n")) + else: + typer.run(main) From af41a521be1745ff23ba1d8a7917ca671f8f5b9d Mon Sep 17 00:00:00 2001 From: Yaniv Eliash Date: Tue, 7 Mar 2023 09:36:31 +0200 Subject: [PATCH 3/5] python requirements file Signed-off-by: Yaniv Eliash --- scripts/integrations/requirements | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 scripts/integrations/requirements diff --git a/scripts/integrations/requirements b/scripts/integrations/requirements new file mode 100644 index 000000000..6e8c85509 --- /dev/null +++ b/scripts/integrations/requirements @@ -0,0 +1,6 @@ +click==8.1.3 +markdown-it-py==2.2.0 +mdurl==0.1.2 +Pygments==2.14.0 +rich==13.3.2 +typer==0.7.0 \ No newline at end of file From 79939e21784abe37faa58c2a3f4ac10bb9d94e62 Mon Sep 17 00:00:00 2001 From: Yaniv Eliash Date: Tue, 7 Mar 2023 09:36:42 +0200 Subject: [PATCH 4/5] default cli variables Signed-off-by: Yaniv Eliash --- scripts/integrations/config.ini | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 scripts/integrations/config.ini diff --git a/scripts/integrations/config.ini b/scripts/integrations/config.ini new file mode 100644 index 000000000..a62499e7c --- /dev/null +++ b/scripts/integrations/config.ini @@ -0,0 +1,2 @@ +[DEFAULT] +LICENSE = MIT \ No newline at end of file From 8e5c3e16c43d437982d25c6f240dada6da8007c2 Mon Sep 17 00:00:00 2001 From: Yaniv Eliash Date: Tue, 7 Mar 2023 19:59:04 +0200 Subject: [PATCH 5/5] * Removed base_integration_path, now new integrations will be created at the script's path * Changed file and directories path concatanation to os.path.join * Linter kicked in and formatted the file. Signed-off-by: Yaniv Eliash --- scripts/integrations/main.py | 39 +++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/scripts/integrations/main.py b/scripts/integrations/main.py index 4c16d8ff8..3dfcf08dd 100644 --- a/scripts/integrations/main.py +++ b/scripts/integrations/main.py @@ -7,26 +7,26 @@ from rich import print app = typer.Typer() -base_integration_path = "../integrations" dirs = ["assets", "info", "samples", "schema", "test"] def createIntegrationDirs(directory, force): if os.path.isdir(directory): if force: - force = typer.confirm(f"Are you sure you want to delete {directory}?") + force = typer.confirm( + f"Are you sure you want to delete {directory}?") if force: shutil.rmtree(directory) os.makedirs(directory) for dir in dirs: - os.makedirs(directory + "/" + dir) + os.makedirs(os.path.join(directory, dir)) else: print(f"[red]Directory {directory} already exists[/red]") sys.exit(1) else: os.makedirs(directory) for dir in dirs: - os.makedirs(directory + "/" + dir) + os.makedirs(os.path.join(directory, dir)) def populateDefaultVars(var_name): @@ -52,7 +52,7 @@ def generateJson(directory, integration_name, integration_desc, schema, license) "github": "https://github.com/opensearch-project/observability/tree/main/integrarions/"+integration_name }} - with open(directory + '/config.json', 'w', encoding='utf-8') as f: + with open(os.path.join(directory, "config.json"), 'w', encoding='utf-8') as f: json.dump(data, f, ensure_ascii=False, indent=4) @@ -62,20 +62,26 @@ def error(txt): def main( - integration_name: str = typer.Option("", "--name", "-n", help="Your new integration name"), - integration_desc: str = typer.Option("", "--description", "-d", help="Your new integration description"), - license: str = typer.Option(populateDefaultVars("LICENSE"), "--license", "-l", help="Opensource license (e.g. Apache, MIT)"), - data_source: str = typer.Option("", "--data-source", "-s", help="The data source to ingest from, as well as which version(s) to support."), - schema: str = typer.Option("", "--schema", "-s", help="Which schema, and at which version, to use. The data will be ingested with this schema."), - catalog: str = typer.Option("", "--catalog", "-c", help="The specific catalog to target, such as `observability` or `security`."), - force: bool = typer.Option(False, "--force", "-f", help="Force integration directoy removal and recreation") + integration_name: str = typer.Option( + "", "--name", "-n", help="Your new integration name"), + integration_desc: str = typer.Option( + "", "--description", "-d", help="Your new integration description"), + license: str = typer.Option(populateDefaultVars( + "LICENSE"), "--license", "-l", help="Opensource license (e.g. Apache, MIT)"), + data_source: str = typer.Option( + "", "--data-source", "-s", help="The data source to ingest from, as well as which version(s) to support."), + schema: str = typer.Option( + "", "--schema", "-s", help="Which schema, and at which version, to use. The data will be ingested with this schema."), + catalog: str = typer.Option( + "", "--catalog", "-c", help="The specific catalog to target, such as `observability` or `security`."), + force: bool = typer.Option( + False, "--force", "-f", help="Force integration directoy removal and recreation") ): - directory = integration_name.lower() - directory = base_integration_path + "/" + directory.replace("_", "-") + directory = integration_name.lower().replace("_", "-") createIntegrationDirs(directory, force) - + generateJson(directory, integration_name, integration_desc, @@ -84,6 +90,7 @@ def main( if __name__ == "__main__": if len(sys.argv) <= 1: - typer.run(error("No options been provided\nIf unsure, run again with --help\n")) + typer.run( + error("No options has been provided\nIf unsure, run again with --help\n")) else: typer.run(main)