Skip to content

Commit 74248d8

Browse files
committed
optimize
1 parent b377f28 commit 74248d8

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

src/main/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public void connect() throws IOException {
193193
String password = options.getPassword();
194194
if (!"".equals(username) && !"".equals(password)) {
195195
interceptedChannel = ClientInterceptors.intercept(rawChannel,
196-
new AuthInterceptor(options.getUsername(), options.getPassword()));
196+
new AuthInterceptor(username, password));
197197
}
198198
// Ensure this.channel is assigned only once.
199199
this.channel = interceptedChannel;

src/main/java/org/apache/skywalking/banyandb/v1/client/auth/AuthInterceptor.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public class AuthInterceptor implements ClientInterceptor {
3030
private final String username;
3131
private final String password;
3232

33+
private static final Metadata.Key<String> USERNAME_KEY =
34+
Metadata.Key.of("username", Metadata.ASCII_STRING_MARSHALLER);
35+
private static final Metadata.Key<String> PASSWORD_KEY =
36+
Metadata.Key.of("password", Metadata.ASCII_STRING_MARSHALLER);
37+
3338
public AuthInterceptor(String username, String password) {
3439
this.username = username;
3540
this.password = password;
@@ -45,11 +50,8 @@ public <REQ_T, RESP_T> ClientCall<REQ_T, RESP_T> interceptCall(
4550
next.newCall(method, callOptions)) {
4651
@Override
4752
public void start(Listener<RESP_T> responseListener, Metadata headers) {
48-
Metadata.Key<String> usernameKey = Metadata.Key.of("username", Metadata.ASCII_STRING_MARSHALLER);
49-
Metadata.Key<String> passwordKey = Metadata.Key.of("password", Metadata.ASCII_STRING_MARSHALLER);
50-
51-
headers.put(usernameKey, username);
52-
headers.put(passwordKey, password);
53+
headers.put(USERNAME_KEY, username);
54+
headers.put(PASSWORD_KEY, password);
5355

5456
super.start(responseListener, headers);
5557
}

src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBAuthTest.java renamed to src/test/java/org/apache/skywalking/banyandb/v1/client/ITBanyanDBAuthTest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@
3333
import java.nio.file.Path;
3434
import java.nio.file.Paths;
3535
import java.nio.file.attribute.PosixFilePermissions;
36-
import java.util.Base64;
3736
import java.util.List;
3837
import java.util.concurrent.TimeUnit;
3938

4039
import static org.awaitility.Awaitility.await;
4140
import static org.junit.Assert.assertThrows;
4241

43-
public class BanyanDBAuthTest {
42+
public class ITBanyanDBAuthTest {
4443
private static final String REGISTRY = "ghcr.io";
4544
private static final String IMAGE_NAME = "apache/skywalking-banyandb";
4645
private static final String TAG = "42ec9df7457868926eb80157b36355d94fcd6bba";
@@ -53,7 +52,7 @@ public class BanyanDBAuthTest {
5352
@Rule
5453
public GenericContainer<?> banyanDB;
5554

56-
public BanyanDBAuthTest() throws Exception {
55+
public ITBanyanDBAuthTest() throws Exception {
5756
// Step 1: prepare config file with 0600 permissions
5857
Path tempConfigPath = Files.createTempFile("bydb_server_config", ".yaml");
5958
Files.write(tempConfigPath, Files.readAllBytes(
@@ -68,14 +67,10 @@ public BanyanDBAuthTest() throws Exception {
6867
"/tmp/bydb_server_config.yaml"
6968
)
7069
.withCommand("standalone",
71-
"--auth-config-file", "/tmp/bydb_server_config.yaml",
72-
"--enable-health-auth", "true"
70+
"--auth-config-file", "/tmp/bydb_server_config.yaml"
7371
)
7472
.withExposedPorts(GRPC_PORT, HTTP_PORT)
75-
.waitingFor(Wait.forHttp("/api/healthz")
76-
.withHeader("Authorization",
77-
"Basic " + Base64.getEncoder().encodeToString("admin:123456".getBytes()))
78-
.forPort(HTTP_PORT));
73+
.waitingFor(Wait.forHttp("/api/healthz").forPort(HTTP_PORT));
7974
}
8075

8176
@Test

0 commit comments

Comments
 (0)