Skip to content

Commit

Permalink
[backend] refact
Browse files Browse the repository at this point in the history
  • Loading branch information
savacano28 committed Oct 2, 2024
1 parent 5a3f7a7 commit fa2957e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import io.openbas.database.model.Endpoint.PLATFORM_TYPE;
import io.openbas.database.model.Payload.PAYLOAD_SOURCE;
import io.openbas.database.model.Payload.PAYLOAD_STATUS;
import io.openbas.database.model.PayloadArgument;
import io.openbas.database.model.PayloadPrerequisite;
import jakarta.validation.constraints.NotBlank;
Expand All @@ -28,11 +30,11 @@ public class PayloadCreateInput {

@NotBlank(message = MANDATORY_MESSAGE)
@JsonProperty("payload_source")
private String source;
private PAYLOAD_SOURCE source;

Check warning on line 33 in openbas-api/src/main/java/io/openbas/rest/payload/form/PayloadCreateInput.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/payload/form/PayloadCreateInput.java#L33

Added line #L33 was not covered by tests

@NotBlank(message = MANDATORY_MESSAGE)
@JsonProperty("payload_status")
private String status;
private PAYLOAD_STATUS status;

Check warning on line 37 in openbas-api/src/main/java/io/openbas/rest/payload/form/PayloadCreateInput.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/payload/form/PayloadCreateInput.java#L37

Added line #L37 was not covered by tests

@NotEmpty(message = MANDATORY_MESSAGE)
@JsonProperty("payload_platforms")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import static io.openbas.database.model.Command.COMMAND_TYPE;
import static io.openbas.database.model.DnsResolution.DNS_RESOLUTION_TYPE;
import static io.openbas.database.model.Payload.PAYLOAD_SOURCE.MANUAL;
import static io.openbas.database.model.Payload.PAYLOAD_STATUS.VERIFIED;

public class PayloadFixture {

Expand All @@ -14,8 +16,8 @@ public static Payload createDefaultCommand() {
command.setContent("cd ..");
command.setExecutor("PowerShell");
command.setPlatforms(new Endpoint.PLATFORM_TYPE[]{Endpoint.PLATFORM_TYPE.Windows});
command.setSource("MANUAL");
command.setStatus("VERIFIED");
command.setSource(MANUAL);
command.setStatus(VERIFIED);
command.setAttackPatterns(Collections.emptyList());
return command;
}
Expand All @@ -24,8 +26,8 @@ public static Payload createDefaultDnsResolution() {
DnsResolution dnsResolution = new DnsResolution("dns-resolution-id", DNS_RESOLUTION_TYPE, "dns resolution payload");
dnsResolution.setHostname("localhost");
dnsResolution.setPlatforms(new Endpoint.PLATFORM_TYPE[]{Endpoint.PLATFORM_TYPE.Linux});
dnsResolution.setSource("MANUAL");
dnsResolution.setStatus("VERIFIED");
dnsResolution.setSource(MANUAL);
dnsResolution.setStatus(VERIFIED);
dnsResolution.setAttackPatterns(Collections.emptyList());
return dnsResolution;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ public enum PAYLOAD_STATUS {
@JsonProperty("payload_external_id")
private String externalId;

@Setter
@Queryable(filterable = true, sortable = true)
@Column(name = "payload_source")
@Enumerated(EnumType.STRING)
@JsonProperty("payload_source")
private PAYLOAD_SOURCE source;

@Setter
@Queryable(filterable = true)
@Column(name = "payload_status")
@Enumerated(EnumType.STRING)
Expand Down Expand Up @@ -166,14 +168,6 @@ private String getCollectorType() {
return this.collector != null ? this.collector.getType() : null;
}

public void setStatus(String status) {
this.status = PAYLOAD_STATUS.valueOf(status.toUpperCase());
}

public void setSource(String source) {
this.source = PAYLOAD_SOURCE.valueOf(source.toUpperCase());
}

@Override
public int hashCode() {
return Objects.hash(id);
Expand Down

0 comments on commit fa2957e

Please sign in to comment.