Skip to content

Commit

Permalink
Merge branch 'main' into docs/sonarqube-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nancymuyeh authored Dec 20, 2024
2 parents 5c46ea6 + e236222 commit d6c89cb
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 56 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Build and Push Docker Image

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Set up Maven settings.xml
run: |
mkdir -p ~/.m2
echo "<settings>
<servers>
<server>
<id>github-webank</id>
<username>${{ github.actor }}</username>
<password>${{ secrets.WEBANK_ACCESS_TOKEN }}</password>
</server>
</servers>
</settings>" > ~/.m2/settings.xml
- name: Build JAR
run: mvn clean package -DskipTests

- name: Verify JAR File Exists
run: |
if [ ! -f ./online-banking-app/target/online-banking-app-0.1-SNAPSHOT.jar ]; then
echo "JAR file not found!" && exit 1
fi
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_PAT }}

- name: Build Docker image
run: |
docker build -t ghcr.io/adorsys-gis/webank-online-banking:${{ github.sha }} .
- name: Push Docker image to GHCR
run: |
docker push ghcr.io/adorsys-gis/webank-online-banking:${{ github.sha }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ log

cms-db-schema/liquibase.properties
ledgers-db/liquibase.properties
.env
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ WORKDIR /webank-OnlineBanking

# py the JAR file from the online-banking-app module
COPY ./online-banking-app/target/online-banking-app-0.1-SNAPSHOT.jar /webank-OnlineBanking/online-banking-app-0.1-SNAPSHOT.jar

# Expose the port your app runs on
EXPOSE 8080

Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,24 @@ The **Webank Online Banking System** is a middleware service designed to connect
mvn clean install
mvn spring-boot:run
```

5. **Access API Documentation**:
4**Access API Documentation**:
- The OpenAPI documentation will be available at `http://localhost:8080/swagger-ui.html` (or the port specified for each module).

## Starting application with Docker Compose

1. Whilst inside the project root directory, Run the command
```bash
docker compose up --build
```
2. Access the API documentation at
```bash
http://localhost:9200/swagger-ui.html
```
3. you can stop the application with
```bash
docker compose down
```

## Usage
- **User Registration**:
- Make a `POST` request to `/register` with `phoneNumber` and `publicKey`.
Expand Down
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "9200:8080"
environment:
SPRING_DATASOURCE_URL: ${SPRING_DATASOURCE_URL}
SPRING_DATASOURCE_USERNAME: ${SPRING_DATASOURCE_USERNAME}
SPRING_DATASOURCE_PASSWORD: ${SPRING_DATASOURCE_PASSWORD}
depends_on:
- db

db:
image: postgres:15
container_name: postgres_container
ports:
- "5433:5432"
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

@RestController
@RequestMapping("/api/registration")
@CrossOrigin(origins = "http://localhost:5173")
public interface RegistrationResourceApi {

@Operation(summary = "Register a new bank account", description = "Accepts a phone number and public key for registration")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.adorsys.webank.obs.resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import jakarta.servlet.http.HttpServletRequest;

import java.util.Enumeration;

@RestController
@RequestMapping("/api")
public class Host {

@GetMapping("/host")
public String getApplicationUrl(HttpServletRequest request) {
// Construct the URL
StringBuilder sb = new StringBuilder();
sb.append("scheme: ").append(request.getScheme()).append("\n"); // http or https
sb.append("serverName: ").append(request.getServerName()).append("\n"); // server name
sb.append("serverPort: ").append(request.getServerPort()).append("\n"); // server port
sb.append("contextPath: ").append(request.getContextPath()).append("\n"); // application context path (if any)

Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement();
sb.append(headerName).append(": ");

Enumeration<String> headers = request.getHeaders(headerName);
while (headers.hasMoreElements()) {
sb.append(headers.nextElement()).append(" ");
}
sb.append("\n");
}

// Format the URL
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class RegistrationResource implements RegistrationResourceApi {

@Autowired
private RegistrationServiceApi registrationService;

@Override
@PostMapping
public ResponseEntity<String> registerAccount(@RequestBody RegistrationRequest registrationRequest) {
Expand Down
11 changes: 10 additions & 1 deletion online-banking-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<ruleset.basedir>../</ruleset.basedir>
</properties>
<dependencies>

<dependency>
<groupId>com.adorsys.webank</groupId>
<artifactId>obs-rest-api</artifactId>
Expand Down Expand Up @@ -66,12 +65,22 @@
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>


<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//package com.adorsys.webank.config;
//
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.filter.ForwardedHeaderFilter;
//
//@Configuration
//public class ForwardedHeaderConfig {
//
// @Bean
// public ForwardedHeaderFilter forwardedHeaderFilter() {
// return new ForwardedHeaderFilter();
// }
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.adorsys.webank.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class RedirectConfig implements WebMvcConfigurer {

@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("redirect:/swagger-ui.html");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
spring.datasource.url=${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/online_banking_db}
spring.datasource.username=${SPRING_DATASOURCE_USERNAME:postgres}
spring.datasource.password=${SPRING_DATASOURCE_PASSWORD:postgres}
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
14 changes: 1 addition & 13 deletions online-banking-app/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
# H2 Database Configuration
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb
server.forward-headers-strategy=framework

# Swagger Configuration
springdoc.api-docs.path=/api-docs
springdoc.swagger-ui.path=/swagger-ui.html

# Additional Settings (if needed)
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=

# Hibernate DDL auto (update, create-drop, validate, etc.)
spring.jpa.hibernate.ddl-auto=update
spring.cloud.compatibility-verifier.enabled=false
28 changes: 15 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
<maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version>
<maven-pmd-plugin.version>3.21.0</maven-pmd-plugin.version>
<owasp.dependency.check.version>11.1.0</owasp.dependency.check.version>

<!-- <owasp.dependency.check.version>11.1.0</owasp.dependency.check.version>-->

<!-- Spring-related versions -->
<spring-boot-dependencies.version>3.3.5</spring-boot-dependencies.version>
Expand All @@ -111,6 +112,7 @@
<commons-collections4.version>4.3</commons-collections4.version>
<commons-io.version>2.17.0</commons-io.version>


<jetbrains.annotations.version>15.0</jetbrains.annotations.version>
<dbunit.version>2.6.0</dbunit.version>
<keycloak.version>24.0.5</keycloak.version>
Expand Down Expand Up @@ -494,21 +496,21 @@
</executions>
</plugin>

<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>${owasp.dependency.check.version}</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<!-- <plugin>-->
<!-- <groupId>org.owasp</groupId>-->
<!-- <artifactId>dependency-check-maven</artifactId>-->
<!-- <version>${owasp.dependency.check.version}</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <goals>-->
<!-- <goal>check</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- <configuration>-->
<!-- <failBuildOnCVSS>5</failBuildOnCVSS>-->
<!-- </configuration>-->
</plugin>
<!-- </plugin>-->

<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down

0 comments on commit d6c89cb

Please sign in to comment.