I'm wanting to publish a python script as a geoprocessing service (a secured service). Is there any way for arcpy to get the name of the arcgis server user who calls the gp task?
e.g. I log in and run the GP tool from the rest url, the script grabs my login name and the current datetime and adds it to a log table. We then end up with a log table of all users and times the script was run.
Sounds like you want something like editor tracking, but for a GP service. I don't think that there's anything within the framework to support that. My only thought is to add a parameter so the user can select their username. Since you'll have a defined list of users within your ArcGIS Server security, you could create a dropdown list of the user names, but you're relying on the user to select the correct one. You can probably do this with an SOI.
Thanks for the reply Jonathan.
I haven't been able to find anything yet within the framework. Seems a little strange that the script is unaware of who is running it.
Relying on the user to input who they are in probably not a realistic option unfortunately.
Unless anyone else has any thoughts then I guess the only option is an SOI as you suggest.
I think when you switch the default log messages level settings from "Warning" to "Verbose", you can capture detailed instance of the GP or even map service being consumed by a user. Just a thought.
You mean it is possible to decipher from the verbose log files who the user is? That is only really useful for debugging. I was wanting the GP service script itself to save a log of the users who ran it.
Even if running in verbose mode could somehow allow the script to detect the user, obviously you couldn't run the GP service permanently in verbose mode...
Thanks for the comment though on an old post! 🙂
all good. just happened to see your post since I am researching on how ArcGIS server picks up usernames. from your original post you did mention it will be a secured service so im guessing you will have a portal built-in user group or AD group to share the GP service with so basically you already have a list of users. but if its a lot of users in that group then that's a bit of a task to identify who uses it most. like the other suggestion, you could just simply make it a "required" parameter on your script for it to execute and store that parameter in a table on your sde or fgdb. You can even go further and auto fill that parameter by somehow hooking up to the AD user table.
Correct me if I'm wrong, but even making it a 'required' parameter doesn't guarantee who is using it. A user hitting the endpoint directly could pass in someone else's username as the parameter.