Exemplo n.º 1
0
function api_config_apply_blessings()
{
    foreach ($GLOBALS['cfg']['api']['blessings'] as $api_key => $key_details) {
        $blessing_defaults = array();
        foreach (array('hosts', 'tokens', 'environments') as $prop) {
            if (isset($key_details[$prop])) {
                $blessing_defaults[$prop] = $key_details[$prop];
            }
        }
        if (is_array($key_details['method_classes'])) {
            foreach ($key_details['method_classes'] as $class_spec => $blessing_details) {
                foreach ($GLOBALS['cfg']['api']['methods'] as $method_name => $method_details) {
                    if (!$method_details['requires_blessing']) {
                        continue;
                    }
                    if (!preg_match("/^{$class_spec}/", $method_name)) {
                        continue;
                    }
                    $blessing = array_merge($blessing_defaults, $blessing_details);
                    _api_config_apply_blessing($method_name, $api_key, $blessing);
                }
            }
        }
        if (is_array($key_details['methods'])) {
            foreach ($key_details['methods'] as $method_name => $blessing_details) {
                $blessing = array_merge($blessing_defaults, $blessing_details);
                _api_config_apply_blessing($method_name, $api_key, $blessing);
            }
        }
    }
}
Exemplo n.º 2
0
function api_config_init_blessings()
{
    # $GLOBALS['timing_keys']["api_blessings"] = "API blessings";
    # $GLOBALS['timings']['api_blessings_count'] = 0;
    # $GLOBALS['timings']['api_blessings_time'] = 0;
    foreach ($GLOBALS['cfg']['api']['blessings'] as $api_key => $key_details) {
        # $GLOBALS['timings']['api_blessings_count'] += 1;
        $start = microtime_ms();
        $whoami = $api_key;
        if ($api_key == 'site_key') {
            loadlib("api_keys");
            $blessed_site_keys = features_is_enabled(array("api_site_keys", "api_site_keys_blessed")) ? 1 : 0;
            if ($blessed_site_keys && ($site_key = api_keys_fetch_site_key())) {
                $api_key = $site_key['api_key'];
            }
        }
        $blessing_defaults = array();
        foreach (array('hosts', 'tokens', 'environments') as $prop) {
            if (isset($key_details[$prop])) {
                $blessing_defaults[$prop] = $key_details[$prop];
            }
        }
        if (is_array($key_details['method_classes'])) {
            foreach ($key_details['method_classes'] as $class_spec => $blessing_details) {
                foreach ($GLOBALS['cfg']['api']['methods'] as $method_name => $method_details) {
                    if (!$method_details['requires_blessing']) {
                        continue;
                    }
                    if (!preg_match("/^{$class_spec}/", $method_name)) {
                        continue;
                    }
                    $blessing = array_merge($blessing_defaults, $blessing_details);
                    _api_config_apply_blessing($method_name, $api_key, $blessing);
                }
            }
        }
        if (is_array($key_details['methods'])) {
            foreach ($key_details['methods'] as $method_name => $blessing_details) {
                $blessing = array_merge($blessing_defaults, $blessing_details);
                _api_config_apply_blessing($method_name, $api_key, $blessing);
            }
        }
        # _api_config_apply_blessing('api.test.isBlessed', $api_key, $blessing_defaults);
        $end = microtime_ms();
        $time = $end - $start;
        # $GLOBALS['timings']['api_blessings_time'] += $time;
    }
}