Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add License header and minor changes #110

Merged
merged 2 commits into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config;

import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.properties.RateLimitProperties;
Expand All @@ -8,6 +24,8 @@

/**
* Key generator for rate limit control.
*
* @author Liel Chayoun
*/
public interface RateLimitKeyGenerator {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public String key(HttpServletRequest request, Route route, RateLimitUtils rateLi
},
;

public abstract boolean apply(HttpServletRequest request, Route route, RateLimitUtils rateLimitUtils,
String matcher);
public abstract boolean apply(HttpServletRequest request, Route route,
RateLimitUtils rateLimitUtils, String matcher);

public abstract String key(HttpServletRequest request, Route route, RateLimitUtils rateLimitUtils);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
* Validates the rate limit policies.
*
* @author Liel Chayoun
*/
public class PoliciesValidator implements ConstraintValidator<Policies, Object> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Object run() {
Route route = route(request);

policy(route, request).forEach(policy -> {
Long requestTime = System.currentTimeMillis() - getRequestStartTime();
long requestTime = System.currentTimeMillis() - getRequestStartTime();
String key = rateLimitKeyGenerator.key(request, route, policy);
rateLimiter.consume(policy, key, requestTime > 0 ? requestTime : 1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.properties.RateLimitProperties.Policy.MatchType;
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.properties.RateLimitType;
import org.jetbrains.annotations.NotNull;
import org.springframework.core.convert.converter.Converter;

/**
Expand All @@ -28,7 +29,7 @@ public class StringToMatchTypeConverter implements Converter<String, MatchType>
private static final String DELIMITER = "=";

@Override
public MatchType convert(String type) {
public MatchType convert(@NotNull String type) {
if (type.contains(DELIMITER)) {
String[] matchType = type.split(DELIMITER);
return new MatchType(RateLimitType.valueOf(matchType[0].toUpperCase()), matchType[1]);
Expand Down