Skip to content

Commit

Permalink
[CNFT1-2846] Configurable logo (#1927)
Browse files Browse the repository at this point in the history
* favicon

* logo

* sonar
  • Loading branch information
adamloup-enquizit authored Oct 15, 2024
1 parent 170085b commit ff90e6f
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 15 deletions.
2 changes: 1 addition & 1 deletion apps/modernization-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ nbs:
- /expired

logging:
file.name:
file:
path: ./log/

spring:
Expand Down
16 changes: 15 additions & 1 deletion apps/nbs-gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ An entry point for an NBS 6.X Application that allows a Strangler Fig approach t

## Running

The NBS Gateway is a Spring Cloud Gateway application that runs on port `8000` by default. It requires the `OIDC_CLIENT_SECRET` environment variable be set. This can be done by running `export OIDC_CLIENT_SECRET=<the value>` or by setting `nbs.security.oidc.client.secret` directly within an `application-local.yml`. The application can be started from the root directory by executing;
The NBS Gateway is a Spring Cloud Gateway application that runs on port `8000` by default. It requires
the `OIDC_CLIENT_SECRET` environment variable be set. This can be done by
running `export OIDC_CLIENT_SECRET=<the value>` or by setting `nbs.security.oidc.client.secret` directly within
an `application-local.yml`. The application can be started from the root directory by executing;

```bash
./gradlew nbs-gateway:bootRun
Expand Down Expand Up @@ -69,6 +72,17 @@ The default profile contains the following properties configuration most likely
| nbs.gateway.pagebuilder.page.management.create.enabled | `false` | Enables the Page Builder Page creation routing |
| nbs.gateway.pagebuilder.page.management.edit.enabled | `false` | Enables the Page Builder Page preview/edit routing |

### Logo

By default, the NBS logo is served from the path `/images/nedssLogo.jpg` with the content coming from
the `nbs.gateway.classic` service. The logo can be changed by setting the `nbs.gateway.logo.file` value to the name of
the file to use as the logo.

| Name | Default | Description |
|-----------------------|-------------------------|-------------------------------------------------------------|
| nbs.gateway.logo.path | `/images/nedssLogo.jpg` | The path to serve the NBS logo on. |
| nbs.gateway.logo.file | | The file system path to the image to serve as the NBS logo. |

### Logging

Shortcut configurations have been created for logging of Spring resources. Each default to `INFO` with valid values
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package gov.cdc.nbs.gateway.favicon;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import static org.springframework.web.reactive.function.server.ServerResponse.ok;

@Configuration
class FaviconEndpoint {

@Bean
RouterFunction<ServerResponse> favicon(
@Value("classpath:favicon.ico") Resource favicon
) {
return route(GET("/favicon.ico"), request -> ok().bodyValue(favicon));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package gov.cdc.nbs.gateway.logo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
class LogoConfiguration {

@Bean
LogoSettings logoSettings(
@Value("${nbs.gateway.logo.path:/images/nedssLogo.jpg}") final String path,
@Value("${nbs.gateway.logo.file:}") final String file
) {
return new LogoSettings(path, file);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package gov.cdc.nbs.gateway.logo;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.FileSystemResource;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import static org.springframework.web.reactive.function.server.ServerResponse.ok;

@Configuration
@ConditionalOnProperty(prefix = "nbs.gateway.logo", name = "file")
class LogoEndpoint {

@Bean
RouterFunction<ServerResponse> logo(
final LogoSettings settings
) {
FileSystemResource logo = new FileSystemResource(settings.file());
return route(GET(settings.path()), request -> ok().bodyValue(logo));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package gov.cdc.nbs.gateway.logo;

record LogoSettings(String path, String file) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package gov.cdc.nbs.gateway.logo;

import gov.cdc.nbs.gateway.classic.NBSClassicService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Configures the routing for the NBS Logo at {@code GET} requests to {@code /images/nedssLogo.jpg} to use the NBS6
* service to resolve the logo. This route becomes active if the property {@code nbs.gateway.logo.location} is not
* present.
*/
@Configuration
@ConditionalOnProperty(prefix = "nbs.gateway.logo", name = "file", matchIfMissing = true)
class NBS6LogoRouteConfiguration {

@Bean
RouteLocator nbsLogoRouteLocator(
final RouteLocatorBuilder builder,
final NBSClassicService service,
final LogoSettings settings
) {
return builder.routes()
.route(
"nbs6-logo",
route -> route.path(settings.path())
.uri(service.uri())
)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ nbs:
log:
level: INFO
gateway:
defaults:
protocol: http
landing:
uri: '${nbs.gateway.defaults.protocol}://${nbs.gateway.modernization.service}'
base: '/welcome'
welcome:
enabled: true
log:
level: INFO
pagebuilder:
Expand Down
8 changes: 2 additions & 6 deletions apps/nbs-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ spring:
- Path=/nbs/**
filters:
- RemoveRequestHeader=Referer
- id: nbs-logo
uri: ${nbs.gateway.classic}
predicates:
- Path=/images/nedssLogo.jpg

nbs:
gateway:
Expand All @@ -30,9 +26,9 @@ nbs:
base: '/nbs/HomePage.do?method=loadHomePage'
landing:
uri: '${nbs.gateway.defaults.protocol}://${nbs.gateway.modernization.service}'
base: '/nbs/login'
base: '/welcome'
welcome:
enabled: false
enabled: true
ui:
service: 'localhost:3000'
uri: '${nbs.gateway.defaults.protocol}://${nbs.gateway.ui.service}'
Expand Down
Binary file added apps/nbs-gateway/src/main/resources/favicon.ico
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package gov.cdc.nbs.gateway.favicon;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.reactive.server.WebTestClient;

@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
class FaviconEndpointTest {

@Autowired
WebTestClient webClient;

@Test
void should_route_to_favicon() {

webClient
.get().uri("/favicon.ico")
.exchange()
.expectStatus()
.isOk();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package gov.cdc.nbs.gateway.logo;

import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.reactive.server.WebTestClient;

import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static com.github.tomakehurst.wiremock.matching.RequestPatternBuilder.allRequests;

@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {
"nbs.gateway.classic=http://localhost:10000",
"nbs.gateway.logo.file=src/test/resources/80x32.png"
}
)
class LogoEndpointTest {

@RegisterExtension
static WireMockExtension classic = WireMockExtension.newInstance()
.options(wireMockConfig().port(10000))
.build();

@Autowired
WebTestClient webClient;

@Test
void should_route_to_file_based_logo_() {

webClient
.get().uri("/images/nedssLogo.jpg")
.exchange()
.expectStatus()
.isOk();

classic.verify(0, allRequests());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package gov.cdc.nbs.gateway.logo;

import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.reactive.server.WebTestClient;

import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.ok;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;

@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {
"nbs.gateway.classic=http://localhost:10000"
}
)
class NBS6LogoRouteConfigurationTest {

@RegisterExtension
static WireMockExtension classic = WireMockExtension.newInstance()
.options(wireMockConfig().port(10000))
.build();

@Autowired
WebTestClient webClient;

@Test
void should_route_logo_path_to_nbs6() {
classic.stubFor(get("/images/nedssLogo.jpg").willReturn(ok()));

webClient
.get().uri("/images/nedssLogo.jpg")
.exchange()
.expectStatus()
.isOk();
}
}
Binary file added apps/nbs-gateway/src/test/resources/80x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ff90e6f

Please sign in to comment.