Skip to content

Commit

Permalink
Merge pull request #64 from dwolfson/v5.2
Browse files Browse the repository at this point in the history
V5.2 Updates to Pyegeria Commands and Documentation
  • Loading branch information
dwolfson authored Dec 19, 2024
2 parents a60da57 + 4f77faf commit de083c8
Show file tree
Hide file tree
Showing 85 changed files with 1,275 additions and 474 deletions.
3 changes: 2 additions & 1 deletion pyegeria/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<!-- Copyright Contributors to the Egeria project. -->

The Commands in this directory provide a simple but useful command line interface for the Egeria environment. They
are built with the **Rich** python package and demonstrate the use of **pyegeria** .
are built with the **Rich** python package and demonstrate the use of **pyegeria**. More detailed documentation can be
found in the `doc` folder.

The commands can either be invoked from one of the command line interfaces or executed directly as python scripts.
To invoke the commands directly, install them with pipx by invoking:
Expand Down
6 changes: 1 addition & 5 deletions pyegeria/commands/cat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
# from .list_glossaries import display_glossaries
# from .list_terms import display_glossary_terms
# from .list_deployed_catalogs import list_deployed_catalogs
# from .list_deployed_database_schemas import list_deployed_database_schemas
# from .list_deployed_databases import list_deployed_databases
""" Placeholder """
2 changes: 1 addition & 1 deletion pyegeria/commands/cat/exp_list_glossaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
Expand Down
2 changes: 1 addition & 1 deletion pyegeria/commands/cat/get_asset_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_INTEGRATION_DAEMON_URL = os.environ.get(
"EGERIA_INTEGRATION_DAEMON_URL", "https://localhost:9443"
)
Expand Down
2 changes: 1 addition & 1 deletion pyegeria/commands/cat/get_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
Expand Down
2 changes: 1 addition & 1 deletion pyegeria/commands/cat/get_project_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
Expand Down
2 changes: 1 addition & 1 deletion pyegeria/commands/cat/get_project_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
Expand Down
4 changes: 2 additions & 2 deletions pyegeria/commands/cat/get_tech_type_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
Expand Down Expand Up @@ -163,7 +163,7 @@ def main():
user_pass = args.password if args.password is not None else EGERIA_USER_PASSWORD
try:
tech_name = Prompt.ask(
"Enter the Asset Name to view:", default="Apache Kafka Server"
"Enter the Asset Name to view:", default="PostgreSQL Server"
)
tech_viewer(tech_name, server, url, userid, user_pass)
except KeyboardInterrupt:
Expand Down
12 changes: 9 additions & 3 deletions pyegeria/commands/cat/glossary_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_INTEGRATION_DAEMON_URL = os.environ.get(
"EGERIA_INTEGRATION_DAEMON_URL", "https://localhost:9443"
)
Expand All @@ -47,6 +47,7 @@
EGERIA_USER_PASSWORD = os.environ.get("EGERIA_USER_PASSWORD", "secret")
EGERIA_WIDTH = os.environ.get("EGERIA_WIDTH", 200)
EGERIA_JUPYTER = os.environ.get("EGERIA_JUPYTER", False)
EGERIA_HOME_GLOSSARY_GUID = os.environ.get("EGERIA_HOME_GLOSSARY_GUID", None)


