Skip to content

Commit

Permalink
Merge pull request #47 from launchableinc/add_verify_command
Browse files Browse the repository at this point in the history
Implement a verify command
  • Loading branch information
shuheiktgw authored Dec 7, 2020
2 parents 4040fe2 + 78fe1f4 commit eb99e0b
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 8 deletions.
2 changes: 2 additions & 0 deletions launchable/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .version import __version__
import click
from .commands.record import record
from .commands.verify import verify


@click.group()
Expand All @@ -10,6 +11,7 @@ def main():


main.add_command(record)
main.add_command(verify)

if __name__ == '__main__':
main()
13 changes: 5 additions & 8 deletions launchable/commands/record/commit.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os

import click
from ...utils.ingester_image import ingester_image
import subprocess

from ...utils.env_keys import REPORT_ERROR_KEY
from ...utils.http_client import get_base_url
from ...utils.ingester_image import ingester_image
from ...utils.java import get_java_command

jar_file_path = os.path.normpath(os.path.join(
os.path.dirname(__file__), "../../jar/exe_deploy.jar"))
Expand Down Expand Up @@ -36,12 +38,7 @@ def commit(source, executable):


def exec_jar(source):
res = subprocess.run(["which", "java"], stdout=subprocess.DEVNULL)
java = None
if res.returncode == 0:
java = "java"
elif os.access(os.path.expandvars("$JAVA_HOME/bin/java"), os.X_OK):
java = "$JAVA_HOME/bin/java"
java = get_java_command()

if not java:
exit("You need to install Java or try --executable docker")
Expand Down
57 changes: 57 additions & 0 deletions launchable/commands/verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os

import click
import platform

from ..utils.env_keys import REPORT_ERROR_KEY
from ..utils.http_client import LaunchableClient
from ..utils.token import parse_token
from ..utils.java import get_java_command

@click.command(name="verify")
def verify():
try:
if os.getenv("LAUNCHABLE_TOKEN") is None:
click.echo(click.style("Could not find the LAUNCHABLE_TOKEN environment variable. Please check if you "
"set it properly.", fg="red"))
return

token, org, workspace = parse_token()

headers = {
"Content-Type": "application/json",
}

path = "/intake/organizations/{}/workspaces/{}/verification".format(
org, workspace)

client = LaunchableClient(token)
res = client.request("get", path, headers=headers)

if res.status_code == 401:
click.echo(click.style("Authentication failed. Most likely the value for the LAUNCHABLE_TOKEN "
"environment variable is invalid.", fg="red"))
return

res.raise_for_status()

click.echo("Platform: " + platform.platform())
click.echo("Python version: " + platform.python_version())

java = get_java_command()

if java is None:
click.echo(click.style(
"Java is not installed. You need Java to use the Launchable CLI.", fg="red"))
return

click.echo("Java command: " + java)

click.echo(click.style(
"Your CLI configuration is successfully verified \U0001f389", fg="green"))

except Exception as e:
if os.getenv(REPORT_ERROR_KEY):
raise e
else:
print(e)
13 changes: 13 additions & 0 deletions launchable/utils/java.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os
import subprocess


def get_java_command():
res = subprocess.run(["which", "java"], stdout=subprocess.DEVNULL)
if res.returncode == 0:
return "java"

if os.access(os.path.expandvars("$JAVA_HOME/bin/java"), os.X_OK):
return "$JAVA_HOME/bin/java"

return None

0 comments on commit eb99e0b

Please sign in to comment.