Переглянути джерело

Merge branch 'master' into kris/request_protector_app

pull/58/head
Kristijan Mitrovic 4 роки тому
джерело
коміт
5d29e31b32
3 змінених файлів з 10 додано та 19 видалено
  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 Переглянути файл

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

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 dbFile;
String ext;
try {
final boolean isFile = url.startsWith(SCHEME_FILE);
if (isFile) {
archive = new File(url.substring(SCHEME_FILE.length()));
ext = FileUtil.extension(archive);
dbFile = new File(archive.getParentFile(), archive.getName()+".database");

} 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 HttpMeta meta = HttpUtil.getHeadMetadata(request);

@@ -104,20 +102,18 @@ public abstract class GeoLocateServiceDriverBase<T> extends CloudServiceDriverBa
if (meta.shouldRefresh(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;
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;
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));
symlink(link, archive);
} else {
@@ -160,6 +156,4 @@ public abstract class GeoLocateServiceDriverBase<T> extends CloudServiceDriverBa
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 Переглянути файл

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

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

public class MaxMindDriver extends GeoLocateServiceDriverBase<CloudApiUrlConfig> {

private DatabaseReader reader;

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

@Override public void postSetup() {
// 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 {
reader = new DatabaseReader.Builder(database).build();
} catch (IOException e) {


+ 1
- 1
bubble-web

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

Завантаження…
Відмінити
Зберегти