Skip to content

Commit

Permalink
Add License header and minor changes (#110)
Browse files Browse the repository at this point in the history
Changes:

  - Add LICENSE Header where it was missing
  - Minor code/style changes
  • Loading branch information
marcosbarbero authored Sep 11, 2018
1 parent 93d01c0 commit 0aedcff
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
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

0 comments on commit 0aedcff

Please sign in to comment.