Skip to content

Commit

Permalink
some PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mmorgantaylor committed Oct 16, 2024
1 parent e1581fa commit a3c9f6b
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ gha-creds-*.json
### jEnv
.java-version

### Python ###
### Python CLI ###
/teaspoons-cli/teaspoons/__pycache__/
/teaspoons-cli/teaspoons/**/__pycache__/
/teaspoons-cli/venv/
Expand Down
3 changes: 3 additions & 0 deletions teaspoons-cli/.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Teaspoons API URL
TEASPOONS_API_URL=https://tsps.dsde-dev.broadinstitute.org

# Port to use for local server (for auth)
SERVER_PORT=10444

# Oauth config stuff
OAUTH_OPENID_CONFIGURATION_URI=https://terradevb2c.b2clogin.com/terradevb2c.onmicrosoft.com/b2c_1a_signup_signin_dev/v2.0/.well-known/openid-configuration
OAUTH_CLIENT_ID=bbd07d43-01cb-4b69-8fd0-5746d9a5c9fe
Expand Down
2 changes: 1 addition & 1 deletion teaspoons-cli/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2022, Broad Institute
Copyright (c) 2024, Broad Institute
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# auth_helper.py

import jwt
import os
Expand All @@ -9,6 +10,9 @@
from config import CliConfig


cli_config = CliConfig() # initialize the config from environment variables


def get_auth_url(client_info: OAuth2ClientInfo, redirect_uri: str) -> str:
"""
Note: this is overridden from then oauth2-cli-auth library to be able to specify a custom auth url
Expand All @@ -27,9 +31,9 @@ def get_auth_url(client_info: OAuth2ClientInfo, redirect_uri: str) -> str:
f"&prompt=login")


def get_access_token_with_browser_open(client_info: OAuth2ClientInfo, server_port: int = 8080) -> str:
def get_access_token_with_browser_open(client_info: OAuth2ClientInfo, server_port: int = cli_config.server_port) -> str:
"""
Note: this is overriden from then oauth2-cli-auth library to use the custom auth url
Note: this is overridden from the oauth2-cli-auth library to use a custom auth url
Provides a simplified API to:
Expand Down
2 changes: 2 additions & 0 deletions teaspoons-cli/teaspoons/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# cli.py

import typer
from commands.auth import auth_app
from commands.pipelines import pipelines_app
Expand Down
4 changes: 3 additions & 1 deletion teaspoons-cli/teaspoons/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# client.py

from generated.teaspoons_client import Configuration, ApiClient
from config import CliConfig
from auth import _load_local_token
from auth_helper import _load_local_token

cli_config = CliConfig() # initialize the config from environment variables

Expand Down
11 changes: 7 additions & 4 deletions teaspoons-cli/teaspoons/commands/auth.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# auth.py

import typer
import click

from auth import get_access_token_with_browser_open, _validate_token, _save_local_token, _load_local_token, _clear_local_token
from auth_helper import get_access_token_with_browser_open, _validate_token, _save_local_token, _load_local_token, _clear_local_token
from config import CliConfig


cli_config = CliConfig() # initialize the config from environment variables

auth_app = typer.Typer()


@auth_app.command()
def login():
token = _load_local_token(cli_config.token_file)
if token and _validate_token(token):
click.echo('Already authenticated')
return
token = get_access_token_with_browser_open(cli_config.client_info, server_port=10444)
token = get_access_token_with_browser_open(cli_config.client_info)
_save_local_token(cli_config.token_file, token)


@auth_app.command()
def logout():
_clear_local_token(cli_config.token_file)
click.echo('Logged out')
click.echo('Logged out')
2 changes: 2 additions & 0 deletions teaspoons-cli/teaspoons/commands/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# teaspoons modules
from client import ClientWrapper
from utils import _pretty_print

pipelines_app = typer.Typer()


Expand All @@ -23,6 +24,7 @@ def list():
click.echo(str(e), err=True)
exit(1)


@pipelines_app.command()
@click.argument('name')
def get_info(name: str):
Expand Down
2 changes: 2 additions & 0 deletions teaspoons-cli/teaspoons/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def __init__(self):
scopes=[f"openid+email+profile+{self.config['OAUTH_CLIENT_ID']}"]
)

self.server_port = int(self.config["SERVER_PORT"])

# Figure out the path to the token file...there must be some way to abstract out local storage
if self.config["LOCAL_STORAGE_PATH"].startswith("/"):
self.token_file = f"{self.config['LOCAL_STORAGE_PATH']}/access_token"
Expand Down
2 changes: 2 additions & 0 deletions teaspoons-cli/teaspoons/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# utils.py

import click
import json

Expand Down

0 comments on commit a3c9f6b

Please sign in to comment.