Skip to content

Commit

Permalink
KNOX-2896 - API services view on Knox Home page can be selected
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
smolnar82 committed Sep 19, 2023
1 parent 3f3a65b commit 6de358f
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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";
Expand Down Expand Up @@ -1325,6 +1327,11 @@ public Set<String> 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
*/
Expand Down Expand Up @@ -1481,4 +1488,5 @@ public Set<String> getHealthCheckTopologies() {
public boolean isAsyncSupported() {
return getBoolean(GATEWAY_SERVLET_ASYNC_SUPPORTED, GATEWAY_SERVLET_ASYNC_SUPPORTED_DEFAULT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class TopologyInformation implements Comparable<TopologyInformation>{
@XmlElement(name = "pinned")
private boolean pinned;

@XmlElement(name = "apiServicesViewVersion")
private String apiServicesViewVersion;

@XmlElement(name = "service")
@XmlElementWrapper(name = "apiServices")
private Set<ServiceModel> apiServices;
Expand All @@ -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<ServiceModel> getApiServices() {
return apiServices;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ public Set<TopologyInformation> getTopologies() {
return topologies;
}

public void addTopology(String name, boolean pinned, Set<ServiceModel> apiServices, Set<ServiceModel> uiServices) {
public void addTopology(String name, boolean pinned, String apiServicesViewVersion, Set<ServiceModel> apiServices, Set<ServiceModel> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,11 @@ public Set<String> getPinnedTopologiesOnHomepage() {
return Collections.emptySet();
}

@Override
public String getApiServicesViewVersionOnHomepage() {
return DEFAULT_API_SERVICES_VIEW_VERSION;
}

/**
* @return returns whether know token permissive failure is enabled
*/
Expand Down Expand Up @@ -1051,4 +1056,5 @@ public Set<String> getHealthCheckTopologies() {
public boolean isAsyncSupported() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -793,6 +795,11 @@ public interface GatewayConfig {
*/
Set<String> getPinnedTopologiesOnHomepage();

/**
* @return the API services view version (v1/v2) on Knox homepage
*/
String getApiServicesViewVersionOnHomepage();

/**
* @return returns whether know token permissive validation is enabled
*/
Expand Down Expand Up @@ -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();

}
3 changes: 3 additions & 0 deletions knox-homepage-ui/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
},
"configurations": {
"production": {
"buildOptimizer": false,
"aot": false,
"fileReplacements": [
{
"replace": "home/environments/environment.ts",
Expand All @@ -68,6 +70,7 @@
},
"development": {
"buildOptimizer": false,
"aot": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
Expand Down
2 changes: 2 additions & 0 deletions knox-homepage-ui/home/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -31,6 +32,7 @@ import {HomepageService} from './homepage.service';
imports: [BrowserModule,
HttpClientModule,
HttpClientXsrfModule,
DataTableModule,
MatGridListModule,
BsModalModule,
RouterModule.forRoot([])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,42 @@ <h3>{{service.description}}</h3>
</mat-grid-tile>
</mat-grid-list>

<!-- API services -->

<h5 *ngIf="topology.apiServices.service.length > 0">API Services</h5>

<!-- API services -->
<mat-grid-list cols="4" rowHeight="130px">
<table *ngIf="topology.apiServicesViewVersion === 'v1'" class="table table-hover" [mfData]="topology.apiServices.service" #api="mfDataTable" [mfRowsOnPage]="5">
<colgroup>
<col width="30%">
<col width="70%">
</colgroup>
<thead>
<tr *ngIf="topology.apiServices.service.length === 0"><th colspan="2">No API services found</th></tr>
<tr *ngIf="topology.apiServices.service.length > 0"><th colspan="2">API services</th></tr>
</thead>
<tbody>
<tr *ngFor="let service of api.data">
<td>
<span class="inline-glyph glyphicon glyphicon-info-sign btn btn-xs"
title="{{service.description}}"
data-toggle="tooltip"></span>
{{service.shortDesc}} <span class="small" *ngIf="service.version">(v{{service.version}})</span>
</td>
<td>
<a href="{{service.serviceUrl}}">{{service.serviceUrl}}</a>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">
<mfBootstrapPaginator [rowsOnPageSet]="[5,10,15]"></mfBootstrapPaginator>
</td>
</tr>
</tfoot>
</table>

<mat-grid-list *ngIf="topology.apiServicesViewVersion === 'v2'" cols="4" rowHeight="130px">
<mat-grid-tile *ngFor="let service of topology.apiServices.service" [colspan]="1" [rowspan]="1">
<span *ngIf="!this['enableServiceText_' + service.serviceName.toLowerCase()]" (click)="openApiServiceInformationModal(service)">
<img src="assets/service-logos/{{service.serviceName.toLowerCase()}}.png" height="50px" (error)="enableServiceText('enableServiceText_' + service.serviceName.toLowerCase())"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {Service} from './service';
export class TopologyInformation {
topology: string;
pinned: boolean;
apiServicesViewVersion: string;
apiServices: Service[];
uiServices: Service[];
}
11 changes: 9 additions & 2 deletions knox-homepage-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions knox-homepage-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6de358f

Please sign in to comment.