Skip to content

Commit

Permalink
Fix PublicKeysListHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
usmansaleem committed Oct 16, 2024
1 parent 2b07efc commit 373a523
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import tech.pegasys.web3signer.core.routes.ReloadRoute;
import tech.pegasys.web3signer.core.routes.eth1.Eth1SignRoute;
import tech.pegasys.web3signer.core.routes.eth1.JsonRpcRoute;
import tech.pegasys.web3signer.core.service.jsonrpc.handlers.HttpResponseFactory;
import tech.pegasys.web3signer.keystorage.azure.AzureKeyVault;
import tech.pegasys.web3signer.keystorage.common.MappedResults;
import tech.pegasys.web3signer.keystorage.hashicorp.HashicorpConnectionFactory;
Expand Down Expand Up @@ -71,12 +70,8 @@
* address to primary key.
*/
public class Eth1Runner extends Runner {
public static final String PUBLIC_KEYS_PATH = "/api/v1/eth1/publicKeys";
public static final String ROOT_PATH = "/";
public static final String SIGN_PATH = "/api/v1/eth1/sign/:identifier";
private static final Logger LOG = LogManager.getLogger();
private final Eth1Config eth1Config;
private final HttpResponseFactory responseFactory = new HttpResponseFactory();

public Eth1Runner(final BaseConfig baseConfig, final Eth1Config eth1Config) {
super(baseConfig);
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/tech/pegasys/web3signer/core/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import tech.pegasys.web3signer.core.config.MetricsPushOptions;
import tech.pegasys.web3signer.core.config.TlsOptions;
import tech.pegasys.web3signer.core.metrics.vertx.VertxMetricsAdapterFactory;
import tech.pegasys.web3signer.core.routes.SwaggerUIRoute;
import tech.pegasys.web3signer.core.service.http.HostAllowListHandler;
import tech.pegasys.web3signer.core.service.http.SwaggerUIRoute;
import tech.pegasys.web3signer.core.service.http.handlers.LogErrorHandler;
import tech.pegasys.web3signer.core.service.http.handlers.UpcheckHandler;
import tech.pegasys.web3signer.core.util.FileUtil;
Expand Down Expand Up @@ -78,7 +78,6 @@ public abstract class Runner implements Runnable, AutoCloseable {
public static final String TEXT_PLAIN = HttpHeaderValues.TEXT_PLAIN.toString();
public static final String HEALTHCHECK_PATH = "/healthcheck";
public static final String UPCHECK_PATH = "/upcheck";
public static final String RELOAD_PATH = "/reload";

private static final Logger LOG = LogManager.getLogger();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.web3signer.core.service.http;
package tech.pegasys.web3signer.core.routes;

import static java.nio.charset.StandardCharsets.UTF_8;

Expand All @@ -30,7 +30,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class SwaggerUIRoute {
public class SwaggerUIRoute implements Web3SignerRoute {
private static final Logger LOG = LogManager.getLogger();
private static final String CONTENT_TYPE_TEXT_HTML = "text/html; charset=utf-8";
private static final String SWAGGER_ENDPOINT = "/swagger-ui";
Expand All @@ -40,13 +40,19 @@ public SwaggerUIRoute(final Router router) {
this.router = router;
}

public void register() throws IOException {
@Override
public void register() {
LOG.info("Registering /swagger-ui routes ...");
final OpenApiSpecsExtractor openApiSpecsExtractor =
new OpenApiSpecsExtractor.OpenApiSpecsExtractorBuilder()
.withConvertRelativeRefToAbsoluteRef(false)
.withForceDeleteOnJvmExit(true)
.build();
final OpenApiSpecsExtractor openApiSpecsExtractor;
try {
openApiSpecsExtractor =
new OpenApiSpecsExtractor.OpenApiSpecsExtractorBuilder()
.withConvertRelativeRefToAbsoluteRef(false)
.withForceDeleteOnJvmExit(true)
.build();
} catch (final IOException e) {
throw new UncheckedIOException(e);
}

final Map<Path, String> swaggerUIWebRoot;
swaggerUIWebRoot = loadSwaggerUIStaticContent(openApiSpecsExtractor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,27 @@

import tech.pegasys.web3signer.signing.ArtifactSignerProvider;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import io.vertx.core.Handler;
import io.vertx.core.json.JsonArray;
import io.vertx.ext.web.RoutingContext;

public class PublicKeysListHandler implements Handler<RoutingContext> {
private final ArtifactSignerProvider artifactSignerProvider;
private final List<ArtifactSignerProvider> artifactSignerProviders;

public PublicKeysListHandler(final ArtifactSignerProvider artifactSignerProvider) {
this.artifactSignerProvider = artifactSignerProvider;
public PublicKeysListHandler(final List<ArtifactSignerProvider> artifactSignerProviders) {
this.artifactSignerProviders = artifactSignerProviders;
}

@Override
public void handle(final RoutingContext context) {
final List<String> availableIdentifiers =
new ArrayList<>(artifactSignerProvider.availableIdentifiers());
artifactSignerProviders.stream()
.flatMap(provider -> provider.availableIdentifiers().stream())
.collect(Collectors.toList());

final String jsonEncodedKeys = new JsonArray(availableIdentifiers).encode();
context.response().putHeader(CONTENT_TYPE, JSON_UTF_8).end(jsonEncodedKeys);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.web3signer.core.service.http;
package tech.pegasys.web3signer.core.routes;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down

0 comments on commit 373a523

Please sign in to comment.