Search in sources :

Example 1 with SeparateServiceDataDirLayout

use of tech.pegasys.teku.service.serviceutils.layout.SeparateServiceDataDirLayout 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;
}
Also used : Path(java.nio.file.Path) ValidatorRestApi(tech.pegasys.teku.validator.client.restapi.ValidatorRestApi) RestApi(tech.pegasys.teku.infrastructure.restapi.RestApi) NoOpKeyManager(tech.pegasys.teku.validator.client.NoOpKeyManager) FileWriter(java.io.FileWriter) IOException(java.io.IOException) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SeparateServiceDataDirLayout(tech.pegasys.teku.service.serviceutils.layout.SeparateServiceDataDirLayout) ValidatorRestApiConfig(tech.pegasys.teku.validator.client.restapi.ValidatorRestApiConfig) KeyManager(tech.pegasys.teku.validator.client.KeyManager) NoOpKeyManager(tech.pegasys.teku.validator.client.NoOpKeyManager) InvalidConfigurationException(tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException) SeparateServiceDataDirLayout(tech.pegasys.teku.service.serviceutils.layout.SeparateServiceDataDirLayout) Command(picocli.CommandLine.Command)

Example 2 with SeparateServiceDataDirLayout

use of tech.pegasys.teku.service.serviceutils.layout.SeparateServiceDataDirLayout in project teku by ConsenSys.

the class ValidatorSourceFactoryTest method mutableValidatorShouldBeSlashingProtected.

@Test
void mutableValidatorShouldBeSlashingProtected(@TempDir final Path tempDir) {
    final DataDirLayout dataDirLayout = new SeparateServiceDataDirLayout(tempDir, Optional.empty(), Optional.empty());
    final ValidatorSourceFactory factory = new ValidatorSourceFactory(spec, config, disabledInteropConfig, () -> httpClient, slashingProtector, publicKeyLoader, asyncRunner, metricsSystem, Optional.of(dataDirLayout));
    factory.createValidatorSources();
    final Optional<ValidatorSource> source = factory.getMutableLocalValidatorSource();
    assertThat(source).isPresent();
    assertThat(source.get()).isInstanceOf(SlashingProtectedValidatorSource.class);
}
Also used : DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SeparateServiceDataDirLayout(tech.pegasys.teku.service.serviceutils.layout.SeparateServiceDataDirLayout) SeparateServiceDataDirLayout(tech.pegasys.teku.service.serviceutils.layout.SeparateServiceDataDirLayout) Test(org.junit.jupiter.api.Test)

Aggregations

DataDirLayout (tech.pegasys.teku.service.serviceutils.layout.DataDirLayout)2 SeparateServiceDataDirLayout (tech.pegasys.teku.service.serviceutils.layout.SeparateServiceDataDirLayout)2 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Test (org.junit.jupiter.api.Test)1 Command (picocli.CommandLine.Command)1 InvalidConfigurationException (tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException)1 RestApi (tech.pegasys.teku.infrastructure.restapi.RestApi)1 KeyManager (tech.pegasys.teku.validator.client.KeyManager)1 NoOpKeyManager (tech.pegasys.teku.validator.client.NoOpKeyManager)1 ValidatorRestApi (tech.pegasys.teku.validator.client.restapi.ValidatorRestApi)1 ValidatorRestApiConfig (tech.pegasys.teku.validator.client.restapi.ValidatorRestApiConfig)1