Exemplo n.º 1
0
    def execute(self, **kwargs):
        """
		Return the login name for the user currently logged in. This is typically used
		by Toolkit to resolve against the 'login' field in the Shotgun users table in order
		to extract further metadata.
		"""
        if sys.platform == "win32":
            local_username = os.environ.get("USERNAME", None)
        else:
            local_username = os.environ.get("USER", None)

            # http://stackoverflow.com/questions/117014/how-to-retrieve-name-of-current-windows-user-ad-or-local-using-python
        if os.environ.get("USERNAMESHOTGUN", None) == None:
            # return os.environ.get("USERNAME", None)
            script_name = "User_Activity"
            script_api_key = "8323196ca1dfe1aee8ec00e0b885dbae9ab02f3144daf19cd23897c85ba168d2"
            shotgun_link = 'https://rts.shotgunstudio.com'

            sg = Shotgun(shotgun_link, script_name, script_api_key)

            fields = ['login', 'tag_list']
            filters = [['login', 'is', local_username]]
            filters_alt = [['tag_list', 'is', local_username]]
            humanuser = sg.find_one("HumanUser", filters, fields)
            humanuser_alt = sg.find_one("HumanUser", filters_alt, fields)

            # If local user match with shotgun user
            if humanuser:
                return local_username
            # If local user match with shotgun alternative user
            elif humanuser_alt:
                return humanuser_alt['login']

        else:
            return os.environ.get("USERNAMESHOTGUN", None)
	def execute(self, **kwargs):
		"""
		Return the login name for the user currently logged in. This is typically used
		by Toolkit to resolve against the 'login' field in the Shotgun users table in order
		to extract further metadata.
		"""
		if sys.platform == "win32": 
			local_username = os.environ.get("USERNAME", None)
		else:
			local_username = os.environ.get("USER", None)
		
			# http://stackoverflow.com/questions/117014/how-to-retrieve-name-of-current-windows-user-ad-or-local-using-python
		if os.environ.get("USERNAMESHOTGUN", None) == None:
			# return os.environ.get("USERNAME", None)
			script_name = "User_Activity"
			script_api_key = "8323196ca1dfe1aee8ec00e0b885dbae9ab02f3144daf19cd23897c85ba168d2"
			shotgun_link = 'https://rts.shotgunstudio.com'

			sg = Shotgun(shotgun_link, script_name, script_api_key)

			fields = [ 'login','tag_list' ]
			filters = [ [ 'login', 'is', local_username ] ]
			filters_alt = [ [ 'tag_list', 'is', local_username ] ]
			humanuser = sg.find_one( "HumanUser", filters, fields )
			humanuser_alt = sg.find_one( "HumanUser", filters_alt, fields )

			# If local user match with shotgun user
			if humanuser:
				return local_username
			# If local user match with shotgun alternative user
			elif humanuser_alt:
				return humanuser_alt['login']

		else:
			return os.environ.get("USERNAMESHOTGUN", None)
Exemplo n.º 3
0
    def are_credentials_expired(self):
        """
        Checks if the credentials for the user are expired.

        :returns: True if the credentials are expired, False otherwise.
        """
        sg = Shotgun(self.get_host(),
                     session_token=self.get_session_token(),
                     http_proxy=self.get_http_proxy())
        try:
            sg.find_one("HumanUser", [])
            return False
        except AuthenticationFault:
            return True
Exemplo n.º 4
0
    def are_credentials_expired(self):
        """
        Checks if the credentials for the user are expired.

        :returns: True if the credentials are expired, False otherwise.
        """
        sg = Shotgun(
            self.get_host(), session_token=self.get_session_token(),
            http_proxy=self.get_http_proxy()
        )
        try:
            sg.find_one("HumanUser", [])
            return False
        except AuthenticationFault:
            return True
Exemplo n.º 5
0
    def are_credentials_expired(self):
        """
        Checks if the credentials for the user are expired.

        :returns: True if the credentials are expired, False otherwise.
        """
        logger.debug("Connecting to shotgun to determine if credentials have expired...")
        sg = Shotgun(
            self.get_host(),
            session_token=self.get_session_token(),
            http_proxy=self.get_http_proxy()
        )
        try:
            sg.find_one("HumanUser", [])
            return False
        except AuthenticationFault:
            return True
Exemplo n.º 6
0
    def are_credentials_expired(self):
        """
        Checks if the credentials for the user are expired.

        This check is done solely on the Shotgun side. If SSO is being used,
        we do not attempt to contact the IdP to validate the session.

        :returns: True if the credentials are expired, False otherwise.
        """
        logger.debug(
            "Connecting to shotgun to determine if credentials have expired..."
        )
        sg = Shotgun(
            self.get_host(),
            session_token=self.get_session_token(),
            http_proxy=self.get_http_proxy(),
        )
        try:
            sg.find_one("HumanUser", [])
            return False
        except ProtocolError as e:
            # One potential source of the error is that our SAML claims have
            # expired. We check if we were given a 302 and the
            # saml_login_request URL.
            # But if we get there, it means our session_token is still valid
            # as far as Shotgun is concerned.
            if (e.errcode == http_client.FOUND and "location" in e.headers
                    and e.headers["location"].endswith(
                        "/saml/saml_login_request")):
                # If we get here, the session_token is still valid.
                logger.debug(
                    "The SAML claims have expired. But the session_token is still valid"
                )
                return False
            else:
                logger.error(
                    "Unexpected exception while validating credentials: %s" %
                    e)
            return True
        except AuthenticationFault:
            return True
