-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from launchableinc/add_verify_command
Implement a verify command
- Loading branch information
Showing
4 changed files
with
77 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |