Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect and update API #11

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading