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. You can also contact SnapLogic Professional Services for help.
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
The person migrating users and groups must have administrative privileges in both environments.
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 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 and members 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. The complete script is attached below.
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. The complete script is attached below.
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))
if response.status_code == 200 :
print( email, "created" )
else :
print( "Status:", response.status_code, response.reason, response.text )
#############################################
# Add user to group
#############################################
groupData = {
"add_user" : email
}
response = requests.patch('https://cdn.emea.snaplogic.com/api/1/rest/public/groups/' + EMEA_CP_orgName + '/' + group, headers=headers, json=groupData, auth=('user-email', EMEA_PWD))
if response.status_code == 200 :
print( email, "added to group" )
else :
print( "Status:", response.status_code, response.reason, response.text )
print( "Groups and users successfully migrated" )
except Exception as e:
print(e)
input("Error... press enter")
exit()
input("Process completed... press enter to close this window")
Example Python Script
The attached script retrieves all groups and their members and re-creates them in the new environment.
Have feedback? Email documentation@snaplogic.com | Ask a question in the SnapLogic Community
© 2017-2024 SnapLogic, Inc.