Skip to content

Commit

Permalink
feat: Support generating default routes pointing to the landing page (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
CH3CHO authored Jan 6, 2025
1 parent 12825df commit 73f0a62
Show file tree
Hide file tree
Showing 37 changed files with 787 additions and 164 deletions.
1 change: 1 addition & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ header:
- 'backend/**/pom.xml'
- 'backend/*.sh'
- 'backend/**/*.json'
- 'backend/**/*.html'
- 'backend/**/*.md'
- 'backend/**/*.yaml'
- 'backend/.mvn/**'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@

import com.alibaba.higress.console.context.HttpContext;
import com.alibaba.higress.console.controller.HealthzController;
import com.alibaba.higress.console.controller.LandingController;
import com.alibaba.higress.console.controller.SessionController;
import com.alibaba.higress.console.controller.SystemController;
import com.alibaba.higress.console.controller.dto.Response;
import com.alibaba.higress.console.controller.dto.User;
import com.alibaba.higress.console.controller.exception.AuthException;
import com.alibaba.higress.console.model.User;
import com.alibaba.higress.console.service.SessionService;
import com.alibaba.higress.console.service.SessionUserHelper;
import com.alibaba.higress.sdk.exception.BusinessException;
Expand Down Expand Up @@ -104,6 +105,9 @@ private static boolean isLoginRequired(ProceedingJoinPoint point) {
if (point.getTarget() instanceof HealthzController) {
return false;
}
if (point.getTarget() instanceof LandingController) {
return false;
}
if (point.getTarget() instanceof SessionController) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ public class SdkConfig {
@Value("${" + SystemConfigKey.NS_KEY + ":" + HigressConstants.NS_DEFAULT + "}")
private String controllerNamespace = HigressConstants.NS_DEFAULT;

@Value("${" + SystemConfigKey.CONTROLLER_INGRESS_CLASS_NAME_KEY + ":"
+ HigressConstants.CONTROLLER_INGRESS_CLASS_NAME_DEFAULT + "}")
private String controllerIngressClassName = HigressConstants.CONTROLLER_INGRESS_CLASS_NAME_DEFAULT;
@Value("${" + SystemConfigKey.CONTROLLER_WATCHED_NAMESPACE_KEY + ":}")
private String controllerWatchedNamespace;

@Value("${" + SystemConfigKey.CONTROLLER_INGRESS_CLASS_NAME_KEY + ":}")
private String controllerWatchedIngressClassName;

@Value("${" + SystemConfigKey.CONTROLLER_SERVICE_HOST_KEY + ":" + HigressConstants.CONTROLLER_SERVICE_HOST_DEFAULT
+ "}")
Expand All @@ -74,7 +76,8 @@ public class SdkConfig {
@PostConstruct
public void initialize() throws IOException {
HigressServiceConfig config = HigressServiceConfig.builder().withKubeConfigPath(kubeConfig)
.withIngressClassName(controllerIngressClassName).withControllerNamespace(controllerNamespace)
.withControllerNamespace(controllerNamespace).withControllerWatchedNamespace(controllerWatchedNamespace)
.withControllerWatchedIngressClassName(controllerWatchedIngressClassName)
.withControllerServiceName(controllerServiceName).withControllerServiceHost(controllerServiceHost)
.withControllerServicePort(controllerServicePort).withControllerJwtPolicy(controllerJwtPolicy)
.withControllerAccessToken(controllerAccessToken).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,20 @@ public class SystemConfigKey {

public static final String CONTROLLER_SERVICE_HOST_KEY = CONFIG_KEY_PREFIX + "controller.service.host";

public static final String CONTROLLER_WATCHED_NAMESPACE_KEY = CONFIG_KEY_PREFIX + "controller.watched-namespace";

public static final String CONTROLLER_INGRESS_CLASS_NAME_KEY = CONFIG_KEY_PREFIX + "controller.ingress-class-name";

public static final String CONTROLLER_SERVICE_NAME_KEY = CONFIG_KEY_PREFIX + "controller.service.name";

public static final String CONSOLE_SERVICE_HOST_KEY = CONFIG_KEY_PREFIX + "service.host";

public static final String DEFAULT_CONSOLE_SERVICE_HOST = "higress-console.higress-system.svc.cluster.local";

public static final String CONSOLE_SERVICE_PORT_KEY = CONFIG_KEY_PREFIX + "service.port";

public static final int DEFAULT_CONSOLE_SERVICE_PORT = 8080;

public static final String CONFIG_MAP_NAME_KEY = CONFIG_KEY_PREFIX + "config-map.name";

public static final String CONFIG_MAP_NAME_KEY_DEFAULT = "higress-console";
Expand Down Expand Up @@ -71,13 +81,15 @@ public class SystemConfigKey {

public static final String DASHBOARD_PASSWORD_DEFAULT = "admin";

public static final String DASHBOARD_DATASOURCE_PROM_NAME_KEY = CONFIG_KEY_PREFIX + "dashboard.datasource.prom.name";
public static final String DASHBOARD_DATASOURCE_PROM_NAME_KEY =
CONFIG_KEY_PREFIX + "dashboard.datasource.prom.name";

public static final String DASHBOARD_DATASOURCE_PROM_NAME_DEFAULT = "Prometheus";

public static final String DASHBOARD_DATASOURCE_PROM_URL_KEY = CONFIG_KEY_PREFIX + "dashboard.datasource.prom.url";

public static final String DASHBOARD_DATASOURCE_LOKI_NAME_KEY = CONFIG_KEY_PREFIX + "dashboard.datasource.loki.name";
public static final String DASHBOARD_DATASOURCE_LOKI_NAME_KEY =
CONFIG_KEY_PREFIX + "dashboard.datasource.loki.name";

public static final String DASHBOARD_DATASOURCE_LOKI_NAME_DEFAULT = "Loki";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class UserConfigKey {

private UserConfigKey() {}

public static final String DEFAULT_ROUTE_INITIALIZED = "route.default.initialized";
public static final String SYSTEM_INITIALIZED = "system.initialized";
public static final String LOGIN_PAGE_PROMPT_KEY = "login.prompt";
public static final String DASHBOARD_URL = "dashboard.url";
Expand All @@ -37,6 +38,7 @@ private UserConfigKey() {}
CONFIG_VALUE_TYPES.put(CHAT_ENABLED, Boolean.class);
CONFIG_VALUE_TYPES.put(ADMIN_PASSWORD_CHANGE_DISABLED, Boolean.class);
CONFIG_VALUE_TYPES.put(DASHBOARD_BUILTIN, Boolean.class);
CONFIG_VALUE_TYPES.put(DEFAULT_ROUTE_INITIALIZED, Boolean.class);
CONFIG_VALUE_TYPES.put(SYSTEM_INITIALIZED, Boolean.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.higress.console.controller.dto.DashboardInfo;
import com.alibaba.higress.console.controller.dto.DashboardType;
import com.alibaba.higress.console.controller.dto.Response;
import com.alibaba.higress.console.model.DashboardInfo;
import com.alibaba.higress.console.model.DashboardType;
import com.alibaba.higress.console.service.DashboardService;
import com.alibaba.higress.sdk.exception.ValidationException;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2022-2025 Alibaba Group Holding Ltd.
*
* 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.alibaba.higress.console.controller;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import javax.annotation.PostConstruct;

import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/landing")
public class LandingController {

private static final String BUILTIN_LANDING_PAGE = "landing/index.html";
private static final String DEFAULT_LANDING_PAGE_HTML = "<h1>Thanks for using Higress.</h1>";

private String landingPageHtml;

@PostConstruct
public void initialize() {
String landingPageHtml;
try (InputStream stream = getClass().getClassLoader().getResourceAsStream(BUILTIN_LANDING_PAGE)) {
landingPageHtml = StreamUtils.copyToString(stream, StandardCharsets.UTF_8);
} catch (IOException ex) {
log.error("Error occurs when loading the built-in landing page.", ex);
landingPageHtml = DEFAULT_LANDING_PAGE_HTML;
}
this.landingPageHtml = landingPageHtml;
}

@RequestMapping(produces = "text/html")
public String index() {
return landingPageHtml;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

import com.alibaba.higress.console.controller.dto.LoginRequest;
import com.alibaba.higress.console.controller.dto.Response;
import com.alibaba.higress.console.controller.dto.User;
import com.alibaba.higress.console.controller.exception.AuthException;
import com.alibaba.higress.sdk.exception.ValidationException;
import com.alibaba.higress.console.controller.util.ControllerUtil;
import com.alibaba.higress.console.model.User;
import com.alibaba.higress.console.service.SessionService;
import com.alibaba.higress.sdk.exception.ValidationException;

/**
* @author CH3CHO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
Expand All @@ -33,13 +30,11 @@

import com.alibaba.higress.console.constant.UserConfigKey;
import com.alibaba.higress.console.controller.dto.Response;
import com.alibaba.higress.console.controller.dto.SystemInfo;
import com.alibaba.higress.console.controller.dto.SystemInitRequest;
import com.alibaba.higress.console.controller.dto.User;
import com.alibaba.higress.console.controller.util.ControllerUtil;
import com.alibaba.higress.console.model.SystemInfo;
import com.alibaba.higress.console.model.User;
import com.alibaba.higress.console.service.ConfigService;
import com.alibaba.higress.console.service.DashboardService;
import com.alibaba.higress.console.service.SessionService;
import com.alibaba.higress.console.service.SystemService;
import com.alibaba.higress.sdk.exception.ValidationException;

Expand All @@ -51,21 +46,9 @@
@Validated
public class SystemController {

private DashboardService dashboardService;
private SessionService sessionService;
private ConfigService configService;
private SystemService systemService;

@Autowired
public void setDashboardService(DashboardService dashboardService) {
this.dashboardService = dashboardService;
}

@Autowired
public void setSessionService(SessionService sessionService) {
this.sessionService = sessionService;
}

@Autowired
public void setConfigService(ConfigService configService) {
this.configService = configService;
Expand All @@ -76,12 +59,6 @@ public void setSystemService(SystemService systemService) {
this.systemService = systemService;
}

@PostConstruct
public void syncSystemState() {
configService.setConfig(UserConfigKey.SYSTEM_INITIALIZED, sessionService.isAdminInitialized());
configService.setConfig(UserConfigKey.DASHBOARD_BUILTIN, dashboardService.isBuiltIn());
}

@PostMapping("/init")
public ResponseEntity<?> initialize(@RequestBody SystemInitRequest request) {
User adminUser = request.getAdminUser();
Expand All @@ -92,16 +69,7 @@ public ResponseEntity<?> initialize(@RequestBody SystemInitRequest request) {
throw new ValidationException("Incomplete adminUser object.");
}

if (!sessionService.isAdminInitialized()) {
sessionService.initializeAdmin(adminUser);
}

Map<String, Object> configs = new HashMap<>();
if (MapUtils.isNotEmpty(request.getConfigs())) {
configs.putAll(request.getConfigs());
}
configs.put(UserConfigKey.SYSTEM_INITIALIZED, true);
configService.setConfigs(configs);
systemService.initSystem(adminUser, request.getConfigs());

return ControllerUtil.buildSuccessResponseEntity();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import com.alibaba.higress.console.controller.dto.ChangePasswordRequest;
import com.alibaba.higress.console.controller.dto.Response;
import com.alibaba.higress.console.controller.dto.User;
import com.alibaba.higress.console.model.User;
import com.alibaba.higress.sdk.exception.ValidationException;
import com.alibaba.higress.console.controller.util.ControllerUtil;
import com.alibaba.higress.console.service.SessionService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import java.util.Map;

import com.alibaba.higress.console.model.User;

import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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.alibaba.higress.console.controller.dto;
package com.alibaba.higress.console.model;

import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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.alibaba.higress.console.controller.dto;
package com.alibaba.higress.console.model;

public enum DashboardType {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
/*
* Copyright (c) 2022-2023 Alibaba Group Holding Ltd.
*
* 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.alibaba.higress.console.controller.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SystemInfo {

private String version;

private List<String> capabilities;
}
/*
* Copyright (c) 2022-2023 Alibaba Group Holding Ltd.
*
* 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.alibaba.higress.console.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SystemInfo {

private String version;

private List<String> capabilities;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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.alibaba.higress.console.controller.dto;
package com.alibaba.higress.console.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Loading

0 comments on commit 73f0a62

Please sign in to comment.