I have a lot of registered database connections---let's call it 100---and my enterprise has a password rotation policy. We have recently begun a cloud migration, and I want to use some of the new automation tooling to keep database passwords rotated.
There is some documentation on how to do this in ArcGIS Enterprise, but it requires the arcpy library (for arcpy.management.CreateDatabaseConnection, not documented there between steps 3 and 4) and is not very direct.
Using the `arcgis` library, I can see the various registered database items in our Enterprise system. There is an update method for the connections, so that their properties can be changed. The properties, which are fed into the update method, look like this:
{
"path": "/enterpriseDatabases/testDsfunc", //a unique path on the server
"type": "egdb", //as this is a database
"id": "09f91102-4bf0-4161-8c8d-0a8ecc159be7",
"totalRefCount":0,
"info": {
"dataStoreConnectionType": "shared",
"isManaged": "false",
"connectionString": "ENCRYPTED_PASSWORD=<big long hexadecimal>;SERVER=User;INSTANCE=sde:sqlserver:User;DBCLIENT=sqlserver;DB_CONNECTION_PROPERTIES=User;DATABASE=dsfunc;USER=sde;VERSION=sde.DEFAULT;AUTHENTICATION_MODE=DBMS"
}
} Having just updated my database password at the database, I now want to update the ENCRYPTED_PASSWORD part of the connectionString (or really, the whole connectionString, but only changing the ENCRYPTED_PASSWORD part).
I would love to see a method update_password(new_password) on the arcgis.gis.server.admin._data.Datastore object that would take the plaintext password and update the connectionString to use the corresponding ENCRYPTED_PASSWORD.
The generalized steps shown in the documentation referenced above would become as follows:
from arcgis.gis import GIS
gis = GIS("https://my.portal.machine.com:7443/arcgis/home", "admin_user", "admin_password")
gis_servers = gis.servers.list()
my_server = gis_servers[0] # Or code to choose the correct server
datastores = my_server.datastores.list()
ds = datastores[7] # Or code to choose the correct datastore connection item
ds.update_password('my_new_passw0rd')
Having that functionality I can then make use of the following scheme for rotating passwords:
A password stored in cloud key store nears expiration, triggering a Python function that generates a new password and updates it in the database and the key store (including new expiration date).
The updated key in the key store triggers a second Python function (arcgis library only, no arcpy) which can log in to the ArcGIS Enterprise, locate the correct datastore connection (based on metadata or a database that matches connections to the database keys), and run the update_password function with the new password.