Exemplo n.º 7
0
    def are_credentials_expired(self):
        """
        Checks if the credentials for the user are expired.

        This check is done solely on the Shotgun side. If SSO is being used,
        we do not attempt to contact the IdP to validate the session.

        :returns: True if the credentials are expired, False otherwise.
        """
        logger.debug("Connecting to shotgun to determine if credentials have expired...")
        sg = Shotgun(
            self.get_host(),
            session_token=self.get_session_token(),
            http_proxy=self.get_http_proxy()
        )
        try:
            sg.find_one("HumanUser", [])
            return False
        except ProtocolError as e:
            # One potential source of the error is that our SAML claims have
            # expired. We check if we were given a 302 and the
            # saml_login_request URL.
            # But if we get there, it means our session_token is still valid
            # as far as Shotgun is concerned.
            if (
                e.errcode == httplib.FOUND and
                "location" in e.headers and
                e.headers["location"].endswith("/saml/saml_login_request")
            ):
                # If we get here, the session_token is still valid.
                logger.debug("The SAML claims have expired. But the session_token is still valid")
                return False
            else:
                logger.error("Unexpected exception while validating credentials: %s" % e)
            return True
        except AuthenticationFault:
            return True
Exemplo n.º 8
0
def __create_sg_connection(shotgun_cfg_path,
                           evaluate_script_user,
                           user="******"):
    """
    Creates a standard toolkit shotgun connection.

    :param shotgun_cfg_path: path to a configuration file to read settings from
    :param evaluate_script_user: if True, the id of the script user will be 
                                 looked up and returned.
    :param user: If a multi-user config is used, this is the user to create the connection for.
    
    :returns: tuple with (sg_api_instance, script_user_dict) where script_user_dict is None if
              evaluate_script_user is False else a dictionary with type and id keys. 
    """

    # get connection parameters
    config_data = __get_sg_config_data(shotgun_cfg_path, user)

    # create API
    sg = Shotgun(config_data["host"],
                 config_data["api_script"],
                 config_data["api_key"],
                 http_proxy=config_data.get("http_proxy", None))

    # bolt on our custom user agent manager
    sg.tk_user_agent_handler = ToolkitUserAgentHandler(sg)

    script_user = None

    if evaluate_script_user:
        # determine the script user running currently
        # get the API script user ID from shotgun
        script_user = sg.find_one(
            "ApiUser", [["firstname", "is", config_data["api_script"]]],
            fields=["type", "id"])
        if script_user is None:
            raise TankError(
                "Could not evaluate the current App Store User! Please contact support."
            )

    return (sg, script_user)
Exemplo n.º 9
0
def __create_sg_connection(shotgun_cfg_path, evaluate_script_user, user="******"):
    """
    Creates a standard toolkit shotgun connection.

    :param shotgun_cfg_path: path to a configuration file to read settings from
    :param evaluate_script_user: if True, the id of the script user will be 
                                 looked up and returned.
    :param user: If a multi-user config is used, this is the user to create the connection for.
    
    :returns: tuple with (sg_api_instance, script_user_dict) where script_user_dict is None if
              evaluate_script_user is False else a dictionary with type and id keys. 
    """

    # get connection parameters
    config_data = __get_sg_config_data(shotgun_cfg_path, user)

    # create API
    sg = Shotgun(config_data["host"],
                 config_data["api_script"],
                 config_data["api_key"],
                 http_proxy=config_data.get("http_proxy", None))

    # bolt on our custom user agent manager
    sg.tk_user_agent_handler = ToolkitUserAgentHandler(sg)

    script_user = None

    if evaluate_script_user:
        # determine the script user running currently
        # get the API script user ID from shotgun
        script_user = sg.find_one("ApiUser",
                                          [["firstname", "is", config_data["api_script"]]],
                                          fields=["type", "id"])
        if script_user is None:
            raise TankError("Could not evaluate the current App Store User! Please contact support.")

    return (sg, script_user)
Exemplo n.º 10
0
        raise TankError("Missing required field 'api_key' in config '%s'" %
                        shotgun_cfg_path)

    # create API
    sg = Shotgun(config_data["host"],
                 config_data["api_script"],
                 config_data["api_key"],
                 http_proxy=config_data.get("http_proxy", None))

    script_user = None

    if evaluate_script_user:
        # determine the script user running currently
        # get the API script user ID from shotgun
        script_user = sg.find_one(
            "ApiUser", [["firstname", "is", config_data["api_script"]]],
            fields=["type", "id"])
        if script_user is None:
            raise TankError(
                "Could not evaluate the current App Store User! Please contact support."
            )

    return (sg, script_user)


def create_sg_connection(user="******"):
    """
    Creates a standard tank shotgun connection.
    User refers to the shotgun user specified in the config shotgun.yml file.

    :param user: Optional shotgun config user to use when
Exemplo n.º 11
0
    # create API
    sg = Shotgun(config_data["host"],
                 config_data["api_script"],
                 config_data["api_key"],
                 http_proxy=config_data.get("http_proxy", None))

    # bolt on our custom user agent manager
    sg.tk_user_agent_handler = ToolkitUserAgentHandler(sg)

    script_user = None

    if evaluate_script_user:
        # determine the script user running currently
        # get the API script user ID from shotgun
        script_user = sg.find_one("ApiUser",
                                          [["firstname", "is", config_data["api_script"]]],
                                          fields=["type", "id"])
        if script_user is None:
            raise TankError("Could not evaluate the current App Store User! Please contact support.")

    return (sg, script_user)

    
    
    
    
    
def create_sg_connection(user="******"):
    """
    Creates a standard tank shotgun connection.
    User refers to the shotgun user specified in the config shotgun.yml file.