Exemplo n.º 1
0
def open_nexus_web():
    base_url = utils.get_selected_deployment_config()[1][URL_KEY]
    print(
        "A browser window will now open, please login, copy your token and use the 'set-token' command "
        "to store it in the CLI")
    input("Press ENTER to continue...")
    webbrowser.open_new(base_url.strip("/v1") + "/web")
Exemplo n.º 2
0
def open_nexus_web():
    # TODO investigate more user friendly ways to login
    # TODO e.g. https://github.com/burnash/gspread/wiki/How-to-get-OAuth-access-token-in-console%3F
    base_url = utils.get_selected_deployment_config()[1][_URL_KEY_]
    print("A browser window will now open, please login, copy your token and use the auth set-token command "
          "to store it in the CLI")
    input("Press ENTER to continue...")
    webbrowser.open_new(base_url.strip("/v1") + "/web")
Exemplo n.º 3
0
def interactive_login(realm_label):
    """Logs in interactively."""
    env, config = utils.get_selected_deployment_config()
    if config is not None and URL_KEY in config:
        nxs.config.set_environment(config[URL_KEY])
    else:
        utils.error(
            "You must first select a profile using the 'profiles' command")

    issuer = ''
    if realm_label:
        try:
            response = nxs.realms.fetch(realm_label)
            issuer = response['_issuer']
        except nxs.HTTPError as e:
            print(e.response.json())
            utils.error(str(e))
    else:
        realm = utils.get_default_realm()
        if realm is None:
            realm = _select_realm()
            issuer = realm['_issuer']
            label = realm['_label']
            print("Saving realm '%s' in your profile" % realm['_label'])
            utils.set_default_realm(label, issuer)
        else:
            issuer = realm['_issuer']
            print(
                "Using default realm '%s' set in your profile. Use --realm to override."
                % realm['_label'])

    default_client_id = utils.get_default_client_id()
    client_id = input("Please enter the client ID [%s]: " % default_client_id)
    if not client_id:
        client_id = default_client_id
    utils.set_default_client_id(client_id)

    detected_user = getpass.getuser()
    username = input("Username [%s]: " % detected_user)
    if not username:
        username = detected_user
    password = getpass.getpass()
    try:
        url, name = issuer.split("realms/")
        keycloak_openid = KeycloakOpenID(server_url=url,
                                         client_id=client_id,
                                         realm_name=name,
                                         verify=True)
        response = keycloak_openid.token(username, password)
        token = response['access_token']
        _set_token(token)
        utils.success(
            "Authentication successful. Use 'view-token' to show your credentials."
        )
    except KeycloakError as e:
        utils.error("Authentication failed: %s" % e)
Exemplo n.º 4
0
def current():
    config = utils.get_cli_config()
    profile, selected_config = utils.get_selected_deployment_config(config)
    if selected_config is None:
        utils.error("You must first select a profile using the 'profiles' command")

    default_project = utils.get_default_project()
    if default_project is not None:
        print(default_project)
    else:
        utils.error("No default project selected in profile '%s'" % profile)