use of com.linecorp.armeria.server.HttpService in project curiostack by curioswitch.
the class ServerModule method decorateService.
private static HttpService decorateService(HttpService service, Tracing tracing, Lazy<FirebaseAuthorizer> firebaseAuthorizer, Lazy<JwtAuthorizer.Factory> jwtAuthorizer, Optional<SslCommonNamesProvider> sslCommonNamesProvider, ServerConfig serverConfig, FirebaseAuthConfig authConfig) {
if (sslCommonNamesProvider.isPresent() && !serverConfig.isDisableSslAuthorization()) {
AuthServiceBuilder authServiceBuilder = AuthService.builder();
authServiceBuilder.add(new SslAuthorizer(sslCommonNamesProvider.get()));
service = service.decorate(authServiceBuilder.newDecorator());
}
if (serverConfig.isEnableIapAuthorization()) {
service = service.decorate((delegate, ctx, req) -> {
DecodedJWT jwt = ctx.attr(JwtAuthorizer.DECODED_JWT);
String loggedInUserEmail = jwt != null ? jwt.getClaim("email").asString() : "unknown";
RequestLoggingContext.put(ctx, "logged_in_user", loggedInUserEmail);
return delegate.serve(ctx, req);
}).decorate(AuthService.builder().addTokenAuthorizer(headers -> OAuth2Token.of(headers.get(HttpHeaderNames.of("x-goog-iap-jwt-assertion"))), jwtAuthorizer.get().create(Algorithm.ES256, "https://www.gstatic.com/iap/verify/public_key")).newDecorator());
}
if (!authConfig.getServiceAccountBase64().isEmpty()) {
FirebaseAuthorizer authorizer = firebaseAuthorizer.get();
service = service.decorate(AuthService.builder().addOAuth2(authorizer).onFailure(authorizer).newDecorator());
}
service = service.decorate(MetricCollectingService.newDecorator(RpcMetricLabels.grpcRequestLabeler("grpc_services"))).decorate(BraveService.newDecorator(tracing)).decorate((delegate, ctx, req) -> {
TraceContext traceCtx = tracing.currentTraceContext().get();
if (traceCtx != null) {
RequestLoggingContext.put(ctx, "traceId", traceCtx.traceIdString());
RequestLoggingContext.put(ctx, "spanId", traceCtx.spanIdString());
}
return delegate.serve(ctx, req);
});
return service;
}
use of com.linecorp.armeria.server.HttpService in project curiostack by curioswitch.
the class StaticSiteService method addToServer.
/**
* Creates a new {@link StaticSiteService}.
*
* @param staticPath the URL path from which static resources will be served, e.g., "/static".
* @param classpathRoot the root directory in the classpath to serve resources from.
*/
public static void addToServer(String urlRoot, String staticPath, String classpathRoot, ServerBuilder sb) {
FileService staticFileService = FileService.builder(StaticSiteService.class.getClassLoader(), classpathRoot).serveCompressedFiles(true).cacheControl(ServerCacheControl.IMMUTABLE).addHeader(HttpHeaderNames.VARY, "Accept-Encoding").build();
HttpService indexHtmlService = HttpFile.builder(StaticSiteService.class.getClassLoader(), classpathRoot + "/index.html").cacheControl(ServerCacheControl.DISABLED).build().asService();
TrailingSlashAddingService indexService = FileService.builder(StaticSiteService.class.getClassLoader(), classpathRoot).serveCompressedFiles(true).cacheControl(ServerCacheControl.DISABLED).build().orElse(indexHtmlService).decorate(TrailingSlashAddingService::new);
String urlRootWithTrailingSlash = urlRoot.endsWith("/") ? urlRoot : urlRoot + "/";
String staticPathWithoutLeadingSlash = staticPath.startsWith("/") ? staticPath.substring(1) : staticPath;
sb.serviceUnder(urlRootWithTrailingSlash + staticPathWithoutLeadingSlash, staticFileService).serviceUnder(urlRootWithTrailingSlash, indexService);
}
use of com.linecorp.armeria.server.HttpService in project zipkin by openzipkin.
the class ZipkinUiConfiguration method uiServerConfigurator.
@Bean
ArmeriaServerConfigurator uiServerConfigurator(HttpService indexService, Optional<MeterRegistry> meterRegistry) throws IOException {
ServerCacheControl maxAgeYear = ServerCacheControl.builder().maxAgeSeconds(TimeUnit.DAYS.toSeconds(365)).build();
HttpService uiFileService = FileService.builder(getClass().getClassLoader(), "zipkin-lens").cacheControl(maxAgeYear).build();
String config = writeConfig(ui);
return sb -> {
sb.service("/zipkin/config.json", HttpFile.builder(HttpData.ofUtf8(config)).cacheControl(ServerCacheControl.builder().maxAgeSeconds(600).build()).contentType(MediaType.JSON_UTF_8).build().asService());
sb.serviceUnder("/zipkin/", uiFileService);
// TODO This approach requires maintenance when new UI routes are added. Change to the following:
// If the path is a a file w/an extension, treat normally.
// Otherwise instead of returning 404, forward to the index.
// See https://github.com/twitter/finatra/blob/458c6b639c3afb4e29873d123125eeeb2b02e2cd/http/src/main/scala/com/twitter/finatra/http/response/ResponseBuilder.scala#L321
sb.service("/zipkin/", indexService).service("/zipkin/index.html", indexService).service("/zipkin/traces/{id}", indexService).service("/zipkin/dependency", indexService).service("/zipkin/traceViewer", indexService);
sb.service("/favicon.ico", new RedirectService(HttpStatus.FOUND, "/zipkin/favicon.ico")).service("/", new RedirectService(HttpStatus.FOUND, "/zipkin/")).service("/zipkin", new RedirectService(HttpStatus.FOUND, "/zipkin/"));
// don't add metrics for favicon
meterRegistry.ifPresent(m -> m.config().meterFilter(MeterFilter.deny(id -> {
String uri = id.getTag("uri");
return uri != null && uri.startsWith("/favicon.ico");
})));
};
}
Aggregations