diff --git a/.gitignore b/.gitignore index 36b2ae68754404908e2d389da36872f86c8e611b..55577554da6b5f3901a94761e30358ae11495d10 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,5 @@ secret.properties volumes/ node_modules/ src/test/resources/schemas/ +/.apt_generated/ +/.apt_generated_tests/ diff --git a/Makefile b/Makefile index 9dd781725686e09bb3c59bb3fd7e58077c93b396..8a3142978ee88a349c3eb40baf8ef274acf6e990 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,15 @@ +SHELL = /bin/bash +pre-setup:; + @echo "Creating environment file from template" + @rm -f .env && envsubst < config/.env.sample > .env +setup:; + @echo "Generating secret files from templates using environment file + variables" + @source .env && rm -f ./config/application/secret.properties && envsubst < config/application/secret.properties.sample | tr -d '\r' > config/application/secret.properties +dev-start:; + mvn compile -e quarkus:dev -Dconfig.secret.path=$$PWD/config/application/secret.properties clean:; mvn clean + docker compose down compile-java: generate-spec; mvn compile package compile-java-quick: generate-spec; @@ -12,8 +22,8 @@ generate-spec: install-yarn validate-spec; yarn run generate-json-schema validate-spec: install-yarn; compile-start: compile-quick; - docker-compose down - docker-compose build - docker-compose up + docker compose down + docker compose build + docker compose up -d start-spec: validate-spec; yarn run start \ No newline at end of file diff --git a/README.md b/README.md index 6caed4f4c0962485f8ec734791f1c0499d7649be..f2585e7d9cc3b374d4d7faf44f9968077dd17397 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,26 @@ # eclipsefdn-mailing-lists-api -Eclipse Foundation API service for the retrieval of active mailing list data for projects within our ecosystem. +Eclipse Foundation API service for the retrieval of active mailing list data for projects within our ecosystem. -## Dependencies to run +## Starting a development environment -- Docker-compose -- Maven -- Java version 11 -- NPM +Requirements: -[^ Top](#eclipsefdn-mailing-lists-api) -## Setup -### MariaDB +* Docker +* Java 11 > +* mvn +* node.js + npm +* make +* Running MariaDB instance -If the user does not have a copy of the Eclipse database already present, the SQL file under `config/mariadb/ddl.sql` can be used to create the table structure required for the application. +1. In MariaDB instance, create a new database called `eclipse` as that is what is configured out of the box. The table definitions for the database can be found under `./config/mariadb/ddl.sql`. +2. Run `make pre-setup`. This command will setup a basic .env file, using some basic variables used in Eclipse development to accelerate the generation of secret files. +3. Ensure that the `.env` file properties reflect the connection settings used for the MariaDB instance and the credentials needed to access the DB created in step 1. +4. Run `make setup` to finish the setup process for this API, generating the secret file under `./config/application/secret.properties`. +5. Run `compile-start` or `make compile-start-headless`. The first option binds the docker containers to the current terminal, and ends the processes when the terminal is closed. The second option starts the docker containers as part of the daemon and persists beyond the terminal session. -Note: This step is not needed if using docker-compose, as the container will create its own tables as needed. - -### API Configuration -As part of the set up, you will need to create a `secret.properties` file within the `./config` folder and set up the secrets that are required to run the application. If named `secret.properties`, the file should be ignored by Github automatically, making it less risky that credentials are accidentally uploaded to a branch. - -The fields required to run are the datasource and OIDC properties. The datasource properties should be a set of user credentials that can write to a local mariadb instance. Within that mariadb instance, a database that follows the guidelines in the [MariaDB setup section](#mariadb) should exist. Once created, a JDBC URL can now be formed for the new database. This URL should follow the pattern below, with port not always required (depending on your local setup and proxy settings). This will be set in the `secret.properties` file. +You can run your application in dev mode that enables live coding using: +```bash +make dev-start ``` -quarkus.datasource.jdbc.url = jdbc:mariadb://<host><:port?>/<databaseName> -``` - -Once this is set, set the `quarkus.datasource.username` and `quarkus.datasource.password` fields to the user with access to the given database in the `secret.properties` file. - -The other half of secret configuration is setting up the OIDC credentials for connecting to a keycloak server. This server will require a realm to be set up for access. Using the name `rem_realm` is easiest as it requires no changes to the configuration to work. - -The `quarkus.oidc.auth-server-url` property in the `secret.properties` file will need to be updated. The value set should be the public realm address for your server and realm. The rest of the endpoints will be taken care of by the wellknown endpoint available in Keycloak, and don't need to be configured. For the dockerized service, this should be set to your local IP address (note, not your public address). This can be retrieved from your IP configuration application and added in the format displayed in the `sample.secret.properties` file. - -Inside that realm, create a client and update the `quarkus.oidc.client-id` property within the `secret.properties` file. Inside that client, open the settings and go to the credentials tab. The secret will need to be copied and set into the `secret.properties` file in the `quarkus.oidc.credentials.client-secret.value` property. For proper reading and usage of development data, 3 users should be created and added to the realm with the usernames `user1`, `user2`, and `user3`. diff --git a/config/.env.sample b/config/.env.sample new file mode 100644 index 0000000000000000000000000000000000000000..a4271db78da50d8e6af110665144803aee27c5dc --- /dev/null +++ b/config/.env.sample @@ -0,0 +1,8 @@ +export MAILING_LISTS_MARIADB_USERNAME=$MARIADB_USERNAME +export MAILING_LISTS_MARIADB_PASSWORD=$MARIADB_PASSWORD +export MAILING_LISTS_MARIADB_HOST=$MARIADB_HOST +export MAILING_LISTS_MARIADB_PORT=$MARIADB_PORT + +export MAILING_LISTS_OAUTH_CLIENT_ID=sample +export MAILING_LISTS_OAUTH_CLIENT_CREDENTIALS=sample +export CONFIG_SECRET_PATH=$PWD/config/application/application.secret.properties diff --git a/config/application/secret.properties.sample b/config/application/secret.properties.sample new file mode 100644 index 0000000000000000000000000000000000000000..c09aa1c79f68541a55d8ca8c665acf6515c3cd6b --- /dev/null +++ b/config/application/secret.properties.sample @@ -0,0 +1,9 @@ +## Required for authenticated requests to profile API +quarkus.oidc-client.client-id=$MAILING_LISTS_OAUTH_CLIENT_ID +quarkus.oidc-client.credentials.secret=$MAILING_LISTS_OAUTH_CLIENT_CREDENTIALS + +quarkus.datasource.username=$MAILING_LISTS_MARIADB_USERNAME +quarkus.datasource.password=$MAILING_LISTS_MARIADB_PASSWORD +quarkus.datasource.jdbc.url=jdbc:mariadb://$MAILING_LISTS_MARIADB_HOST:$MAILING_LISTS_MARIADB_PORT/eclipse + +config.secret.path=$CONFIG_SECRET_PATH \ No newline at end of file diff --git a/config/sample.secret.properties b/config/sample.secret.properties deleted file mode 100644 index cc4e58cf9c6a32c4c4398b692f5b54689b853b8e..0000000000000000000000000000000000000000 --- a/config/sample.secret.properties +++ /dev/null @@ -1,7 +0,0 @@ -quarkus.datasource.username = sample -quarkus.datasource.password = sample -quarkus.datasource.jdbc.url=jdbc:mariadb://mariadb/eclipse - -## Accounts.eclipse.org eclipsefdn_view_all_profiles scope access client -quarkus.oidc-client.client-id=sample -quarkus.oidc-client.credentials.secret=sample \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 78da69222918e8c3df74e7ddb22d5145973d621a..dd44d4b119eb46e1c4cafa63030f1f6b5c1b4bd5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,7 @@ services: - CONFIG_SECRET_PATH=/var/run/secrets/secret.properties - VIRTUAL_PORT=8090 volumes: - - ./config/secret.properties:/var/run/secrets/secret.properties + - ./config/application/secret.properties:/var/run/secrets/secret.properties deploy: restart_policy: condition: on-failure @@ -26,12 +26,14 @@ services: depends_on: - mariadb mariadb: + profiles: + - full image: mariadb:latest command: --max_allowed_packet=100000000 ports: - '3306:3306' environment: - MYSQL_ROOT_PASSWORD: ${REM_MYSQL_PASSWORD} + MYSQL_ROOT_PASSWORD: ${MAILING_LISTS_MARIADB_PASSWORD} MYSQL_DATABASE: eclipse volumes: - ./config/mariadb/ddl.sql:/docker-entrypoint-initdb.d/ddl.sql diff --git a/pom.xml b/pom.xml index 7e2035294dcd022aaacf7481b0e3582151387b93..415c1086d3b25597f3a6e338c6caa059b64bf691 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ <artifactId>eclipsefdn-mailing-lists</artifactId> <version>1.0.0-SNAPSHOT</version> <properties> - <eclipse-api-version>0.6.1-SNAPSHOT</eclipse-api-version> + <eclipse-api-version>0.6.5-SNAPSHOT</eclipse-api-version> <surefire-plugin.version>2.22.1</surefire-plugin.version> <compiler-plugin.version>3.8.1</compiler-plugin.version> <maven.compiler.target>11</maven.compiler.target> diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 77b221172767f574d65897de627cda0893647360..37d3f61ebc65658fabe6845394cf743c87813102 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,9 @@ quarkus.log.level=INFO quarkus.http.port=8090 quarkus.http.cors=true + security.csrf.enabled=true +security.csrf.distributed-mode.default-provider=false ## DATASOURCE CONFIG eclipse.db.default.limit=10 @@ -9,6 +11,7 @@ eclipse.db.default.limit.max=100 quarkus.datasource.db-kind=mariadb quarkus.datasource.jdbc.min-size = 5 quarkus.datasource.jdbc.max-size = 15 +quarkus.oidc.enabled=false accounts/mp-rest/url=https://api.eclipse.org quarkus.oauth2.enabled=false @@ -19,6 +22,6 @@ quarkus.oidc-client.grant.type=client quarkus.oidc-client.scopes=eclipsefdn_view_all_profiles # Tells Quarkus which objects are associated with what databases (used to generate entity tables internally) -quarkus.hibernate-orm.packages=org.eclipsefoundation.mailing.dto +quarkus.hibernate-orm.packages=org.eclipsefoundation.mailing.dto,org.eclipsefoundation.persistence.dto quarkus.hibernate-orm.datasource=<default> quarkus.hibernate-orm.physical-naming-strategy=org.eclipsefoundation.mailing.config.DefaultPhysicalNamingStrategy \ No newline at end of file