🎉 Init

This commit is contained in:
2026-07-19 16:46:43 +02:00
parent 3e380643d7
commit f787478414
34 changed files with 1736 additions and 0 deletions
+100
View File
@@ -0,0 +1,100 @@
####
# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode
#
# Before building the container image run:
#
# ./mvnw package
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/backend-jvm .
#
# Then run the container using:
#
# docker run -i --rm -p 8080:8080 quarkus/backend-jvm
#
# If you want to include the debug port into your docker image
# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005.
# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005
# when running the container
#
# Then run the container using :
#
# docker run -i --rm -p 8080:8080 quarkus/backend-jvm
#
# This image uses the `run-java.sh` script to run the application.
# This scripts computes the command line to execute your Java application, and
# includes memory/GC tuning.
# You can configure the behavior using the following environment properties:
# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") - Be aware that this will override
# the default JVM options, use `JAVA_OPTS_APPEND` to append options
# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options
# in JAVA_OPTS (example: "-Dsome.property=foo")
# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is
# used to calculate a default maximal heap memory based on a containers restriction.
# If used in a container without any memory constraints for the container then this
# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio
# of the container available memory as set here. The default is `50` which means 50%
# of the available memory is used as an upper boundary. You can skip this mechanism by
# setting this value to `0` in which case no `-Xmx` option is added.
# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This
# is used to calculate a default initial heap memory based on the maximum heap memory.
# If used in a container without any memory constraints for the container then this
# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio
# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx`
# is used as the initial heap size. You can skip this mechanism by setting this value
# to `0` in which case no `-Xms` option is added (example: "25")
# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS.
# This is used to calculate the maximum value of the initial heap memory. If used in
# a container without any memory constraints for the container then this option has
# no effect. If there is a memory constraint then `-Xms` is limited to the value set
# here. The default is 4096MB which means the calculated value of `-Xms` never will
# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096")
# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output
# when things are happening. This option, if set to true, will set
# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true").
# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example:
# true").
# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787").
# - CONTAINER_CORE_LIMIT: A calculated core limit as described in
# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2")
# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024").
# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion.
# (example: "20")
# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking.
# (example: "40")
# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection.
# (example: "4")
# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus
# previous GC times. (example: "90")
# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20")
# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100")
# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should
# contain the necessary JRE command-line options to specify the required GC, which
# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC).
# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080")
# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080")
# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be
# accessed directly. (example: "foo.example.com,bar.example.com")
#
# You can find more information about the UBI base runtime images and their configuration here:
# https://rh-openjdk.github.io/redhat-openjdk-containers/
###
FROM registry.access.redhat.com/ubi8/openjdk-21:1.23
ENV LANGUAGE='en_US:en'
# We make four distinct layers so if there are application changes the library layers can be re-used
COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/
COPY --chown=185 target/quarkus-app/*.jar /deployments/
COPY --chown=185 target/quarkus-app/app/ /deployments/app/
COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/
EXPOSE 8080
USER 185
ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"
ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ]
@@ -0,0 +1,96 @@
####
# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode
#
# Before building the container image run:
#
# ./mvnw package -Dquarkus.package.jar.type=legacy-jar
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile.legacy-jar -t quarkus/backend-legacy-jar .
#
# Then run the container using:
#
# docker run -i --rm -p 8080:8080 quarkus/backend-legacy-jar
#
# If you want to include the debug port into your docker image
# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005.
# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005
# when running the container
#
# Then run the container using :
#
# docker run -i --rm -p 8080:8080 quarkus/backend-legacy-jar
#
# This image uses the `run-java.sh` script to run the application.
# This scripts computes the command line to execute your Java application, and
# includes memory/GC tuning.
# You can configure the behavior using the following environment properties:
# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") - Be aware that this will override
# the default JVM options, use `JAVA_OPTS_APPEND` to append options
# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options
# in JAVA_OPTS (example: "-Dsome.property=foo")
# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is
# used to calculate a default maximal heap memory based on a containers restriction.
# If used in a container without any memory constraints for the container then this
# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio
# of the container available memory as set here. The default is `50` which means 50%
# of the available memory is used as an upper boundary. You can skip this mechanism by
# setting this value to `0` in which case no `-Xmx` option is added.
# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This
# is used to calculate a default initial heap memory based on the maximum heap memory.
# If used in a container without any memory constraints for the container then this
# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio
# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx`
# is used as the initial heap size. You can skip this mechanism by setting this value
# to `0` in which case no `-Xms` option is added (example: "25")
# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS.
# This is used to calculate the maximum value of the initial heap memory. If used in
# a container without any memory constraints for the container then this option has
# no effect. If there is a memory constraint then `-Xms` is limited to the value set
# here. The default is 4096MB which means the calculated value of `-Xms` never will
# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096")
# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output
# when things are happening. This option, if set to true, will set
# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true").
# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example:
# true").
# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787").
# - CONTAINER_CORE_LIMIT: A calculated core limit as described in
# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2")
# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024").
# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion.
# (example: "20")
# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking.
# (example: "40")
# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection.
# (example: "4")
# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus
# previous GC times. (example: "90")
# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20")
# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100")
# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should
# contain the necessary JRE command-line options to specify the required GC, which
# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC).
# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080")
# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080")
# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be
# accessed directly. (example: "foo.example.com,bar.example.com")
#
# You can find more information about the UBI base runtime images and their configuration here:
# https://rh-openjdk.github.io/redhat-openjdk-containers/
###
FROM registry.access.redhat.com/ubi8/openjdk-21:1.23
ENV LANGUAGE='en_US:en'
COPY target/lib/* /deployments/lib/
COPY target/*-runner.jar /deployments/quarkus-run.jar
EXPOSE 8080
USER 185
ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"
ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ]
+29
View File
@@ -0,0 +1,29 @@
####
# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode.
#
# Before building the container image run:
#
# ./mvnw package -Dnative
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile.native -t quarkus/backend .
#
# Then run the container using:
#
# docker run -i --rm -p 8080:8080 quarkus/backend
#
# The ` registry.access.redhat.com/ubi8/ubi-minimal:8.10` base image is based on UBI 9.
# To use UBI 8, switch to `quay.io/ubi8/ubi-minimal:8.10`.
###
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.10
WORKDIR /work/
RUN chown 1001 /work \
&& chmod "g+rwX" /work \
&& chown 1001:root /work
COPY --chown=1001:root --chmod=0755 target/*-runner /work/application
EXPOSE 8080
USER 1001
ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"]
@@ -0,0 +1,32 @@
####
# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode.
# It uses a micro base image, tuned for Quarkus native executables.
# It reduces the size of the resulting container image.
# Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image.
#
# Before building the container image run:
#
# ./mvnw package -Dnative
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/backend .
#
# Then run the container using:
#
# docker run -i --rm -p 8080:8080 quarkus/backend
#
# The `quay.io/quarkus/quarkus-micro-image:2.0` base image is based on UBI 9.
# To use UBI 8, switch to `quay.io/quarkus/quarkus-micro-image:2.0`.
###
FROM quay.io/quarkus/quarkus-micro-image:2.0
WORKDIR /work/
RUN chown 1001 /work \
&& chmod "g+rwX" /work \
&& chown 1001:root /work
COPY --chown=1001:root --chmod=0755 target/*-runner /work/application
EXPOSE 8080
USER 1001
ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"]
@@ -0,0 +1,50 @@
package dev.dinauer.lockaway;
import dev.dinauer.lockaway.secret.SecretService;
import dev.dinauer.lockaway.secret.dto.SecretCreate;
import io.quarkus.arc.profile.IfBuildProfile;
import io.quarkus.runtime.StartupEvent;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;
import java.util.List;
import java.util.Map;
@ApplicationScoped
@IfBuildProfile("dev")
public class Dev
{
@Inject
SecretService secretService;
void onStart(@Observes StartupEvent event)
{
if (!secretService.getAll(null).isEmpty())
{
return;
}
secretService.create(new SecretCreate(
"smtp-creds",
List.of("demo-1"),
Map.of("password", "0ombOg6l6dUTcdvBT33MmZpTFHYnD1Ri/l0V0thaJDLxIxWbfUc+5m2lBZu0"),
"Opaque")
);
secretService.create(new SecretCreate(
"postgres-user",
List.of("demo-2", "demo-3"),
Map.ofEntries(Map.entry("password", "FnMkHYDu06a0B8tu/vngT/7Fq46dsxnGJf417ba21XGeV6EPoch+6hfZVphB"),
Map.entry("username", "Jwd5fO/H5iPvZBjFLJZn33tgBsBzUtmpVOqlEP8bo6Noxe2i"),
Map.entry("host", "Jv/vWzljHl69MbgzS6T98jSiOs9IAhS23q7oOYqM+QXx9oBuR88eXFsXy2jFb7tcLQl82EfEu6m4evw="),
Map.entry("port", "QQ6pfAxcEbRnI5LO8G6uQuy9XuWa5KfU9feI30xYPOw=")),
"Opaque")
);
secretService.create(new SecretCreate(
"minio-keys",
List.of("demo-4", "demo-5", "demo-6"),
Map.ofEntries(Map.entry("access-key", "DPbtxA3fZ3LZbbpCRD8eXUNAc6NZ2FxipREEKcw4NUegipUfg7yXBXKZkvSDERw="),
Map.entry("secret-key", "zeaJXSZqWjKAgnUUxG8jB4rcPha35Jt4aE3LS+8QbRlFiKk6+xGH/GN/X8LSVgSIU+KkPxRpeQ8GL6WM16XRKBrsgo8=")),
"Opaque")
);
}
}
@@ -0,0 +1,46 @@
package dev.dinauer.lockaway.secret;
import com.fasterxml.jackson.databind.ObjectMapper;
import dev.dinauer.lockaway.secret.dto.Secret;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.List;
@Path("/_export")
public class ExportResource
{
@Inject
SecretService secretService;
@Inject
SecretMapper secretMapper;
@Inject
ObjectMapper objectMapper;
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response export()
{
List<Secret> secrets = secretService.getAll(null).stream().map(secretMapper::toDto).toList();
String pretty;
try
{
pretty = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(secrets);
}
catch (Exception e)
{
throw new WebApplicationException(e);
}
return Response.ok(pretty)
.header("Content-Disposition", "attachment; filename=\"lockaway-export.json\"")
.build();
}
}
@@ -0,0 +1,27 @@
package dev.dinauer.lockaway.secret;
import dev.dinauer.lockaway.secret.dto.Secret;
import dev.dinauer.lockaway.secret.dto.SecretCreate;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.MediaType;
import java.util.List;
@Path("/_import")
public class ImportResource
{
@Inject
SecretService secretService;
@POST
@Consumes(MediaType.APPLICATION_JSON)
public void importAll(List<Secret> secrets)
{
for (Secret secret : secrets)
{
secretService.create(new SecretCreate(secret.name(), secret.namespaces(), secret.entries(), secret.type()));
}
}
}
@@ -0,0 +1,91 @@
package dev.dinauer.lockaway.secret;
import dev.dinauer.lockaway.secret.entry.EntryEntity;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.annotations.UuidGenerator;
@Entity
@Table(name = "secret")
public class SecretEntity
{
@Id
@GeneratedValue
@UuidGenerator
private String id;
private String name;
@ElementCollection
@CollectionTable(name = "secret_namespace", joinColumns = @JoinColumn(name = "secret_id"))
@Column(name = "namespace")
private List<String> namespaces = new ArrayList<>();
private String contentHash;
private String type;
@OneToMany(mappedBy = "secret", cascade = CascadeType.ALL, orphanRemoval = true)
private List<EntryEntity> entries = new ArrayList<>();
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public List<String> getNamespaces()
{
return namespaces;
}
public void setNamespaces(List<String> namespaces)
{
this.namespaces = namespaces;
}
public String getContentHash()
{
return contentHash;
}
public void setContentHash(String contentHash)
{
this.contentHash = contentHash;
}
public String getType()
{
return type;
}
public void setType(String type)
{
this.type = type;
}
public List<EntryEntity> getEntries()
{
return entries;
}
public void setEntries(List<EntryEntity> entries)
{
this.entries = entries;
}
}
@@ -0,0 +1,21 @@
package dev.dinauer.lockaway.secret;
import dev.dinauer.lockaway.secret.dto.Secret;
import dev.dinauer.lockaway.secret.entry.EntryEntity;
import jakarta.enterprise.context.ApplicationScoped;
import java.util.stream.Collectors;
@ApplicationScoped
public class SecretMapper
{
public Secret toDto(SecretEntity entity)
{
return new Secret(
entity.getId(),
entity.getName(),
entity.getNamespaces(),
entity.getContentHash(),
entity.getEntries().stream().collect(Collectors.toMap(EntryEntity::getKey, EntryEntity::getValue)),
entity.getType());
}
}
@@ -0,0 +1,15 @@
package dev.dinauer.lockaway.secret;
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase;
import jakarta.enterprise.context.ApplicationScoped;
import java.util.List;
@ApplicationScoped
public class SecretRepository implements PanacheRepositoryBase<SecretEntity, String>
{
public List<SecretEntity> findByNameAndNamespace(String name, List<String> namespaces)
{
return list("select distinct s from SecretEntity s join s.namespaces n where s.name = ?1 and n in ?2",
name, namespaces);
}
}
@@ -0,0 +1,57 @@
package dev.dinauer.lockaway.secret;
import dev.dinauer.lockaway.secret.dto.Secret;
import dev.dinauer.lockaway.secret.dto.SecretCreate;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import java.util.List;
@Path("/secrets")
public class SecretResource
{
@Inject
SecretService secretService;
@Inject
SecretMapper secretMapper;
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Secret> getAll(@QueryParam("searchText") String searchText)
{
return secretService.getAll(searchText).stream().map(secretMapper::toDto).toList();
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public SecretEntity create(SecretCreate create)
{
return secretService.create(create);
}
@PUT
@Path("/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public SecretEntity update(@PathParam("id") String id, SecretCreate update)
{
return secretService.update(id, update);
}
@DELETE
@Path("/{id}")
public void delete(@PathParam("id") String id)
{
secretService.delete(id);
}
}
@@ -0,0 +1,139 @@
package dev.dinauer.lockaway.secret;
import dev.dinauer.lockaway.secret.dto.SecretCreate;
import dev.dinauer.lockaway.secret.entry.EntryEntity;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.NotFoundException;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HexFormat;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ApplicationScoped
public class SecretService
{
@Inject
SecretRepository secretRepository;
@Transactional
public SecretEntity create(SecretCreate create)
{
checkForCollisions(null, create.name(), create.namespaces());
SecretEntity secret = new SecretEntity();
secret.setName(create.name());
secret.setNamespaces(create.namespaces());
secret.setEntries(toEntries(secret, create.entries()));
secret.setContentHash(hash(create.type(), create.entries()));
secret.setType(create.type());
secretRepository.persist(secret);
return secret;
}
@Transactional
public SecretEntity update(String id, SecretCreate update)
{
SecretEntity secret = secretRepository.findByIdOptional(id)
.orElseThrow(() -> new NotFoundException("Secret not found: " + id));
checkForCollisions(id, update.name(), update.namespaces());
secret.setName(update.name());
secret.setNamespaces(update.namespaces());
secret.getEntries().clear();
secret.getEntries().addAll(toEntries(secret, update.entries()));
secret.setContentHash(hash(update.type(), update.entries()));
secret.setType(update.type());
return secret;
}
private void checkForCollisions(String excludeId, String name, List<String> namespaces)
{
boolean collision = secretRepository.findByNameAndNamespace(name, namespaces).stream()
.anyMatch(existing -> !existing.getId().equals(excludeId));
if (collision)
{
throw new WebApplicationException(Response.status(Response.Status.CONFLICT)
.entity(Map.of("error", "secret_conflict"))
.build());
}
}
public List<SecretEntity> getAll(String searchText)
{
List<SecretEntity> secrets = secretRepository.listAll();
if (searchText == null || searchText.isBlank())
{
return secrets;
}
String needle = searchText.toLowerCase();
return secrets.stream().filter(secret -> matches(secret, needle)).toList();
}
private boolean matches(SecretEntity secret, String needle)
{
if (secret.getName().toLowerCase().contains(needle))
{
return true;
}
if (secret.getNamespaces().stream().anyMatch(namespace -> namespace.toLowerCase().contains(needle)))
{
return true;
}
return secret.getEntries().stream().anyMatch(entry -> entry.getKey().toLowerCase().contains(needle));
}
@Transactional
public void delete(String id)
{
secretRepository.deleteById(id);
}
private List<EntryEntity> toEntries(SecretEntity secret, Map<String, String> entries)
{
return entries.entrySet().stream()
.map(e ->
{
EntryEntity entry = new EntryEntity();
entry.setSecret(secret);
entry.setKey(e.getKey());
entry.setValue(e.getValue());
return entry;
})
.toList();
}
private String hash(String type, Map<String, String> entries)
{
String content = entries.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.map(e -> e.getKey() + "=" + e.getValue())
.collect(Collectors.joining(";"));
return hash(type + ";" + content);
}
private String hash(String value)
{
try
{
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] bytes = digest.digest(value.getBytes(StandardCharsets.UTF_8));
return HexFormat.of().formatHex(bytes);
}
catch (NoSuchAlgorithmException e)
{
throw new IllegalStateException(e);
}
}
}
@@ -0,0 +1,8 @@
package dev.dinauer.lockaway.secret.dto;
import java.util.List;
import java.util.Map;
public record Secret(String id, String name, List<String> namespaces, String contentHash, Map<String, String> entries, String type)
{
}
@@ -0,0 +1,8 @@
package dev.dinauer.lockaway.secret.dto;
import java.util.List;
import java.util.Map;
public record SecretCreate(String name, List<String> namespaces, Map<String, String> entries, String type)
{
}
@@ -0,0 +1,63 @@
package dev.dinauer.lockaway.secret.entry;
import dev.dinauer.lockaway.secret.SecretEntity;
import jakarta.persistence.*;
import org.hibernate.annotations.UuidGenerator;
@Entity
@Table(name = "entry")
public class EntryEntity
{
@Id
@GeneratedValue
@UuidGenerator
private String id;
@ManyToOne
private SecretEntity secret;
private String key;
@Column(columnDefinition = "TEXT")
private String value;
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public SecretEntity getSecret()
{
return secret;
}
public void setSecret(SecretEntity secret)
{
this.secret = secret;
}
public String getKey()
{
return key;
}
public void setKey(String key)
{
this.key = key;
}
public String getValue()
{
return value;
}
public void setValue(String value)
{
this.value = value;
}
}
@@ -0,0 +1,37 @@
package dev.dinauer.lockaway.verification;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name = "verification")
public class VerificationEntity
{
public static final long SINGLETON_ID = 1L;
@Id
private Long id = SINGLETON_ID;
private String value;
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
public String getValue()
{
return value;
}
public void setValue(String value)
{
this.value = value;
}
}
@@ -0,0 +1,14 @@
package dev.dinauer.lockaway.verification;
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase;
import jakarta.enterprise.context.ApplicationScoped;
import java.util.Optional;
@ApplicationScoped
public class VerificationRepository implements PanacheRepositoryBase<VerificationEntity, Long>
{
public Optional<VerificationEntity> findSingleton()
{
return findByIdOptional(VerificationEntity.SINGLETON_ID);
}
}
@@ -0,0 +1,31 @@
package dev.dinauer.lockaway.verification;
import dev.dinauer.lockaway.verification.dto.VerificationValue;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
@Path("/verification")
public class VerificationResource
{
@Inject
VerificationService verificationService;
@GET
@Produces(MediaType.APPLICATION_JSON)
public VerificationValue get()
{
return verificationService.getValue().map(VerificationValue::new).orElse(null);
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
public void set(VerificationValue body)
{
verificationService.setValue(body.value());
}
}
@@ -0,0 +1,26 @@
package dev.dinauer.lockaway.verification;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import java.util.Optional;
@ApplicationScoped
public class VerificationService
{
@Inject
VerificationRepository verificationRepository;
public Optional<String> getValue()
{
return verificationRepository.findSingleton().map(VerificationEntity::getValue);
}
@Transactional
public void setValue(String value)
{
VerificationEntity verification = verificationRepository.findSingleton().orElseGet(VerificationEntity::new);
verification.setValue(value);
verificationRepository.persist(verification);
}
}
@@ -0,0 +1,5 @@
package dev.dinauer.lockaway.verification.dto;
public record VerificationValue(String value)
{
}
@@ -0,0 +1,13 @@
quarkus.datasource.db-kind=postgresql
%dev.quarkus.datasource.username=postgres
%dev.quarkus.datasource.password=postgres
%dev.quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:32876/postgres
quarkus.hibernate-orm.schema-management.strategy=validate
quarkus.hibernate-orm.physical-naming-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategySnakeCaseImpl
quarkus.flyway.migrate-at-start=true
%dev.quarkus.flyway.clean-at-start=true
quarkus.http.cors.enabled=true
quarkus.http.cors.origins=/http:\/\/localhost:[0-9]+/
@@ -0,0 +1,24 @@
CREATE TABLE secret
(
id VARCHAR(255) NOT NULL,
name VARCHAR(255),
content_hash VARCHAR(255),
PRIMARY KEY (id)
);
CREATE TABLE secret_namespace
(
secret_id VARCHAR(255) NOT NULL,
namespace VARCHAR(255),
CONSTRAINT fk_secret_namespace_secret FOREIGN KEY (secret_id) REFERENCES secret (id)
);
CREATE TABLE entry
(
id VARCHAR(255) NOT NULL,
secret_id VARCHAR(255),
key VARCHAR(255),
value VARCHAR(255),
PRIMARY KEY (id),
CONSTRAINT fk_entry_secret FOREIGN KEY (secret_id) REFERENCES secret (id)
);
@@ -0,0 +1,6 @@
CREATE TABLE verification
(
id BIGINT NOT NULL,
value VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
@@ -0,0 +1,2 @@
ALTER TABLE entry
ALTER COLUMN value TYPE TEXT;
@@ -0,0 +1,2 @@
ALTER TABLE secret
ADD COLUMN type VARCHAR(255);
+6
View File
@@ -0,0 +1,6 @@
-- This file allow to write SQL commands that will be emitted in test and dev.
-- The commands are commented as their support depends of the database
-- insert into myentity (id, field) values(1, 'field-1');
-- insert into myentity (id, field) values(2, 'field-2');
-- insert into myentity (id, field) values(3, 'field-3');
-- alter sequence myentity_seq restart with 4;