diff --git a/akms-simulator/Dockerfile b/akms-simulator/Dockerfile index 2bb8f1e8248007fe17bdee3c21af74939f65fce7..2286f46717de61edbae3b2c81f9f24aeb3ca3506 100644 --- a/akms-simulator/Dockerfile +++ b/akms-simulator/Dockerfile @@ -14,6 +14,7 @@ RUN --mount=type=cache,target=/root/go/pkg/mod \ FROM ${GITLAB_PROXY}debian:12-slim AS debian RUN apt-get update && apt-get upgrade -y COPY --from=builder app/artifacts/akms-simulator /usr/bin/akms-simulator +RUN mkdir /logs EXPOSE 4444 ENTRYPOINT ["/usr/bin/akms-simulator"] diff --git a/akms-simulator/akms-simulator.go b/akms-simulator/akms-simulator.go index 6edfe88c86a4a8bcb0360297b6ca6d7fa960a804..c45501a2664a5fb681534e6ee4c1bfe3f6c1528c 100644 --- a/akms-simulator/akms-simulator.go +++ b/akms-simulator/akms-simulator.go @@ -12,6 +12,11 @@ import ( "github.com/sirupsen/logrus" ) +const ( + // LogFile is the file where the log is stored. + LogFilePath = "/logs/akms-simulator.log" +) + type LogFile struct { Source string `json:"source"` Body PushKSAKeyRequest `json:"body"` @@ -79,7 +84,7 @@ func main() { func getLogFile(w http.ResponseWriter, r *http.Request) { logrus.Info("Log file requested") - http.ServeFile(w, r, "akms-simulator.log") + http.ServeFile(w, r, LogFilePath) } func handlePushKsaKey(w http.ResponseWriter, r *http.Request) { @@ -116,7 +121,7 @@ func handlePushKsaKey(w http.ResponseWriter, r *http.Request) { } // Append jsonLogFile to akms-logfile.log - f, err := os.OpenFile("akms-simulator.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + f, err := os.OpenFile(LogFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { logrus.Errorf("Error opening log file: %s", err) w.WriteHeader(http.StatusInternalServerError) @@ -128,6 +133,12 @@ func handlePushKsaKey(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) return } + // Write the newline character + if _, err := f.Write([]byte("\n")); err != nil { + logrus.Errorf("Error writing newline to log file: %s", err) + w.WriteHeader(http.StatusInternalServerError) + return + } w.WriteHeader(http.StatusNoContent) }