Browse Source

Merge branch 'master' into kris/request_protector_app

pull/58/head
Kristijan Mitrovic 4 years ago
parent
commit
5d29e31b32
3 changed files with 10 additions and 19 deletions
  1. +8
    -14
      bubble-server/src/main/java/bubble/cloud/geoLocation/GeoLocateServiceDriverBase.java
  2. +1
    -4
      bubble-server/src/main/java/bubble/cloud/geoLocation/maxmind/MaxMindDriver.java
  3. +1
    -1
      bubble-web

+ 8
- 14
bubble-server/src/main/java/bubble/cloud/geoLocation/GeoLocateServiceDriverBase.java View File

@@ -17,7 +17,6 @@ import org.cobbzilla.util.http.HttpMeta;
import org.cobbzilla.util.http.HttpRequestBean; import org.cobbzilla.util.http.HttpRequestBean;
import org.cobbzilla.util.http.HttpUtil; import org.cobbzilla.util.http.HttpUtil;
import org.cobbzilla.util.io.Decompressors; import org.cobbzilla.util.io.Decompressors;
import org.cobbzilla.util.io.FileUtil;
import org.cobbzilla.util.io.TempDir; import org.cobbzilla.util.io.TempDir;
import org.cobbzilla.wizard.cache.redis.RedisService; import org.cobbzilla.wizard.cache.redis.RedisService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -78,19 +77,18 @@ public abstract class GeoLocateServiceDriverBase<T> extends CloudServiceDriverBa


protected abstract GeoLocation _geolocate (String ip); protected abstract GeoLocation _geolocate (String ip);


public File initFile(String url, String pathMatch, List<NameAndValue> headers) {
public File initFile(String url, String pathMatch, List<NameAndValue> headers, String extension) {
final File archive; final File archive;
final File dbFile; final File dbFile;
String ext;
try { try {
final boolean isFile = url.startsWith(SCHEME_FILE); final boolean isFile = url.startsWith(SCHEME_FILE);
if (isFile) { if (isFile) {
archive = new File(url.substring(SCHEME_FILE.length())); archive = new File(url.substring(SCHEME_FILE.length()));
ext = FileUtil.extension(archive);
dbFile = new File(archive.getParentFile(), archive.getName()+".database"); dbFile = new File(archive.getParentFile(), archive.getName()+".database");


} else { } else {
final String urlWithLicense = HandlebarsUtil.apply(getHandlebars(), url, getCredentials().newContext(), '[', ']');
final String urlWithLicense = HandlebarsUtil.apply(getHandlebars(), url, getCredentials().newContext(), '[', ']')
.replace("&amp;", "&");
final HttpRequestBean request = new HttpRequestBean(urlWithLicense).setHeaders(headers); final HttpRequestBean request = new HttpRequestBean(urlWithLicense).setHeaders(headers);
final HttpMeta meta = HttpUtil.getHeadMetadata(request); final HttpMeta meta = HttpUtil.getHeadMetadata(request);


@@ -104,20 +102,18 @@ public abstract class GeoLocateServiceDriverBase<T> extends CloudServiceDriverBa
if (meta.shouldRefresh(archive)) { if (meta.shouldRefresh(archive)) {
downloadDbFile(request, archive); downloadDbFile(request, archive);
} }

// create a symlink with the proper extension, so "unroll" can detect the archive type
ext = getExtension(url);
} }


if (ext.startsWith(".")) ext = ext.substring(1);
switch (ext) {
if (extension.startsWith(".")) extension = extension.substring(1);
switch (extension) {
case "zip": case "tgz": case "gz": case "tar.gz": case "tar.bz2": break; case "zip": case "tgz": case "gz": case "tar.gz": case "tar.bz2": break;
default: return die("initFile: unrecognized archive extension: "+ext+", from URL="+url);
default: return die("initFile: unrecognized archive extension: "+extension+", from URL="+url);
} }


// create a symlink with the proper extension, so "unroll" can detect the archive type
final File link; final File link;
if (!isFile) { if (!isFile) {
link = new File(abs(archive) + "." + ext);
link = new File(abs(archive) + "." + extension);
if (link.exists() && !link.delete()) return die("initFile: error removing link: " + abs(link)); if (link.exists() && !link.delete()) return die("initFile: error removing link: " + abs(link));
symlink(link, archive); symlink(link, archive);
} else { } else {
@@ -160,6 +156,4 @@ public abstract class GeoLocateServiceDriverBase<T> extends CloudServiceDriverBa
throw new IllegalStateException(msg, lastEx); throw new IllegalStateException(msg, lastEx);
} }


public String getExtension(String url) { return FileUtil.extension(url); }

} }

+ 1
- 4
bubble-server/src/main/java/bubble/cloud/geoLocation/maxmind/MaxMindDriver.java View File

@@ -15,17 +15,14 @@ import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;


import static org.cobbzilla.util.daemon.ZillaRuntime.die; import static org.cobbzilla.util.daemon.ZillaRuntime.die;
import static org.cobbzilla.util.http.URIUtil.queryParams;


public class MaxMindDriver extends GeoLocateServiceDriverBase<CloudApiUrlConfig> { public class MaxMindDriver extends GeoLocateServiceDriverBase<CloudApiUrlConfig> {


private DatabaseReader reader; private DatabaseReader reader;


@Override public String getExtension(String url) { return queryParams(url).get("suffix"); }

@Override public void postSetup() { @Override public void postSetup() {
// grab latest DB // grab latest DB
final File database = initFile(config.getUrl(), config.getFile(), config.headersList());
final File database = initFile(config.getUrl(), config.getFile(), config.headersList(), ".tar.gz");
try { try {
reader = new DatabaseReader.Builder(database).build(); reader = new DatabaseReader.Builder(database).build();
} catch (IOException e) { } catch (IOException e) {


+ 1
- 1
bubble-web

@@ -1 +1 @@
Subproject commit 8382f725aeddf39f562a45f32f70292b9187418e
Subproject commit 36279fd83f9653c93dceac4ec7029eb416271c10

Loading…
Cancel
Save