-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from HomeAdvisor/kafdrop-2.0.0
Sync Kafdrop 2.0.0 from HomeAdvisor
- Loading branch information
Showing
38 changed files
with
522 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/main/java/com/homeadvisor/kafdrop/config/CorsConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright 2017 HomeAdvisor, Inc. | ||
* | ||
* 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.homeadvisor.kafdrop.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import javax.servlet.*; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Auto configuration for enabling CORS support. Can override behavior with | ||
* various configs: | ||
* | ||
* <ul> | ||
* <li>cors.enabled</li> | ||
* <li>cors.allowOrigins</li> | ||
* <li>cors.allowMethods</li> | ||
* <li>cors.maxAge</li> | ||
* <li>cors.allowCredentials</li> | ||
* <li>cors.allowHeaders</li> | ||
* </ul> | ||
* <br/> | ||
* To disable CORS entirely, set <b>cors.enabled=false</b>. All other configs are | ||
* just Strings that get used as-is to set the corresponding CORS header. | ||
*/ | ||
@Configuration | ||
@ConditionalOnProperty(value = "cors.enabled", matchIfMissing = true) | ||
public class CorsConfiguration | ||
{ | ||
@Value("${cors.allowOrigins:*}") | ||
private String corsAllowOrigins; | ||
|
||
@Value("${cors.allowMethods:GET,POST,PUT,DELETE}") | ||
private String corsAllowMethods; | ||
|
||
@Value("${cors.maxAge:3600}") | ||
private String corsMaxAge; | ||
|
||
@Value("${cors.allowCredentials:true}") | ||
private String corsAllowCredentials; | ||
|
||
@Value("${cors.allowHeaders:Origin,Accept,X-Requested-With,Content-Type,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization}") | ||
private String corsAllowHeaders; | ||
|
||
@Bean | ||
@Order(Ordered.HIGHEST_PRECEDENCE) | ||
public Filter corsFilter() | ||
{ | ||
return new Filter() | ||
{ | ||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException | ||
{} | ||
|
||
@Override | ||
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException | ||
{ | ||
HttpServletResponse response = (HttpServletResponse) res; | ||
HttpServletRequest request = (HttpServletRequest) req; | ||
|
||
response.setHeader("Access-Control-Allow-Origin", corsAllowOrigins); | ||
response.setHeader("Access-Control-Allow-Methods", corsAllowMethods); | ||
response.setHeader("Access-Control-Max-Age", corsMaxAge); | ||
response.setHeader("Access-Control-Allow-Credentials", corsAllowCredentials); | ||
response.setHeader("Access-Control-Allow-Headers", corsAllowHeaders); | ||
|
||
if(request.getMethod().equals(HttpMethod.OPTIONS.name())) | ||
{ | ||
response.setStatus(HttpStatus.NO_CONTENT.value()); | ||
} | ||
else | ||
{ | ||
chain.doFilter(req, res); | ||
} | ||
} | ||
|
||
@Override | ||
public void destroy() {} | ||
}; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/homeadvisor/kafdrop/config/CuratorConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/homeadvisor/kafdrop/config/HealthCheckConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/homeadvisor/kafdrop/config/ServiceDiscoveryConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/com/homeadvisor/kafdrop/config/SwaggerConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2017 HomeAdvisor, Inc. | ||
* | ||
* 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.homeadvisor.kafdrop.config; | ||
|
||
import com.google.common.base.Predicate; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.MediaType; | ||
import springfox.documentation.RequestHandler; | ||
import springfox.documentation.builders.ApiInfoBuilder; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
/** | ||
* Auto configuration for Swagger. Can be disabled by setting swagger.enabled=false. | ||
*/ | ||
@Configuration | ||
@EnableSwagger2 | ||
@ConditionalOnProperty(value = "swagger.enabled", matchIfMissing = true) | ||
public class SwaggerConfiguration | ||
{ | ||
@Bean | ||
public Docket swagger() | ||
{ | ||
return new Docket(DocumentationType.SWAGGER_2) | ||
.useDefaultResponseMessages(false) | ||
.apiInfo(new ApiInfoBuilder() | ||
.title("Kafdrop API") | ||
.description("JSON APIs for Kafdrop") | ||
.build()) | ||
.select() | ||
.apis(new JsonRequestHandlerPredicate()) | ||
.paths(new IgnoreDebugPathPredicate()) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Swagger Predicate for only selecting JSON endpoints. | ||
*/ | ||
public class JsonRequestHandlerPredicate implements Predicate<RequestHandler> | ||
{ | ||
@Override | ||
public boolean apply(RequestHandler input) | ||
{ | ||
return input.produces().contains(MediaType.APPLICATION_JSON); | ||
} | ||
} | ||
|
||
/** | ||
* Swagger Predicate for ignoring /debug endpoints. | ||
*/ | ||
public class IgnoreDebugPathPredicate implements Predicate<String> | ||
{ | ||
@Override | ||
public boolean apply(String input) | ||
{ | ||
return !input.startsWith("/debug"); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/homeadvisor/kafdrop/config/ini/IniFileProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/homeadvisor/kafdrop/config/ini/IniFilePropertySource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/homeadvisor/kafdrop/config/ini/IniFileReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.