@click.command("create-glossary")
Expand Down Expand Up @@ -125,7 +126,7 @@ def create_glossary(
@click.option("--userid", default=EGERIA_USER, help="Egeria user")
@click.option("--password", default=EGERIA_USER_PASSWORD, help="Egeria user password")
@click.option("--timeout", default=60, help="Number of seconds to wait")
@click.argument("glossary-guid")
@click.argument("glossary-guid", default=EGERIA_HOME_GLOSSARY_GUID)
def delete_glossary(server, url, userid, password, timeout, glossary_guid):
"""Delete the glossary specified"""
m_client = EgeriaTech(server, url, user_id=userid, user_pwd=password)
Expand Down Expand Up @@ -317,7 +318,12 @@ def import_terms(


@click.command("export-terms")
@click.option("--glossary-guid", help="GUID of Glossary to export", required=True)
@click.option(
"--glossary-guid",
default=EGERIA_HOME_GLOSSARY_GUID,
help="GUID of Glossary to export",
required=True,
)
@click.option("--file-name", help="Path of CSV file", required=True)
@click.option("--server", default=EGERIA_VIEW_SERVER, help="Egeria view server to use")
@click.option(
Expand Down
2 changes: 1 addition & 1 deletion pyegeria/commands/cat/list_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
Expand Down
2 changes: 1 addition & 1 deletion pyegeria/commands/cat/list_cert_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
Expand Down
2 changes: 1 addition & 1 deletion pyegeria/commands/cat/list_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
Expand Down
2 changes: 1 addition & 1 deletion pyegeria/commands/cat/list_deployed_catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
Expand Down
2 changes: 1 addition & 1 deletion pyegeria/commands/cat/list_deployed_database_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
Expand Down
2 changes: 1 addition & 1 deletion pyegeria/commands/cat/list_deployed_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
Expand Down
2 changes: 1 addition & 1 deletion pyegeria/commands/cat/list_glossaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
Expand Down
2 changes: 1 addition & 1 deletion pyegeria/commands/cat/list_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_INTEGRATION_DAEMON_URL = os.environ.get(
"EGERIA_INTEGRATION_DAEMON_URL", "https://localhost:9443"
)
Expand Down
2 changes: 1 addition & 1 deletion pyegeria/commands/cat/list_servers_deployed_imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_INTEGRATION_DAEMON_URL = os.environ.get(
"EGERIA_INTEGRATION_DAEMON_URL", "https://localhost:9443"
)
Expand Down
190 changes: 190 additions & 0 deletions pyegeria/commands/cat/list_tech_type_elements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#!/usr/bin/env python3
"""
SPDX-License-Identifier: Apache-2.0
Copyright Contributors to the ODPi Egeria project.
Display the status of cataloged platforms and servers.
"""
import argparse
import os
import sys
import time

import rich.box as box
from rich import print
from rich.console import Console
from rich.markdown import Markdown
from rich.panel import Panel
from rich.prompt import Prompt
from rich.table import Table

from pyegeria import (
InvalidParameterException,
PropertyServerException,
UserNotAuthorizedException,
print_exception_response,
AutomatedCuration,
)

EGERIA_METADATA_STORE = os.environ.get("EGERIA_METADATA_STORE", "active-metadata-store")
EGERIA_KAFKA_ENDPOINT = os.environ.get("KAFKA_ENDPOINT", "localhost:9092")
EGERIA_PLATFORM_URL = os.environ.get("EGERIA_PLATFORM_URL", "https://localhost:9443")
EGERIA_VIEW_SERVER = os.environ.get("VIEW_SERVER", "view-server")
EGERIA_VIEW_SERVER_URL = os.environ.get(
"EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
)
EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration_daemon")
EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
EGERIA_USER_PASSWORD = os.environ.get("EGERIA_USER_PASSWORD", "secret")
EGERIA_JUPYTER = bool(os.environ.get("EGERIA_JUPYTER", "False"))
EGERIA_WIDTH = int(os.environ.get("EGERIA_WIDTH", "200"))


disable_ssl_warnings = True
console = Console(width=200)

guid_list = []


def list_tech_elements(
tech_name: str,
server_name: str,
platform_url: str,
user: str,
user_pass: str,
jupyter: bool = EGERIA_JUPYTER,
width: int = EGERIA_WIDTH,
):
console = Console(width=width, force_terminal=not jupyter)

a_client = AutomatedCuration(server_name, platform_url, user_id=user)
token = a_client.create_egeria_bearer_token(user, user_pass)

def build_classifications(classification: dict) -> Markdown:
class_md = "\n"
for c in classification:
c_type = c["classificationName"]
if c_type == "Anchors":
continue
class_md += f"* Classification: {c_type}\n"
class_props = c.get("classificationProperties", None)
if class_props is None:
continue
for prop in class_props.keys():
class_md += f"\t* {prop}: {class_props[prop]}\n"
if class_md == "-":
output = None
else:
output = class_md
return output

def generate_table() -> Table:
"""Make a new table."""
table = Table(
title=f"Tech Type Elements for {tech_name} @ {time.asctime()}",
caption=f"{platform_url} - {server_name} @ {time.asctime()}",
style="bold bright_white on black",
row_styles=["bold bright_white on black"],
header_style="white on dark_blue",
title_style="bold bright_white on black",
caption_style="white on black",
show_lines=True,
box=box.ROUNDED,
expand=True,
)

table.add_column("Qualified Name/GUID", width=38, no_wrap=True)
table.add_column("Properties", width=40)
table.add_column("Classifications", width=50)

tech_elements = a_client.get_technology_type_elements(
tech_name, get_templates=False
)
if type(tech_elements) is str:
console.print(f"No elements found for {tech_name}")
sys.exit(1)

note: str = " "
for element in tech_elements:
header = element["elementHeader"]
tech_type = header["type"]["typeName"]
tech_collection = header["origin"]["homeMetadataCollectionName"]
tech_created_by = header["versions"]["createdBy"]
tech_created_at = header["versions"]["createTime"]
tech_guid = header["guid"]
tech_classifications = header["classifications"]
class_md = build_classifications(tech_classifications)

referenceables = element["referenceableProperties"]
tech_qualified_name = referenceables["qualifiedName"]
extended = referenceables["extendedProperties"]
ex_md: str = ""
for key, value in extended.items():
ex_md += f"* {key}: {value}\n"

note = (
f"{ex_md}\n"
f"* Created by: {tech_created_by}\n"
f"* Created at: {tech_created_at}\n"
f"* Home Collection: {tech_collection}\n"
)

interfaces = extended.get("connectorInterfaces", None)
if interfaces is not None:
interface_type_name = interfaces["typeName"]
interface_array_cnt = interfaces["arrayCount"]
note += f"* Interface Type: {interface_type_name}\n"
for i in range(0, int(interface_array_cnt)):
note += (
f"\t* Type: {interfaces['arrayValues']['propertyValueMap'][str(i)]['typeName']}"
f"\tName: {interfaces['arrayValues']['propertiesAsStrings'][str(i)]}\n"
)
note_md = Markdown(note)
qn = Markdown(f"\n{tech_qualified_name}\n \n--- \n\n\n{tech_guid}")
cm = Markdown(class_md)
table.add_row(qn, note_md, cm)
return table

try:
console = Console(width=width, force_terminal=not jupyter)

with console.pager(styles=True):
console.print(generate_table())

except (
InvalidParameterException,
PropertyServerException,
UserNotAuthorizedException,
) as e:
print_exception_response(e)
print("\n\nPerhaps the type name isn't known")
finally:
a_client.close_session()


def main():
parser = argparse.ArgumentParser()

parser.add_argument("--server", help="Name of the server to display status for")
parser.add_argument("--url", help="URL Platform to connect to")
parser.add_argument("--userid", help="User Id")
parser.add_argument("--password", help="User Password")
args = parser.parse_args()

server = args.server if args.server is not None else EGERIA_VIEW_SERVER
url = args.url if args.url is not None else EGERIA_PLATFORM_URL
userid = args.userid if args.userid is not None else EGERIA_USER
user_pass = args.password if args.password is not None else EGERIA_USER_PASSWORD
try:
tech_name = Prompt.ask(
"Enter the tech type to view:", default="PostgreSQL Server"
)
list_tech_elements(tech_name, server, url, userid, user_pass)
except KeyboardInterrupt:
pass


if __name__ == "__main__":
main()
Loading

0 comments on commit de083c8

Please sign in to comment.