Rubrik : Managing Users From CLI


Background

I came across a challenge the other day. A new starter in the company! With 7 different clusters worldwide, not easy to handle (well - painful, waste of time, ... you name it). The pity is : our clusters are still using local authentication. I was sure we can automate this.

Yes, we can! (automate)

Using my php framework, almost all needed API calls were in place already, it was just a matter of putting everything together. So, first : what functions do I need ? the basics for sure : add, delete and list users on a specific cluster. I think this is a good start.

So, we need 3 files to achieve this
  • List of clusters with the relevant credentials -> rkClusters.php
  • The php framework -> rkFramework.php
  • The code itself - > rkUsers.php
rkClusters.php looks like this : 

<?php
$clusterConnect=array(
0 => array(
"cluster" => "BE",
"username" => "username",
"password" => "password",
"ip" => "192.168.1.x"
),
1 => array(
"cluster" => "UK",
"username" => "username",
"password" => "password",
"ip" => "192.168.2.x"
),
2 => array(
"cluster" => "US",
"username" => "username",
"password" => "password",
"ip" => "192.168.3.x"
),
);
?>

Basically, you need to provide to the $clusterConnect array all credentials to all your clusters (virtual or physical). The good practice is to avoid space in the cluster name.
  • rkFramework.php is on my gitHub
  • rkUsers.php is alo on my gitHub
Note, you may also be interested into this script.

The script in action!

  • The syntax

$ ./rkUsers.php ============================================ Syntax error : min 2 keywords are required! ============================================ ./rkUsers.php [ACTION] [ClusteName] [UserName] Action can be : add, del, list Example: ./rkUsers.php add US flhoest Example: ./rkUsers.php list BE Note : keywords are case insensitive. Ended.
  • Add user

$ ./rkUsers.php add be test_user

Creating user test_user in be
Password : ****************
User has been created (id=User:::94958077-fb79-4d9e-b26f-5b762270d12a)
User has been granted with admin rights.
  • List users
$ ./rkUsers.php list be Listing users in BE Username : test_user ID : User:::94958077-fb79-4d9e-b26f-5b762270d12a Username : admin ID : User:::9d999b1f-0e27-4028-a7d9-1ac7b5527092 Listing completed.

  • Delete user

$ ./rkUsers.php del be test_user
deleting user test_user in BE User has been deleted

  • List users again to confirm
$ ./rkUsers.php list be Listing users in BE Username : admin ID : User:::9d999b1f-0e27-4028-a7d9-1ac7b5527092 Listing completed.

Next step could be using a * in the cluster name to propagate action on each defined clusters in the rkClusters.php file. That should not be too complicated to add. I'll think about it !

Comments

What's hot ?

Wallbox : Get The Most Of It (with API)

Mac OS X : Display images in-line with terminal