Created
November 21, 2013 15:21
-
-
Save underscorephil/7583408 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include('softlayer-api-php-client/SoftLayer/SoapClient.class.php'); | |
/* | |
* Loop through all permissions and remove permission objects who's key | |
* appears in the $permissionsToRemove array | |
*/ | |
function unsetArray($allPermissions, $permissionsToRemove) { | |
foreach($permissionsToRemove as $permissionToRemove) { | |
foreach($allPermissions as $index => $permission){ | |
if($permission->key == $permissionToRemove) { | |
print_r("Removing -> [" . $permission->key . "] " . $permission->name . "\n"); | |
unset($allPermissions[$index]); | |
} | |
} | |
} | |
return $allPermissions; | |
} | |
$apiUsername = ''; | |
$apiKey = ''; | |
$userId = ; | |
$userClient = SoftLayer_SoapClient::getClient('SoftLayer_User_Customer', $userId, $apiUsername, $apiKey); | |
$permissionClient = Softlayer_SoapClient::getClient('SoftLayer_User_Customer_CustomerPermission_Permission', null, $apiUsername, $apiKey); | |
// Get all possible portal permissions | |
$allPermissions = $permissionClient->getAllObjects(); | |
// Define the permission keys to exclude | |
$permissionsToRemove = array("SO_4", "A_0", "A_2", "A_3", "A_4", "H_2", "H_6", "NAS_2", "PU_2", "SE_3", "A_12", "A_11","T_4", "T_5","SO_8", "AP_1", "AP_2", "AP_3", "A_14", "A_13", "A_15", "A_16", "GTW_1", "DA_1", "DA_2"); | |
// Cull out the unwanted permissions | |
$culledPermissions = unsetArray($allPermissions, $permissionsToRemove); | |
try { | |
/* | |
* addBulkPortalPermission expects an array of objects, no conversion | |
* is needed from the return value of getAllObjects() | |
*/ | |
$result = $userClient->addBulkPortalPermission($culledPermissions); | |
} catch ( Exception $e) { | |
die( $e->getMessage() . "\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment