Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java/105-useshed-usecache-flags #259

Merged
merged 4 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion java/src/main/java/de/gdata/vaas/SimpleTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.time.Duration;
import java.time.Instant;
import java.time.temporal.TemporalUnit;
import java.util.concurrent.TimeUnit;

public class SimpleTimer {
Expand Down
309 changes: 209 additions & 100 deletions java/src/main/java/de/gdata/vaas/Vaas.java

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions java/src/main/java/de/gdata/vaas/messages/VaasOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package de.gdata.vaas.messages;

import com.beust.jcommander.internal.Nullable;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.Setter;

public class VaasOptions {

@Getter
@Setter
@SerializedName("use_hash_lookup")
boolean UseHashLookup;

@Getter
@Setter
@SerializedName("use_cache")
boolean UseCache;

public VaasOptions() {
this.UseCache = false;
this.UseHashLookup = true;
}
}
40 changes: 40 additions & 0 deletions java/src/main/java/de/gdata/vaas/messages/VerdictRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;

Expand All @@ -25,6 +26,16 @@ public class VerdictRequest extends MessageType {
@Setter
@SerializedName("verdict_request_attributes")
VerdictRequestAttributes verdictRequestAttributes;
@Getter
@Setter
@Nullable
@SerializedName("use_hash_lookup")
boolean UseHashLookup;
@Getter
@Setter
@Nullable
@SerializedName("use_cache")
boolean UseCache;

public VerdictRequest(Sha256 sha256, String sessionId) {
super(Kind.VerdictRequest);
Expand All @@ -33,11 +44,40 @@ public VerdictRequest(Sha256 sha256, String sessionId) {
this.sha256 = sha256.getValue();
}

public VerdictRequest(Sha256 sha256, String sessionId, UUID guid) {
super(Kind.VerdictRequest);
this.sessionId = sessionId;
this.guid = guid.toString();
this.sha256 = sha256.getValue();
}

public VerdictRequest(Sha256 sha256, String sessionId, VerdictRequestAttributes verdictRequestAttributes) {
this(sha256, sessionId);
this.verdictRequestAttributes = verdictRequestAttributes;
}

public VerdictRequest(Sha256 sha256, String sessionId, VaasOptions options) {
this(sha256, sessionId);
this.UseCache = options.UseCache;
this.UseHashLookup = options.UseHashLookup;
}

public VerdictRequest(Sha256 sha256, String sessionId, UUID guid, VerdictRequestAttributes verdictRequestAttributes) {
this(sha256, sessionId, guid);
this.verdictRequestAttributes = verdictRequestAttributes;
}

public VerdictRequest(Sha256 sha256, String sessionId, UUID guid, VaasOptions options) {
this(sha256, sessionId, guid);
this.UseCache = options.UseCache;
this.UseHashLookup = options.UseHashLookup;
}

public VerdictRequest(Sha256 sha256, String sessionId, UUID guid, VerdictRequestAttributes verdictRequestAttributes, VaasOptions options) {
this(sha256, sessionId, guid, options);
this.verdictRequestAttributes = verdictRequestAttributes;
}

public String toJson() {
return new GsonBuilder().serializeNulls().create().toJson(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.jetbrains.annotations.Nullable;

import java.net.URL;
import java.util.UUID;
Expand All @@ -26,22 +27,36 @@ public class VerdictRequestForUrl extends MessageType {
@SerializedName("verdict_request_attributes")
VerdictRequestAttributes verdictRequestAttributes;
@Getter
@Setter
@SerializedName("use_hash_lookup")
transient boolean UseHashLookup;
@Getter
@SerializedName("use_cache")
boolean useCache = true;
boolean UseCache;

public VerdictRequestForUrl(URL url, String sessionId) {
public VerdictRequestForUrl(URL url, String sessionId, UUID guid) {
super(Kind.VerdictRequestForUrl);
this.sessionId = sessionId;
this.guid = UUID.randomUUID().toString();
this.guid = guid.toString();
this.url = url.toString();
}

public VerdictRequestForUrl(URL url, String sessionId, VerdictRequestAttributes verdictRequestAttributes) {
this(url, sessionId);
public VerdictRequestForUrl(URL url, String sessionId, UUID guid, VerdictRequestAttributes verdictRequestAttributes) {
this(url, sessionId, guid);
this.verdictRequestAttributes = verdictRequestAttributes;
}

public VerdictRequestForUrl(URL url, String sessionId, UUID guid, VaasOptions options) {
this(url, sessionId, guid);
this.UseCache = options.UseCache;
this.UseHashLookup = options.UseHashLookup;
}

public VerdictRequestForUrl(URL url, String sessionId, UUID guid, VerdictRequestAttributes verdictRequestAttributes, VaasOptions options) {
this(url, sessionId, guid);
this.verdictRequestAttributes = verdictRequestAttributes;
}


public String toJson() {
return new Gson().toJson(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public String getToken() throws IOException, InterruptedException {
var dotenv = Dotenv.configure()
.ignoreIfMissing()
.load();
var tokenUrl = dotenv.get("TOKEN_URL");
var vaasUrl = dotenv.get("VAAS_URL");
var config = new VaasConfig(new URI(vaasUrl));
var authenticator = new MockAuthenticator();
Expand Down