diff --git a/docs/site/content/en/openapi/openapi.yaml b/docs/site/content/en/openapi/openapi.yaml index a5983eef1..fa6f03a5c 100644 --- a/docs/site/content/en/openapi/openapi.yaml +++ b/docs/site/content/en/openapi/openapi.yaml @@ -2895,6 +2895,7 @@ components: description: Type of backend datastore required: - builtIn + - type - apiKey - url type: object @@ -2902,6 +2903,9 @@ components: builtIn: description: Built In type: boolean + type: + description: type information + type: string apiKey: description: Collector API KEY type: string @@ -3223,6 +3227,13 @@ components: oneOf: - $ref: "#/components/schemas/ElasticsearchDatastoreConfig" - $ref: "#/components/schemas/PostgresDatastoreConfig" + - $ref: "#/components/schemas/CollectorApiDatastoreConfig" + discriminator: + propertyName: type + mapping: + ELASTICSEARCH: "#/components/schemas/ElasticsearchDatastoreConfig" + POSTGRES: "#/components/schemas/PostgresDatastoreConfig" + COLLECTORAPI: "#/components/schemas/CollectorApiDatastoreConfig" type: description: Type of backend datastore enum: @@ -3263,12 +3274,16 @@ components: description: Type of backend datastore required: - builtIn + - type - url type: object properties: builtIn: description: Built In type: boolean + type: + description: type information + type: string apiKey: description: Elasticsearch API KEY type: string @@ -3884,11 +3899,15 @@ components: description: Built in backend datastore required: - builtIn + - type type: object properties: builtIn: description: Built In type: boolean + type: + description: type information + type: string ProtectedTimeType: required: - access diff --git a/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/BaseDatastoreConfig.java b/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/BaseDatastoreConfig.java index 929e92ebf..7ad283c4b 100644 --- a/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/BaseDatastoreConfig.java +++ b/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/BaseDatastoreConfig.java @@ -8,11 +8,15 @@ public abstract class BaseDatastoreConfig { @Schema(type = SchemaType.BOOLEAN, required = true, description = "Built In") public Boolean builtIn = true; + @Schema(type = SchemaType.STRING, required = true, description = "type information") + public String type = ""; + public BaseDatastoreConfig() { } - public BaseDatastoreConfig(Boolean builtIn) { + public BaseDatastoreConfig(Boolean builtIn, String type) { this.builtIn = builtIn; + this.type = type; } public abstract String validateConfig(); diff --git a/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/CollectorApiDatastoreConfig.java b/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/CollectorApiDatastoreConfig.java index 21b2d5927..6698cbacc 100644 --- a/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/CollectorApiDatastoreConfig.java +++ b/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/CollectorApiDatastoreConfig.java @@ -7,7 +7,7 @@ public class CollectorApiDatastoreConfig extends BaseDatastoreConfig { public CollectorApiDatastoreConfig() { - super(false); + super(false, "COLLECTORAPI"); } @Schema(type = SchemaType.STRING, required = true, description = "Collector API KEY") diff --git a/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/Datastore.java b/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/Datastore.java index 4f63bb9c6..f032508de 100644 --- a/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/Datastore.java +++ b/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/Datastore.java @@ -3,6 +3,7 @@ import jakarta.validation.constraints.NotNull; import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.DiscriminatorMapping; import org.eclipse.microprofile.openapi.annotations.media.Schema; import com.fasterxml.jackson.annotation.JsonProperty; @@ -30,7 +31,12 @@ public class Datastore extends ProtectedType { @JsonProperty(required = true) @Schema(type = SchemaType.OBJECT, oneOf = { ElasticsearchDatastoreConfig.class, - PostgresDatastoreConfig.class + PostgresDatastoreConfig.class, + CollectorApiDatastoreConfig.class + }, discriminatorProperty = "type", discriminatorMapping = { + @DiscriminatorMapping(value = "ELASTICSEARCH", schema = ElasticsearchDatastoreConfig.class), + @DiscriminatorMapping(value = "POSTGRES", schema = PostgresDatastoreConfig.class), + @DiscriminatorMapping(value = "COLLECTORAPI", schema = CollectorApiDatastoreConfig.class) }) public ObjectNode config; diff --git a/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/DatastoreType.java b/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/DatastoreType.java index 8770743f5..c362f9afc 100644 --- a/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/DatastoreType.java +++ b/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/DatastoreType.java @@ -8,10 +8,13 @@ @Schema(type = SchemaType.STRING, required = true, description = "Type of backend datastore") public enum DatastoreType { + @com.fasterxml.jackson.annotation.JsonProperty("POSTGRES") POSTGRES("POSTGRES", new TypeReference() { }), + @com.fasterxml.jackson.annotation.JsonProperty("ELASTICSEARCH") ELASTICSEARCH("ELASTICSEARCH", new TypeReference() { }), + @com.fasterxml.jackson.annotation.JsonProperty("COLLECTORAPI") COLLECTORAPI("COLLECTORAPI", new TypeReference() { }); @@ -29,6 +32,11 @@ public TypeReference getTypeReference() { return (TypeReference) typeReference; } + @com.fasterxml.jackson.annotation.JsonValue + public String toValue() { + return name; + } + @JsonCreator public static DatastoreType fromString(String str) { try { diff --git a/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/ElasticsearchDatastoreConfig.java b/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/ElasticsearchDatastoreConfig.java index eaed6afce..0578e801b 100644 --- a/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/ElasticsearchDatastoreConfig.java +++ b/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/ElasticsearchDatastoreConfig.java @@ -12,7 +12,7 @@ public class ElasticsearchDatastoreConfig extends BaseDatastoreConfig { public ElasticsearchDatastoreConfig() { - super(false); + super(false, "ELASTICSEARCH"); } @Schema(type = SchemaType.STRING, description = "Elasticsearch API KEY") diff --git a/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/PostgresDatastoreConfig.java b/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/PostgresDatastoreConfig.java index 2082f764d..b85e17a2c 100644 --- a/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/PostgresDatastoreConfig.java +++ b/horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/datastore/PostgresDatastoreConfig.java @@ -6,6 +6,10 @@ @Schema(type = SchemaType.OBJECT, required = true, description = "Built in backend datastore") public class PostgresDatastoreConfig extends BaseDatastoreConfig { + public PostgresDatastoreConfig() { + super(false, "POSTGRES"); + } + @Override public String validateConfig() { return null; diff --git a/horreum-web/src/domain/admin/Datastores.tsx b/horreum-web/src/domain/admin/Datastores.tsx index d7c028c73..3657dcadf 100644 --- a/horreum-web/src/domain/admin/Datastores.tsx +++ b/horreum-web/src/domain/admin/Datastores.tsx @@ -22,11 +22,9 @@ import VerifyBackendModal from "./datastore/VerifyBackendModal"; import { Access, apiCall, - CollectorApiDatastoreConfig, configApi, - Datastore, + Datastore, DatastoreConfig, DatastoreTypeEnum, - ElasticsearchDatastoreConfig } from "../../api"; import {AppContext} from "../../context/appContext"; import {AppContextType} from "../../context/@types/appContextTypes"; @@ -66,10 +64,9 @@ const DatastoresTable = ( props: dataStoreTableProps) => { }, ]; - const newBackendConfig: ElasticsearchDatastoreConfig | CollectorApiDatastoreConfig = { - url: "", - apiKey: "", - builtIn: false + const newBackendConfig: DatastoreConfig = { + builtIn: false, + type: DatastoreTypeEnum.Postgres } const newDataStore: Datastore = { diff --git a/horreum-web/src/domain/admin/datastore/ModifyDatastoreModal.tsx b/horreum-web/src/domain/admin/datastore/ModifyDatastoreModal.tsx index c21104af4..5e6d81d47 100644 --- a/horreum-web/src/domain/admin/datastore/ModifyDatastoreModal.tsx +++ b/horreum-web/src/domain/admin/datastore/ModifyDatastoreModal.tsx @@ -9,7 +9,7 @@ import { Modal, TextInput } from "@patternfly/react-core" import { - Datastore, + Datastore, DatastoreConfig, DatastoreTypeEnum, ElasticsearchDatastoreConfig, } from "../../../api"; import {AppContext} from "../../../context/appContext"; @@ -134,8 +134,10 @@ export default function ModifyDatastoreModal({isOpen, onClose, persistDatastore, { - const config :ElasticsearchDatastoreConfig = dataStore.config as ElasticsearchDatastoreConfig; - config.url = value + const config :DatastoreConfig = { + type: DatastoreTypeEnum.Elasticsearch, + url: value + } as DatastoreConfig; updateDatastore({...dataStore, config: config}) }} isDisabled={enabledURL} @@ -157,8 +159,11 @@ export default function ModifyDatastoreModal({isOpen, onClose, persistDatastore, { - const config :ElasticsearchDatastoreConfig = dataStore.config as ElasticsearchDatastoreConfig; - config.apiKey = value + const config :DatastoreConfig = { + type: DatastoreTypeEnum.Elasticsearch, + apiKey: value + } as DatastoreConfig; + updateDatastore({...dataStore, config: config}) }}isDisabled={enabledToken} type="text" @@ -180,8 +185,10 @@ export default function ModifyDatastoreModal({isOpen, onClose, persistDatastore, { - const config :ElasticsearchDatastoreConfig = dataStore.config as ElasticsearchDatastoreConfig; - config.username = value + const config :DatastoreConfig = { + type: DatastoreTypeEnum.Elasticsearch, + username: value + } as DatastoreConfig; updateDatastore({...dataStore, config: config}) }}isDisabled={enabledToken} type="text" @@ -202,8 +209,10 @@ export default function ModifyDatastoreModal({isOpen, onClose, persistDatastore, { - const config :ElasticsearchDatastoreConfig = dataStore.config as ElasticsearchDatastoreConfig; - config.password = value + const config :DatastoreConfig = { + type: DatastoreTypeEnum.Elasticsearch, + password: value + } as DatastoreConfig; updateDatastore({...dataStore, config: config}) }}isDisabled={enabledToken} type="text"