Skip to main content
Solved

Get Job Requestor User Name as an Attribute


jeffpickles
Contributor
Forum|alt.badge.img+13

Is there a way to bring the user name who requested a job run into the workspace as an attribute? 

 

My current attempt uses a PythonCaller with the following code: 

import fme, os
import fmeobjects
 
def processFeature(feature):
    feature.setAttribute('Username', os.getenv('USERNAME'))
    pass

...and passes Username on as an exposed attribute. This works fine in Desktop, but in Server it always results in the Service Account username populating the attribute. 

 

So if I run this in Desktop, Username is populated with jpickles... if I run this in Server, Username is populated with serviceaccount even though I am logged into FME Server as jpickles. 

 

Is there an easier way to accomplish this task that I am currently unaware of? 

Best answer by hkingsbury

Thats the expected behavior as on server engines, and subsequently the workbenches the run, use the service account.

 

The parameter FME_SECURITY_USER will display the user who is running the process on server

image 

It will be empty on desktop, so if the process needs to do it on both desktop and server, you could add soem logic to see if the parameter is empty, if it is, use the python, if not, use the param value

image

View original
Did this help you find an answer to your question?

6 replies

hkingsbury
Celebrity
Forum|alt.badge.img+55
  • Celebrity
  • Best Answer
  • December 8, 2021

Thats the expected behavior as on server engines, and subsequently the workbenches the run, use the service account.

 

The parameter FME_SECURITY_USER will display the user who is running the process on server

image 

It will be empty on desktop, so if the process needs to do it on both desktop and server, you could add soem logic to see if the parameter is empty, if it is, use the python, if not, use the param value

image


jeffpickles
Contributor
Forum|alt.badge.img+13
  • Author
  • Contributor
  • December 8, 2021
hkingsbury wrote:

Thats the expected behavior as on server engines, and subsequently the workbenches the run, use the service account.

 

The parameter FME_SECURITY_USER will display the user who is running the process on server

image 

It will be empty on desktop, so if the process needs to do it on both desktop and server, you could add soem logic to see if the parameter is empty, if it is, use the python, if not, use the param value

image

Thank you. This works when running the workspace in both FME Desktop and FME Server now. 

 

For future reference to anyone following this, this snippet in a PythonCaller will do the trick: 

def processFeature(feature):
    if not FME_MacroValues['FME_SECURITY_USER']: 
        feature.setAttribute('Username', os.getenv('USERNAME')) 
    else:
        feature.setAttribute('Username', FME_MacroValues['FME_SECURITY_USER'])
    pass

 

My issue now is that when I run this workflow in a Workspace App, it still pushes the service account user name instead of the security_user. Manually running it via Run Workspace works as expected, but any runs through the Workspace App do not. 

 

Is there any particular way to force the correct username through a Workspace App?


david_r
Celebrity
  • December 9, 2021
jeffpickles wrote:

Thank you. This works when running the workspace in both FME Desktop and FME Server now. 

 

For future reference to anyone following this, this snippet in a PythonCaller will do the trick: 

def processFeature(feature):
    if not FME_MacroValues['FME_SECURITY_USER']: 
        feature.setAttribute('Username', os.getenv('USERNAME')) 
    else:
        feature.setAttribute('Username', FME_MacroValues['FME_SECURITY_USER'])
    pass

 

My issue now is that when I run this workflow in a Workspace App, it still pushes the service account user name instead of the security_user. Manually running it via Run Workspace works as expected, but any runs through the Workspace App do not. 

 

Is there any particular way to force the correct username through a Workspace App?

Unless the App forces a login to your FME Server instance, there is no way for FME Server to know the username of the App user. (Maybe unless you have activated SSO, and even then I'm not sure it would work).

 

PS, you can safely remove "pass" from the above code, it does nothing :-)


jeffpickles
Contributor
Forum|alt.badge.img+13
  • Author
  • Contributor
  • December 9, 2021
jeffpickles wrote:

Thank you. This works when running the workspace in both FME Desktop and FME Server now. 

 

For future reference to anyone following this, this snippet in a PythonCaller will do the trick: 

def processFeature(feature):
    if not FME_MacroValues['FME_SECURITY_USER']: 
        feature.setAttribute('Username', os.getenv('USERNAME')) 
    else:
        feature.setAttribute('Username', FME_MacroValues['FME_SECURITY_USER'])
    pass

 

My issue now is that when I run this workflow in a Workspace App, it still pushes the service account user name instead of the security_user. Manually running it via Run Workspace works as expected, but any runs through the Workspace App do not. 

 

Is there any particular way to force the correct username through a Workspace App?

We have SSO enabled and force log-in to use the workspace. The info should be there. 


david_r
Celebrity
  • December 9, 2021
jeffpickles wrote:

Thank you. This works when running the workspace in both FME Desktop and FME Server now. 

 

For future reference to anyone following this, this snippet in a PythonCaller will do the trick: 

def processFeature(feature):
    if not FME_MacroValues['FME_SECURITY_USER']: 
        feature.setAttribute('Username', os.getenv('USERNAME')) 
    else:
        feature.setAttribute('Username', FME_MacroValues['FME_SECURITY_USER'])
    pass

 

My issue now is that when I run this workflow in a Workspace App, it still pushes the service account user name instead of the security_user. Manually running it via Run Workspace works as expected, but any runs through the Workspace App do not. 

 

Is there any particular way to force the correct username through a Workspace App?

It might interest you that this idea just now changed status to "in beta":

https://community.safe.com/s/idea/0874Q000000j0L1QAI/detail


jeffpickles
Contributor
Forum|alt.badge.img+13
  • Author
  • Contributor
  • December 9, 2021
jeffpickles wrote:

Thank you. This works when running the workspace in both FME Desktop and FME Server now. 

 

For future reference to anyone following this, this snippet in a PythonCaller will do the trick: 

def processFeature(feature):
    if not FME_MacroValues['FME_SECURITY_USER']: 
        feature.setAttribute('Username', os.getenv('USERNAME')) 
    else:
        feature.setAttribute('Username', FME_MacroValues['FME_SECURITY_USER'])
    pass

 

My issue now is that when I run this workflow in a Workspace App, it still pushes the service account user name instead of the security_user. Manually running it via Run Workspace works as expected, but any runs through the Workspace App do not. 

 

Is there any particular way to force the correct username through a Workspace App?

Ah yes. That would do the trick. And now we wait patiently for release. 

 

Thanks! 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings