Exemplo n.º 1
0
def generate_session_token(hostname, login, password, http_proxy):
    """
    Generates a session token for a given username/password on a given site.

    :param hostname: The host to connect to.
    :param login: The user to get a session for.
    :param password: Password for the user.
    :param http_proxy: Proxy to use. Can be None.

    :returns: The generated session token for that user/password/site combo.

    :raises: AuthenticationError if the credentials were invalid.
    """
    try:
        # Create the instance taht does not connect right away for speed...
        sg = Shotgun(hostname,
                     login=login,
                     password=password,
                     http_proxy=http_proxy,
                     connect=False)
        # .. and generate the session token. If it throws, we have invalid
        # credentials or invalid host/proxy settings.
        return sg.get_session_token()
    except AuthenticationFault:
        raise AuthenticationError("Authentication failed.")
    except (ProtocolError, httplib2.ServerNotFoundError):
        raise AuthenticationError("Server %s was not found." % hostname)
    except:
        logger.exception("There was a problem logging in.")
        raise
def generate_session_token(hostname, login, password, http_proxy):
    """
    Generates a session token for a given username/password on a given site.

    :param hostname: The host to connect to.
    :param login: The user to get a session for.
    :param password: Password for the user.
    :param http_proxy: Proxy to use. Can be None.

    :returns: The generated session token for that user/password/site combo.

    :raises: AuthenticationError if the credentials were invalid.
    """
    try:
        # Create the instance taht does not connect right away for speed...
        sg = Shotgun(
            hostname,
            login=login,
            password=password,
            http_proxy=http_proxy,
            connect=False
        )
        # .. and generate the session token. If it throws, we have invalid
        # credentials or invalid host/proxy settings.
        return sg.get_session_token()
    except AuthenticationFault:
        raise AuthenticationError("Authentication failed.")
    except (ProtocolError, httplib2.ServerNotFoundError):
        raise AuthenticationError("Server %s was not found." % hostname)
    except:
        logger.exception("There was a problem logging in.")
        raise
Exemplo n.º 3
0
def generate_session_token(hostname,
                           login,
                           password,
                           http_proxy,
                           auth_token=None):
    """
    Generates a session token for a given username/password on a given site.

    :param hostname: The host to connect to.
    :param login: The user to get a session for.
    :param password: Password for the user.
    :param http_proxy: Proxy to use. Can be None.
    :param auth_token: Two factor authentication token for the user. Can be None.

    :returns: The generated session token for that user/password/auth_token/site combo.

    :raises AuthenticationError: Raised when the user information is invalid.
    :raises MissingTwoFactorAuthenticationFault: Raised when missing a two factor authentication
        code or backup code.
    :raises Exception: Raised when a network error occurs.
    """
    try:
        # Create the instance that does not connect right away for speed...
        logger.debug("Connecting to Shotgun to generate session token...")
        sg = Shotgun(hostname,
                     login=login,
                     password=password,
                     http_proxy=http_proxy,
                     connect=False,
                     auth_token=auth_token)
        # .. and generate the session token. If it throws, we have invalid
        # credentials or invalid host/proxy settings.
        return sg.get_session_token()
    except AuthenticationFault:
        raise AuthenticationError("Authentication failed.")
    except (ProtocolError, httplib2.ServerNotFoundError):
        raise AuthenticationError("Server %s was not found." % hostname)
    # In the following handlers, we are not rethrowing an AuthenticationError for
    # a very specific reason. While wrong credentials or host is a user
    # recoverable error, problems with proxy settings or network errors are much
    # more severe errors which can't be fixed by reprompting. Therefore, they have
    # nothing to do with authentication and shouldn't be reported as such.
    except socket.error, e:
        logger.exception("Unexpected connection error.")
        # e.message is always an empty string, so look at the exception's arguments.
        # The arguments are always a string or a number and a string.
        if isinstance(e.args[0], str):
            # if the error is just a string, simply forward the message.
            raise Exception(e.args[0])
        else:
            # We could argue here that we should only display the string portion of the
            # error since the error code is of little relevance to the user, but since
            # Toolkit doesn't properly log everything to a file at the moment, it's probably
            # safer to have the error code a little bit more in the open. Also, the formatting
            # of this exception type is pretty bad so let's reformat it ourselves. By default, it
            # turns a tuple into a string.
            raise Exception("%s (%d)" % (e.args[1], e.args[0]))
