Ejemplo n.º 1
0
def retrieve_auth():
    """Searches the env for auth, prompting the user if necessary.

    On success, return (wc_kwargs, mm_kwargs). On failure, raise ValueError."""

    get_kwargs = lambda envargs: dict([(arg.kwarg, os.environ.get(arg.envarg))
                                       for arg in envargs])

    wc_kwargs = get_kwargs(wc_envargs)
    mm_kwargs = get_kwargs(mm_envargs)

    if not all([wc_kwargs[arg] for arg in ('email', 'password')]):
        if os.environ.get('TRAVIS'):
            print 'on Travis but could not read auth from environ; quitting.'
            sys.exit(1)

        wc_kwargs.update(zip(['email', 'password'], prompt_for_wc_auth()))

    if mm_kwargs['oauth_credentials'] is None:
        # ignoring race
        if not os.path.isfile(OAUTH_FILEPATH):
            raise ValueError(
                "You must have oauth credentials stored at the default"
                " path by Musicmanager.perform_oauth prior to running.")
        del mm_kwargs['oauth_credentials']  # mm default is not None
    else:
        mm_kwargs['oauth_credentials'] = \
            credentials_from_refresh_token(mm_kwargs['oauth_credentials'])

    return (wc_kwargs, mm_kwargs)
Ejemplo n.º 2
0
def retrieve_auth():
    """Searches the env for auth, prompting the user if necessary.

    On success, return (mc_kwargs, mm_kwargs). On failure, raise ValueError."""

    def get_kwargs(envargs):
        return dict([(arg.kwarg, os.environ.get(arg.envarg))
                     for arg in envargs])

    mc_kwargs = get_kwargs(mc_envargs)
    mm_kwargs = get_kwargs(mm_envargs)

    if not all([mc_kwargs[arg] for arg in ('email', 'password', 'android_id')]):
        if os.environ.get('TRAVIS'):
            print('on Travis but could not read auth from environ; quitting.')
            sys.exit(1)

        mc_kwargs.update(zip(['email', 'password', 'android_id'], prompt_for_mc_auth()))

    if mm_kwargs['oauth_credentials'] is None:
        # ignoring race
        if not os.path.isfile(OAUTH_FILEPATH):
            raise ValueError("You must have oauth credentials stored at the default"
                             " path by Musicmanager.perform_oauth prior to running.")
        del mm_kwargs['oauth_credentials']  # mm default is not None
    else:
        mm_kwargs['oauth_credentials'] = \
            credentials_from_refresh_token(mm_kwargs['oauth_credentials'])

    return (mc_kwargs, mm_kwargs)
Ejemplo n.º 3
0
def retrieve_auth():
    """Searches the env for auth, prompting the user if necessary.

    On success, return (wc_kwargs, mc_kwargs, mm_kwargs). On failure, raise ValueError."""

    def get_kwargs(envargs):
        return dict([(arg.kwarg, os.environ.get(arg.envarg))
                     for arg in envargs])

    wc_kwargs = get_kwargs(wc_envargs)
    mm_kwargs = get_kwargs(mm_envargs)

    if not all([wc_kwargs[arg] for arg in ('email', 'password')]):
        if os.environ.get('TRAVIS'):
            print('on Travis but could not read auth from environ; quitting.')
            sys.exit(1)

        wc_kwargs.update(zip(['email', 'password'], prompt_for_wc_auth()))

    if mm_kwargs['oauth_credentials'] is None:
        # ignoring race
        if not os.path.isfile(OAUTH_FILEPATH):
            raise ValueError("You must have oauth credentials stored at the default"
                             " path by Musicmanager.perform_oauth prior to running.")
        del mm_kwargs['oauth_credentials']  # mm default is not None
    else:
        mm_kwargs['oauth_credentials'] = \
            credentials_from_refresh_token(mm_kwargs['oauth_credentials'])

    mc_kwargs = wc_kwargs.copy()

    try:
        android_id = os.environ['GM_AA_D_ID']
    except KeyError:
        android_id = input("Device ID ('mac' for FROM_MAC_ADDRESS): ")

    if android_id == "mac":
        android_id = Mobileclient.FROM_MAC_ADDRESS

    if not android_id:
        print('a device id must be provided')
        sys.exit(1)

    mc_kwargs['android_id'] = android_id

    return (wc_kwargs, mc_kwargs, mm_kwargs)
Ejemplo n.º 4
0
def retrieve_auth():
    """Searches the env for auth, prompting the user if necessary.

    On success, return (wc_kwargs, mc_kwargs, mm_kwargs). On failure, raise ValueError."""

    def get_kwargs(envargs):
        return dict([(arg.kwarg, os.environ.get(arg.envarg)) for arg in envargs])

    wc_kwargs = get_kwargs(wc_envargs)
    mm_kwargs = get_kwargs(mm_envargs)

    if not all([wc_kwargs[arg] for arg in ("email", "password")]):
        if os.environ.get("TRAVIS"):
            print "on Travis but could not read auth from environ; quitting."
            sys.exit(1)

        wc_kwargs.update(zip(["email", "password"], prompt_for_wc_auth()))

    if mm_kwargs["oauth_credentials"] is None:
        # ignoring race
        if not os.path.isfile(OAUTH_FILEPATH):
            raise ValueError(
                "You must have oauth credentials stored at the default"
                " path by Musicmanager.perform_oauth prior to running."
            )
        del mm_kwargs["oauth_credentials"]  # mm default is not None
    else:
        mm_kwargs["oauth_credentials"] = credentials_from_refresh_token(mm_kwargs["oauth_credentials"])

    if "GM_AA_D_ID" not in os.environ:
        print "an android id must be provided in the env var GM_AA_D_ID"
        sys.exit(1)

    mc_kwargs = wc_kwargs.copy()
    mc_kwargs["android_id"] = os.environ["GM_AA_D_ID"]

    return (wc_kwargs, mc_kwargs, mm_kwargs)
