Skip to content

Commit 8f443fc

Browse files
Fix coverage
1 parent 5e00829 commit 8f443fc

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

dd-java-agent/agent-aiguard/src/main/java/com/datadog/aiguard/AIGuardInternal.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.datadog.aiguard;
22

3+
import static datadog.trace.util.Strings.isBlank;
34
import static java.util.Collections.singletonMap;
45

56
import com.squareup.moshi.JsonAdapter;
@@ -70,12 +71,12 @@ public static void install() {
7071
final Config config = Config.get();
7172
final String apiKey = config.getApiKey();
7273
final String appKey = config.getApplicationKey();
73-
if (isEmpty(apiKey) || isEmpty(appKey)) {
74+
if (isBlank(apiKey) || isBlank(appKey)) {
7475
throw new BadConfigurationException(
7576
"AI Guard: Missing api and/or application key, use DD_API_KEY and DD_APP_KEY");
7677
}
7778
String endpoint = config.getAiGuardEndpoint();
78-
if (isEmpty(endpoint)) {
79+
if (isBlank(endpoint)) {
7980
endpoint = String.format("https://app.%s/api/v2/ai-guard", config.getSite());
8081
}
8182
final Map<String, String> headers = mapOf("DD-API-KEY", apiKey, "DD-APPLICATION-KEY", appKey);
@@ -157,8 +158,8 @@ private static String getToolName(final Message current, final List<Message> mes
157158
return null;
158159
}
159160

160-
private boolean isBlockingEnabled(final Object isBlockingEnabled) {
161-
return isBlockingEnabled != null && isBlockingEnabled.toString().equalsIgnoreCase("true");
161+
private boolean isBlockingEnabled(final Options options, final Object isBlockingEnabled) {
162+
return options.block() && "true".equalsIgnoreCase(isBlockingEnabled.toString());
162163
}
163164

164165
@Override
@@ -202,8 +203,9 @@ public Evaluation evaluate(final List<Message> messages, final Options options)
202203
final String reason = (String) result.get("reason");
203204
span.setTag(ACTION_TAG, action);
204205
span.setTag(REASON_TAG, reason);
205-
final boolean blockingEnabled = isBlockingEnabled(result.get("is_blocking_enabled"));
206-
if (blockingEnabled && options.block() && action != Action.ALLOW) {
206+
final boolean blockingEnabled =
207+
isBlockingEnabled(options, result.get("is_blocking_enabled"));
208+
if (blockingEnabled && action != Action.ALLOW) {
207209
span.setTag(BLOCKED_TAG, true);
208210
throw new AIGuardAbortError(action, reason);
209211
}
@@ -246,10 +248,6 @@ private static OkHttpClient buildClient(final HttpUrl url, final long timeout) {
246248
return OkHttpUtils.buildHttpClient(url, timeout).newBuilder().build();
247249
}
248250

249-
private static boolean isEmpty(final String value) {
250-
return value == null || value.isEmpty();
251-
}
252-
253251
private static Map<String, String> mapOf(
254252
final String key1, final String prop1, final String key2, final String prop2) {
255253
final Map<String, String> map = new HashMap<>(2);

0 commit comments

Comments
 (0)