Skip to content

Commit

Permalink
access-token
Browse files Browse the repository at this point in the history
  • Loading branch information
romekodexa committed Mar 22, 2024
1 parent 510eef9 commit 7b3375b
Showing 1 changed file with 39 additions and 25 deletions.
64 changes: 39 additions & 25 deletions kodexa_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@
}


def get_current_kodexa_url():
try:
return KodexaPlatform.get_url()
except:
return ""


def get_current_access_token():
try:
return KodexaPlatform.get_access_token()
except:
return ""


@contextmanager
def set_directory(path: Path):
"""Sets the cwd within the context
Expand Down Expand Up @@ -194,7 +208,7 @@ def safe_entry_point():
start_time = datetime.now().replace(microsecond=0)

try:
print(f"Using profile {KodexaPlatform.get_current_profile()} @ {KodexaPlatform.get_url()}\n")
print(f"Using profile {KodexaPlatform.get_current_profile()} @ {get_current_kodexa_url()}\n")
except:
print("Unable to load profile")

Expand All @@ -220,10 +234,10 @@ def safe_entry_point():
@click.argument("ref", required=True)
@click.argument("paths", required=True, nargs=-1)
@click.option(
"--url", default=KodexaPlatform.get_url(), help="The URL to the Kodexa server"
"--url", default=get_current_kodexa_url(), help="The URL to the Kodexa server"
)
@click.option("--threads", default=5, help="Number of threads to use")
@click.option("--token", default=KodexaPlatform.get_access_token(), help="Access token")
@click.option("--token", default=get_current_access_token(), help="Access token")
@pass_info
def upload(_: Info, ref: str, paths: list[str], token: str, url: str, threads: int):
"""
Expand Down Expand Up @@ -287,9 +301,9 @@ def upload_file(path):
default=False,
)
@click.option(
"--url", default=KodexaPlatform.get_url(), help="The URL to the Kodexa server"
"--url", default=get_current_kodexa_url(), help="The URL to the Kodexa server"
)
@click.option("--token", default=KodexaPlatform.get_access_token(), help="Access token")
@click.option("--token", default=get_current_access_token(), help="Access token")
@click.option(
"--format", default=None, help="The format to input if from stdin (json, yaml)"
)
Expand Down Expand Up @@ -418,9 +432,9 @@ def deploy_obj(obj):
@cli.command()
@click.argument("execution_id", required=True)
@click.option(
"--url", default=KodexaPlatform.get_url(), help="The URL to the Kodexa server"
"--url", default=get_current_kodexa_url(), help="The URL to the Kodexa server"
)
@click.option("--token", default=KodexaPlatform.get_access_token(), help="Access token")
@click.option("--token", default=get_current_access_token(), help="Access token")
@pass_info
def logs(_: Info, execution_id: str, url: str, token: str):
"""
Expand All @@ -443,9 +457,9 @@ def logs(_: Info, execution_id: str, url: str, token: str):
@click.argument("ref", required=True)
@click.argument("output_file", required=False, default="model_implementation")
@click.option(
"--url", default=KodexaPlatform.get_url(), help="The URL to the Kodexa server"
"--url", default=get_current_kodexa_url(), help="The URL to the Kodexa server"
)
@click.option("--token", default=KodexaPlatform.get_access_token(), help="Access token")
@click.option("--token", default=get_current_access_token(), help="Access token")
@pass_info
def download_implementation(_: Info, ref: str, output_file: str, url: str, token: str):
"""
Expand All @@ -461,9 +475,9 @@ def download_implementation(_: Info, ref: str, output_file: str, url: str, token
@click.argument("object_type", required=True)
@click.argument("ref", required=False)
@click.option(
"--url", default=KodexaPlatform.get_url(), help="The URL to the Kodexa server"
"--url", default=get_current_kodexa_url(), help="The URL to the Kodexa server"
)
@click.option("--token", default=KodexaPlatform.get_access_token(), help="Access token")
@click.option("--token", default=get_current_access_token(), help="Access token")
@click.option("--query", default="*", help="Limit the results using a query")
@click.option("--format", default=None, help="The format to output (json, yaml)")
@click.option("--page", default=1, help="Page number")
Expand Down Expand Up @@ -615,9 +629,9 @@ def print_object_table(object_metadata, objects_endpoint, query, page, pagesize,
@click.argument("ref", required=True)
@click.argument("query", nargs=-1)
@click.option(
"--url", default=KodexaPlatform.get_url(), help="The URL to the Kodexa server"
"--url", default=get_current_kodexa_url(), help="The URL to the Kodexa server"
)
@click.option("--token", default=KodexaPlatform.get_access_token(), help="Access token")
@click.option("--token", default=get_current_access_token(), help="Access token")
@click.option(
"--download/--no-download",
default=False,
Expand Down Expand Up @@ -823,9 +837,9 @@ def process_family(document_family):
@cli.command()
@click.argument("project_id", required=True)
@click.option(
"--url", default=KodexaPlatform.get_url(), help="The URL to the Kodexa server"
"--url", default=get_current_kodexa_url(), help="The URL to the Kodexa server"
)
@click.option("--token", default=KodexaPlatform.get_access_token(), help="Access token")
@click.option("--token", default=get_current_access_token(), help="Access token")
@click.option("--output", help="The path to export to")
@pass_info
def export_project(_: Info, project_id: str, url: str, token: str, output: str):
Expand All @@ -843,9 +857,9 @@ def export_project(_: Info, project_id: str, url: str, token: str, output: str):
@click.argument("org_slug", required=True)
@click.argument("path", required=True)
@click.option(
"--url", default=KodexaPlatform.get_url(), help="The URL to the Kodexa server"
"--url", default=get_current_kodexa_url(), help="The URL to the Kodexa server"
)
@click.option("--token", default=KodexaPlatform.get_access_token(), help="Access token")
@click.option("--token", default=get_current_access_token(), help="Access token")
@pass_info
def import_project(_: Info, org_slug: str, url: str, token: str, path: str):
"""
Expand All @@ -870,9 +884,9 @@ def import_project(_: Info, org_slug: str, url: str, token: str, path: str):
@click.argument("project_id", required=True)
@click.argument("assistant_id", required=True)
@click.option(
"--url", default=KodexaPlatform.get_url(), help="The URL to the Kodexa server"
"--url", default=get_current_kodexa_url(), help="The URL to the Kodexa server"
)
@click.option("--token", default=KodexaPlatform.get_access_token(), help="Access token")
@click.option("--token", default=get_current_access_token(), help="Access token")
@click.option("--file", help="The path to the file containing the event to send")
@click.option(
"--format", default=None, help="The format to use if from stdin (json, yaml)"
Expand Down Expand Up @@ -940,13 +954,13 @@ def platform(_: Info, python: bool, show_token: bool):
"""

print(f"Profile: {KodexaPlatform.get_current_profile()}")
platform_url = KodexaPlatform.get_url()
platform_url = get_current_kodexa_url()

if platform_url is not None:
print(f"URL: {KodexaPlatform.get_url()}")
print(f"URL: {get_current_kodexa_url()}")

if show_token:
print(f"Access Token: {KodexaPlatform.get_access_token()}")
print(f"Access Token: {get_current_access_token()}")
kodexa_version = KodexaPlatform.get_server_info()
print(f"Environment: {kodexa_version['environment']}")
print(f"Version: {kodexa_version['version']}")
Expand All @@ -955,7 +969,7 @@ def platform(_: Info, python: bool, show_token: bool):
print("\nPython example:\n\n")
print(f"from kodexa import KodexaClient")
print(
f"client = KodexaClient('{KodexaPlatform.get_url()}', '{KodexaPlatform.get_access_token()}')"
f"client = KodexaClient('{get_current_kodexa_url()}', '{get_current_access_token()}')"
)
else:
print("Kodexa is not logged in")
Expand All @@ -965,9 +979,9 @@ def platform(_: Info, python: bool, show_token: bool):
@click.argument("object_type")
@click.argument("ref")
@click.option(
"--url", default=KodexaPlatform.get_url(), help="The URL to the Kodexa server"
"--url", default=get_current_kodexa_url(), help="The URL to the Kodexa server"
)
@click.option("--token", default=KodexaPlatform.get_access_token(), help="Access token")
@click.option("--token", default=get_current_access_token(), help="Access token")
@pass_info
def delete(_: Info, object_type: str, ref: str, url: str, token: str):
"""
Expand Down

0 comments on commit 7b3375b

Please sign in to comment.