Ejemplo n.º 5
0
def freeze_login_details():
    """Searches the environment for credentials, and freezes them to
    client.login if found.

    If no auth is present in the env, the user is prompted. OAuth is read from
    the default path.

    If running on Travis, the prompt will never be fired; sys.exit is called
    if the envvars are not present.
    """

    #Attempt to get auth from environ.
    user, passwd, refresh_tok = [
        os.environ.get(name) for name in ('GM_USER', 'GM_PASS', 'GM_OAUTH')
    ]

    on_travis = os.environ.get('TRAVIS')

    mm_kwargs = {}
    wc_kwargs = {}

    has_env_auth = user and passwd and refresh_tok

    if not has_env_auth and on_travis:
        print 'on Travis but could not read auth from environ; quitting.'
        sys.exit(1)

    if os.environ.get('TRAVIS'):
        #Travis runs on VMs with no "real" mac - we have to provide one.
        mm_kwargs.update({
            'uploader_id': travis_id,
            'uploader_name': travis_name
        })

    if has_env_auth:
        wc_kwargs.update({'email': user, 'password': passwd})

        # mm expects a full OAuth2Credentials object
        credentials = credentials_from_refresh_token(refresh_tok)
        mm_kwargs.update({'oauth_credentials': credentials})

    else:
        # no travis, no credentials

        # we need to login here to verify their credentials.
        # the authenticated api is then thrown away.

        wclient = Webclient()
        valid_auth = False

        print(
            "These tests will never delete or modify your music."
            "\n\n"
            "If the tests fail, you *might* end up with a test"
            " song/playlist in your library, though."
            "You must have oauth credentials stored at the default"
            " path by Musicmanager.perform_oauth prior to running.")

        while not valid_auth:
            print
            email = raw_input("Email: ")
            passwd = getpass()

            valid_auth = wclient.login(email, passwd)

        wc_kwargs.update({'email': email, 'password': passwd})

    # globally freeze our params in place.
    # they can still be overridden manually; they're just the defaults now.
    Musicmanager.login = MethodType(
        update_wrapper(partial(Musicmanager.login, **mm_kwargs),
                       Musicmanager.login), None, Musicmanager)

    Webclient.login = MethodType(
        update_wrapper(partial(Webclient.login, **wc_kwargs), Webclient.login),
        None, Webclient)
Ejemplo n.º 6
0
def freeze_login_details():
    """Searches the environment for credentials, and freezes them to
    client.login if found.

    If no auth is present in the env, the user is prompted. OAuth is read from
    the default path.

    If running on Travis, the prompt will never be fired; sys.exit is called
    if the envvars are not present.
    """

    #Attempt to get auth from environ.
    user, passwd, refresh_tok = [os.environ.get(name) for name in
                                 ('GM_USER',
                                  'GM_PASS',
                                  'GM_OAUTH')]

    on_travis = os.environ.get('TRAVIS')

    mm_kwargs = {}
    wc_kwargs = {}

    has_env_auth = user and passwd and refresh_tok

    if not has_env_auth and on_travis:
        print 'on Travis but could not read auth from environ; quitting.'
        sys.exit(1)

    if os.environ.get('TRAVIS'):
        #Travis runs on VMs with no "real" mac - we have to provide one.
        mm_kwargs.update({'uploader_id': travis_id,
                          'uploader_name': travis_name})

    if has_env_auth:
        wc_kwargs.update({'email': user, 'password': passwd})

        # mm expects a full OAuth2Credentials object
        credentials = credentials_from_refresh_token(refresh_tok)
        mm_kwargs.update({'oauth_credentials': credentials})

    else:
        # no travis, no credentials

        # we need to login here to verify their credentials.
        # the authenticated api is then thrown away.

        wclient = Webclient()
        valid_auth = False

        print ("These tests will never delete or modify your music."
               "\n\n"
               "If the tests fail, you *might* end up with a test"
               " song/playlist in your library, though."
               "You must have oauth credentials stored at the default"
               " path by Musicmanager.perform_oauth prior to running.")

        while not valid_auth:
            print
            email = raw_input("Email: ")
            passwd = getpass()

            valid_auth = wclient.login(email, passwd)

        wc_kwargs.update({'email': email, 'password': passwd})

    # globally freeze our params in place.
    # they can still be overridden manually; they're just the defaults now.
    Musicmanager.login = MethodType(
        update_wrapper(partial(Musicmanager.login, **mm_kwargs), Musicmanager.login),
        None, Musicmanager
    )

    Webclient.login = MethodType(
        update_wrapper(partial(Webclient.login, **wc_kwargs), Webclient.login),
        None, Webclient
    )