From 6de358ffb7d7dcfb30eed9dedda022ead458224c Mon Sep 17 00:00:00 2001 From: Sandor Molnar Date: Tue, 19 Sep 2023 10:39:44 +0200 Subject: [PATCH] KNOX-2896 - API services view on Knox Home page can be selected The default view is the 'old' list view which belongs to v1. If end-users want the most recent modal-window style, they will need to use v2 as gateway.api.services.view.version in gateway-site.xml. --- .../config/impl/GatewayConfigImpl.java | 8 +++++ .../metadata/KnoxMetadataResource.java | 2 +- .../service/metadata/TopologyInformation.java | 11 ++++++ .../metadata/TopologyInformationWrapper.java | 3 +- .../knox/gateway/GatewayTestConfig.java | 6 ++++ .../knox/gateway/config/GatewayConfig.java | 8 +++++ knox-homepage-ui/angular.json | 3 ++ knox-homepage-ui/home/app/app.module.ts | 2 ++ .../topology.information.component.html | 36 +++++++++++++++++-- .../app/topologies/topology.information.ts | 1 + knox-homepage-ui/package-lock.json | 11 ++++-- knox-homepage-ui/package.json | 1 + 12 files changed, 86 insertions(+), 6 deletions(-) diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java index e3f4847ed4..5663aaf342 100644 --- a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java +++ b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java @@ -302,6 +302,8 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig { private static final String KNOX_HOMEPAGE_PROFILE_PREFIX = "knox.homepage.profile."; private static final String KNOX_HOMEPAGE_PINNED_TOPOLOGIES = "knox.homepage.pinned.topologies"; private static final String KNOX_HOMEPAGE_HIDDEN_TOPOLOGIES = "knox.homepage.hidden.topologies"; + private static final String KNOX_HOMEPAGE_API_SERVICES_VIEW_VERSION = "knox.homepage.api.services.view.version"; + private static final Set KNOX_HOMEPAGE_HIDDEN_TOPOLOGIES_DEFAULT = new HashSet<>(Arrays.asList("admin", "manager", "knoxsso", "metadata", "homepage")); private static final String KNOX_HOMEPAGE_LOGOUT_ENABLED = "knox.homepage.logout.enabled"; private static final String GLOBAL_LOGOUT_PAGE_URL = "knox.global.logout.page.url"; @@ -1325,6 +1327,11 @@ public Set getPinnedTopologiesOnHomepage() { return pinnedTopologies == null ? Collections.emptySet() : new HashSet<>(pinnedTopologies); } + @Override + public String getApiServicesViewVersionOnHomepage() { + return getTrimmed(KNOX_HOMEPAGE_API_SERVICES_VIEW_VERSION, DEFAULT_API_SERVICES_VIEW_VERSION); + } + /** * @return returns whether know token permissive failure is enabled */ @@ -1481,4 +1488,5 @@ public Set getHealthCheckTopologies() { public boolean isAsyncSupported() { return getBoolean(GATEWAY_SERVLET_ASYNC_SUPPORTED, GATEWAY_SERVLET_ASYNC_SUPPORTED_DEFAULT); } + } diff --git a/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/KnoxMetadataResource.java b/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/KnoxMetadataResource.java index 591d2daf1d..ec826c62bd 100644 --- a/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/KnoxMetadataResource.java +++ b/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/KnoxMetadataResource.java @@ -242,7 +242,7 @@ private TopologyInformationWrapper getTopologies(String topologyName) { } }); }); - topologies.addTopology(topology.getName(), isPinnedTopology(topology.getName(), config), new TreeSet<>(apiServices), new TreeSet<>(uiServices)); + topologies.addTopology(topology.getName(), isPinnedTopology(topology.getName(), config), config.getApiServicesViewVersionOnHomepage(), new TreeSet<>(apiServices), new TreeSet<>(uiServices)); } } } diff --git a/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformation.java b/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformation.java index c544f77a0f..7bfb0c649f 100644 --- a/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformation.java +++ b/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformation.java @@ -32,6 +32,9 @@ public class TopologyInformation implements Comparable{ @XmlElement(name = "pinned") private boolean pinned; + @XmlElement(name = "apiServicesViewVersion") + private String apiServicesViewVersion; + @XmlElement(name = "service") @XmlElementWrapper(name = "apiServices") private Set apiServices; @@ -56,6 +59,14 @@ public void setPinned(boolean pinned) { this.pinned = pinned; } + public void setApiServicesViewVersion(String apiServicesViewVersion) { + this.apiServicesViewVersion = apiServicesViewVersion; + } + + public String getApiServicesViewVersion() { + return apiServicesViewVersion; + } + public Set getApiServices() { return apiServices; } diff --git a/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformationWrapper.java b/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformationWrapper.java index 5613b9fd41..f27a25673c 100644 --- a/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformationWrapper.java +++ b/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformationWrapper.java @@ -36,12 +36,13 @@ public Set getTopologies() { return topologies; } - public void addTopology(String name, boolean pinned, Set apiServices, Set uiServices) { + public void addTopology(String name, boolean pinned, String apiServicesViewVersion, Set apiServices, Set uiServices) { final TopologyInformation topology = new TopologyInformation(); topology.setTopologyName(name); topology.setPinned(pinned); topology.setApiServices(apiServices); topology.setUiServices(uiServices); + topology.setApiServicesViewVersion(apiServicesViewVersion); this.topologies.add(topology); } diff --git a/gateway-spi-common/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java b/gateway-spi-common/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java index 64c4e43660..f34a83cc4a 100644 --- a/gateway-spi-common/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java +++ b/gateway-spi-common/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java @@ -911,6 +911,11 @@ public Set getPinnedTopologiesOnHomepage() { return Collections.emptySet(); } + @Override + public String getApiServicesViewVersionOnHomepage() { + return DEFAULT_API_SERVICES_VIEW_VERSION; + } + /** * @return returns whether know token permissive failure is enabled */ @@ -1051,4 +1056,5 @@ public Set getHealthCheckTopologies() { public boolean isAsyncSupported() { return false; } + } diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java b/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java index 8de39010c1..7c37a96c49 100644 --- a/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java +++ b/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java @@ -113,6 +113,8 @@ public interface GatewayConfig { int DEFAULT_CM_SERVICE_DISCOVERY_MAX_RETRY_ATTEMPTS = 3; + String DEFAULT_API_SERVICES_VIEW_VERSION = "v1"; + /** * The location of the gateway configuration. * Subdirectories will be: topologies @@ -793,6 +795,11 @@ public interface GatewayConfig { */ Set getPinnedTopologiesOnHomepage(); + /** + * @return the API services view version (v1/v2) on Knox homepage + */ + String getApiServicesViewVersionOnHomepage(); + /** * @return returns whether know token permissive validation is enabled */ @@ -879,4 +886,5 @@ public interface GatewayConfig { * @return true if the async supported flag is enabled in jetty gateway servlet; false otherwise (defaults to false) */ boolean isAsyncSupported(); + } diff --git a/knox-homepage-ui/angular.json b/knox-homepage-ui/angular.json index b6fbb6253e..2e90da6217 100644 --- a/knox-homepage-ui/angular.json +++ b/knox-homepage-ui/angular.json @@ -58,6 +58,8 @@ }, "configurations": { "production": { + "buildOptimizer": false, + "aot": false, "fileReplacements": [ { "replace": "home/environments/environment.ts", @@ -68,6 +70,7 @@ }, "development": { "buildOptimizer": false, + "aot": false, "optimization": false, "vendorChunk": true, "extractLicenses": false, diff --git a/knox-homepage-ui/home/app/app.module.ts b/knox-homepage-ui/home/app/app.module.ts index 87aa93efbe..79019acd3c 100644 --- a/knox-homepage-ui/home/app/app.module.ts +++ b/knox-homepage-ui/home/app/app.module.ts @@ -15,6 +15,7 @@ * limitations under the License. */ import {NgModule} from '@angular/core'; +import {DataTableModule} from 'angular2-datatable'; import {BrowserModule} from '@angular/platform-browser'; import {HttpClientModule, HttpClientXsrfModule} from '@angular/common/http'; import {MatGridListModule} from '@angular/material/grid-list'; @@ -31,6 +32,7 @@ import {HomepageService} from './homepage.service'; imports: [BrowserModule, HttpClientModule, HttpClientXsrfModule, + DataTableModule, MatGridListModule, BsModalModule, RouterModule.forRoot([]) diff --git a/knox-homepage-ui/home/app/topologies/topology.information.component.html b/knox-homepage-ui/home/app/topologies/topology.information.component.html index 281ce60df8..9086f087b7 100644 --- a/knox-homepage-ui/home/app/topologies/topology.information.component.html +++ b/knox-homepage-ui/home/app/topologies/topology.information.component.html @@ -53,10 +53,42 @@

{{service.description}}

+ +
API Services
- - + + + + + + + + + + + + + + + + + + + + +
No API services found
API services
+ + {{service.shortDesc}} (v{{service.version}}) + + {{service.serviceUrl}} +
+ +
+ + diff --git a/knox-homepage-ui/home/app/topologies/topology.information.ts b/knox-homepage-ui/home/app/topologies/topology.information.ts index 5bb00a0a46..dabd4c8e28 100644 --- a/knox-homepage-ui/home/app/topologies/topology.information.ts +++ b/knox-homepage-ui/home/app/topologies/topology.information.ts @@ -19,6 +19,7 @@ import {Service} from './service'; export class TopologyInformation { topology: string; pinned: boolean; + apiServicesViewVersion: string; apiServices: Service[]; uiServices: Service[]; } diff --git a/knox-homepage-ui/package-lock.json b/knox-homepage-ui/package-lock.json index 47056ec438..ea3192d698 100644 --- a/knox-homepage-ui/package-lock.json +++ b/knox-homepage-ui/package-lock.json @@ -2967,6 +2967,14 @@ "integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==", "dev": true }, + "angular2-datatable": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/angular2-datatable/-/angular2-datatable-0.6.0.tgz", + "integrity": "sha512-Fgg3hg3Pyg80Tp21Fu9qzsj9yx4941cIbbWpbKHJlQua5eketQPAp+yEbnz0KnaMprlpQg5IBe6xdIAg1G6aCQ==", + "requires": { + "lodash": "^4.0.0" + } + }, "ansi-colors": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", @@ -6291,8 +6299,7 @@ "lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "lodash.debounce": { "version": "4.0.8", diff --git a/knox-homepage-ui/package.json b/knox-homepage-ui/package.json index 3e69cda28e..5ebcec3344 100644 --- a/knox-homepage-ui/package.json +++ b/knox-homepage-ui/package.json @@ -21,6 +21,7 @@ "@angular/platform-browser": "^13.0.1", "@angular/platform-browser-dynamic": "^13.0.1", "@angular/router": "^13.0.1", + "angular2-datatable": "^0.6.0", "bootstrap": "^3.4.1", "core-js": "^2.6.11", "jquery": "^3.5.1",