use of tech.pegasys.web3signer.core.service.http.SwaggerUIRoute in project web3signer by ConsenSys.
the class Runner method run.
@Override
public void run() {
if (config.getLogLevel() != null) {
System.out.println("Setting logging level to " + config.getLogLevel().name());
Configurator.setRootLevel(config.getLogLevel());
}
final MetricsEndpoint metricsEndpoint = new MetricsEndpoint(config.isMetricsEnabled(), config.getMetricsPort(), config.getMetricsNetworkInterface(), config.getMetricCategories(), config.getMetricsHostAllowList());
final MetricsSystem metricsSystem = metricsEndpoint.getMetricsSystem();
final Vertx vertx = Vertx.vertx(createVertxOptions(metricsSystem));
final LogErrorHandler errorHandler = new LogErrorHandler();
final ArtifactSignerProvider artifactSignerProvider = createArtifactSignerProvider(vertx, metricsSystem);
try {
metricsEndpoint.start(vertx);
try {
// wait for signers to get loaded ...
artifactSignerProvider.load().get();
} catch (final InterruptedException | ExecutionException e) {
LOG.error("Error loading signers", e);
}
incSignerLoadCount(metricsSystem, artifactSignerProvider.availableIdentifiers().size());
final OpenApiSpecsExtractor openApiSpecsExtractor = new OpenApiSpecsExtractor.OpenApiSpecsExtractorBuilder().withConvertRelativeRefToAbsoluteRef(true).withForceDeleteOnJvmExit(true).build();
final Path openApiSpec = openApiSpecsExtractor.getSpecFilePathAtDestination(getOpenApiSpecResource()).orElseThrow(() -> new RuntimeException("Unable to load OpenApi spec " + getOpenApiSpecResource()));
// vertx needs a scheme present (file://) to determine this is an absolute path
final URI openApiSpecUri = openApiSpec.toUri();
final RouterBuilder routerBuilder = getRouterBuilder(vertx, openApiSpecUri.toString());
// register access log handler first
if (config.isAccessLogsEnabled()) {
routerBuilder.rootHandler(LoggerHandler.create(LoggerFormat.DEFAULT));
}
routerBuilder.rootHandler(CorsHandler.create(buildCorsRegexFromConfig()).allowedHeader("*").allowedMethod(HttpMethod.GET).allowedMethod(HttpMethod.POST).allowedMethod(HttpMethod.DELETE).allowedMethod(HttpMethod.OPTIONS));
registerUpcheckRoute(routerBuilder, errorHandler);
registerHttpHostAllowListHandler(routerBuilder);
final Context context = new Context(routerBuilder, metricsSystem, errorHandler, vertx, artifactSignerProvider);
final Router router = populateRouter(context);
if (config.isSwaggerUIEnabled()) {
new SwaggerUIRoute(router).register();
}
final HttpServer httpServer = createServerAndWait(vertx, router);
final String tlsStatus = config.getTlsOptions().isPresent() ? "enabled" : "disabled";
LOG.info("Web3Signer has started with TLS {}, and ready to handle signing requests on {}:{}", tlsStatus, config.getHttpListenHost(), httpServer.actualPort());
persistPortInformation(httpServer.actualPort(), metricsEndpoint.getPort());
} catch (final InitializationException e) {
throw e;
} catch (final Throwable e) {
if (artifactSignerProvider != null) {
artifactSignerProvider.close();
}
vertx.close();
metricsEndpoint.stop();
LOG.error("Failed to initialise application", e);
}
}
Aggregations