Setting buckets limits in WHMCS

You can limit operations rate with the ostor-limits service and the following parameters: bucket specifying the bucket name, default=, get=, put=, list=, delete= specifying the limit value.

Similarly, you can limit outgoing bandwidth of a response with the ostor-limits service and the following parameters: bucket specifying the bucket name, out= specifying the limit value. WHMCS configures the bucket limits in S3 cluster when you click the Set button. Create a file S3_setLimitsForBucket.php with the following contents:

<?php

// Load configuration and libraries.
require('../../includes/staas_scripts/S3_getConfig.php');
require('../../includes/staas_scripts/S3_requestCurl.php');
require('../../init.php');

// Set s3 bucket limits.
function S3_setLimitsForBucket($vars) {

    // Load configuration.
    $s3_config = s3_getConfig();

    // Set only if value specified.
    if (!empty($vars['ops-value'])) {

        // Set s3 bucket limits (ops).
        S3_requestCurl(
            $s3_config['s3_key'],
            $s3_config['s3_secret'],
            $s3_config['s3_gateway'],
                "/?ostor-limits&bucket=" . $vars['bucket'] .
                "&limit-type=ops&limit-resource=" . $vars['ops-name'] .
                    '&limit-value=' . $vars['ops-value'],
            "PUT"
        );
    }

    // Set only if value specified.
    if (!empty($vars['bandwidth-value'])) {

        // Set s3 bucket limits (bandwidth).
        S3_requestCurl(
            $s3_config['s3_key'],
            $s3_config['s3_secret'],
            $s3_config['s3_gateway'],
                "/?ostor-limits&bucket=" . $vars['bucket'] .
                "&limit-type=bandwidth&limit-resource=" . $vars['bandwidth-name'] .
                    '&limit-value=' . $vars['bandwidth-value'],
            "PUT"
        );
    }

    // Redirect back.
    header('Location: ' . $_SERVER['HTTP_REFERER']);
}

// Call function.
S3_setLimitsForBucket($_GET);

?>