# Path: alertaclient/auth/github.py
# def login(client, github_url, client_id):
# 
# Path: alertaclient/auth/utils.py
# def save_token(endpoint, username, token):
#     with open(NETRC_FILE, 'a'):  # touch file
#         pass
#     try:
#         info = netrc(NETRC_FILE)
#     except Exception as e:
#         raise ConfigurationError(f'{e}')
#     info.hosts[machine(endpoint)] = (username, None, token)
#     with open(NETRC_FILE, 'w') as f:
#         f.write(dump_netrc(info))


import sys
import click
from alertaclient.auth import azure, github, gitlab, google, oidc
from alertaclient.auth.token import Jwt
from alertaclient.auth.utils import save_token
from alertaclient.exceptions import AuthError




@click.command('login', short_help='Login with user credentials')
@click.argument('username', required=False)
@click.pass_obj
def cli(obj, username):
    """Authenticate using Azure, Github, Gitlab, Google OAuth2, OpenID or
    Basic Auth username/password instead of using an API key."""
    client = obj['client']
    provider = obj['provider']
    client_id = obj['client_id']

    try:
        if provider == 'azure':

# Path: alertaclient/auth/github.py
# def login(client, github_url, client_id):
# 
# Path: alertaclient/auth/utils.py
# def save_token(endpoint, username, token):
#     with open(NETRC_FILE, 'a'):  # touch file
#         pass
#     try:
#         info = netrc(NETRC_FILE)
#     except Exception as e:
#         raise ConfigurationError(f'{e}')
#     info.hosts[machine(endpoint)] = (username, None, token)
#     with open(NETRC_FILE, 'w') as f:
#         f.write(dump_netrc(info))


# Path: alertaclient/commands/cmd_login.py
import sys
import click
from alertaclient.auth import azure, github, gitlab, google, oidc
from alertaclient.auth.token import Jwt
from alertaclient.auth.utils import save_token
from alertaclient.exceptions import AuthError





@click.command('login', short_help='Login with user credentials')
@click.argument('username', required=False)
@click.pass_obj
def cli(obj, username):
    """Authenticate using Azure, Github, Gitlab, Google OAuth2, OpenID or
    Basic Auth username/password instead of using an API key."""
    client = obj['client']
    provider = obj['provider']
    client_id = obj['client_id']

    try:
        if provider == 'azure':

            token = azure.login(client, obj['azure_tenant'], client_id)['token']