Exemplo n.º 4
0
def generate_session_token(hostname, login, password, http_proxy, auth_token=None):
    """
    Generates a session token for a given username/password on a given site.

    :param hostname: The host to connect to.
    :param login: The user to get a session for.
    :param password: Password for the user.
    :param http_proxy: Proxy to use. Can be None.
    :param auth_token: Two factor authentication token for the user. Can be None.

    :returns: The generated session token for that user/password/auth_token/site combo.

    :raises AuthenticationError: Raised when the user information is invalid.
    :raises MissingTwoFactorAuthenticationFault: Raised when missing a two factor authentication
        code or backup code.
    :raises Exception: Raised when a network error occurs.
    """
    try:
        # Create the instance that does not connect right away for speed...
        logger.debug("Connecting to Shotgun to generate session token...")
        sg = Shotgun(
            hostname,
            login=login,
            password=password,
            http_proxy=http_proxy,
            connect=False,
            auth_token=auth_token
        )
        # .. and generate the session token. If it throws, we have invalid
        # credentials or invalid host/proxy settings.
        return sg.get_session_token()
    except AuthenticationFault:
        raise AuthenticationError("Authentication failed.")
    except (ProtocolError, httplib2.ServerNotFoundError):
        raise AuthenticationError("Server %s was not found." % hostname)
    # In the following handlers, we are not rethrowing an AuthenticationError for
    # a very specific reason. While wrong credentials or host is a user
    # recoverable error, problems with proxy settings or network errors are much
    # more severe errors which can't be fixed by reprompting. Therefore, they have
    # nothing to do with authentication and shouldn't be reported as such.
    except socket.error, e:
        logger.exception("Unexpected connection error.")
        # e.message is always an empty string, so look at the exception's arguments.
        # The arguments are always a string or a number and a string.
        if isinstance(e.args[0], str):
            # if the error is just a string, simply forward the message.
            raise Exception(e.args[0])
        else:
            # We could argue here that we should only display the string portion of the
            # error since the error code is of little relevance to the user, but since
            # Toolkit doesn't properly log everything to a file at the moment, it's probably
            # safer to have the error code a little bit more in the open. Also, the formatting
            # of this exception type is pretty bad so let's reformat it ourselves. By default, it
            # turns a tuple into a string.
            raise Exception("%s (%d)" % (e.args[1], e.args[0]))
Exemplo n.º 5
0
def generate_session_token(hostname,
                           login,
                           password,
                           http_proxy,
                           auth_token=None):
    """
    Generates a session token for a given username/password on a given site.

    :param hostname: The host to connect to.
    :param login: The user to get a session for.
    :param password: Password for the user.
    :param http_proxy: Proxy to use. Can be None.
    :param auth_token: Two factor authentication token for the user. Can be None.

    :returns: The generated session token for that user/password/auth_token/site combo.

    :raises AuthenticationError: Raised when the user information is invalid.
    :raises MissingTwoFactorAuthenticationFault: Raised when missing a two factor authentication
        code or backup code.
    """
    try:
        # Create the instance that does not connect right away for speed...
        sg = Shotgun(hostname,
                     login=login,
                     password=password,
                     http_proxy=http_proxy,
                     connect=False,
                     auth_token=auth_token)
        # .. and generate the session token. If it throws, we have invalid
        # credentials or invalid host/proxy settings.
        return sg.get_session_token()
    except AuthenticationFault:
        raise AuthenticationError("Authentication failed.")
    except (ProtocolError, httplib2.ServerNotFoundError):
        raise AuthenticationError("Server %s was not found." % hostname)
    except MissingTwoFactorAuthenticationFault:
        # Silently catch and rethrow to avoid logging.
        raise
    except:
        logger.exception("There was a problem logging in.")
        raise
def generate_session_token(hostname, login, password, http_proxy, auth_token=None):
    """
    Generates a session token for a given username/password on a given site.

    :param hostname: The host to connect to.
    :param login: The user to get a session for.
    :param password: Password for the user.
    :param http_proxy: Proxy to use. Can be None.
    :param auth_token: Two factor authentication token for the user. Can be None.

    :returns: The generated session token for that user/password/auth_token/site combo.

    :raises AuthenticationError: Raised when the user information is invalid.
    :raises MissingTwoFactorAuthenticationFault: Raised when missing a two factor authentication
        code or backup code.
    """
    try:
        # Create the instance that does not connect right away for speed...
        sg = Shotgun(
            hostname,
            login=login,
            password=password,
            http_proxy=http_proxy,
            connect=False,
            auth_token=auth_token
        )
        # .. and generate the session token. If it throws, we have invalid
        # credentials or invalid host/proxy settings.
        return sg.get_session_token()
    except AuthenticationFault:
        raise AuthenticationError("Authentication failed.")
    except (ProtocolError, httplib2.ServerNotFoundError):
        raise AuthenticationError("Server %s was not found." % hostname)
    except MissingTwoFactorAuthenticationFault:
        # Silently catch and rethrow to avoid logging.
        raise
    except:
        logger.exception("There was a problem logging in.")
        raise