Quellcode durchsuchen

load hashes locally when possible

tags/v1.1.4
Jonathan Cobb vor 4 Jahren
Ursprung
Commit
8613e8a994
3 geänderte Dateien mit 43 neuen und 7 gelöschten Zeilen
  1. +7
    -6
      bubble-server/src/main/java/bubble/service/packer/PackerJob.java
  2. +33
    -1
      bubble-server/src/main/java/bubble/service/packer/PackerService.java
  3. +3
    -0
      bubble-server/src/main/resources/packer/roles/bubble/templates/bubble_versions.properties.j2

+ 7
- 6
bubble-server/src/main/java/bubble/service/packer/PackerJob.java Datei anzeigen

@@ -163,8 +163,8 @@ public class PackerJob implements Callable<List<PackerImage>> {
if (installType == AnsibleInstallType.node) {
// ensure we use the latest algo and mitmproxy versions
final Map<String, String> versions = new HashMap<>();
versions.putAll(useLatestVersion(ROLE_ALGO, tempDir));
versions.putAll(useLatestVersion(ROLE_MITMPROXY, tempDir));
versions.putAll(getSoftwareVersion(ROLE_ALGO, tempDir));
versions.putAll(getSoftwareVersion(ROLE_MITMPROXY, tempDir));

// write versions to bubble vars
writeBubbleVersions(tempDir, versions);
@@ -304,7 +304,7 @@ public class PackerJob implements Callable<List<PackerImage>> {
FileUtil.toFileOrDie(new File(varsDir, "main.yml"), b.toString());
}

private Map<String, String> useLatestVersion(String roleName, TempDir tempDir) throws IOException {
private Map<String, String> getSoftwareVersion(String roleName, TempDir tempDir) throws IOException {
final Map<String, String> vars = new HashMap<>();
final String releaseUrlBase = configuration.getReleaseUrlBase();
final File varsDir = mkdirOrDie(abs(tempDir) + "/roles/"+roleName+"/vars");
@@ -313,14 +313,15 @@ public class PackerJob implements Callable<List<PackerImage>> {
final String version = packerService.getSoftwareVersion(roleName);
vars.put(roleName, version);

final String hash = url2string(releaseUrlBase+"/"+roleName+"/"+version+"/"+roleName+".zip.sha256").trim();
String varsData = roleName+"_sha256 : '"+hash+"'\n"
final String hash = packerService.getSoftwareHash(roleName, version);
String varsData = roleName+"_sha : '"+hash+"'\n"
+ roleName+"_version : '" + version + "'\n";

if (roleName.equals(ROLE_ALGO)) {
// capture dnscrypt_proxy version for algo
final String dnscryptVersion = url2string(releaseUrlBase+"/"+roleName+"/"+version+"/dnscrypt-proxy_version.txt").trim();
varsData += "dnscrypt_version : '"+dnscryptVersion+"'";
varsData += "dnscrypt_proxy_version : '"+dnscryptVersion+"'\n"
+ "dnscrypt_proxy_sha : '"+packerService.getSoftwareHash(ROLE_DNSCRYPT, dnscryptVersion)+"'";
vars.put(ROLE_DNSCRYPT, dnscryptVersion);
}
FileUtil.toFileOrDie(new File(varsDir, "main.yml"), varsData);


+ 33
- 1
bubble-server/src/main/java/bubble/service/packer/PackerService.java Datei anzeigen

@@ -123,7 +123,8 @@ public class PackerService {
public String getSoftwareVersion(String roleName) {
final Properties defaults = configuration.getDefaultSoftwareVersions();
if (defaults != null) {
final String version = defaults.getProperty(roleName.replace("-", "_"));
final String propName = roleName.replace("-", "_")+"_version";
final String version = defaults.getProperty(propName);
if (version != null) return version;
}
final String releaseUrlBase = configuration.getReleaseUrlBase();
@@ -136,4 +137,35 @@ public class PackerService {
});
}

private final Map<String, String> softwareHashes = new HashMap<>();

public String getSoftwareHash(String roleName, String version) {
final Properties defaults = configuration.getDefaultSoftwareVersions();
if (defaults != null) {
final String roleBase = roleName.replace("-", "_");
final String foundVersion = defaults.getProperty(roleBase +"_version");
if (foundVersion != null && foundVersion.equals(version)) {
final String hash = defaults.getProperty(roleBase +"_sha");
if (hash != null) return hash;
}
}
final String releaseUrlBase = configuration.getReleaseUrlBase();
return softwareHashes.computeIfAbsent(roleName, r -> {
try {
return url2string(releaseUrlBase+"/"+roleName+"/"+version+"/"+roleName+getSoftwareSuffix(roleName)+".sha256").trim();
} catch (IOException e) {
return die("getSoftwareHash("+r+"): "+shortError(e), e);
}
});
}

private String getSoftwareSuffix(String roleName) {
switch (roleName) {
case ROLE_ALGO: case ROLE_MITMPROXY: return ".zip";
case ROLE_DNSCRYPT: return "";
default: return die("getSoftwareSuffix: unrecognized roleName: "+roleName);
}

}

}

+ 3
- 0
bubble-server/src/main/resources/packer/roles/bubble/templates/bubble_versions.properties.j2 Datei anzeigen

@@ -1,3 +1,6 @@
algo_version={{ algo_version }}
algo_sha={{ algo_sha }}
dnscrypt_proxy_version={{ dnscrypt_proxy_version }}
dnscrypt_proxy_sha={{ dnscrypt_proxy_sha }}
mitmproxy_version={{ mitmproxy_version }}
mitmproxy_sha={{ mitmproxy_sha }}

Laden…
Abbrechen
Speichern