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

Handle absent OTX API key in ThreatIntelPluginConfiguration #54

Merged
merged 1 commit into from
Sep 27, 2017

Conversation

joschi
Copy link
Contributor

@joschi joschi commented Sep 26, 2017

Fixes #53

@@ -19,7 +19,8 @@
public abstract boolean otxEnabled();

@JsonProperty("otx_api_key")
public abstract Optional<String> otxApiKey();
@Nullable
public abstract String otxApiKey();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be enough so we can keep the nice properties of java.util.Optional?

diff --git src/main/java/org/graylog/plugins/threatintel/ThreatIntelPluginConfiguration.java src/main/java/org/graylog/plugins/threatintel/ThreatIntelPluginConfiguration.java
index 130fa5d..9b983fa 100644
--- src/main/java/org/graylog/plugins/threatintel/ThreatIntelPluginConfiguration.java
+++ src/main/java/org/graylog/plugins/threatintel/ThreatIntelPluginConfiguration.java
@@ -38,7 +37,7 @@ public abstract class ThreatIntelPluginConfiguration {
                                                         @JsonProperty("abusech_ransom_enabled") boolean abusechRansomEnabled) {
         return builder()
                 .otxEnabled(otxEnabled)
-                .otxApiKey(otxApiKey)
+                .otxApiKey(Optional.ofNullable(otxApiKey))
                 .torEnabled(torEnabled)
                 .spamhausEnabled(spamhausEnabled)
                 .abusechRansomEnabled(abusechRansomEnabled)
@@ -62,7 +61,7 @@ public abstract class ThreatIntelPluginConfiguration {
     public static abstract class Builder {
         public abstract Builder otxEnabled(boolean otxEnabled);
 
-        public abstract Builder otxApiKey(String otxApiKey);
+        public abstract Builder otxApiKey(Optional<String> otxApiKey);
 
         public abstract Builder torEnabled(boolean torEnabled);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but Optional<T> is pretty useless in this case anyway (check the usages of ThreatIntelPluginConfiguration#otxApiKey()).
In other words, getting rid of the Optional<T> meant having less code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't call it useless, but fair enough.

@bernd bernd self-assigned this Sep 27, 2017
@bernd bernd merged commit e3b1ca2 into master Sep 27, 2017
@bernd bernd deleted the issue-53 branch September 27, 2017 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants