Managing users with the command line

Use the cpd-cli user-mgmt command-line interface to manage IBM® Software Hub users and user groups, and import LDAP users.

Before you begin

Before you run any cpd-cli user-mgmt commands, complete the following prerequisites.

Managing users

To list all users, including their usernames, roles, and email addresses, use the following command.

cpd-cli user-mgmt list-users \
--profile ${CPD_PROFILE_NAME} \
--output type

For the output type, you can specify json, text, or yaml. The default output type is text.

To retrieve details on a specific user, use the following command.

cpd-cli user-mgmt get-user username \
--profile ${CPD_PROFILE_NAME} \
--output type

For the output type, you can specify json or yaml. The default output type is json.

To add or update an existing user with parameters from a JSON file, use the following command.

cpd-cli user-mgmt upsert-user username \
--profile ${CPD_PROFILE_NAME} \
--data user.json

Supply a user.json file that is similar to the following example.

{
   "username":"chec9",
   "displayName":"chec",
   "email":"chec@ibm.co",
   "user_roles":[
      "zen_user_role"
   ],
   "password":"password"
}

By default, new roles are always added to the existing roles. To overwrite the exiting roles of a user instead, append the --replace-roles flag.

Alternatively, to add or update multiple users with comma-separated parameters in a CSV file, use the following command.

cpd-cli user-mgmt bulk-upsert-users \
--profile ${CPD_PROFILE_NAME} \
--from-csv-file bulkUsers.csv

Supply a bulkUsers.csv file that is similar to the following example.

username,password,email,displayName,user_roles
tim,pass,tim@test.com,timothee,zen_administrator_role;zen_user_role
keshav999,pass,k@test.com:wq,Keshav,zen_user_role
monil99,past,monil@test.com,Monil,
Tom,12345,tom@test.com,Tim,zen_administrator_role zen_user_role

Managing user groups

To list all user groups, use the following command.

cpd-cli user-mgmt list-groups \
--profile ${CPD_PROFILE_NAME}

To retrieve details on a specific user group, use the following command.

cpd-cli user-mgmt get-group group-name \
--profile ${CPD_PROFILE_NAME}

To add or update an existing user group with parameters from a JSON file, use the following command.

cpd-cli user-mgmt upsert-group \
--profile ${CPD_PROFILE_NAME} \
--data group.json

By default, new roles are always added to the existing roles. To overwrite the exiting roles of a user group instead, append the --replace-roles flag.

Supply a group.json file that is similar to the following example.

{
    "name": "Trial1",
    "description": "Upsert group test",
    "role_identifiers": ["zen_developer_role", "wkc_data_scientist_role"]
}

Importing LDAP users and user groups

To configure LDAP with parameters from a JSON file, use the following command.

cpd-cli user-mgmt config-ldap \
--profile ${CPD_PROFILE_NAME} \
--config ldap-config.json

Supply a ldap-config.json file that is similar to the following example.

{
  "externalLDAPHost": "ldap://9.87.654.321",
  "externalLDAPPort": 389,
  "externalLDAPSearchBase": "dc=wdp,dc=com",
  "externalLDAPSearchField": "cn",
  "externalLDAPSearchUser": "jdoe@wdp.com",
  "externalLDAPSearchPassword": "XXXXXXXXX"
}

To add an LDAP user to a user group, use the following command.

cpd-cli user-mgmt add-ldap-user-to-cpd-group \
--profile ${CPD_PROFILE_NAME} \
--ldap-user ldap-user \
--group cpd-group

To add an LDAP group to an existing user group, use the following command.

cpd-cli user-mgmt add-ldap-group-to-cpd-group \
--profile ${CPD_PROFILE_NAME} \
--ldap-group ldap-group \
--group cpd-group