Migrate user accounts and groups
In the SnapLogic Platform, because every asset has an owner, you must populate the users and groups in the new environment before migrating other assets. For environments with many users, you will want to automate the process.
In the SnapLogic Platform, because every asset has an owner, you must populate the users and groups in the new environment before migrating other assets. For environments with many users, you will want to automate the process. You can also contact SnapLogic Professional Services for help.
The person migrating users and groups must have administrative privileges in both environments. The main steps required to migrate users and groups include:
- Get a list of all users and the groups to which they belong
- Re-create the groups in the new environment
- Re-create the users in the new environment
Get the users list
From the Admin Manager Users page, you can download a .csv file that lists all users. The file contains all of the information necessary to re-create users in the new environment. The following screenshot shows the first two rows of an example .csv file opened as a spreadsheet:
If you prefer to use a script, the following SnapLogic public APIs are available.
-
Get the list of groups in the environment
The default
admins
andmembers
groups contain all of the admin and non-admin members, respectively.
Re-create the groups
From the list of groups retrieved in the previous step, re-create the groups in the new environment:
-
For only a few groups, you can create them quickly using Admin Manager.
-
If the environment has many groups, you might want to create a script and use the create a group API.
The following extract from a Python script shows an example where the groupData
input to
the API provides the list of group names. Download the complete example.
print( "Create group:", group )
groupData = {
"organization" : EMEA_CP_orgName,
"name" : group
}
response = requests.post(
'https://cdn.emea.snaplogic.com/api/1/rest/public/groups',
headers=headers, json=groupData, auth=('user-email', EMEA_PWD)
)
if response.status_code == 200 :
print( group, "created" )
elif response.status_code == 409 :
print( group, "already exists" )
else :
print( "Status:", response.status_code, response.reason, response.text )
Re-create the user accounts
Use the create a user API to re-create the user accounts in the new environment. The following extract from a Python script shows an example where the usernames are passed in as groupInfo, the accounts are re-created, and then assigned to groups. Download the complete example.
for email in groupInfo['members']:
print( "Create user:", email )
# Retrieve user from NA CP org
response = requests.get(
'https://cdn.elastic.snaplogic.com/api/1/rest/public/users/' + email,
headers=headers, auth=('user-email', US_PWD)
)
userInfo = json.loads( response.text )
# print( userInfo )
# Create user in EMEA CP
admin = "False"
for org in userInfo['organizations']:
if org['name'] == US_CP_orgName :
admin = org['administrator']
break
userData = {
"email" : email,
"first_name" : userInfo['first_name'],
"last_name" : userInfo['last_name'],
"organization" : EMEA_CP_orgName,
"administrator" : admin,
"allow_password_login" : userInfo['allow_password_login'],
"ui_access" : userInfo['ui_access'],
"create_home_directory" : "True"
}
# print( userData )
response = requests.post(
'https://cdn.emea.snaplogic.com/api/1/rest/public/users',
headers=headers, json=userData, auth=('user-email', EMEA_PWD)
)
if response.status_code == 409 :
# User already exists, update it
print( "Rather update existing user", email )
userData = {
"send_email" : "True",
"create_home_directory" : "True"
}
response = requests.put(
'https://cdn.emea.snaplogic.com/api/1/rest/public/users/' + email + '/org/' + EMEA_CP_orgName,
headers=headers, json=userData, auth=('user-email', EMEA_PWD)
)
Example Python Script
The attached script retrieves all groups and their members and re-creates them in the new environment. migrate-us-to-emea.py