-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract bookkeeper admin common
Signed-off-by: ZhangJian He <shoothzj@gmail.com>
- Loading branch information
ZhangJian He
committed
Aug 30, 2024
1 parent
32fe92d
commit aa50f62
Showing
23 changed files
with
176 additions
and
86 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...keeper-admin-api/src/main/java/io/github/protocol/bookkeeper/admin/api/Configuration.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,34 @@ | ||
package io.github.protocol.bookkeeper.admin.api; | ||
|
||
public class Configuration { | ||
public String host = "localhost"; | ||
|
||
public int port; | ||
|
||
public boolean tlsEnabled; | ||
|
||
public TlsConfig tlsConfig; | ||
|
||
public Configuration() { | ||
} | ||
|
||
public Configuration host(String host) { | ||
this.host = host; | ||
return this; | ||
} | ||
|
||
public Configuration port(int port) { | ||
this.port = port; | ||
return this; | ||
} | ||
|
||
public Configuration tlsEnabled(boolean tlsEnabled) { | ||
this.tlsEnabled = tlsEnabled; | ||
return this; | ||
} | ||
|
||
public Configuration tlsConfig(TlsConfig tlsConfig) { | ||
this.tlsConfig = tlsConfig; | ||
return this; | ||
} | ||
} |
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,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.protocol-laboratory</groupId> | ||
<artifactId>bookkeeper-admin-parent</artifactId> | ||
<version>0.0.3</version> | ||
</parent> | ||
|
||
<artifactId>bookkeeper-admin-common</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.github.protocol-laboratory</groupId> | ||
<artifactId>bookkeeper-admin-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
20 changes: 1 addition & 19 deletions
20
.../bookkeeper/admin/jdk/JacksonService.java → ...okkeeper/admin/common/JacksonService.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
1 change: 1 addition & 0 deletions
1
...r-admin-common/src/main/java/io/github/protocol/bookkeeper/admin/common/package-info.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 @@ | ||
package io.github.protocol.bookkeeper.admin.common; |
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
1 change: 1 addition & 0 deletions
1
...per-admin-jdk/src/main/java/io/github/protocol/bookkeeper/admin/jdk/AutoRecoveryImpl.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
1 change: 1 addition & 0 deletions
1
bookkeeper-admin-jdk/src/main/java/io/github/protocol/bookkeeper/admin/jdk/BookiesImpl.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
2 changes: 2 additions & 0 deletions
2
...-admin-jdk/src/main/java/io/github/protocol/bookkeeper/admin/jdk/BookkeeperAdminImpl.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: 2 additions & 0 deletions
2
bookkeeper-admin-jdk/src/main/java/io/github/protocol/bookkeeper/admin/jdk/ConfigsImpl.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
15 changes: 0 additions & 15 deletions
15
...keeper-admin-jdk/src/main/java/io/github/protocol/bookkeeper/admin/jdk/Configuration.java
This file was deleted.
Oops, something went wrong.
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
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
33 changes: 33 additions & 0 deletions
33
...ctive/src/main/java/io/github/protocol/bookkeeper/admin/reactive/InnerReactiveClient.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,33 @@ | ||
package io.github.protocol.bookkeeper.admin.reactive; | ||
|
||
import io.github.protocol.bookkeeper.admin.api.Configuration; | ||
import io.netty.handler.ssl.SslContext; | ||
import reactor.netty.http.client.HttpClient; | ||
import reactor.netty.http.client.HttpClientSecurityUtils; | ||
|
||
public class InnerReactiveClient { | ||
private final HttpClient httpClient; | ||
|
||
private final String httpPrefix; | ||
|
||
public InnerReactiveClient(Configuration conf) { | ||
HttpClient client = HttpClient.create(); | ||
|
||
if (conf.tlsEnabled) { | ||
client = client.secure(spec -> { | ||
SslContext context = SslContextUtil.build(conf.tlsConfig); | ||
if (conf.tlsConfig.hostnameVerifyDisabled) { | ||
spec.sslContext(context) | ||
.handlerConfigurator(HttpClientSecurityUtils.HOSTNAME_VERIFICATION_CONFIGURER); | ||
} else { | ||
spec.sslContext(context); | ||
} | ||
}); | ||
this.httpPrefix = "https://" + conf.host + ":" + conf.port; | ||
} else { | ||
this.httpPrefix = "http://" + conf.host + ":" + conf.port; | ||
} | ||
|
||
this.httpClient = client; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...n-reactive/src/main/java/io/github/protocol/bookkeeper/admin/reactive/SslContextUtil.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,57 @@ | ||
package io.github.protocol.bookkeeper.admin.reactive; | ||
|
||
import io.github.protocol.bookkeeper.admin.api.TlsConfig; | ||
import io.netty.handler.ssl.SslContext; | ||
import io.netty.handler.ssl.SslContextBuilder; | ||
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; | ||
|
||
import java.io.FileInputStream; | ||
import java.security.KeyStore; | ||
import java.util.Arrays; | ||
import javax.net.ssl.KeyManagerFactory; | ||
import javax.net.ssl.TrustManagerFactory; | ||
|
||
public class SslContextUtil { | ||
|
||
public static SslContext build(TlsConfig config) { | ||
try { | ||
SslContextBuilder sslContextBuilder = SslContextBuilder.forClient(); | ||
|
||
if (config.keyStorePath != null && config.keyStorePassword != null) { | ||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); | ||
try (FileInputStream keyStoreInputStream = new FileInputStream(config.keyStorePath)) { | ||
keyStore.load(keyStoreInputStream, config.keyStorePassword); | ||
} | ||
String defaultKeyAlgorithm = KeyManagerFactory.getDefaultAlgorithm(); | ||
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(defaultKeyAlgorithm); | ||
keyManagerFactory.init(keyStore, config.keyStorePassword); | ||
sslContextBuilder.keyManager(keyManagerFactory); | ||
} | ||
|
||
if (config.verifyDisabled) { | ||
sslContextBuilder.trustManager(InsecureTrustManagerFactory.INSTANCE); | ||
} else if (config.trustStorePath != null && config.trustStorePassword != null) { | ||
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); | ||
try (FileInputStream trustStoreInputStream = new FileInputStream(config.trustStorePath)) { | ||
trustStore.load(trustStoreInputStream, config.trustStorePassword); | ||
} | ||
String defaultTrustAlgorithm = TrustManagerFactory.getDefaultAlgorithm(); | ||
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(defaultTrustAlgorithm); | ||
trustManagerFactory.init(trustStore); | ||
sslContextBuilder.trustManager(trustManagerFactory); | ||
} | ||
|
||
if (config.versions != null) { | ||
sslContextBuilder.protocols(config.versions); | ||
} | ||
|
||
if (config.cipherSuites != null) { | ||
sslContextBuilder.ciphers(Arrays.asList(config.cipherSuites)); | ||
} | ||
|
||
return sslContextBuilder.build(); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Error setting up SSL configuration", e); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...min-reactive/src/main/java/io/github/protocol/bookkeeper/admin/reactive/package-info.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 @@ | ||
package io.github.protocol.bookkeeper.admin.reactive; |
17 changes: 0 additions & 17 deletions
17
...dmin-reactor/src/main/java/io/github/protocol/bookkeeper/admin/reactor/Configuration.java
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
...reactor/src/main/java/io/github/protocol/bookkeeper/admin/reactor/InnerReactorClient.java
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...admin-reactor/src/main/java/io/github/protocol/bookkeeper/admin/reactor/package-info.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.