Skip to content

Commit

Permalink
Merge pull request #95 from wireapp/staging
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
dkovacevic authored Sep 15, 2022
2 parents cbc3d7d + 45e051e commit d9bf46e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 50 deletions.
6 changes: 3 additions & 3 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.wire.bots</groupId>
<artifactId>roman</artifactId>
<version>1.18.0</version>
<version>1.18.1</version>

<name>Roman</name>
<description>Wire Bot API Proxy</description>
Expand Down Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.3</version>
<version>2.13.4</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
Expand Down Expand Up @@ -104,7 +104,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.4</version>
<version>4.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
48 changes: 1 addition & 47 deletions backend/src/main/java/com/wire/bots/roman/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,14 @@
import com.wire.xenon.factories.CryptoFactory;
import com.wire.xenon.factories.StorageFactory;
import io.dropwizard.bundles.assets.ConfiguredAssetsBundle;
import io.dropwizard.bundles.redirect.PathRedirect;
import io.dropwizard.bundles.redirect.Redirect;
import io.dropwizard.server.DefaultServerFactory;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.dropwizard.util.Strings;
import io.dropwizard.websockets.WebsocketBundle;
import io.jsonwebtoken.security.Keys;
import org.apache.http.HttpHeaders;
import org.eclipse.jetty.servlets.CrossOriginFilter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.Key;
import java.util.EnumSet;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -95,7 +88,7 @@ protected void initialize(Config config, Environment env) {
this.config = config;
this.key = Keys.hmacShaKeyFor(config.key.getBytes());

if (!Strings.isNullOrEmpty(this.config.allowedCors)) {
if (!Tools.isNullOrEmpty(this.config.allowedCors)) {
// Enable CORS headers
final FilterRegistration.Dynamic cors = environment.servlets().addFilter("CORS", CrossOriginFilter.class);

Expand All @@ -118,14 +111,6 @@ protected void onRun(Config config, Environment env) {
ProviderClient providerClient = new ProviderClient(getClient(), config.apiHost);
Sender sender = new Sender(getRepo());

var rootPath = ((DefaultServerFactory) config.getServerFactory()).getJerseyRootPath().orElse("");
rootPath = rootPath.endsWith("/") ? rootPath : rootPath + "/";
var swaggerPath = rootPath + "swagger#/default";
registerRedirects(
new PathRedirect("/swagger-ui", swaggerPath),
new PathRedirect("/swagger", swaggerPath)
);

final var jdbi = getJdbi();
addResource(new ProviderResource(jdbi, providerClient));
addResource(new ServiceResource(jdbi, providerClient));
Expand All @@ -137,37 +122,6 @@ protected void onRun(Config config, Environment env) {
messageHandler.setSender(sender);
}

private void registerRedirects(PathRedirect... redirects) {
environment.servlets().addFilter("redirect", new Filter() {
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
if (req instanceof HttpServletRequest) {
HttpServletRequest request = (HttpServletRequest) req;

for (Redirect redirect : redirects) {
String redirectUrl = redirect.getRedirect(request);
if (redirectUrl != null) {
HttpServletResponse response = (HttpServletResponse) res;

response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader(HttpHeaders.LOCATION, redirectUrl);
return;
}
}
}

chain.doFilter(req, res);
}

@Override
public void destroy() { /* unused */ }

@Override
public void init(FilterConfig filterConfig) { /* unused */ }
}).addMappingForUrlPatterns(null, false, "*");
}

@Override
protected ClientRepo createClientRepo() {
StorageFactory storageFactory = getStorageFactory();
Expand Down
5 changes: 5 additions & 0 deletions backend/src/main/java/com/wire/bots/roman/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.jsonwebtoken.Jwts;

import javax.annotation.Nullable;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Date;
Expand Down Expand Up @@ -39,4 +40,8 @@ public static String decodeBase64(final String base64String) {
byte[] keyBytes = Base64.getDecoder().decode(base64String);
return new String(keyBytes, StandardCharsets.UTF_8);
}

public static boolean isNullOrEmpty(@Nullable String string) {
return string == null || string.isEmpty();
}
}

0 comments on commit d9bf46e

Please sign in to comment.