From e193427048725ff92a7aec270d30de9c70569ba4 Mon Sep 17 00:00:00 2001 From: Hutomo Saleh <hutomo.saleh@iem.fraunhofer.de> Date: Sun, 28 Jul 2024 21:32:53 +0200 Subject: [PATCH] chore: use optional spring config imports in application.properties --- .../resources/application-local.properties | 51 --------------- .../resources/application-prod.properties | 44 ------------- ...-dev.properties => application.properties} | 65 +++++++++++-------- app/backend/src/main/resources/dev.properties | 3 + .../src/main/resources/local.properties | 4 ++ .../src/main/resources/prod.properties | 0 docker-compose.yml | 8 +-- 7 files changed, 47 insertions(+), 128 deletions(-) delete mode 100644 app/backend/src/main/resources/application-local.properties delete mode 100644 app/backend/src/main/resources/application-prod.properties rename app/backend/src/main/resources/{application-dev.properties => application.properties} (58%) create mode 100644 app/backend/src/main/resources/dev.properties create mode 100644 app/backend/src/main/resources/local.properties create mode 100644 app/backend/src/main/resources/prod.properties diff --git a/app/backend/src/main/resources/application-local.properties b/app/backend/src/main/resources/application-local.properties deleted file mode 100644 index ed4445ef..00000000 --- a/app/backend/src/main/resources/application-local.properties +++ /dev/null @@ -1,51 +0,0 @@ -spring.config.import=optional:classpath:.env[.properties] -# Config for the OpencoDE platform -# Token can be an empty string to access public repositories only -opencode.host=https://gitlab.dev.o4oe.de/ -opencode.access-token=${OC_GL_APIKEY:} -opencode.analyze-private-repos=true -opencode.user-name=${OC_GL_USER:} -# Tool APIs -opencode.api.base-path=https://sl.dev.o4oe.de/api/v1/project/ -opencode.api.ort=/cve-result -# API key to access this server's API -# The api key is needed for all routes. -# the admin password is needed for the repo changed route. -# It is expected as basic auth with the admin username -# details can be found in configuration/security/WebSecurityConfiguration.kt -security.api-key=${API_KEY:} -security.admin-password=${ADMIN_PASSWORD:} -security.admin-username=${ADMIN_USERNAME:} -security.cors-origin=${CORS_ORIGIN:} -security.hmac-key=${HMAC_KEY:} -# OCCMD specific settings -# path to the occmd tool executable -# this can e.g, be the occmd.sh script in this project -occmd.git-clone-target-directory=${GIT_CLONE_TARGET_DIRECTORY:} -occmd.occmd-path=${OCCMD_PATH:} -server.port=${PORT} -management.server.port=${MANAGEMENT_PORT:} -springdoc.use-management-port=true -management.endpoints.web.exposure.include=health,metrics, openapi, swagger-ui, logfile, loggers, prometheus, auditevents -springdoc.show-actuator=true -spring.main.web-application-type=REACTIVE -# Generates db schema if it doesn't exist in db -spring.jpa.generate-ddl=true -spring.jpa.show-sql=false -# This setting should only be used in dev. In prod we want to switch to update -spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.properties.hibernate.format_sql=true -spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true -spring.jpa.properties.hibernate.bytecode.use_reflection_optimizer=false -spring.jpa.open-in-view=false -spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.CockroachDialect -opencode.api.auth=https://sl.dev.o4oe.de/api/receive-session/ -opencode.api.auth-api-key=${AUTH_API_KEY} -# DB Login data -spring.datasource.url=${DB_URL:} -spring.datasource.username=${DB_USER:} -spring.datasource.password=${DB_PW:} -spring.datasource.driver-class-name=org.postgresql.Driver -projects.project-ids=159, 161 -#, 888, 438, 1189, 820, 788, 400, 1052 diff --git a/app/backend/src/main/resources/application-prod.properties b/app/backend/src/main/resources/application-prod.properties deleted file mode 100644 index 325aae17..00000000 --- a/app/backend/src/main/resources/application-prod.properties +++ /dev/null @@ -1,44 +0,0 @@ -spring.config.import=optional:classpath:.env[.properties] -# Config for the OpencoDE platform -# Token can be an empty string to access public repositories only -opencode.host=https://gitlab.opencode.de/ -opencode.access-token=${OC_GL_APIKEY:} -# Tool APIs -opencode.api.base-path=https://software.opencode.de/api/v1/project/ -opencode.api.ort=/cve-result -# API key to access this server's API -# The api key is needed for all routes. -# the admin password is needed for the repo changed route. -# It is expected as basic auth with the admin username -# details can be found in configuration/security/WebSecurityConfiguration.kt -security.api-key=${API_KEY:} -security.admin-password=${ADMIN_PASSWORD:} -security.admin-username=${ADMIN_USERNAME:} -security.cors-origin=${CORS_ORIGIN:} -security.hmac-key=${HMAC_KEY:} -# OCCMD specific settings -# path to the occmd tool executable -# this can e.g, be the occmd.sh script in this project -occmd.git-clone-target-directory=${GIT_CLONE_TARGET_DIRECTORY:} -occmd.occmd-path=${OCCMD_PATH:} -server.port=${PORT} -management.server.port=${MANAGEMENT_PORT:} -springdoc.use-management-port=true -management.endpoints.web.exposure.include=health,metrics, openapi, swagger-ui, logfile, loggers, prometheus, auditevents -springdoc.show-actuator=true -spring.main.web-application-type=REACTIVE -# Generates db schema if it doesn't exist in db -spring.jpa.generate-ddl=true -spring.jpa.show-sql=false -# This setting should only be used in dev. In prod we want to switch to update -spring.jpa.hibernate.ddl-auto=validate -spring.jpa.properties.hibernate.format_sql=true -spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true -spring.jpa.properties.hibernate.bytecode.use_reflection_optimizer=false -spring.jpa.open-in-view=false -spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.CockroachDialect -# DB Login data -spring.datasource.url=jdbc:postgresql://${host}:26257/${DB_USER}?sslmode=${ssl_mode}&sslrootcert=${ca_crt}&sslcert=${ssl_cert}&sslkey=${ssl_key} -spring.datasource.username=${DB_USER:} -projects.project-ids=1108, 888, 438, 1189, 820, 788, 400, 1052 diff --git a/app/backend/src/main/resources/application-dev.properties b/app/backend/src/main/resources/application.properties similarity index 58% rename from app/backend/src/main/resources/application-dev.properties rename to app/backend/src/main/resources/application.properties index 19cce4b6..1b3c96d6 100644 --- a/app/backend/src/main/resources/application-dev.properties +++ b/app/backend/src/main/resources/application.properties @@ -1,39 +1,42 @@ -spring.config.import=optional:classpath:.env[.properties] # Config for the OpencoDE platform # Token can be an empty string to access public repositories only -opencode.host=https://gitlab.dev.o4oe.de/ -opencode.access-token=${OC_GL_APIKEY:} +opencode.host=https://gitlab.opencode.de/ +opencode.access-token=${OC_GL_APIKEY} opencode.analyze-private-repos=true -opencode.user-name=${OC_GL_USER:} +opencode.user-name=${OC_GL_USER} +projects.project-ids=${PROJECT_IDS} + +# API key to access this server's API +# The api key is needed for all routes. +# the admin password is needed for the repo changed route. +# It is expected as basic auth with the admin username +# details can be found in configuration/security/WebSecurityConfiguration.kt +security.api-key=${API_KEY} +security.admin-password=${ADMIN_PASSWORD} +security.admin-username=${ADMIN_USERNAME} +security.cors-origin=${CORS_ORIGIN} +security.hmac-key=${HMAC_KEY} + # Tool APIs opencode.api.base-path=https://sl.dev.o4oe.de/api/v1/project/ -opencode.api.ort=/cve-result -opencode.api.auth=https://sl.dev.o4oe.de/api/ opencode.api.auth-api-key=${AUTH_API_KEY} -# API key to access this server's API -# The api key is needed for all routes. -# the admin password is needed for the repo changed route. -# It is expected as basic auth with the admin username -# details can be found in configuration/security/WebSecurityConfiguration.kt -security.api-key=${API_KEY:} -security.admin-password=${ADMIN_PASSWORD:} -security.admin-username=${ADMIN_USERNAME:} -security.cors-origin=${CORS_ORIGIN:} -security.hmac-key=${HMAC_KEY:} +opencode.api.auth=https://sl.dev.o4oe.de/api/ +opencode.api.ort=/cve-result + # OCCMD specific settings # path to the occmd tool executable # this can e.g, be the occmd.sh script in this project -occmd.git-clone-target-directory=${GIT_CLONE_TARGET_DIRECTORY:} -occmd.occmd-path=${OCCMD_PATH:} -server.port=${PORT} -management.server.port=${MANAGEMENT_PORT:} -springdoc.use-management-port=${USE_MANAGEMENT_PORT:} +occmd.git-clone-target-directory=${GIT_CLONE_TARGET_DIRECTORY} +occmd.occmd-path=${OCCMD_PATH} + +# Spring actuator settings +management.server.port=${MANAGEMENT_PORT} +springdoc.use-management-port=${USE_MANAGEMENT_PORT} management.endpoints.web.exposure.include=health,metrics, openapi, swagger-ui, logfile, loggers, prometheus, auditevents springdoc.show-actuator=true spring.main.web-application-type=REACTIVE -# Generates db schema if it doesn't exist in db -spring.jpa.generate-ddl=true -spring.jpa.show-sql=false +server.port=${PORT} + # This setting should only be used in dev. In prod we want to switch to update spring.jpa.hibernate.ddl-auto=update spring.jpa.properties.hibernate.format_sql=true @@ -42,8 +45,14 @@ spring.jpa.properties.hibernate.bytecode.use_reflection_optimizer=false spring.jpa.open-in-view=false spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.CockroachDialect -# DB Login data -spring.datasource.url=jdbc:postgresql://${DB_HOST:}:${DB_PORT:}/${DB_NAME:}?sslmode=disable&user=root -spring.datasource.username=${DB_USER:} + +# DB settings +spring.datasource.url=jdbc:postgresql://${host}:26257/${DB_USER}?sslmode=${ssl_mode}&sslrootcert=${ca_crt}&sslcert=${ssl_cert}&sslkey=${ssl_key} +spring.datasource.username=${DB_USER} spring.datasource.driver-class-name=org.postgresql.Driver -projects.project-ids=${PROJECT_IDS:} +# Generates db schema if it doesn't exist in db +spring.jpa.generate-ddl=true +spring.jpa.show-sql=false + +# Import profile specific properties (Default is prod) +spring.config.import=optional:file:${SPRING_PROFILE}.properties diff --git a/app/backend/src/main/resources/dev.properties b/app/backend/src/main/resources/dev.properties new file mode 100644 index 00000000..6932bb8f --- /dev/null +++ b/app/backend/src/main/resources/dev.properties @@ -0,0 +1,3 @@ +spring.datasource.url=jdbc:postgresql://${host}:${DB_PORT}/${DB_NAME}?sslmode=disable&user=root +spring.jpa.hibernate.ddl-auto=create-drop +opencode.host=https://gitlab.dev.o4oe.de/ diff --git a/app/backend/src/main/resources/local.properties b/app/backend/src/main/resources/local.properties new file mode 100644 index 00000000..09d24568 --- /dev/null +++ b/app/backend/src/main/resources/local.properties @@ -0,0 +1,4 @@ +spring.datasource.url=jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=disable&user=root +spring.jpa.hibernate.ddl-auto=create-drop +opencode.host=https://gitlab.opencode.de/ +opencode.analyze-private-repos=false diff --git a/app/backend/src/main/resources/prod.properties b/app/backend/src/main/resources/prod.properties new file mode 100644 index 00000000..e69de29b diff --git a/docker-compose.yml b/docker-compose.yml index 1dc7ba83..3d97b3f2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,7 +18,7 @@ services: - OC_GL_APIKEY=${SECRET_OC_GL_APIKEY} - XDG_CONFIG_HOME=/app/.config/ - GIT_CLONE_TARGET_DIRECTORY=/app/git/ - - USE_MANAGEMENT_PORT=false + - USE_MANAGEMENT_PORT=true - MANAGEMENT_PORT=4001 - PROJECT_IDS=1448,2991,1317,560,2188,2155,2149,2235 # occmd-public, Covid19 fraud detection, Opendesk, Helm chart, e2e tests - CORS_ORIGIN=* # Must be without quotes i.e. allow everything: * | originally https://sec-kpi.opencode.de @@ -28,14 +28,12 @@ services: - DB_USER=sa - DB_NAME=dataprovider - DB_PORT=26257 - - HMAC_KEY=123456789012345678901234567890 - ADMIN_PASSWORD=01234567890123456789 - ADMIN_USERNAME=012345678901234567890123456789 + - HMAC_KEY=012345678901234567890123456789 - API_KEY=012345678901234567890123456789 - - SPRING_PROFILES_ACTIVE=local + - SPRING_PROFILE=local ports: - 4000:4000 - volumes: - - ./app/backend/src/main/resources/application-local.properties:/app/application-local.properties -- GitLab