-
Notifications
You must be signed in to change notification settings - Fork 163
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
Updated to new kafka client version with an option to connect to secured kafka cluster #30
base: master
Are you sure you want to change the base?
Changes from all commits
5885f77
1f0f7ee
86a87fd
f04b9c1
40e0f11
d374988
2dc8961
dcb8153
b82d25a
9696d20
ff2d2f3
b2bd7f2
e25371b
c729913
e06310c
8b33a1b
79a26de
ad8d259
62edd62
9413d1d
666b4b6
c08766f
d1e28fe
e57ad28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Client { | ||
org.apache.zookeeper.server.auth.DigestLoginModule required | ||
username="xyz" | ||
password="xyz"; | ||
}; | ||
|
||
KafkaClient { | ||
org.apache.kafka.common.security.plain.PlainLoginModule required | ||
username="xyz" | ||
password="xyz"; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import com.google.common.base.Throwables; | ||
import com.homeadvisor.kafdrop.config.ini.IniFilePropertySource; | ||
import com.homeadvisor.kafdrop.config.ini.IniFileReader; | ||
import joptsimple.internal.Strings; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.Banner; | ||
|
@@ -36,7 +37,12 @@ | |
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||
|
||
import java.io.*; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.util.Objects; | ||
import java.util.stream.Stream; | ||
|
||
|
@@ -83,17 +89,15 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) | |
catch (Exception ex) | ||
{ | ||
System.err.println("Unable to set up logging.dir from logging.file " + loggingFile + ": " + | ||
Throwables.getStackTraceAsString(ex)); | ||
Throwables.getStackTraceAsString(ex)); | ||
} | ||
} | ||
if (environment.containsProperty("debug") && | ||
!"false".equalsIgnoreCase(environment.getProperty("debug", String.class))) | ||
!"false".equalsIgnoreCase(environment.getProperty("debug", String.class))) | ||
{ | ||
System.setProperty(PROP_SPRING_BOOT_LOG_LEVEL, "DEBUG"); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
private static class EnvironmentSetupListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered | ||
|
@@ -107,19 +111,41 @@ public int getOrder() | |
return Ordered.HIGHEST_PRECEDENCE + 10; | ||
} | ||
|
||
@Override | ||
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) | ||
{ | ||
final ConfigurableEnvironment environment = event.getEnvironment(); | ||
if (environment.containsProperty(SM_CONFIG_DIR)) | ||
{ | ||
Stream.of("kafdrop", "global") | ||
.map(name -> readProperties(environment, name)) | ||
.filter(Objects::nonNull) | ||
.forEach(iniPropSource -> environment.getPropertySources() | ||
.addBefore("applicationConfigurationProperties", iniPropSource)); | ||
} | ||
} | ||
@Override | ||
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) | ||
{ | ||
final ConfigurableEnvironment environment = event.getEnvironment(); | ||
|
||
LOG.info("Initializing jaas config"); | ||
String env = environment.getProperty("kafka.env"); | ||
Boolean isSecured = environment.getProperty("kafka.isSecured", Boolean.class); | ||
LOG.info("env: {} .Issecured kafka: {}", env, isSecured); | ||
if (isSecured && Strings.isNullOrEmpty(env)) { | ||
throw new RuntimeException("'env' cannot be null if connecting to secured kafka."); | ||
} | ||
|
||
LOG.info("ENV: {}", env); | ||
String path; | ||
|
||
if (isSecured) { | ||
if ((env.equalsIgnoreCase("stage") || env.equalsIgnoreCase("prod") || env.equalsIgnoreCase("local"))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there something special about these particular environment names? Would rather not dictate how folks organize their environments. There's already a check for a non-null environment, so couldn't this just use the environment name as provided? |
||
path = environment.getProperty("user.dir") + "/kaas_" + env.toLowerCase() + "_jaas.conf"; | ||
LOG.info("PATH: {}", path); | ||
System.setProperty("java.security.auth.login.config", path); | ||
} | ||
else { | ||
throw new RuntimeException("unable to identify env. set 'evn' variable either to 'stage' or 'prod' or local"); | ||
} | ||
} | ||
|
||
if (environment.containsProperty(SM_CONFIG_DIR)) { | ||
Stream.of("kafdrop", "global") | ||
.map(name -> readProperties(environment, name)) | ||
.filter(Objects::nonNull) | ||
.forEach(iniPropSource -> environment.getPropertySources() | ||
.addBefore("applicationConfigurationProperties", iniPropSource)); | ||
} | ||
} | ||
|
||
private IniFilePropertySource readProperties(Environment environment, String name) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.homeadvisor.kafdrop.config; | ||
|
||
import lombok.*; | ||
import org.springframework.boot.context.properties.*; | ||
import org.springframework.stereotype.*; | ||
|
||
/** | ||
* Created by Satendra Sahu on 9/26/18 | ||
*/ | ||
@Component | ||
@ConfigurationProperties(prefix = "kafka") | ||
@Data | ||
public class KafkaConfiguration | ||
{ | ||
private String env = "local"; | ||
private String brokerConnect; | ||
private Boolean isSecured = false; | ||
private String keyDeserializer; | ||
private String valueDeserializer; | ||
private String saslMechanism; | ||
private String securityProtocol; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,10 +28,16 @@ | |
import io.swagger.annotations.ApiResponse; | ||
import io.swagger.annotations.ApiResponses; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
@@ -112,4 +118,10 @@ public static class ClusterInfoVO | |
public List<BrokerVO> brokers; | ||
public List<TopicVO> topics; | ||
} | ||
|
||
@ResponseStatus(HttpStatus.OK) | ||
@RequestMapping("/health_check") | ||
public void healthCheck() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spring Boot already provides a health status endpoint. What is this endpoint needed for? |
||
{ | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like
IllegalArgumentException
orIllegalStateException
would be a more appropriate exception here.