Background:
Requirement:
As a sysadmin, I want to automate updating the database connection details in the ArcGIS Server data store settings, so that my services will continue to access the data in the database.
Challenges & Thoughts:
Q.1 Do you need Arcpy to create a .SDE file?
This Esri Script looks like it would meet my needs.
However, it makes no mention on how to encrypt the password.
Q3. Where does the variable sample_1 come from in the linked python script?
Q3. How do we encrypt the password?
Looking at the help for DataItem:
It is recommended that you encrypt the credentials using the encryption scheme before storing it into the server. This can be achieved by invoking Get Database Connection String tool inside the Publishing Tools toolbox published as a system service on the server.
This would indicate that there might be a step missing in the linked script. Struggling to find much documentation/samples on how to use 'Get Database Connection String' without a SDE file?
This issue appears to have been addressed via a GitHub issue: https://github.com/Esri/arcgis-python-api/issues/990. However, the method for getting the SDE file path into the cloud environment is not entirely clear, nor is the original issue of how to create a function to update the password clarified.
The step missing between 3 and 4 of the documentation is to create the SDE file, which requires the arcpy library's CreateDatabaseConnection function.
arcpy.management.CreateDatabaseConnection(out_folder_path, out_name, database_platform, instance, {account_authentication}, {username}, {password}, {save_user_pass}, {database}, {schema}, {version_type}, {version}, {date})
At this time, there is no method to directly generate the ENCRYPTED_PASSWORD, nor to do it without invoking the arcpy library. I have created a related Enterprise Ideas post recommending that there should be one for exactly this use case.