SGTK - Publish Files as User

Hi,
I’m trying to get a farm script to publish files as a HumanUser instead of the api script.
How would I do that?

Currently just using some of the bootstrap code, what needs to be added or changed for this to work?

    try:
        ########################################################
        ################## CONNECT TO SGTK (TANK) ##############
        # If your render nodes can access the same tk-core install location as
        # artist workstations, retrieve its path from the environment and ensure
        # it is in the PYTHONPATH
        TK_CORE_PATH = os.environ["SHOTGUN_SGTK_MODULE_PATH"]
        if TK_CORE_PATH not in sys.path:
            print "Appending SYS PATH"
            sys.path.append(TK_CORE_PATH)

        # Import Toolkit so we can access to Toolkit specific features.
        import sgtk

        # Import the ShotgunAuthenticator from the tank_vendor.shotgun_authentication
        # module. This class allows you to authenticate either interactively or, in this
        # case, programmatically.
        from tank_vendor.shotgun_authentication import ShotgunAuthenticator

        # Instantiate the CoreDefaultsManager. This allows the ShotgunAuthenticator to
        # retrieve the site, proxy and optional script_user credentials from shotgun.yml
        cdm = sgtk.util.CoreDefaultsManager()

        # Instantiate the authenticator object, passing in the defaults manager.
        authenticator = ShotgunAuthenticator(cdm)

        # Create a user programmatically using the script's key.
        user = authenticator.create_script_user(
        api_script=os.environ["SHOTGUN_API_SCRIPT_NAME"],
        api_key=os.environ["SHOTGUN_API_SCRIPT_KEY"]
        )

        # print "User is '%s'" % user

        # Tells Toolkit which user to use for connecting to Shotgun.
        sgtk.set_authenticated_user(user)
4 Likes

Hey Ricardo

I would use script authentication as you suggested above.

Then I would modify the get_current_login.py core hook as detailed in step 1 of this topic, and get it to grab the user name from an environment variable you would have pre defined when submitting the job.
That hook is designed to get the user when authenticating as a script.

It should mean that Toolkit will authenticate as a script but register the publish as the user.

6 Likes