This is an automated email from the ASF dual-hosted git repository.
mchades pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new ba8df392c6 [#5987] improvement: Add more configurations for the config
API (#5999)
ba8df392c6 is described below
commit ba8df392c6436b01d3988caad6b5b00b90eef1ec
Author: roryqi <[email protected]>
AuthorDate: Thu Dec 26 20:40:57 2024 +0800
[#5987] improvement: Add more configurations for the config API (#5999)
### What changes were proposed in this pull request?
Add more configurations for the config API
### Why are the changes needed?
Fix #5987
Front end can use this config option to optimize the user experience.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?

---
.../apache/gravitino/server/web/ConfigServlet.java | 10 ++---
.../gravitino/server/web/TestConfigServlet.java | 46 ++++++++++++++++++++++
web/web/src/lib/store/auth/index.js | 2 +-
3 files changed, 51 insertions(+), 7 deletions(-)
diff --git
a/server/src/main/java/org/apache/gravitino/server/web/ConfigServlet.java
b/server/src/main/java/org/apache/gravitino/server/web/ConfigServlet.java
index cdce0a0b12..345a555cd9 100644
--- a/server/src/main/java/org/apache/gravitino/server/web/ConfigServlet.java
+++ b/server/src/main/java/org/apache/gravitino/server/web/ConfigServlet.java
@@ -42,22 +42,20 @@ public class ConfigServlet extends HttpServlet {
ImmutableSet.of(OAuthConfig.DEFAULT_SERVER_URI,
OAuthConfig.DEFAULT_TOKEN_PATH);
private static final ImmutableSet<ConfigEntry<?>> basicConfigEntries =
- ImmutableSet.of(Configs.AUTHENTICATORS);
+ ImmutableSet.of(Configs.AUTHENTICATORS, Configs.ENABLE_AUTHORIZATION);
- private final Map<String, String> configs = Maps.newHashMap();
+ private final Map<String, Object> configs = Maps.newHashMap();
public ConfigServlet(ServerConfig serverConfig) {
for (ConfigEntry<?> key : basicConfigEntries) {
- String config = String.valueOf(serverConfig.get(key));
- configs.put(key.getKey(), config);
+ configs.put(key.getKey(), serverConfig.get(key));
}
if (serverConfig
.get(Configs.AUTHENTICATORS)
.contains(AuthenticatorType.OAUTH.name().toLowerCase())) {
for (ConfigEntry<?> key : oauthConfigEntries) {
- String config = String.valueOf(serverConfig.get(key));
- configs.put(key.getKey(), config);
+ configs.put(key.getKey(), serverConfig.get(key));
}
}
}
diff --git
a/server/src/test/java/org/apache/gravitino/server/web/TestConfigServlet.java
b/server/src/test/java/org/apache/gravitino/server/web/TestConfigServlet.java
new file mode 100644
index 0000000000..c76587d039
--- /dev/null
+++
b/server/src/test/java/org/apache/gravitino/server/web/TestConfigServlet.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.gravitino.server.web;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.PrintWriter;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.gravitino.server.ServerConfig;
+import org.junit.jupiter.api.Test;
+
+public class TestConfigServlet {
+
+ @Test
+ public void testConfigServlet() throws Exception {
+ ServerConfig serverConfig = new ServerConfig();
+ ConfigServlet configServlet = new ConfigServlet(serverConfig);
+ configServlet.init();
+ HttpServletResponse res = mock(HttpServletResponse.class);
+ PrintWriter writer = mock(PrintWriter.class);
+ when(res.getWriter()).thenReturn(writer);
+ configServlet.doGet(null, res);
+ verify(writer)
+ .write(
+
"{\"gravitino.authorization.enable\":false,\"gravitino.authenticators\":[\"simple\"]}");
+ configServlet.destroy();
+ }
+}
diff --git a/web/web/src/lib/store/auth/index.js
b/web/web/src/lib/store/auth/index.js
index 83d58394c9..ec0f1f5212 100644
--- a/web/web/src/lib/store/auth/index.js
+++ b/web/web/src/lib/store/auth/index.js
@@ -40,7 +40,7 @@ export const getAuthConfigs =
createAsyncThunk('auth/getAuthConfigs', async () =
oauthUrl =
`${res['gravitino.authenticator.oauth.serverUri']}${res['gravitino.authenticator.oauth.tokenPath']}`
// ** get the first authenticator from the response. response example:
"[simple, oauth]"
- authType = res['gravitino.authenticators'].slice(1, -1).split(',')[0].trim()
+ authType = res['gravitino.authenticators'][0].trim()
localStorage.setItem('oauthUrl', oauthUrl)