use of com.predic8.membrane.core.interceptor.apimanagement.policy.Policy in project service-proxy by membrane.
the class ApiManagementConfiguration method parsePoliciesForKeys.
private Map<String, Key> parsePoliciesForKeys(Map<String, Object> yaml) {
Map<String, Key> result = new HashMap<String, Key>();
// assumption: the yaml is valid
List<Object> keys = (List<Object>) yaml.get("keys");
if (keys == null) {
log.info("No API keys in policy file");
return result;
}
for (Object keyObject : keys) {
LinkedHashMap<String, Object> key = (LinkedHashMap<String, Object>) keyObject;
Key keyRes = new Key();
String keyName = (String) key.get("key");
keyRes.setName(keyName);
parseExpiration(key, keyRes);
List<Object> policiesForKey = (List<Object>) key.get("policies");
HashSet<Policy> policies = new HashSet<Policy>();
for (Object polObj : policiesForKey) {
String policyName = (String) polObj;
Policy p = this.policies.get(policyName);
policies.add(p);
}
keyRes.setPolicies(policies);
result.put(keyName, keyRes);
}
return result;
}
use of com.predic8.membrane.core.interceptor.apimanagement.policy.Policy in project service-proxy by membrane.
the class AMQuota method fillPolicyQuotas.
private void fillPolicyQuotas() {
policyQuotas.clear();
for (Policy policy : amc.getPolicies().values()) {
String name = policy.getName();
long quotaSize = policy.getQuota().getSize();
int interval = policy.getQuota().getInterval();
HashSet<String> services = new HashSet<String>(policy.getServiceProxies());
PolicyQuota pq = new PolicyQuota();
pq.setName(name);
pq.setSize(quotaSize);
pq.setInterval(Duration.standardSeconds(interval));
pq.incrementNextCleanup();
pq.setServices(services);
policyQuotas.put(name, pq);
}
}
use of com.predic8.membrane.core.interceptor.apimanagement.policy.Policy in project service-proxy by membrane.
the class AMRateLimiter method addRequestEntry.
private void addRequestEntry(String apiKey) {
synchronized (keyInformation) {
if (!keyInformation.containsKey(apiKey)) {
ApiKeyRequestCounter value = new ApiKeyRequestCounter();
Key key = amc.getKeys().get(apiKey);
for (Policy p : key.getPolicies()) {
value.getPolicyCounters().put(p.getName(), new AtomicInteger());
}
keyInformation.put(apiKey, value);
}
}
ApiKeyRequestCounter keyInfo = keyInformation.get(apiKey);
for (AtomicInteger counter : keyInfo.getPolicyCounters().values()) {
counter.incrementAndGet();
}
}
Aggregations