use of tech.pegasys.teku.validator.client.restapi.ValidatorRestApiConfig in project teku by ConsenSys.
the class DebugToolsCommand method generateSwaggerDocs.
@Command(name = "generate-swagger-docs", description = "Generate swagger-docs for rest APIs.", mixinStandardHelpOptions = true, showDefaultValues = true, abbreviateSynopsis = true, versionProvider = PicoCliVersionProvider.class, synopsisHeading = "%n", descriptionHeading = "%nDescription:%n%n", optionListHeading = "%nOptions:%n", footerHeading = "%n", footer = "Teku is licensed under the Apache License 2.0")
public int generateSwaggerDocs(@Option(required = true, names = { "--output", "-o" }, description = "Directory to write swagger docs to.") final Path outputPath) throws Exception {
if (!outputPath.toFile().mkdirs() && !outputPath.toFile().isDirectory()) {
throw new InvalidConfigurationException(String.format("Destination path %s could not be created or is not a directory", outputPath.toAbsolutePath()));
}
ValidatorRestApiConfig config = ValidatorRestApiConfig.builder().restApiDocsEnabled(true).build();
final Path tempDir = Files.createTempDirectory("teku_debug_tools");
if (!tempDir.toFile().mkdirs() && !tempDir.toFile().isDirectory()) {
System.err.println("Could not create temp directory");
return 1;
}
tempDir.toFile().deleteOnExit();
DataDirLayout dataDirLayout = new SeparateServiceDataDirLayout(tempDir, Optional.empty(), Optional.empty());
final KeyManager keyManager = new NoOpKeyManager();
RestApi api = ValidatorRestApi.create(config, keyManager, dataDirLayout);
if (api.getRestApiDocs().isPresent()) {
final String docs = api.getRestApiDocs().get();
final Path validatorApiPath = outputPath.resolve("validator-api.json");
System.out.println("Writing validator-api to " + validatorApiPath.toAbsolutePath());
try (FileWriter fileWriter = new FileWriter(validatorApiPath.toFile(), StandardCharsets.UTF_8)) {
fileWriter.write(docs);
} catch (IOException e) {
System.err.println("Failed to write validator-api.json: " + e.getMessage());
return 1;
}
} else {
System.err.println("Failed to create rest api document for the validator api.");
return 1;
}
return 0;
}
use of tech.pegasys.teku.validator.client.restapi.ValidatorRestApiConfig in project teku by ConsenSys.
the class ValidatorClientService method create.
public static ValidatorClientService create(final ServiceConfig services, final ValidatorClientConfiguration config) {
final EventChannels eventChannels = services.getEventChannels();
final AsyncRunner asyncRunner = services.createAsyncRunner("validator");
final boolean generateEarlyAttestations = config.getValidatorConfig().generateEarlyAttestations();
final BeaconNodeApi beaconNodeApi = config.getValidatorConfig().getBeaconNodeApiEndpoint().map(endpoint -> RemoteBeaconNodeApi.create(services, asyncRunner, endpoint, config.getSpec(), generateEarlyAttestations)).orElseGet(() -> InProcessBeaconNodeApi.create(services, asyncRunner, generateEarlyAttestations, config.getSpec()));
final ValidatorApiChannel validatorApiChannel = beaconNodeApi.getValidatorApi();
final GenesisDataProvider genesisDataProvider = new GenesisDataProvider(asyncRunner, validatorApiChannel);
final ForkProvider forkProvider = new ForkProvider(config.getSpec(), genesisDataProvider);
final ValidatorLoader validatorLoader = createValidatorLoader(config, asyncRunner, services);
final ValidatorRestApiConfig validatorApiConfig = config.getValidatorRestApiConfig();
Optional<RestApi> validatorRestApi = Optional.empty();
if (validatorApiConfig.isRestApiEnabled()) {
validatorRestApi = Optional.of(ValidatorRestApi.create(validatorApiConfig, new ActiveKeyManager(validatorLoader, services.getEventChannels().getPublisher(ValidatorTimingChannel.class)), services.getDataDirLayout()));
} else {
LOG.info("validator-api-enabled is false, not starting rest api.");
}
ValidatorClientService validatorClientService = new ValidatorClientService(eventChannels, validatorLoader, beaconNodeApi, validatorRestApi, forkProvider, config.getSpec(), services.getMetricsSystem());
asyncRunner.runAsync(() -> validatorClientService.initializeValidators(config, validatorApiChannel, asyncRunner)).propagateTo(validatorClientService.initializationComplete);
return validatorClientService;
}
Aggregations