Skip to content

Commit

Permalink
Merge pull request #11 from cased/login-updates
Browse files Browse the repository at this point in the history
Connect and update API
  • Loading branch information
tnm authored Oct 15, 2024
2 parents 988fe74 + 735c8c8 commit e5d244a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions cased/commands/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,18 @@ def login():
"""
console.print(Panel("Welcome to Cased CLI", style="bold blue"))

org_name = Prompt.ask("Enter your organization name")
api_key = Prompt.ask("Enter your API key", password=True)
org_name = click.prompt("Enter your organization name")
api_key = click.prompt("Enter your API key")

with Progress() as progress:
task = progress.add_task("[cyan]Validating credentials...", total=100)

# Simulate API call with progress
for i in range(0, 101, 10):
progress.update(task, advance=10)
if i == 50:
response = validate_tokens(api_key, org_name)
progress.update(task, completed=100)
progress.update(task, advance=50)
response = validate_tokens(api_key, org_name)
progress.update(task, completed=100)

# 200 would mean success,
# 403 would mean validation success but necessary integration is not set up.
# (E.g. Github)
if response.status_code == 200 or response.status_code == 403:
data = response.json()
elif response.status_code == 401:
Expand Down Expand Up @@ -100,8 +96,11 @@ def login():
CasedConstants.CASED_ORG_ID: org_id,
CasedConstants.CASED_ORG_NAME: org_name,
}

save_config(data)

console.print(Panel("[bold green]Login successful![/bold green]", expand=False))

# Ask user to select a project.
ctx = click.get_current_context()
ctx.invoke(projects, details=False)
Expand Down
3 changes: 1 addition & 2 deletions cased/utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class CasedAPI:
def __init__(self):
configs = load_config(CasedConstants.ENV_FILE)
self.request_headers = {
"X-CASED-API-KEY": str(configs.get(CasedConstants.CASED_API_AUTH_KEY)),
"X-CASED-ORG-ID": str(configs.get(CasedConstants.CASED_ORG_ID)),
"Authorization": f"Bearer {str(configs.get(CasedConstants.CASED_API_AUTH_KEY))}",
"Accept": "application/json",
}

Expand Down
1 change: 1 addition & 0 deletions cased/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def save_config(
):
os.makedirs(config_dir, mode=0o700, exist_ok=True)
current_config = load_config(file_name)

if not current_config:
current_config = {}
current_config.update(data)
Expand Down

0 comments on commit e5d244a

Please sign in to comment.