Change UserCredentials with Python

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Change UserCredentials with Python

Gunter Becker
Hi all,

I have the requirement of changing the configuration elements (servicename, username, password) of all SQLServerSpatial FeatureSources in a library.
I thought this would be a perfect test case for Jackies "IronPython Console" in Maestro especially since I haven't written a python script before.

Changing the servicename was no problem but now I'm struggling with changing the user credentials.

I thought I just have to use the SetEncryptedCredentials method of the FeatureSource but this ended up in this error:

AttributeError: 'FeatureSourceType' object has no attribute 'SetEncryptedCredentials'

This error is also thrown on other methods like GetConfigurationContent or GetConnectionProperties.

That is what I have so far:

def ChangeSQLServerFeatureSources(conn, folder, oldServiceName, newServiceName, userName, password):
    """ 
    Changes all SQLServer FeatureSources with the specified oldServiceName
    """
    resList = conn.ResourceService.GetRepositoryResources(folder, "FeatureSource")
    
    for child in resList.Children:
        
        fs = conn.ResourceService.GetResource(child.ResourceId)
        if (fs.Provider == 'OSGeo.SQLServerSpatial' ):
            if (fs.GetConnectionProperty('Service') == oldServiceName):
                fs.SetConnectionProperty('Service',newServiceName)
                fs.SetEncryptedCredentials(userName,password)  """ ERROR """
                conn.ResourceService.SaveResource(fs)
                print fs.ResourceID + ": Changed '%s' to '%s'" % (oldServiceName, newServiceName)

Any help would be appreciated,

Gunter
Reply | Threaded
Open this post in threaded view
|

Re: Change UserCredentials with Python

Jackie Ng
SetEncryptedCredentials is an extension method. One of those .net-isms that doesn't cleanly translate to python.

Check my post for how to work with .net extension methods: http://themapguyde.blogspot.com.au/2013/08/maestro-ironpython-console-tips-and.html

- Jackie
Reply | Threaded
Open this post in threaded view
|

Re: Change UserCredentials with Python

Gunter Becker
I must have been blind while reading your blog post before.

Thanks, Gunter