forked from nzymedefense/nzyme
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba76aa3
commit dca27c1
Showing
21 changed files
with
704 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/app/nzyme/core/connect/ConnectHealthIndicatorReport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package app.nzyme.core.connect; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.auto.value.AutoValue; | ||
import org.joda.time.DateTime; | ||
|
||
@AutoValue | ||
public abstract class ConnectHealthIndicatorReport { | ||
|
||
@JsonProperty("name") | ||
public abstract String indicatorName(); | ||
|
||
@JsonProperty("id") | ||
public abstract String indicatorId(); | ||
|
||
@JsonProperty("last_checked") | ||
public abstract DateTime lastChecked(); | ||
|
||
@JsonProperty("result_level") | ||
public abstract String resultLevel(); | ||
|
||
@JsonProperty("active") | ||
public abstract boolean active(); | ||
|
||
public static ConnectHealthIndicatorReport create(String indicatorName, String indicatorId, DateTime lastChecked, String resultLevel, boolean active) { | ||
return builder() | ||
.indicatorName(indicatorName) | ||
.indicatorId(indicatorId) | ||
.lastChecked(lastChecked) | ||
.resultLevel(resultLevel) | ||
.active(active) | ||
.build(); | ||
} | ||
|
||
public static Builder builder() { | ||
return new AutoValue_ConnectHealthIndicatorReport.Builder(); | ||
} | ||
|
||
@AutoValue.Builder | ||
public abstract static class Builder { | ||
public abstract Builder indicatorName(String indicatorName); | ||
|
||
public abstract Builder indicatorId(String indicatorId); | ||
|
||
public abstract Builder lastChecked(DateTime lastChecked); | ||
|
||
public abstract Builder resultLevel(String resultLevel); | ||
|
||
public abstract Builder active(boolean active); | ||
|
||
public abstract ConnectHealthIndicatorReport build(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/app/nzyme/core/connect/ConnectRegistryKeys.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package app.nzyme.core.connect; | ||
|
||
import app.nzyme.plugin.EncryptedRegistryKey; | ||
import app.nzyme.plugin.RegistryKey; | ||
import app.nzyme.plugin.rest.configuration.ConfigurationEntryConstraint; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Optional; | ||
|
||
public class ConnectRegistryKeys { | ||
|
||
public static final RegistryKey CONNECT_ENABLED = RegistryKey.create( | ||
"connect_enabled", | ||
Optional.of(new ArrayList<>() {{ | ||
add(ConfigurationEntryConstraint.createSimpleBooleanConstraint()); | ||
}}), | ||
Optional.of("false"), | ||
false | ||
); | ||
|
||
public static EncryptedRegistryKey CONNECT_API_KEY = EncryptedRegistryKey.create( | ||
"connect_api_key", | ||
Optional.of(new ArrayList<>() {{ | ||
add(ConfigurationEntryConstraint.createStringLengthConstraint(64, 64)); | ||
}}), | ||
false | ||
); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package app.nzyme.core.connect; | ||
|
||
import app.nzyme.core.NzymeNode; | ||
import app.nzyme.plugin.RegistryCryptoException; | ||
import com.google.common.base.Strings; | ||
import jakarta.annotation.Nullable; | ||
|
||
import java.net.URI; | ||
import java.util.Optional; | ||
|
||
public class ConnectService { | ||
|
||
private final NzymeNode nzyme; | ||
|
||
private static final String DEFAULT_API_URI = "https://connect.nzyme.org/"; | ||
|
||
public ConnectService(NzymeNode nzyme) { | ||
this.nzyme = nzyme; | ||
} | ||
|
||
public boolean isEnabled() { | ||
Optional<String> enabled = nzyme.getDatabaseCoreRegistry().getValue(ConnectRegistryKeys.CONNECT_ENABLED.key()); | ||
|
||
return enabled.isPresent() && enabled.get().equals("true") && getApiKey() != null; | ||
} | ||
|
||
public URI getApiUri() { | ||
if (Strings.isNullOrEmpty(nzyme.getConfiguration().connectApiUri())) { | ||
return URI.create(DEFAULT_API_URI); | ||
} else { | ||
return URI.create(nzyme.getConfiguration().connectApiUri()); | ||
} | ||
} | ||
|
||
@Nullable | ||
public String getApiKey() { | ||
Optional<String> apiKey; | ||
try { | ||
apiKey = nzyme.getDatabaseCoreRegistry().getEncryptedValue(ConnectRegistryKeys.CONNECT_API_KEY.key()); | ||
} catch(RegistryCryptoException e) { | ||
throw new RuntimeException("Could not decrypt Connect API key.", e); | ||
} | ||
|
||
return apiKey.orElse(null); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/app/nzyme/core/connect/ConnectStatusReport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package app.nzyme.core.connect; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.auto.value.AutoValue; | ||
import org.joda.time.DateTime; | ||
|
||
import java.util.List; | ||
|
||
@AutoValue | ||
public abstract class ConnectStatusReport { | ||
|
||
@JsonProperty("version") | ||
public abstract String version(); | ||
|
||
@JsonProperty("local_time") | ||
public abstract DateTime localTime(); | ||
|
||
@JsonProperty("java_vendor") | ||
public abstract String javaVendor(); | ||
|
||
@JsonProperty("java_version") | ||
public abstract String javaVersion(); | ||
|
||
@JsonProperty("os_name") | ||
public abstract String osName(); | ||
|
||
@JsonProperty("os_architecture") | ||
public abstract String osArchitecture(); | ||
|
||
@JsonProperty("os_version") | ||
public abstract String osVersion(); | ||
|
||
@JsonProperty("health_indicators") | ||
public abstract List<ConnectHealthIndicatorReport> healthIndicators(); | ||
|
||
public static ConnectStatusReport create(String version, DateTime localTime, String javaVendor, String javaVersion, String osName, String osArchitecture, String osVersion, List<ConnectHealthIndicatorReport> healthIndicators) { | ||
return builder() | ||
.version(version) | ||
.localTime(localTime) | ||
.javaVendor(javaVendor) | ||
.javaVersion(javaVersion) | ||
.osName(osName) | ||
.osArchitecture(osArchitecture) | ||
.osVersion(osVersion) | ||
.healthIndicators(healthIndicators) | ||
.build(); | ||
} | ||
|
||
public static Builder builder() { | ||
return new AutoValue_ConnectStatusReport.Builder(); | ||
} | ||
|
||
@AutoValue.Builder | ||
public abstract static class Builder { | ||
public abstract Builder version(String version); | ||
|
||
public abstract Builder localTime(DateTime localTime); | ||
|
||
public abstract Builder javaVendor(String javaVendor); | ||
|
||
public abstract Builder javaVersion(String javaVersion); | ||
|
||
public abstract Builder osName(String osName); | ||
|
||
public abstract Builder osArchitecture(String osArchitecture); | ||
|
||
public abstract Builder osVersion(String osVersion); | ||
|
||
public abstract Builder healthIndicators(List<ConnectHealthIndicatorReport> healthIndicators); | ||
|
||
public abstract ConnectStatusReport build(); | ||
} | ||
} |
Oops, something went wrong.