From 6d115abb95ba2e2f3b0e74a225bce773e70ce907 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sun, 25 May 2025 23:32:39 +0530 Subject: [PATCH 01/87] Making changes to workflow pipeline --- .gitea/workflows/test_image_build_push.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index f5805cb..fac82f9 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -20,8 +20,6 @@ jobs: java-version: '17' - name: Validate Gradle Wrapper uses: gradle/actions/wrapper-validation@v3 - - name: Check secrets - run: echo "my secret is ${{ secrets.TOKEN }}" - name: Log in to Gitea Docker Registry uses: docker/login-action@v3 with: @@ -29,6 +27,6 @@ jobs: username: hitanshu password: ${{ secrets.TOKEN }} - name: Gradle build - run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:latest + run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:test - name: Push to Gitea Registry - run: docker push 192.168.0.100:8928/hithomelabs/cftunnels:latest + run: docker push 192.168.0.100:8928/hithomelabs/cftunnels:test -- 2.45.2 From cef7dd18e2f04952b3f26bd570fa4671ca8af733 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Tue, 27 May 2025 01:08:07 +0530 Subject: [PATCH 02/87] Adding field path to ingress --- .../java/com/hithomelabs/CFTunnels/Models/Ingress.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/hithomelabs/CFTunnels/Models/Ingress.java b/src/main/java/com/hithomelabs/CFTunnels/Models/Ingress.java index 8adcc89..7c6c7be 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Models/Ingress.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Models/Ingress.java @@ -8,6 +8,16 @@ public class Ingress { private String service; private String hostname; private Map originRequest; + private String path; + + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } public static boolean deleteByHostName(List ingressList, String toBeDeleted){ return ingressList.removeIf(ingress -> ingress.getHostname() != null && ingress.getHostname().equals(toBeDeleted)); -- 2.45.2 From 5d74960c7f97f776d2fa642664039ea6f6b9a107 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Wed, 28 May 2025 19:15:50 +0530 Subject: [PATCH 03/87] Adding env agnostic docker compose file --- .env.example | 4 ++++ docker-compose.yaml | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 .env.example create mode 100644 docker-compose.yaml diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..08c0845 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +CLOUDFLARE_ACCOUNT_ID="" +CLOUDFLARE_API_KEY="" +CLOUDFLARE_EMAIL="" +ENV="" \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..1c03e48 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,12 @@ +services: + app: + image: gitea.hithomelabs.com/hithomelabs/cftunnels:${ENV} + container_name: cftunnels_${ENV} + environment: + - CLOUDFLARE_ACCOUNT_ID=${CLOUDFLARE_ACCOUNT_ID} + - CLOUDFLARE_API_KEY=${CLOUDFLARE_API_KEY} + - CLOUDFLARE_EMAIL=${CLOUDFLARE_EMAIL} + - ENV=${ENV} + ports: + - 5002:8080 + restart: unless-stopped \ No newline at end of file -- 2.45.2 From 75eb4089805285648e5960bef47f091044362335 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Wed, 28 May 2025 18:55:38 +0530 Subject: [PATCH 04/87] Workflow to only build on PR and building an image only on push to test --- .gitea/workflows/test_build.yml | 20 ++++++++++++++++++++ .gitea/workflows/test_image_build_push.yml | 3 --- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 .gitea/workflows/test_build.yml diff --git a/.gitea/workflows/test_build.yml b/.gitea/workflows/test_build.yml new file mode 100644 index 0000000..0a4e7d0 --- /dev/null +++ b/.gitea/workflows/test_build.yml @@ -0,0 +1,20 @@ +name: sample gradle build and test +run-name: Build started by $ {{gitea.actor}} +on: + pull_request: + branches: [test] +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: JDK setup + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v3 + - name: Gradle build + run: /gradlew build --debug \ No newline at end of file diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index fac82f9..f45a5a8 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -3,9 +3,6 @@ run-name: Build started by $ {{gitea.actor}} on: push: branches: [test] - pull_request: - branches: [test] -jobs: build: runs-on: ubuntu-latest container: -- 2.45.2 From 558b570121fdebfa6754d7f46c6872d99be2af14 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Wed, 28 May 2025 19:01:11 +0530 Subject: [PATCH 05/87] Fixing issue related to not beaing able to execute gradlew --- .gitea/workflows/test_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test_build.yml b/.gitea/workflows/test_build.yml index 0a4e7d0..05e8adb 100644 --- a/.gitea/workflows/test_build.yml +++ b/.gitea/workflows/test_build.yml @@ -17,4 +17,4 @@ jobs: - name: Validate Gradle Wrapper uses: gradle/actions/wrapper-validation@v3 - name: Gradle build - run: /gradlew build --debug \ No newline at end of file + run: ./gradlew build --debug \ No newline at end of file -- 2.45.2 From c90756ebe38b19d14284b6ba438442f76c6af8bd Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Wed, 28 May 2025 20:39:53 +0530 Subject: [PATCH 06/87] Changing open api springdoc version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 663b328..467f49e 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ repositories { } dependencies { - implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.0.3' + implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.8.8' implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' -- 2.45.2 From 89f66202140a1629f218a21215971530e7604234 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Wed, 28 May 2025 23:54:27 +0530 Subject: [PATCH 07/87] Changing some bruno env variables --- CFTunnels/Get tunnels.bru | 2 +- CFTunnels/Tunnel.bru | 2 +- CFTunnels/Write ingress.bru | 2 +- CFTunnels/delete mapping.bru | 2 +- CFTunnels/environments/CFTunnels Local.bru | 2 +- CFTunnels/environments/CFTunnels.bru | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CFTunnels/Get tunnels.bru b/CFTunnels/Get tunnels.bru index b3cb95a..231ee08 100644 --- a/CFTunnels/Get tunnels.bru +++ b/CFTunnels/Get tunnels.bru @@ -5,7 +5,7 @@ meta { } get { - url: {{base_url}}cloudflare/tunnels + url: {{base_url}}/cloudflare/tunnels body: none auth: none } diff --git a/CFTunnels/Tunnel.bru b/CFTunnels/Tunnel.bru index d19374e..826b583 100644 --- a/CFTunnels/Tunnel.bru +++ b/CFTunnels/Tunnel.bru @@ -5,7 +5,7 @@ meta { } get { - url: {{base_url}}cloudflare/tunnel/{{tunnel_id}} + url: {{base_url}}/cloudflare/tunnel/{{tunnel_id}} body: none auth: none } diff --git a/CFTunnels/Write ingress.bru b/CFTunnels/Write ingress.bru index 61f4ebc..9930a0b 100644 --- a/CFTunnels/Write ingress.bru +++ b/CFTunnels/Write ingress.bru @@ -5,7 +5,7 @@ meta { } put { - url: {{base_url}}cloudflare/tunnel/{{tunnel_id}}/add + url: {{base_url}}/cloudflare/tunnel/{{tunnel_id}}/add body: json auth: none } diff --git a/CFTunnels/delete mapping.bru b/CFTunnels/delete mapping.bru index 857a43e..c9e3dbb 100644 --- a/CFTunnels/delete mapping.bru +++ b/CFTunnels/delete mapping.bru @@ -5,7 +5,7 @@ meta { } put { - url: {{base_url}}cloudflare/tunnel/{{tunnel_id}}/delete + url: {{base_url}}/cloudflare/tunnel/{{tunnel_id}}/delete body: json auth: none } diff --git a/CFTunnels/environments/CFTunnels Local.bru b/CFTunnels/environments/CFTunnels Local.bru index 9e83a22..6d2b6b0 100644 --- a/CFTunnels/environments/CFTunnels Local.bru +++ b/CFTunnels/environments/CFTunnels Local.bru @@ -1,4 +1,4 @@ vars { tunnel_id: 50df9101-f625-4618-b7c5-100338a57124 - base_url: http://localhost:8080/ + base_url: http://localhost:8080 } diff --git a/CFTunnels/environments/CFTunnels.bru b/CFTunnels/environments/CFTunnels.bru index 1c61ef6..d8219ab 100644 --- a/CFTunnels/environments/CFTunnels.bru +++ b/CFTunnels/environments/CFTunnels.bru @@ -1,4 +1,4 @@ vars { tunnel_id: 50df9101-f625-4618-b7c5-100338a57124 - base_url: https://testcf.hithomelabs.com/ + base_url: https://testcf.hithomelabs.com } -- 2.45.2 From f64579e393f26f43181898f9c204d55d801afc4c Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Thu, 29 May 2025 00:13:49 +0530 Subject: [PATCH 08/87] Fixing broken image creation --- .gitea/workflows/test_image_build_push.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index f45a5a8..e4cdd2f 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -3,6 +3,7 @@ run-name: Build started by $ {{gitea.actor}} on: push: branches: [test] +jobs: build: runs-on: ubuntu-latest container: -- 2.45.2 From 507fd17539f5c01e8f27f9518fb32aae04825982 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sun, 1 Jun 2025 17:29:24 +0530 Subject: [PATCH 09/87] Changes derver in OpenAPI Config to avoid CORS --- build.gradle | 2 +- .../CFTunnels/Config/OpenApiConfig.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java diff --git a/build.gradle b/build.gradle index 467f49e..aaa90d3 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ repositories { } dependencies { - implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.8.8' + implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.8.5' implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' diff --git a/src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java b/src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java new file mode 100644 index 0000000..0b2aa4b --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java @@ -0,0 +1,22 @@ +package com.hithomelabs.CFTunnels.Config; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.servers.Server; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.ArrayList; + +@Configuration +public class OpenApiConfig { + + @Bean + public OpenAPI openAPI(){ + Server httpsServer = new Server().url("https://testcf.hithomelabs.com"); + OpenAPI openApi = new OpenAPI(); + ArrayList servers = new ArrayList<>(); + servers.add(httpsServer); + openApi.setServers(servers); + return openApi; + } +} -- 2.45.2 From 72ada2d0ddbcc8523097f112d90ad4fc5b0c7df5 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Wed, 4 Jun 2025 01:27:34 +0530 Subject: [PATCH 10/87] Adding profiles for different OpenAPI server URLS in different environments --- .../com/hithomelabs/CFTunnels/Config/OpenApiConfig.java | 6 +++++- src/main/resources/application-local.properties | 1 + src/main/resources/application-prod.properties | 1 + src/main/resources/application-test.properties | 1 + src/main/resources/application.properties | 1 + 5 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/application-local.properties create mode 100644 src/main/resources/application-prod.properties create mode 100644 src/main/resources/application-test.properties diff --git a/src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java b/src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java index 0b2aa4b..e24e6f5 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java @@ -2,6 +2,7 @@ package com.hithomelabs.CFTunnels.Config; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.servers.Server; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -10,9 +11,12 @@ import java.util.ArrayList; @Configuration public class OpenApiConfig { + @Value("${api.baseUrl}") + private String baseUrl; + @Bean public OpenAPI openAPI(){ - Server httpsServer = new Server().url("https://testcf.hithomelabs.com"); + Server httpsServer = new Server().url(baseUrl); OpenAPI openApi = new OpenAPI(); ArrayList servers = new ArrayList<>(); servers.add(httpsServer); diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties new file mode 100644 index 0000000..fdb25ce --- /dev/null +++ b/src/main/resources/application-local.properties @@ -0,0 +1 @@ +api.baseUrl=http://localhost:8080 \ No newline at end of file diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties new file mode 100644 index 0000000..dec0f4b --- /dev/null +++ b/src/main/resources/application-prod.properties @@ -0,0 +1 @@ +api.baseUrl=https://cftunnels.hithomelabs.com \ No newline at end of file diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties new file mode 100644 index 0000000..e5c014b --- /dev/null +++ b/src/main/resources/application-test.properties @@ -0,0 +1 @@ +api.baseUrl=https://testcf.hithomelabs.com \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2c265e1..9b04cc9 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,3 +2,4 @@ spring.application.name=CFTunnels cloudflare.accountId=${CLOUDFLARE_ACCOUNT_ID} cloudflare.apiKey=${CLOUDFLARE_API_KEY} cloudflare.email=${CLOUDFLARE_EMAIL} +spring.profiles.active=${ENV} -- 2.45.2 From 524be544bc88b85b6ed06496bf9a6d0f7f96bfa2 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Wed, 4 Jun 2025 01:34:19 +0530 Subject: [PATCH 11/87] Changing verbosity of gradle logs --- .gitea/workflows/test_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test_build.yml b/.gitea/workflows/test_build.yml index 05e8adb..ae070cd 100644 --- a/.gitea/workflows/test_build.yml +++ b/.gitea/workflows/test_build.yml @@ -17,4 +17,4 @@ jobs: - name: Validate Gradle Wrapper uses: gradle/actions/wrapper-validation@v3 - name: Gradle build - run: ./gradlew build --debug \ No newline at end of file + run: ./gradlew build --info \ No newline at end of file -- 2.45.2 From c0b881974bf20e7db5e9a999c84e9fb24d567893 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Wed, 4 Jun 2025 01:50:41 +0530 Subject: [PATCH 12/87] Adding default profile test for gradle build test task --- build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.gradle b/build.gradle index aaa90d3..49a3976 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,10 @@ java { } } +test { + systemProperty 'spring.profiles.active', 'test' +} + repositories { mavenCentral() } -- 2.45.2 From f10c52adcba014a803b4e7e7272c310489e48211 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Mon, 15 Sep 2025 00:21:49 +0530 Subject: [PATCH 13/87] Final cahnges to add OIDC, setting groups and authorities --- build.gradle | 1 + docker-compose.yaml | 2 + .../Config/AuthoritiesToGroupMapping.java | 28 ++++++++++++ .../Config/CustomOidcUserConfiguration.java | 45 +++++++++++++++++++ .../Config/Security/SecuirtyConfig.java | 39 ++++++++++++++++ .../Controllers/TunnelController.java | 27 +++++++++-- .../CFTunnels/Models/Authorities.java | 10 +++++ .../hithomelabs/CFTunnels/Models/Groups.java | 10 +++++ src/main/resources/application.properties | 12 +++++ 9 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Config/AuthoritiesToGroupMapping.java create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Config/CustomOidcUserConfiguration.java create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Config/Security/SecuirtyConfig.java create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Models/Authorities.java create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Models/Groups.java diff --git a/build.gradle b/build.gradle index 49a3976..bfc0540 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,7 @@ repositories { dependencies { implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.8.5' + implementation group: 'org.springframework.boot', name:'spring-boot-starter-oauth2-client', version: '3.5.5' implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' diff --git a/docker-compose.yaml b/docker-compose.yaml index 1c03e48..7cac007 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -7,6 +7,8 @@ services: - CLOUDFLARE_API_KEY=${CLOUDFLARE_API_KEY} - CLOUDFLARE_EMAIL=${CLOUDFLARE_EMAIL} - ENV=${ENV} + - OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID} + - OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET} ports: - 5002:8080 restart: unless-stopped \ No newline at end of file diff --git a/src/main/java/com/hithomelabs/CFTunnels/Config/AuthoritiesToGroupMapping.java b/src/main/java/com/hithomelabs/CFTunnels/Config/AuthoritiesToGroupMapping.java new file mode 100644 index 0000000..b323700 --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Config/AuthoritiesToGroupMapping.java @@ -0,0 +1,28 @@ +package com.hithomelabs.CFTunnels.Config; + +import com.hithomelabs.CFTunnels.Models.Authorities; +import com.hithomelabs.CFTunnels.Models.Groups; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@Configuration +public class AuthoritiesToGroupMapping { + + public Map> getAuthorityForGroup(){ + HashMap> mappings = new HashMap<>(); + mappings.put(Groups.GITEA_USER, new HashSet<>(Set.of(new SimpleGrantedAuthority(Authorities.ROLE_USER)))); + mappings.put(Groups.POWER_USER, new HashSet<>(Set.of(new SimpleGrantedAuthority(Authorities.ROLE_USER)))); + mappings.put(Groups.HOMELAB_DEVELOPER, new HashSet<>(Set.of(new SimpleGrantedAuthority(Authorities.ROLE_DEVELOPER)))); + mappings.put(Groups.SYSTEM_ADMIN, new HashSet<>(Set.of(new SimpleGrantedAuthority(Authorities.ROLE_APPROVER), new SimpleGrantedAuthority(Authorities.ROLE_ADMIN)))); + return mappings; + } + + + +} diff --git a/src/main/java/com/hithomelabs/CFTunnels/Config/CustomOidcUserConfiguration.java b/src/main/java/com/hithomelabs/CFTunnels/Config/CustomOidcUserConfiguration.java new file mode 100644 index 0000000..22a4e64 --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Config/CustomOidcUserConfiguration.java @@ -0,0 +1,45 @@ +package com.hithomelabs.CFTunnels.Config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserRequest; +import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserService; +import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser; +import org.springframework.security.oauth2.core.oidc.user.OidcUser; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Configuration +public class CustomOidcUserConfiguration extends OidcUserService { + + @Autowired + AuthoritiesToGroupMapping authoritiesToGroupMapping; + + @Override + public OidcUser loadUser(OidcUserRequest userRequest) { + // * * Delegate to the default implementation for loading user and claims + OidcUser oidcUser = super.loadUser(userRequest); + + // * * Copy existing authorities (e.g. scopes → authorities) + Set mappedAuthorities = new HashSet<>(); + + // * * Extract your custom claim (change "roles" to your claim name) + List groups = oidcUser.getClaimAsStringList("groups"); + if (groups != null) { + groups.forEach(group -> + mappedAuthorities.addAll(authoritiesToGroupMapping.getAuthorityForGroup().get(group)) + ); + } + + // * * Return a new DefaultOidcUser with merged authorities + return new DefaultOidcUser( + mappedAuthorities, + oidcUser.getIdToken(), + oidcUser.getUserInfo() + ); + } + } + diff --git a/src/main/java/com/hithomelabs/CFTunnels/Config/Security/SecuirtyConfig.java b/src/main/java/com/hithomelabs/CFTunnels/Config/Security/SecuirtyConfig.java new file mode 100644 index 0000000..7bd9c1e --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Config/Security/SecuirtyConfig.java @@ -0,0 +1,39 @@ +package com.hithomelabs.CFTunnels.Config.Security; + +import com.hithomelabs.CFTunnels.Config.CustomOidcUserConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.oauth2.client.OAuth2LoginConfigurer; +import org.springframework.security.web.SecurityFilterChain; + + +@Configuration +@EnableWebSecurity +@EnableMethodSecurity( + prePostEnabled = true, + securedEnabled = true, + jsr250Enabled = true +) +public class SecuirtyConfig { + + @Autowired + private CustomOidcUserConfiguration customOidcUserConfiguration; + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http + .authorizeHttpRequests(auth -> auth + .anyRequest().authenticated() + ) + .with(new OAuth2LoginConfigurer<>(), oauth2 -> oauth2.userInfoEndpoint(u -> u.oidcUserService(customOidcUserConfiguration))); + + + return http.build(); + } + +} diff --git a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java index 9e8ad9c..fc8819f 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java @@ -1,8 +1,7 @@ package com.hithomelabs.CFTunnels.Controllers; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; +import com.hithomelabs.CFTunnels.Config.AuthoritiesToGroupMapping; import com.hithomelabs.CFTunnels.Config.CloudflareConfig; import com.hithomelabs.CFTunnels.Config.RestTemplateConfig; import com.hithomelabs.CFTunnels.Headers.AuthKeyEmailHeader; @@ -11,7 +10,10 @@ import com.hithomelabs.CFTunnels.Models.Ingress; import com.hithomelabs.CFTunnels.Models.TunnelResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.*; -import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.oauth2.core.oidc.user.OidcUser; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; @@ -25,6 +27,8 @@ public class TunnelController { private final RestTemplate restTemplate = new RestTemplate(); + @Autowired + private AuthoritiesToGroupMapping authoritiesToGroupMapping; @Autowired private CloudflareConfig cloudflareConfig; @@ -34,6 +38,20 @@ public class TunnelController { @Autowired private RestTemplateConfig restTemplateConfig; + @PreAuthorize("hasAnyRole('USER')") + @GetMapping("/whoami") + public Map whoAmI(@AuthenticationPrincipal OidcUser oidcUser) { + + List authorities = oidcUser.getAuthorities().stream() + .map(GrantedAuthority::getAuthority) + .toList(); + return Map.of( + "username", oidcUser.getPreferredUsername(), + "roles", authorities + ); + } + + @PreAuthorize("hasAnyRole('USER')") @GetMapping("/tunnels") public ResponseEntity> getTunnels(){ @@ -50,6 +68,7 @@ public class TunnelController { return ResponseEntity.ok(jsonResponse); } + @PreAuthorize("hasAnyRole('DEVELOPER')") @GetMapping("/tunnel/{tunnelId}") public ResponseEntity> getTunnelConfigurations(@PathVariable String tunnelId) throws JsonProcessingException { @@ -67,6 +86,7 @@ public class TunnelController { } // 50df9101-f625-4618-b7c5-100338a57124 + @PreAuthorize("hasAnyRole('ADMIN')") @PutMapping("/tunnel/{tunnelId}/add") public ResponseEntity> addTunnelconfiguration(@PathVariable String tunnelId, @RequestBody Ingress ingress) throws JsonProcessingException { @@ -95,6 +115,7 @@ public class TunnelController { return ResponseEntity.ok(jsonResponse); } + @PreAuthorize("hasAnyRole('DEVELOPER')") @PutMapping("/tunnel/{tunnelId}/delete") public ResponseEntity> deleteTunnelConfiguration(@PathVariable String tunnelId, @RequestBody Ingress ingress) throws JsonProcessingException { diff --git a/src/main/java/com/hithomelabs/CFTunnels/Models/Authorities.java b/src/main/java/com/hithomelabs/CFTunnels/Models/Authorities.java new file mode 100644 index 0000000..f26a17b --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Models/Authorities.java @@ -0,0 +1,10 @@ +package com.hithomelabs.CFTunnels.Models; + +public class Authorities { + + public static final String ROLE_ADMIN = "ROLE_ADMIN"; + public static final String ROLE_DEVELOPER = "ROLE_DEVELOPER"; + public static final String ROLE_USER = "ROLE_USER"; + public static final String ROLE_APPROVER = "ROLE_APPROVER"; + +} diff --git a/src/main/java/com/hithomelabs/CFTunnels/Models/Groups.java b/src/main/java/com/hithomelabs/CFTunnels/Models/Groups.java new file mode 100644 index 0000000..f7c213d --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Models/Groups.java @@ -0,0 +1,10 @@ +package com.hithomelabs.CFTunnels.Models; + +public class Groups { + + public static final String HOMELAB_DEVELOPER = "homelab developer"; + public static final String SYSTEM_ADMIN = "authentik Admins"; + public static final String POWER_USER = "arr premium"; + public static final String GITEA_USER = "gitrestricted"; + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9b04cc9..3ba3827 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,3 +3,15 @@ cloudflare.accountId=${CLOUDFLARE_ACCOUNT_ID} cloudflare.apiKey=${CLOUDFLARE_API_KEY} cloudflare.email=${CLOUDFLARE_EMAIL} spring.profiles.active=${ENV} + +spring.security.oauth2.client.registration.cftunnels.client-id=${OAUTH_CLIENT_ID} +spring.security.oauth2.client.registration.cftunnels.client-secret=${OAUTH_CLIENT_SECRET} +spring.security.oauth2.client.registration.cftunnels.authorization-grant-type=authorization_code +spring.security.oauth2.client.registration.cftunnels.redirect-uri={baseUrl}/login/oauth2/code/cftunnels +spring.security.oauth2.client.registration.cftunnels.scope=openid,profile,email,offline_access,cftunnels + +spring.security.oauth2.client.provider.cftunnels.authorization-uri=https://auth.hithomelabs.com/application/o/authorize/ +spring.security.oauth2.client.provider.cftunnels.token-uri=https://auth.hithomelabs.com/application/o/token/ +spring.security.oauth2.client.provider.cftunnels.user-info-uri=https://auth.hithomelabs.com/application/o/userinfo/ +spring.security.oauth2.client.provider.cftunnels.jwk-set-uri=https://auth.hithomelabs.com/application/o/cftunnels/jwks/ +spring.security.oauth2.client.provider.cftunnels.issuer-uri=https://auth.hithomelabs.com/application/o/cftunnels/ \ No newline at end of file -- 2.45.2 From 50d2fc099bc38c34ce59365a1744a8dc62158d73 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Thu, 5 Jun 2025 01:52:45 +0530 Subject: [PATCH 14/87] Adding tags to release and images --- .gitea/workflows/test_image_build_push.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index e4cdd2f..96b71d2 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -18,6 +18,16 @@ jobs: java-version: '17' - name: Validate Gradle Wrapper uses: gradle/actions/wrapper-validation@v3 + - name: Get latest tag + run: echo "VERSION=$(git describe --tags --abbrev=0)" + - name: Increment version + run: echo "NEW_VERSION=$(echo $VERSION | awk -F'v' '{print $2}' | awk -F. '{print "v"$1"."$2"."$3+1}')" + - name: Extract commit message + run: echo "COMMIT_MESSAGE=$((git log -1 --pretty=%B)" + - name: Create and push tag + run: | + git tag -a ${NEW_VERSION} -m "${COMMIT_MESSAGE}" + git push origin ${NEW_VERSION} - name: Log in to Gitea Docker Registry uses: docker/login-action@v3 with: @@ -25,6 +35,10 @@ jobs: username: hitanshu password: ${{ secrets.TOKEN }} - name: Gradle build - run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:test + run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:${NEW_VERSION} + - name: Tag image as test + run: docker tag 192.168.0.100:8928/hithomelabs/cftunnels:${NEW_VERSION} 192.168.0.100:8928/hithomelabs/cftunnels:test - name: Push to Gitea Registry - run: docker push 192.168.0.100:8928/hithomelabs/cftunnels:test + run: | + docker push 192.168.0.100:8928/hithomelabs/cftunnels:test + docker push 192.168.0.100:8928/hithomelabs/cftunnels:${NEW_VERSION} -- 2.45.2 From baef77d3897e3bbf309828c861eb2f593cc1aa2b Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Thu, 5 Jun 2025 01:59:40 +0530 Subject: [PATCH 15/87] Minor bugfix --- .gitea/workflows/test_image_build_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 96b71d2..6abc8a3 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -23,7 +23,7 @@ jobs: - name: Increment version run: echo "NEW_VERSION=$(echo $VERSION | awk -F'v' '{print $2}' | awk -F. '{print "v"$1"."$2"."$3+1}')" - name: Extract commit message - run: echo "COMMIT_MESSAGE=$((git log -1 --pretty=%B)" + run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" - name: Create and push tag run: | git tag -a ${NEW_VERSION} -m "${COMMIT_MESSAGE}" -- 2.45.2 From 2a242df197abff00df35f75f8793d8b875ccc8e2 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Thu, 5 Jun 2025 02:19:59 +0530 Subject: [PATCH 16/87] Fetching tags explicitly --- .gitea/workflows/test_image_build_push.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 6abc8a3..4bcfafc 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -26,6 +26,7 @@ jobs: run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" - name: Create and push tag run: | + git fetch --tags git tag -a ${NEW_VERSION} -m "${COMMIT_MESSAGE}" git push origin ${NEW_VERSION} - name: Log in to Gitea Docker Registry -- 2.45.2 From c45df6867faa1247bc94b54cc95bd6d4ee7ef70f Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Thu, 5 Jun 2025 02:29:02 +0530 Subject: [PATCH 17/87] using fetch-depth 0 as specified in https://github.com/actions/checkout/issues/1781 --- .gitea/workflows/test_image_build_push.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 4bcfafc..4130c59 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -11,6 +11,8 @@ jobs: steps: - name: Check out repository code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: JDK setup uses: actions/setup-java@v4 with: @@ -26,7 +28,6 @@ jobs: run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" - name: Create and push tag run: | - git fetch --tags git tag -a ${NEW_VERSION} -m "${COMMIT_MESSAGE}" git push origin ${NEW_VERSION} - name: Log in to Gitea Docker Registry -- 2.45.2 From e40bcce20212de51d2d206c79eafa9c4f7839e89 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Thu, 5 Jun 2025 02:36:19 +0530 Subject: [PATCH 18/87] Adding awk --- .gitea/workflows/test_image_build_push.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 4130c59..f74f74f 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -18,6 +18,8 @@ jobs: with: distribution: 'zulu' java-version: '17' + - name: Install AWK + run: sudo apt-get update && sudo apt-get install -y gawk - name: Validate Gradle Wrapper uses: gradle/actions/wrapper-validation@v3 - name: Get latest tag -- 2.45.2 From e16548b54a1cc088382697face9e206204cf5c17 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Thu, 5 Jun 2025 21:45:30 +0530 Subject: [PATCH 19/87] Using cut to increment version --- .gitea/workflows/test_image_build_push.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index f74f74f..18792f0 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -18,14 +18,18 @@ jobs: with: distribution: 'zulu' java-version: '17' - - name: Install AWK - run: sudo apt-get update && sudo apt-get install -y gawk - name: Validate Gradle Wrapper uses: gradle/actions/wrapper-validation@v3 - name: Get latest tag - run: echo "VERSION=$(git describe --tags --abbrev=0)" + run: | + echo "VERSION=$(git describe --tags --abbrev=0)" + MAJOR=$(echo $VERSION | cut -d "." -f 1) + MINOR=$(echo $VERSION | cut -d "." -f 2) + PATCH=$(echo $VERSION | cut -d "." -f 3) - name: Increment version - run: echo "NEW_VERSION=$(echo $VERSION | awk -F'v' '{print $2}' | awk -F. '{print "v"$1"."$2"."$3+1}')" + run: | + PATCH=$((PATCH + 1)) + echo "NEW_VERSION=$(echo $MAJOR.$MINOR.$PATCH)" - name: Extract commit message run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" - name: Create and push tag -- 2.45.2 From 9423178737ea14b102a5cb6e4c0252d4a3b125d5 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Thu, 5 Jun 2025 22:05:51 +0530 Subject: [PATCH 20/87] Checking if cut is installed on gitea runner --- .gitea/workflows/test_image_build_push.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 18792f0..b035c3b 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -20,12 +20,14 @@ jobs: java-version: '17' - name: Validate Gradle Wrapper uses: gradle/actions/wrapper-validation@v3 + - name: Check if cut is installed + run: echo $(which cut) - name: Get latest tag run: | echo "VERSION=$(git describe --tags --abbrev=0)" - MAJOR=$(echo $VERSION | cut -d "." -f 1) - MINOR=$(echo $VERSION | cut -d "." -f 2) - PATCH=$(echo $VERSION | cut -d "." -f 3) + echo "MAJOR=$(echo $VERSION | cut -d "." -f 1)" + echo "MINOR=$(echo $VERSION | cut -d "." -f 2)" + echo "PATCH=$(echo $VERSION | cut -d "." -f 3)" - name: Increment version run: | PATCH=$((PATCH + 1)) -- 2.45.2 From 475ac22f79e320b4e412373f50a880fac05d2704 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Thu, 5 Jun 2025 23:13:27 +0530 Subject: [PATCH 21/87] Trying a different base image --- .gitea/workflows/test_image_build_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index b035c3b..aa75baf 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -7,7 +7,7 @@ jobs: build: runs-on: ubuntu-latest container: - image: catthehacker/ubuntu:act-latest + image: catthehacker/ubuntu:runner-latest steps: - name: Check out repository code uses: actions/checkout@v4 -- 2.45.2 From 07f9f2f4795ab6cd0d1361dc9af43f740992d9f4 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Thu, 5 Jun 2025 23:23:44 +0530 Subject: [PATCH 22/87] Trying to figure out RCA --- .gitea/workflows/test_build.yml | 7 +++++++ .gitea/workflows/test_image_build_push.yml | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/test_build.yml b/.gitea/workflows/test_build.yml index ae070cd..a546543 100644 --- a/.gitea/workflows/test_build.yml +++ b/.gitea/workflows/test_build.yml @@ -15,6 +15,13 @@ jobs: distribution: 'zulu' java-version: '17' - name: Validate Gradle Wrapper + - name: Get latest tag dry run + run: | + echo "VERSION=$(git describe --tags --abbrev=0)" + echo $VERSION + echo "MAJOR=$(echo $VERSION | cut -d "." -f 1)" + echo "MINOR=$(echo $VERSION | cut -d "." -f 2)" + echo "PATCH=$(echo $VERSION | cut -d "." -f 3)" uses: gradle/actions/wrapper-validation@v3 - name: Gradle build run: ./gradlew build --info \ No newline at end of file diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index aa75baf..3feddd2 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -7,7 +7,7 @@ jobs: build: runs-on: ubuntu-latest container: - image: catthehacker/ubuntu:runner-latest + image: catthehacker/ubuntu:act-latest steps: - name: Check out repository code uses: actions/checkout@v4 @@ -25,6 +25,7 @@ jobs: - name: Get latest tag run: | echo "VERSION=$(git describe --tags --abbrev=0)" + echo $VERSION echo "MAJOR=$(echo $VERSION | cut -d "." -f 1)" echo "MINOR=$(echo $VERSION | cut -d "." -f 2)" echo "PATCH=$(echo $VERSION | cut -d "." -f 3)" -- 2.45.2 From c3fddb29dd141aa0c79d90d0ce1ab9217bf2a461 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Thu, 5 Jun 2025 23:26:25 +0530 Subject: [PATCH 23/87] Trying to figure out RCA --- .gitea/workflows/test_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test_build.yml b/.gitea/workflows/test_build.yml index a546543..85e9353 100644 --- a/.gitea/workflows/test_build.yml +++ b/.gitea/workflows/test_build.yml @@ -15,6 +15,7 @@ jobs: distribution: 'zulu' java-version: '17' - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v3 - name: Get latest tag dry run run: | echo "VERSION=$(git describe --tags --abbrev=0)" @@ -22,6 +23,5 @@ jobs: echo "MAJOR=$(echo $VERSION | cut -d "." -f 1)" echo "MINOR=$(echo $VERSION | cut -d "." -f 2)" echo "PATCH=$(echo $VERSION | cut -d "." -f 3)" - uses: gradle/actions/wrapper-validation@v3 - name: Gradle build run: ./gradlew build --info \ No newline at end of file -- 2.45.2 From babd86e063a068ce4b65599c7442bb931e4cd444 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Thu, 5 Jun 2025 23:43:57 +0530 Subject: [PATCH 24/87] Trying to figure out RCA --- .gitea/workflows/test_build.yml | 7 ------- .gitea/workflows/test_image_build_push.yml | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.gitea/workflows/test_build.yml b/.gitea/workflows/test_build.yml index 85e9353..ae070cd 100644 --- a/.gitea/workflows/test_build.yml +++ b/.gitea/workflows/test_build.yml @@ -16,12 +16,5 @@ jobs: java-version: '17' - name: Validate Gradle Wrapper uses: gradle/actions/wrapper-validation@v3 - - name: Get latest tag dry run - run: | - echo "VERSION=$(git describe --tags --abbrev=0)" - echo $VERSION - echo "MAJOR=$(echo $VERSION | cut -d "." -f 1)" - echo "MINOR=$(echo $VERSION | cut -d "." -f 2)" - echo "PATCH=$(echo $VERSION | cut -d "." -f 3)" - name: Gradle build run: ./gradlew build --info \ No newline at end of file diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 3feddd2..c6f314b 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -26,8 +26,8 @@ jobs: run: | echo "VERSION=$(git describe --tags --abbrev=0)" echo $VERSION - echo "MAJOR=$(echo $VERSION | cut -d "." -f 1)" - echo "MINOR=$(echo $VERSION | cut -d "." -f 2)" + echo "MAJOR=$(echo $VERSION | /usr/bin/cut -d "." -f 1)" + sudo echo "MINOR=$(echo $VERSION | cut -d "." -f 2)" echo "PATCH=$(echo $VERSION | cut -d "." -f 3)" - name: Increment version run: | -- 2.45.2 From 926feca855a814e9f54247ffda2fce2c8cfc02e5 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 00:02:30 +0530 Subject: [PATCH 25/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index c6f314b..492ed6e 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -25,10 +25,10 @@ jobs: - name: Get latest tag run: | echo "VERSION=$(git describe --tags --abbrev=0)" - echo $VERSION - echo "MAJOR=$(echo $VERSION | /usr/bin/cut -d "." -f 1)" - sudo echo "MINOR=$(echo $VERSION | cut -d "." -f 2)" - echo "PATCH=$(echo $VERSION | cut -d "." -f 3)" + echo "${VERSION}" + echo "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" + sudo echo "MINOR=$(echo ${VERSION} | cut -d "." -f 2)" + echo "PATCH=$(echo ${VERSION} | cut -d "." -f 3)" - name: Increment version run: | PATCH=$((PATCH + 1)) -- 2.45.2 From 1dd7b9143dd3e37bd20469265e2f1d156cf2bfda Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 00:30:25 +0530 Subject: [PATCH 26/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 27 +++++++--------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 492ed6e..250d553 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -18,27 +18,16 @@ jobs: with: distribution: 'zulu' java-version: '17' - - name: Validate Gradle Wrapper - uses: gradle/actions/wrapper-validation@v3 - - name: Check if cut is installed - run: echo $(which cut) - - name: Get latest tag - run: | - echo "VERSION=$(git describe --tags --abbrev=0)" - echo "${VERSION}" - echo "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" - sudo echo "MINOR=$(echo ${VERSION} | cut -d "." -f 2)" - echo "PATCH=$(echo ${VERSION} | cut -d "." -f 3)" - - name: Increment version - run: | - PATCH=$((PATCH + 1)) - echo "NEW_VERSION=$(echo $MAJOR.$MINOR.$PATCH)" - - name: Extract commit message - run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" + - name: Get Next Patch Version + id: version + uses: reecetech/version-increment@v2024.10.1 + with: + scheme: semver + increment: patch - name: Create and push tag run: | - git tag -a ${NEW_VERSION} -m "${COMMIT_MESSAGE}" - git push origin ${NEW_VERSION} + git tag -a ${{ steps.version.outputs.version }} -m "Tagging with ${{ steps.version.outputs.version }}" + git push origin ${{ steps.version.outputs.version }} - name: Log in to Gitea Docker Registry uses: docker/login-action@v3 with: -- 2.45.2 From d3456b5efd7802538c0f05dbb9fe7947a15f3438 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 00:31:06 +0530 Subject: [PATCH 27/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 250d553..5693c1b 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -35,10 +35,10 @@ jobs: username: hitanshu password: ${{ secrets.TOKEN }} - name: Gradle build - run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:${NEW_VERSION} + run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:${{ steps.version.outputs.version }} - name: Tag image as test - run: docker tag 192.168.0.100:8928/hithomelabs/cftunnels:${NEW_VERSION} 192.168.0.100:8928/hithomelabs/cftunnels:test + run: docker tag 192.168.0.100:8928/hithomelabs/cftunnels:${{ steps.version.outputs.version }} 192.168.0.100:8928/hithomelabs/cftunnels:test - name: Push to Gitea Registry run: | docker push 192.168.0.100:8928/hithomelabs/cftunnels:test - docker push 192.168.0.100:8928/hithomelabs/cftunnels:${NEW_VERSION} + docker push 192.168.0.100:8928/hithomelabs/cftunnels:${{ steps.version.outputs.version }} -- 2.45.2 From c09615d06672fd8318680d87981d82e7fa2a387c Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 00:48:35 +0530 Subject: [PATCH 28/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 31 ++++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 5693c1b..a7f80aa 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -18,16 +18,25 @@ jobs: with: distribution: 'zulu' java-version: '17' - - name: Get Next Patch Version - id: version - uses: reecetech/version-increment@v2024.10.1 - with: - scheme: semver - increment: patch + - name: Check if cut is installed + run: echo $(which cut) + - name: Get latest tag + run: | + export "VERSION=$(git describe --tags --abbrev=0)" >> $GITEA_OUTPUT + echo "${GITEA_OUTPUT}" + echo "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" + sudo echo "MINOR=$(echo ${VERSION} | cut -d "." -f 2)" + echo "PATCH=$(echo ${VERSION} | cut -d "." -f 3)" + - name: Increment version + run: | + PATCH=$((PATCH + 1)) + echo "NEW_VERSION=$(echo $MAJOR.$MINOR.$PATCH)" + - name: Extract commit message + run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" - name: Create and push tag run: | - git tag -a ${{ steps.version.outputs.version }} -m "Tagging with ${{ steps.version.outputs.version }}" - git push origin ${{ steps.version.outputs.version }} + git tag -a ${NEW_VERSION} -m "${COMMIT_MESSAGE}" + git push origin ${NEW_VERSION} - name: Log in to Gitea Docker Registry uses: docker/login-action@v3 with: @@ -35,10 +44,10 @@ jobs: username: hitanshu password: ${{ secrets.TOKEN }} - name: Gradle build - run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:${{ steps.version.outputs.version }} + run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:${NEW_VERSION} - name: Tag image as test - run: docker tag 192.168.0.100:8928/hithomelabs/cftunnels:${{ steps.version.outputs.version }} 192.168.0.100:8928/hithomelabs/cftunnels:test + run: docker tag 192.168.0.100:8928/hithomelabs/cftunnels:${NEW_VERSION} 192.168.0.100:8928/hithomelabs/cftunnels:test - name: Push to Gitea Registry run: | docker push 192.168.0.100:8928/hithomelabs/cftunnels:test - docker push 192.168.0.100:8928/hithomelabs/cftunnels:${{ steps.version.outputs.version }} + docker push 192.168.0.100:8928/hithomelabs/cftunnels:${NEW_VERSION} -- 2.45.2 From a72d751951e14792dee02ca354eb9d3445bc268b Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 01:07:33 +0530 Subject: [PATCH 29/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index a7f80aa..217374d 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -24,9 +24,12 @@ jobs: run: | export "VERSION=$(git describe --tags --abbrev=0)" >> $GITEA_OUTPUT echo "${GITEA_OUTPUT}" - echo "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" - sudo echo "MINOR=$(echo ${VERSION} | cut -d "." -f 2)" - echo "PATCH=$(echo ${VERSION} | cut -d "." -f 3)" + export "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" + echo "${MAJOR}" + export "MINOR=$(echo ${VERSION} | cut -d "." -f 2)" + echo "${MINOR}" + export "PATCH=$(echo ${VERSION} | cut -d "." -f 3)" + echo "${PATCH} - name: Increment version run: | PATCH=$((PATCH + 1)) -- 2.45.2 From 611fe50a253d3c62d5fc26549cda67c2616e5ae9 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 01:11:09 +0530 Subject: [PATCH 30/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 217374d..dace717 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -22,14 +22,14 @@ jobs: run: echo $(which cut) - name: Get latest tag run: | - export "VERSION=$(git describe --tags --abbrev=0)" >> $GITEA_OUTPUT - echo "${GITEA_OUTPUT}" + export "VERSION=$(git describe --tags --abbrev=0)" + echo "${VERSION}" export "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" echo "${MAJOR}" export "MINOR=$(echo ${VERSION} | cut -d "." -f 2)" echo "${MINOR}" export "PATCH=$(echo ${VERSION} | cut -d "." -f 3)" - echo "${PATCH} + echo "${PATCH}" - name: Increment version run: | PATCH=$((PATCH + 1)) -- 2.45.2 From 889e29d82e00f24b9162937d7578a285629a15b9 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 01:33:41 +0530 Subject: [PATCH 31/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index dace717..317c324 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -18,22 +18,21 @@ jobs: with: distribution: 'zulu' java-version: '17' - - name: Check if cut is installed - run: echo $(which cut) - name: Get latest tag + id: get_tag run: | export "VERSION=$(git describe --tags --abbrev=0)" echo "${VERSION}" export "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" - echo "${MAJOR}" + echo "MAJOR=${MAJOR}" export "MINOR=$(echo ${VERSION} | cut -d "." -f 2)" - echo "${MINOR}" + echo "MINOR=${MINOR}" export "PATCH=$(echo ${VERSION} | cut -d "." -f 3)" - echo "${PATCH}" + echo "PATCH=${PATCH}" - name: Increment version run: | - PATCH=$((PATCH + 1)) - echo "NEW_VERSION=$(echo $MAJOR.$MINOR.$PATCH)" + export "NEW_VERSION=$(echo ${{ steps.get_tag.outputs.MAJOR }}.${{ steps.get_tag.outputs.MINOR }}.$( ${{ steps.get_tag.outputs.PATCH }} + 1) ) + echo "NEW_VERSION=${NEW_VERSION}" - name: Extract commit message run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" - name: Create and push tag -- 2.45.2 From 431b4ff0c740975dca3b8d838dca0c0a02476833 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 01:36:57 +0530 Subject: [PATCH 32/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 317c324..6bc41d8 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -31,7 +31,7 @@ jobs: echo "PATCH=${PATCH}" - name: Increment version run: | - export "NEW_VERSION=$(echo ${{ steps.get_tag.outputs.MAJOR }}.${{ steps.get_tag.outputs.MINOR }}.$( ${{ steps.get_tag.outputs.PATCH }} + 1) ) + export "NEW_VERSION=$(echo ${{ steps.get_tag.outputs.MAJOR }}.${{ steps.get_tag.outputs.MINOR }}.$( ${{ steps.get_tag.outputs.PATCH }} + 1) )" echo "NEW_VERSION=${NEW_VERSION}" - name: Extract commit message run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" -- 2.45.2 From 60711270c43122642d37c6892ddffee6fa0b4235 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 01:41:34 +0530 Subject: [PATCH 33/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 6bc41d8..998c7c7 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -31,7 +31,7 @@ jobs: echo "PATCH=${PATCH}" - name: Increment version run: | - export "NEW_VERSION=$(echo ${{ steps.get_tag.outputs.MAJOR }}.${{ steps.get_tag.outputs.MINOR }}.$( ${{ steps.get_tag.outputs.PATCH }} + 1) )" + export "NEW_VERSION=$(echo ${{ steps.get_tag.outputs.MAJOR }}.${{ steps.get_tag.outputs.MINOR }}.${{ steps.get_tag.outputs.PATCH }})" echo "NEW_VERSION=${NEW_VERSION}" - name: Extract commit message run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" -- 2.45.2 From b02a334dbe37f4ae0dabb2df0e375d4123307a45 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 01:46:54 +0530 Subject: [PATCH 34/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 998c7c7..30b431a 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -31,7 +31,7 @@ jobs: echo "PATCH=${PATCH}" - name: Increment version run: | - export "NEW_VERSION=$(echo ${{ steps.get_tag.outputs.MAJOR }}.${{ steps.get_tag.outputs.MINOR }}.${{ steps.get_tag.outputs.PATCH }})" + export "NEW_VERSION=${{ steps.get_tag.outputs.MAJOR }}" echo "NEW_VERSION=${NEW_VERSION}" - name: Extract commit message run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" -- 2.45.2 From 014cac1fc03ee080e28c2ef386ca82498c201adc Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 01:54:20 +0530 Subject: [PATCH 35/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 30b431a..99f6a46 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -21,7 +21,7 @@ jobs: - name: Get latest tag id: get_tag run: | - export "VERSION=$(git describe --tags --abbrev=0)" + export "VERSION=$(git describe --tags --abbrev=0)" >> $GITEA_ENV echo "${VERSION}" export "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" echo "MAJOR=${MAJOR}" @@ -31,8 +31,7 @@ jobs: echo "PATCH=${PATCH}" - name: Increment version run: | - export "NEW_VERSION=${{ steps.get_tag.outputs.MAJOR }}" - echo "NEW_VERSION=${NEW_VERSION}" + cat $GITEA_ENV - name: Extract commit message run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" - name: Create and push tag -- 2.45.2 From a3ca19d48a3428754d15fb722a66088421516a17 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 02:02:19 +0530 Subject: [PATCH 36/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 99f6a46..51d6af2 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -23,15 +23,17 @@ jobs: run: | export "VERSION=$(git describe --tags --abbrev=0)" >> $GITEA_ENV echo "${VERSION}" - export "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" + export "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" >> $GITEA_ENV echo "MAJOR=${MAJOR}" - export "MINOR=$(echo ${VERSION} | cut -d "." -f 2)" + export "MINOR=$(echo ${VERSION} | cut -d "." -f 2)" >> $GITEA_ENV echo "MINOR=${MINOR}" - export "PATCH=$(echo ${VERSION} | cut -d "." -f 3)" + export "PATCH=$(echo ${VERSION} | cut -d "." -f 3)" >> $GITEA_ENV echo "PATCH=${PATCH}" - name: Increment version run: | - cat $GITEA_ENV + export "PATCH=$((${PATCH} + 1))" >> $GITEA_ENV + export "NEW_VERSION=$(echo ${MAJOR}.${MINOR}.${PATCH})" >> $GITEA_ENV + echo "NEW_VERSION=${NEW_VERSION}" - name: Extract commit message run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" - name: Create and push tag -- 2.45.2 From 8146145be5feb1a613277c690151712ee1bf8a0f Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 02:06:12 +0530 Subject: [PATCH 37/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 51d6af2..b302553 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -31,6 +31,7 @@ jobs: echo "PATCH=${PATCH}" - name: Increment version run: | + echo "MAJOR=${MAJOR}" export "PATCH=$((${PATCH} + 1))" >> $GITEA_ENV export "NEW_VERSION=$(echo ${MAJOR}.${MINOR}.${PATCH})" >> $GITEA_ENV echo "NEW_VERSION=${NEW_VERSION}" -- 2.45.2 From 5a179ae287e79362eb67206e3b3223b1e90cd43d Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 02:11:28 +0530 Subject: [PATCH 38/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index b302553..641a094 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -31,7 +31,7 @@ jobs: echo "PATCH=${PATCH}" - name: Increment version run: | - echo "MAJOR=${MAJOR}" + echo $GITEA_ENV export "PATCH=$((${PATCH} + 1))" >> $GITEA_ENV export "NEW_VERSION=$(echo ${MAJOR}.${MINOR}.${PATCH})" >> $GITEA_ENV echo "NEW_VERSION=${NEW_VERSION}" -- 2.45.2 From 089c7facee8530f9b4e8fc79a857a88cfb3bc9a0 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 02:14:30 +0530 Subject: [PATCH 39/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 641a094..ebc6e00 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -31,7 +31,7 @@ jobs: echo "PATCH=${PATCH}" - name: Increment version run: | - echo $GITEA_ENV + cat /var/run/act/workflow/envs.txt export "PATCH=$((${PATCH} + 1))" >> $GITEA_ENV export "NEW_VERSION=$(echo ${MAJOR}.${MINOR}.${PATCH})" >> $GITEA_ENV echo "NEW_VERSION=${NEW_VERSION}" -- 2.45.2 From 58d8f2fed05f1b0c4e83b122d162268f21c8b547 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 02:19:18 +0530 Subject: [PATCH 40/87] Trying to figure out RCA --- .gitea/workflows/test_image_build_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index ebc6e00..a07f84a 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -31,7 +31,7 @@ jobs: echo "PATCH=${PATCH}" - name: Increment version run: | - cat /var/run/act/workflow/envs.txt + source $GITEA_ENV export "PATCH=$((${PATCH} + 1))" >> $GITEA_ENV export "NEW_VERSION=$(echo ${MAJOR}.${MINOR}.${PATCH})" >> $GITEA_ENV echo "NEW_VERSION=${NEW_VERSION}" -- 2.45.2 From 19ef13d8f72e0b8d41dc3799955f4c5e0159e006 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 02:20:03 +0530 Subject: [PATCH 41/87] Trying to figure out RCA --- .gitea/workflows/test_build.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.gitea/workflows/test_build.yml b/.gitea/workflows/test_build.yml index ae070cd..b991e53 100644 --- a/.gitea/workflows/test_build.yml +++ b/.gitea/workflows/test_build.yml @@ -16,5 +16,22 @@ jobs: java-version: '17' - name: Validate Gradle Wrapper uses: gradle/actions/wrapper-validation@v3 + - name: Get latest tag + id: get_tag + run: | + export "VERSION=$(git describe --tags --abbrev=0)" >> $GITEA_ENV + echo "${VERSION}" + export "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" >> $GITEA_ENV + echo "MAJOR=${MAJOR}" + export "MINOR=$(echo ${VERSION} | cut -d "." -f 2)" >> $GITEA_ENV + echo "MINOR=${MINOR}" + export "PATCH=$(echo ${VERSION} | cut -d "." -f 3)" >> $GITEA_ENV + echo "PATCH=${PATCH}" + - name: Increment version + run: | + source $GITEA_ENV + export "PATCH=$((${PATCH} + 1))" >> $GITEA_ENV + export "NEW_VERSION=$(echo ${MAJOR}.${MINOR}.${PATCH})" >> $GITEA_ENV + echo "NEW_VERSION=${NEW_VERSION}" - name: Gradle build run: ./gradlew build --info \ No newline at end of file -- 2.45.2 From af7adec1cb7aceec010ff430c925dae9f1c139ef Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 6 Jun 2025 02:24:53 +0530 Subject: [PATCH 42/87] Trying to figure out RCA --- .gitea/workflows/test_build.yml | 4 +++- .gitea/workflows/test_image_build_push.yml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/test_build.yml b/.gitea/workflows/test_build.yml index b991e53..3817663 100644 --- a/.gitea/workflows/test_build.yml +++ b/.gitea/workflows/test_build.yml @@ -6,6 +6,8 @@ on: jobs: build: runs-on: ubuntu-latest + container: + image: catthehacker/ubuntu:act-latest steps: - name: Check out repository code uses: actions/checkout@v4 @@ -29,7 +31,7 @@ jobs: echo "PATCH=${PATCH}" - name: Increment version run: | - source $GITEA_ENV + . $GITEA_ENV export "PATCH=$((${PATCH} + 1))" >> $GITEA_ENV export "NEW_VERSION=$(echo ${MAJOR}.${MINOR}.${PATCH})" >> $GITEA_ENV echo "NEW_VERSION=${NEW_VERSION}" diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index a07f84a..d96fd01 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -31,7 +31,7 @@ jobs: echo "PATCH=${PATCH}" - name: Increment version run: | - source $GITEA_ENV + . $GITEA_ENV export "PATCH=$((${PATCH} + 1))" >> $GITEA_ENV export "NEW_VERSION=$(echo ${MAJOR}.${MINOR}.${PATCH})" >> $GITEA_ENV echo "NEW_VERSION=${NEW_VERSION}" -- 2.45.2 From 770da7d67533d2a72eb2a4161d6512d82f6733f5 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Tue, 10 Jun 2025 21:21:39 +0530 Subject: [PATCH 43/87] Trying to pass variables between steps using outputs --- .gitea/workflows/test_build.yml | 19 ----------- .gitea/workflows/test_image_build_push.yml | 37 +++++++++++----------- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/.gitea/workflows/test_build.yml b/.gitea/workflows/test_build.yml index 3817663..ae070cd 100644 --- a/.gitea/workflows/test_build.yml +++ b/.gitea/workflows/test_build.yml @@ -6,8 +6,6 @@ on: jobs: build: runs-on: ubuntu-latest - container: - image: catthehacker/ubuntu:act-latest steps: - name: Check out repository code uses: actions/checkout@v4 @@ -18,22 +16,5 @@ jobs: java-version: '17' - name: Validate Gradle Wrapper uses: gradle/actions/wrapper-validation@v3 - - name: Get latest tag - id: get_tag - run: | - export "VERSION=$(git describe --tags --abbrev=0)" >> $GITEA_ENV - echo "${VERSION}" - export "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" >> $GITEA_ENV - echo "MAJOR=${MAJOR}" - export "MINOR=$(echo ${VERSION} | cut -d "." -f 2)" >> $GITEA_ENV - echo "MINOR=${MINOR}" - export "PATCH=$(echo ${VERSION} | cut -d "." -f 3)" >> $GITEA_ENV - echo "PATCH=${PATCH}" - - name: Increment version - run: | - . $GITEA_ENV - export "PATCH=$((${PATCH} + 1))" >> $GITEA_ENV - export "NEW_VERSION=$(echo ${MAJOR}.${MINOR}.${PATCH})" >> $GITEA_ENV - echo "NEW_VERSION=${NEW_VERSION}" - name: Gradle build run: ./gradlew build --info \ No newline at end of file diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index d96fd01..425a819 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -18,29 +18,28 @@ jobs: with: distribution: 'zulu' java-version: '17' + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v3 - name: Get latest tag id: get_tag run: | - export "VERSION=$(git describe --tags --abbrev=0)" >> $GITEA_ENV - echo "${VERSION}" - export "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" >> $GITEA_ENV - echo "MAJOR=${MAJOR}" - export "MINOR=$(echo ${VERSION} | cut -d "." -f 2)" >> $GITEA_ENV - echo "MINOR=${MINOR}" - export "PATCH=$(echo ${VERSION} | cut -d "." -f 3)" >> $GITEA_ENV - echo "PATCH=${PATCH}" + VERSION=$(git describe --tags --abbrev=0) + echo "VERSION=${VERSION}" >> $GITEA_OUTPUT + MAJOR=$(echo ${VERSION} | cut -d "." -f 1) + echo "MAJOR=${MAJOR}" >> $GITEA_OUTPUT + MINOR=$(echo ${VERSION} | cut -d "." -f 2) + echo "MINOR=${MINOR}" >> $GITEA_OUTPUT + PATCH=$(echo ${VERSION} | cut -d "." -f 3) + echo "PATCH=${PATCH}" >> $GITEA_OUTPUT - name: Increment version + id: calc_new_tag run: | - . $GITEA_ENV - export "PATCH=$((${PATCH} + 1))" >> $GITEA_ENV - export "NEW_VERSION=$(echo ${MAJOR}.${MINOR}.${PATCH})" >> $GITEA_ENV - echo "NEW_VERSION=${NEW_VERSION}" - - name: Extract commit message - run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" + echo "NEW_PATCH=$((${{ steps.get_id.outputs.PATCH }} + 1))" >> $GITEA_OUTPUT + echo "NEW_VERSION=$( ${{ steps.get_id.outputs.MAJOR }}.${{ steps.get_id.outputs.MINOR }}.${{ steps.get_id.outputs.NEW_PATCH }})" >> $GITEA_OUTPUT - name: Create and push tag run: | - git tag -a ${NEW_VERSION} -m "${COMMIT_MESSAGE}" - git push origin ${NEW_VERSION} + git tag -a ${{ steps.calc_new_tag.outputs.NEW_VERSION }} -m "Pushing new version ${{ steps.calc_new_tag.outputs.NEW_VERSION }}" + git push origin ${{ steps.calc_new_tag.outputs.NEW_VERSION }} - name: Log in to Gitea Docker Registry uses: docker/login-action@v3 with: @@ -48,10 +47,10 @@ jobs: username: hitanshu password: ${{ secrets.TOKEN }} - name: Gradle build - run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:${NEW_VERSION} + run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:${{ steps.calc_new_tag.outputs.NEW_VERSION }} - name: Tag image as test - run: docker tag 192.168.0.100:8928/hithomelabs/cftunnels:${NEW_VERSION} 192.168.0.100:8928/hithomelabs/cftunnels:test + run: docker tag 192.168.0.100:8928/hithomelabs/cftunnels:${{ steps.calc_new_tag.outputs.NEW_VERSION }} 192.168.0.100:8928/hithomelabs/cftunnels:test - name: Push to Gitea Registry run: | docker push 192.168.0.100:8928/hithomelabs/cftunnels:test - docker push 192.168.0.100:8928/hithomelabs/cftunnels:${NEW_VERSION} + docker push 192.168.0.100:8928/hithomelabs/cftunnels:${{ steps.calc_new_tag.outputs.NEW_VERSION }} -- 2.45.2 From b5886c4ecafec20d4fb81554b3030a4f59a3b740 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Tue, 10 Jun 2025 21:29:54 +0530 Subject: [PATCH 44/87] Trying to pass variables between steps using outputs --- .gitea/workflows/test_image_build_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 425a819..f4b42f1 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -35,7 +35,7 @@ jobs: id: calc_new_tag run: | echo "NEW_PATCH=$((${{ steps.get_id.outputs.PATCH }} + 1))" >> $GITEA_OUTPUT - echo "NEW_VERSION=$( ${{ steps.get_id.outputs.MAJOR }}.${{ steps.get_id.outputs.MINOR }}.${{ steps.get_id.outputs.NEW_PATCH }})" >> $GITEA_OUTPUT + echo "NEW_VERSION=$( ${{ steps.get_id.outputs.MAJOR }}.${{ steps.get_id.outputs.MINOR }}.${NEW_PATCH})" >> $GITEA_OUTPUT - name: Create and push tag run: | git tag -a ${{ steps.calc_new_tag.outputs.NEW_VERSION }} -m "Pushing new version ${{ steps.calc_new_tag.outputs.NEW_VERSION }}" -- 2.45.2 From ce2f83106c175ce72c1d5d231ce3c212676f801e Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Tue, 10 Jun 2025 21:39:17 +0530 Subject: [PATCH 45/87] Trying to pass variables between steps using outputs --- .gitea/workflows/test_image_build_push.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index f4b42f1..b44a6f1 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -34,7 +34,8 @@ jobs: - name: Increment version id: calc_new_tag run: | - echo "NEW_PATCH=$((${{ steps.get_id.outputs.PATCH }} + 1))" >> $GITEA_OUTPUT + echo "${{ steps.get_id.outputs.PATCH }}" + echo "NEW_PATCH=$(( ${{ steps.get_id.outputs.PATCH }} + 1))" >> $GITEA_OUTPUT echo "NEW_VERSION=$( ${{ steps.get_id.outputs.MAJOR }}.${{ steps.get_id.outputs.MINOR }}.${NEW_PATCH})" >> $GITEA_OUTPUT - name: Create and push tag run: | -- 2.45.2 From df63ab652fded79957f6494aa2ccd887464f2868 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Tue, 10 Jun 2025 21:46:10 +0530 Subject: [PATCH 46/87] Trying to use --- .gitea/workflows/test_image_build_push.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index b44a6f1..1295a5f 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -24,19 +24,19 @@ jobs: id: get_tag run: | VERSION=$(git describe --tags --abbrev=0) - echo "VERSION=${VERSION}" >> $GITEA_OUTPUT + echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT MAJOR=$(echo ${VERSION} | cut -d "." -f 1) - echo "MAJOR=${MAJOR}" >> $GITEA_OUTPUT + echo "MAJOR=${MAJOR}" >> $GITHUB_OUTPUT MINOR=$(echo ${VERSION} | cut -d "." -f 2) - echo "MINOR=${MINOR}" >> $GITEA_OUTPUT + echo "MINOR=${MINOR}" >> $GITHUB_OUTPUT PATCH=$(echo ${VERSION} | cut -d "." -f 3) - echo "PATCH=${PATCH}" >> $GITEA_OUTPUT + echo "PATCH=${PATCH}" >> $GITHUB_OUTPUT - name: Increment version id: calc_new_tag run: | echo "${{ steps.get_id.outputs.PATCH }}" - echo "NEW_PATCH=$(( ${{ steps.get_id.outputs.PATCH }} + 1))" >> $GITEA_OUTPUT - echo "NEW_VERSION=$( ${{ steps.get_id.outputs.MAJOR }}.${{ steps.get_id.outputs.MINOR }}.${NEW_PATCH})" >> $GITEA_OUTPUT + echo "NEW_PATCH=$(( ${{ steps.get_id.outputs.PATCH }} + 1))" >> $GITHUB_OUTPUT + echo "NEW_VERSION=$( ${{ steps.get_id.outputs.MAJOR }}.${{ steps.get_id.outputs.MINOR }}.${NEW_PATCH})" >> $GITHUB_OUTPUT - name: Create and push tag run: | git tag -a ${{ steps.calc_new_tag.outputs.NEW_VERSION }} -m "Pushing new version ${{ steps.calc_new_tag.outputs.NEW_VERSION }}" -- 2.45.2 From 8b90815f69cb48d4a89532a0e656a89b7a73da6f Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Tue, 10 Jun 2025 23:14:11 +0530 Subject: [PATCH 47/87] Trying to use --- .gitea/workflows/test_image_build_push.yml | 44 +++++++++++----------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 1295a5f..dec2b35 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -4,8 +4,25 @@ on: push: branches: [test] jobs: + tag: + runs-on: ubuntu-latest + outputs: + new_version: ${{ steps.new_version.outputs.new_version }} + steps: + id: new_version + run: | + VERSION=$(git describe --tags --abbrev=0) + echo ${VERSION} + MAJOR=$(echo ${VERSION} | cut -d "." -f 1) + MINOR=$(echo ${VERSION} | cut -d "." -f 2) + PATCH=$(echo ${VERSION} | cut -d "." -f 3) + NEW_PATCH=$(( ${PATCH} + 1)) + echo ${NEW_PATCH} + echo "new_version=$($MAJOR.$MINOR.$NEW_PATCH)" >> $GITHUB_OUTPUT + echo ${new_version} build: runs-on: ubuntu-latest + needs: tag container: image: catthehacker/ubuntu:act-latest steps: @@ -20,27 +37,10 @@ jobs: java-version: '17' - name: Validate Gradle Wrapper uses: gradle/actions/wrapper-validation@v3 - - name: Get latest tag - id: get_tag - run: | - VERSION=$(git describe --tags --abbrev=0) - echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT - MAJOR=$(echo ${VERSION} | cut -d "." -f 1) - echo "MAJOR=${MAJOR}" >> $GITHUB_OUTPUT - MINOR=$(echo ${VERSION} | cut -d "." -f 2) - echo "MINOR=${MINOR}" >> $GITHUB_OUTPUT - PATCH=$(echo ${VERSION} | cut -d "." -f 3) - echo "PATCH=${PATCH}" >> $GITHUB_OUTPUT - - name: Increment version - id: calc_new_tag - run: | - echo "${{ steps.get_id.outputs.PATCH }}" - echo "NEW_PATCH=$(( ${{ steps.get_id.outputs.PATCH }} + 1))" >> $GITHUB_OUTPUT - echo "NEW_VERSION=$( ${{ steps.get_id.outputs.MAJOR }}.${{ steps.get_id.outputs.MINOR }}.${NEW_PATCH})" >> $GITHUB_OUTPUT - name: Create and push tag run: | - git tag -a ${{ steps.calc_new_tag.outputs.NEW_VERSION }} -m "Pushing new version ${{ steps.calc_new_tag.outputs.NEW_VERSION }}" - git push origin ${{ steps.calc_new_tag.outputs.NEW_VERSION }} + git tag -a ${{ needs.tag.outputs.new_version }} -m "Pushing new version ${{ needs.tag.outputs.new_version }}" + git push origin ${{ needs.tag.outputs.new_version }} - name: Log in to Gitea Docker Registry uses: docker/login-action@v3 with: @@ -48,10 +48,10 @@ jobs: username: hitanshu password: ${{ secrets.TOKEN }} - name: Gradle build - run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:${{ steps.calc_new_tag.outputs.NEW_VERSION }} + run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:${{ needs.tag.outputs.new_version }} - name: Tag image as test - run: docker tag 192.168.0.100:8928/hithomelabs/cftunnels:${{ steps.calc_new_tag.outputs.NEW_VERSION }} 192.168.0.100:8928/hithomelabs/cftunnels:test + run: docker tag 192.168.0.100:8928/hithomelabs/cftunnels:${{ needs.tag.outputs.new_version }} 192.168.0.100:8928/hithomelabs/cftunnels:test - name: Push to Gitea Registry run: | docker push 192.168.0.100:8928/hithomelabs/cftunnels:test - docker push 192.168.0.100:8928/hithomelabs/cftunnels:${{ steps.calc_new_tag.outputs.NEW_VERSION }} + docker push 192.168.0.100:8928/hithomelabs/cftunnels:${{ needs.tag.outputs.new_version }} -- 2.45.2 From af51165e49010afd5d6be384ffcec8e418c40535 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Tue, 10 Jun 2025 23:15:19 +0530 Subject: [PATCH 48/87] Trying to multiple jobs --- .gitea/workflows/test_image_build_push.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index dec2b35..749327a 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -9,6 +9,10 @@ jobs: outputs: new_version: ${{ steps.new_version.outputs.new_version }} steps: + - name: Check out repository code + uses: actions/checkout@v4 + with: + fetch-depth: 0 id: new_version run: | VERSION=$(git describe --tags --abbrev=0) -- 2.45.2 From eaaa1f7cc3679eaa5a94c148e81d19ed87ae4ae5 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Tue, 10 Jun 2025 23:24:03 +0530 Subject: [PATCH 49/87] Correcting syntax --- .gitea/workflows/test_image_build_push.yml | 31 +++++++++++----------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 749327a..26b78f7 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -9,21 +9,22 @@ jobs: outputs: new_version: ${{ steps.new_version.outputs.new_version }} steps: - - name: Check out repository code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - id: new_version - run: | - VERSION=$(git describe --tags --abbrev=0) - echo ${VERSION} - MAJOR=$(echo ${VERSION} | cut -d "." -f 1) - MINOR=$(echo ${VERSION} | cut -d "." -f 2) - PATCH=$(echo ${VERSION} | cut -d "." -f 3) - NEW_PATCH=$(( ${PATCH} + 1)) - echo ${NEW_PATCH} - echo "new_version=$($MAJOR.$MINOR.$NEW_PATCH)" >> $GITHUB_OUTPUT - echo ${new_version} + - name: Check out repository code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Get new version + id: new_version + run: | + VERSION=$(git describe --tags --abbrev=0) + echo ${VERSION} + MAJOR=$(echo ${VERSION} | cut -d "." -f 1) + MINOR=$(echo ${VERSION} | cut -d "." -f 2) + PATCH=$(echo ${VERSION} | cut -d "." -f 3) + NEW_PATCH=$(( ${PATCH} + 1)) + echo ${NEW_PATCH} + echo "new_version=$($MAJOR.$MINOR.$NEW_PATCH)" >> $GITHUB_OUTPUT + echo ${new_version} build: runs-on: ubuntu-latest needs: tag -- 2.45.2 From a239a7e143b9db373042614ace4287a5a18ba063 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Tue, 10 Jun 2025 23:32:54 +0530 Subject: [PATCH 50/87] Minor bugfix --- .gitea/workflows/test_image_build_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 26b78f7..213fa22 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -23,7 +23,7 @@ jobs: PATCH=$(echo ${VERSION} | cut -d "." -f 3) NEW_PATCH=$(( ${PATCH} + 1)) echo ${NEW_PATCH} - echo "new_version=$($MAJOR.$MINOR.$NEW_PATCH)" >> $GITHUB_OUTPUT + echo "new_version=$MAJOR.$MINOR.$NEW_PATCH" >> $GITHUB_OUTPUT echo ${new_version} build: runs-on: ubuntu-latest -- 2.45.2 From 35e83eed48bdea29dfe4f8f647d69fba26533625 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Tue, 10 Jun 2025 23:44:55 +0530 Subject: [PATCH 51/87] Adding git config --- .gitea/workflows/test_image_build_push.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index 213fa22..f97fdc9 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -23,7 +23,7 @@ jobs: PATCH=$(echo ${VERSION} | cut -d "." -f 3) NEW_PATCH=$(( ${PATCH} + 1)) echo ${NEW_PATCH} - echo "new_version=$MAJOR.$MINOR.$NEW_PATCH" >> $GITHUB_OUTPUT + echo "new_version=$(echo "${MAJOR}.${MINOR}.${NEW_PATCH}")" >> $GITHUB_OUTPUT echo ${new_version} build: runs-on: ubuntu-latest @@ -44,6 +44,8 @@ jobs: uses: gradle/actions/wrapper-validation@v3 - name: Create and push tag run: | + git config --global user.name "${{gitea.actor}}" + git config --global user.email "${{ gitea.actor }}@users.noreply.github.com" git tag -a ${{ needs.tag.outputs.new_version }} -m "Pushing new version ${{ needs.tag.outputs.new_version }}" git push origin ${{ needs.tag.outputs.new_version }} - name: Log in to Gitea Docker Registry -- 2.45.2 From 9561772b9c66c4f5b034d74752cdbdac0dc90a0b Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Tue, 10 Jun 2025 23:45:42 +0530 Subject: [PATCH 52/87] Adding git config --- .gitea/workflows/test_image_build_push.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index f97fdc9..a933b76 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -44,6 +44,7 @@ jobs: uses: gradle/actions/wrapper-validation@v3 - name: Create and push tag run: | + echo "NEW_VERSION=${{ needs.tag.outputs.new_version }}" git config --global user.name "${{gitea.actor}}" git config --global user.email "${{ gitea.actor }}@users.noreply.github.com" git tag -a ${{ needs.tag.outputs.new_version }} -m "Pushing new version ${{ needs.tag.outputs.new_version }}" -- 2.45.2 From 8efa0e495e2ca76b9455b779ac59ac4e04b6fdc5 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Tue, 10 Jun 2025 23:55:45 +0530 Subject: [PATCH 53/87] Add semantic versioning, when pushing to test PATH is incremented by 1 --- .gitea/workflows/test_image_build_push.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index a933b76..f53e140 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -24,8 +24,7 @@ jobs: NEW_PATCH=$(( ${PATCH} + 1)) echo ${NEW_PATCH} echo "new_version=$(echo "${MAJOR}.${MINOR}.${NEW_PATCH}")" >> $GITHUB_OUTPUT - echo ${new_version} - build: + build_tag_push: runs-on: ubuntu-latest needs: tag container: -- 2.45.2 From c380f8da10c1463ea31d104b815ebc5a4f7a7cc4 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Mon, 15 Sep 2025 00:59:13 +0530 Subject: [PATCH 54/87] Trying to address the issue of redirect_uri --- src/main/resources/application-test.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index e5c014b..9f52712 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -1 +1 @@ -api.baseUrl=https://testcf.hithomelabs.com \ No newline at end of file +api.baseUrl=http://192.168.0.100:5002 \ No newline at end of file -- 2.45.2 From 2f6104725567be009dda7dd58d006d0915a95921 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Mon, 15 Sep 2025 01:17:29 +0530 Subject: [PATCH 55/87] Tinkering with redirect-uri --- src/main/resources/application-test.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index 9f52712..e5c014b 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -1 +1 @@ -api.baseUrl=http://192.168.0.100:5002 \ No newline at end of file +api.baseUrl=https://testcf.hithomelabs.com \ No newline at end of file -- 2.45.2 From b4112eb00598371883aabb36c10374045d1898be Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Mon, 15 Sep 2025 01:43:31 +0530 Subject: [PATCH 56/87] Trying something seeing if it works --- src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3ba3827..1b13697 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -7,7 +7,7 @@ spring.profiles.active=${ENV} spring.security.oauth2.client.registration.cftunnels.client-id=${OAUTH_CLIENT_ID} spring.security.oauth2.client.registration.cftunnels.client-secret=${OAUTH_CLIENT_SECRET} spring.security.oauth2.client.registration.cftunnels.authorization-grant-type=authorization_code -spring.security.oauth2.client.registration.cftunnels.redirect-uri={baseUrl}/login/oauth2/code/cftunnels +spring.security.oauth2.client.registration.cftunnels.redirect-uri=http://localhost:8080/login/oauth2/code/cftunnels spring.security.oauth2.client.registration.cftunnels.scope=openid,profile,email,offline_access,cftunnels spring.security.oauth2.client.provider.cftunnels.authorization-uri=https://auth.hithomelabs.com/application/o/authorize/ -- 2.45.2 From f9c8d9fcca7fcd7a635e556796fee73835a63fdc Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Mon, 15 Sep 2025 01:57:34 +0530 Subject: [PATCH 57/87] Trying to avoid clash with baseUrl variable --- .../com/hithomelabs/CFTunnels/Config/OpenApiConfig.java | 6 +++--- src/main/resources/application-local.properties | 2 +- src/main/resources/application-prod.properties | 2 +- src/main/resources/application-test.properties | 2 +- src/main/resources/application.properties | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java b/src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java index e24e6f5..ef3b098 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java @@ -11,12 +11,12 @@ import java.util.ArrayList; @Configuration public class OpenApiConfig { - @Value("${api.baseUrl}") - private String baseUrl; + @Value("${api.corsResolveUrl}") + private String corsResolveUrl; @Bean public OpenAPI openAPI(){ - Server httpsServer = new Server().url(baseUrl); + Server httpsServer = new Server().url(corsResolveUrl); OpenAPI openApi = new OpenAPI(); ArrayList servers = new ArrayList<>(); servers.add(httpsServer); diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index fdb25ce..9001ed2 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -1 +1 @@ -api.baseUrl=http://localhost:8080 \ No newline at end of file +api.corsResolveUrl=http://localhost:8080 \ No newline at end of file diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index dec0f4b..5126249 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -1 +1 @@ -api.baseUrl=https://cftunnels.hithomelabs.com \ No newline at end of file +api.corsResolveUrl=https://cftunnels.hithomelabs.com \ No newline at end of file diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index e5c014b..1ea328b 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -1 +1 @@ -api.baseUrl=https://testcf.hithomelabs.com \ No newline at end of file +api.corsResolveUrl=https://testcf.hithomelabs.com \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 1b13697..3ba3827 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -7,7 +7,7 @@ spring.profiles.active=${ENV} spring.security.oauth2.client.registration.cftunnels.client-id=${OAUTH_CLIENT_ID} spring.security.oauth2.client.registration.cftunnels.client-secret=${OAUTH_CLIENT_SECRET} spring.security.oauth2.client.registration.cftunnels.authorization-grant-type=authorization_code -spring.security.oauth2.client.registration.cftunnels.redirect-uri=http://localhost:8080/login/oauth2/code/cftunnels +spring.security.oauth2.client.registration.cftunnels.redirect-uri={baseUrl}/login/oauth2/code/cftunnels spring.security.oauth2.client.registration.cftunnels.scope=openid,profile,email,offline_access,cftunnels spring.security.oauth2.client.provider.cftunnels.authorization-uri=https://auth.hithomelabs.com/application/o/authorize/ -- 2.45.2 From 4a545d8a309a3610651bf753559010060708109d Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Tue, 16 Sep 2025 00:27:12 +0530 Subject: [PATCH 58/87] Adding config to make sping boot return an https redirect URI --- src/main/resources/application.properties | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3ba3827..c3fb4db 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,6 +4,8 @@ cloudflare.apiKey=${CLOUDFLARE_API_KEY} cloudflare.email=${CLOUDFLARE_EMAIL} spring.profiles.active=${ENV} +server.forward-headers-strategy=framework + spring.security.oauth2.client.registration.cftunnels.client-id=${OAUTH_CLIENT_ID} spring.security.oauth2.client.registration.cftunnels.client-secret=${OAUTH_CLIENT_SECRET} spring.security.oauth2.client.registration.cftunnels.authorization-grant-type=authorization_code -- 2.45.2 From 4a0c4dba52cfa3ea1711794cfaed0935989ad8b0 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Tue, 16 Sep 2025 01:30:02 +0530 Subject: [PATCH 59/87] Trying to do everythng via http --- src/main/resources/application-test.properties | 3 ++- src/main/resources/application.properties | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index 1ea328b..fb3cd9e 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -1 +1,2 @@ -api.corsResolveUrl=https://testcf.hithomelabs.com \ No newline at end of file +api.corsResolveUrl=https://testcf.hithomelabs.com +spring.security.oauth2.client.registration.cftunnels.redirect-uri=http://192.168.0.100:5002/login/oauth2/code/cftunnels \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c3fb4db..3ba3827 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,8 +4,6 @@ cloudflare.apiKey=${CLOUDFLARE_API_KEY} cloudflare.email=${CLOUDFLARE_EMAIL} spring.profiles.active=${ENV} -server.forward-headers-strategy=framework - spring.security.oauth2.client.registration.cftunnels.client-id=${OAUTH_CLIENT_ID} spring.security.oauth2.client.registration.cftunnels.client-secret=${OAUTH_CLIENT_SECRET} spring.security.oauth2.client.registration.cftunnels.authorization-grant-type=authorization_code -- 2.45.2 From c6af4cf227471a4f55d979062eee70876cc284c3 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sat, 20 Sep 2025 20:29:48 +0530 Subject: [PATCH 60/87] Trying to fix OIDC configuration with TLS termination behind reverse proxy --- src/main/resources/application-test.properties | 3 +-- src/main/resources/application.properties | 8 ++------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index fb3cd9e..1ea328b 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -1,2 +1 @@ -api.corsResolveUrl=https://testcf.hithomelabs.com -spring.security.oauth2.client.registration.cftunnels.redirect-uri=http://192.168.0.100:5002/login/oauth2/code/cftunnels \ No newline at end of file +api.corsResolveUrl=https://testcf.hithomelabs.com \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3ba3827..03b15a5 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,14 +4,10 @@ cloudflare.apiKey=${CLOUDFLARE_API_KEY} cloudflare.email=${CLOUDFLARE_EMAIL} spring.profiles.active=${ENV} +server.forward-headers-strategy=framework spring.security.oauth2.client.registration.cftunnels.client-id=${OAUTH_CLIENT_ID} spring.security.oauth2.client.registration.cftunnels.client-secret=${OAUTH_CLIENT_SECRET} spring.security.oauth2.client.registration.cftunnels.authorization-grant-type=authorization_code spring.security.oauth2.client.registration.cftunnels.redirect-uri={baseUrl}/login/oauth2/code/cftunnels spring.security.oauth2.client.registration.cftunnels.scope=openid,profile,email,offline_access,cftunnels - -spring.security.oauth2.client.provider.cftunnels.authorization-uri=https://auth.hithomelabs.com/application/o/authorize/ -spring.security.oauth2.client.provider.cftunnels.token-uri=https://auth.hithomelabs.com/application/o/token/ -spring.security.oauth2.client.provider.cftunnels.user-info-uri=https://auth.hithomelabs.com/application/o/userinfo/ -spring.security.oauth2.client.provider.cftunnels.jwk-set-uri=https://auth.hithomelabs.com/application/o/cftunnels/jwks/ -spring.security.oauth2.client.provider.cftunnels.issuer-uri=https://auth.hithomelabs.com/application/o/cftunnels/ \ No newline at end of file +spring.security.oauth2.client.provider.cftunnels.issuer-uri=https://auth.hithomelabs.com/application/o/cftunnels \ No newline at end of file -- 2.45.2 From dd67fe89c9770db98051eff17dba10c649fa1a28 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sat, 20 Sep 2025 20:40:19 +0530 Subject: [PATCH 61/87] Fixing breaking build --- src/main/resources/application.properties | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 03b15a5..b95f4d1 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -10,4 +10,8 @@ spring.security.oauth2.client.registration.cftunnels.client-secret=${OAUTH_CLIEN spring.security.oauth2.client.registration.cftunnels.authorization-grant-type=authorization_code spring.security.oauth2.client.registration.cftunnels.redirect-uri={baseUrl}/login/oauth2/code/cftunnels spring.security.oauth2.client.registration.cftunnels.scope=openid,profile,email,offline_access,cftunnels -spring.security.oauth2.client.provider.cftunnels.issuer-uri=https://auth.hithomelabs.com/application/o/cftunnels \ No newline at end of file +spring.security.oauth2.client.provider.cftunnels.authorization-uri=https://auth.hithomelabs.com/application/o/authorize/ +spring.security.oauth2.client.provider.cftunnels.token-uri=https://auth.hithomelabs.com/application/o/token/ +spring.security.oauth2.client.provider.cftunnels.user-info-uri=https://auth.hithomelabs.com/application/o/userinfo/ +spring.security.oauth2.client.provider.cftunnels.jwk-set-uri=https://auth.hithomelabs.com/application/o/cftunnels/jwks/ +spring.security.oauth2.client.provider.cftunnels.issuer-uri=https://auth.hithomelabs.com/application/o/cftunnels/ \ No newline at end of file -- 2.45.2 From ecf87ad1e3f50b55731c40bb5600121921212b74 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sat, 20 Sep 2025 21:00:58 +0530 Subject: [PATCH 62/87] Adding new URL mapping that redirects / to swagger UI --- .../hithomelabs/CFTunnels/Controllers/TunnelController.java | 5 +++++ src/main/resources/application.properties | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java index fc8819f..8c9d145 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java @@ -38,6 +38,11 @@ public class TunnelController { @Autowired private RestTemplateConfig restTemplateConfig; + @GetMapping("/") + public String redirectToSwagger() { + return "redirect:/swagger-ui/index.html"; + } + @PreAuthorize("hasAnyRole('USER')") @GetMapping("/whoami") public Map whoAmI(@AuthenticationPrincipal OidcUser oidcUser) { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b95f4d1..4774989 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,7 +4,9 @@ cloudflare.apiKey=${CLOUDFLARE_API_KEY} cloudflare.email=${CLOUDFLARE_EMAIL} spring.profiles.active=${ENV} +/ * * Masking sure app works behind a reverse proxy server.forward-headers-strategy=framework + spring.security.oauth2.client.registration.cftunnels.client-id=${OAUTH_CLIENT_ID} spring.security.oauth2.client.registration.cftunnels.client-secret=${OAUTH_CLIENT_SECRET} spring.security.oauth2.client.registration.cftunnels.authorization-grant-type=authorization_code -- 2.45.2 From 3b572787f84625b7784a542524d4456ad616a18e Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sat, 20 Sep 2025 21:29:53 +0530 Subject: [PATCH 63/87] Adding a new HomeController to redirect to swagger UI --- .../CFTunnels/Controllers/HomeController.java | 32 +++++++++++++++++++ .../Controllers/TunnelController.java | 9 ++---- 2 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Controllers/HomeController.java diff --git a/src/main/java/com/hithomelabs/CFTunnels/Controllers/HomeController.java b/src/main/java/com/hithomelabs/CFTunnels/Controllers/HomeController.java new file mode 100644 index 0000000..43ea57a --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Controllers/HomeController.java @@ -0,0 +1,32 @@ +package com.hithomelabs.CFTunnels.Controllers; + + +import org.springframework.boot.web.servlet.error.ErrorController; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class HomeController implements ErrorController { + + private static final String ERROR_PATH = "/error"; + + /** + * Redirects the root (including any query params like ?continue=…) + * straight into Swagger UI. + */ + @GetMapping("/") + public String rootRedirect() { + return "redirect:/swagger-ui/index.html"; + } + + /** + * Catches any errors (404s, unhandled paths) and punts them + * into the same Swagger UI page. + */ + @RequestMapping(ERROR_PATH) + public String onError() { + return "redirect:/swagger-ui/index.html"; + } + +} diff --git a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java index 8c9d145..612fc78 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java @@ -9,6 +9,7 @@ import com.hithomelabs.CFTunnels.Models.Config; import com.hithomelabs.CFTunnels.Models.Ingress; import com.hithomelabs.CFTunnels.Models.TunnelResponse; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.http.*; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.GrantedAuthority; @@ -23,9 +24,10 @@ import java.util.Map; @RestController @RequestMapping("/cloudflare") -public class TunnelController { +public class TunnelController implements ErrorController { private final RestTemplate restTemplate = new RestTemplate(); + private static final String ERROR_PATH = "/error"; @Autowired private AuthoritiesToGroupMapping authoritiesToGroupMapping; @@ -38,11 +40,6 @@ public class TunnelController { @Autowired private RestTemplateConfig restTemplateConfig; - @GetMapping("/") - public String redirectToSwagger() { - return "redirect:/swagger-ui/index.html"; - } - @PreAuthorize("hasAnyRole('USER')") @GetMapping("/whoami") public Map whoAmI(@AuthenticationPrincipal OidcUser oidcUser) { -- 2.45.2 From 5cc342462c1756776a1be0b78484ab697b5ac83b Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sat, 20 Sep 2025 23:31:18 +0530 Subject: [PATCH 64/87] Incrementing minor version and building an PROD image when PR merged to main --- .gitea/workflows/prod_image_build_push.yaml | 64 +++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .gitea/workflows/prod_image_build_push.yaml diff --git a/.gitea/workflows/prod_image_build_push.yaml b/.gitea/workflows/prod_image_build_push.yaml new file mode 100644 index 0000000..ec31a2c --- /dev/null +++ b/.gitea/workflows/prod_image_build_push.yaml @@ -0,0 +1,64 @@ +name: Promote image with tag test to prod +run-name: Build started by $ {{gitea.actor}} +on: + push: + branches: [main] +jobs: + tag: + runs-on: ubuntu-latest + outputs: + new_version: ${{ steps.new_version.outputs.new_version }} + steps: + - name: Check out repository code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Get new version + id: new_version + run: | + VERSION=$(git describe --tags --abbrev=0) + echo ${VERSION} + MAJOR=$(echo ${VERSION} | cut -d "." -f 1) + MINOR=$(echo ${VERSION} | cut -d "." -f 2) + PATCH=0 + NEW_MINOR=$(( ${MINOR} + 1)) + echo ${NEW_MINOR} + echo "new_version=$(echo "${MAJOR}.${NEW_MINOR}.${PATCH}")" >> $GITHUB_OUTPUT + build_tag_push: + runs-on: ubuntu-latest + needs: tag + container: + image: catthehacker/ubuntu:act-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: JDK setup + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v3 + - name: Create and push tag + run: | + echo "NEW_VERSION=${{ needs.tag.outputs.new_version }}" + git config --global user.name "${{gitea.actor}}" + git config --global user.email "${{ gitea.actor }}@users.noreply.github.com" + git tag -a ${{ needs.tag.outputs.new_version }} -m "Pushing new version ${{ needs.tag.outputs.new_version }}" + git push origin ${{ needs.tag.outputs.new_version }} + - name: Log in to Gitea Docker Registry + uses: docker/login-action@v3 + with: + registry: 'http://192.168.0.100:8928' + username: hitanshu + password: ${{ secrets.TOKEN }} + - name: Gradle build + run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:${{ needs.tag.outputs.new_version }} + - name: Tag image as test + run: docker tag 192.168.0.100:8928/hithomelabs/cftunnels:${{ needs.tag.outputs.new_version }} 192.168.0.100:8928/hithomelabs/cftunnels:prod + - name: Push to Gitea Registry + run: | + docker push 192.168.0.100:8928/hithomelabs/cftunnels:prod + docker push 192.168.0.100:8928/hithomelabs/cftunnels:${{ needs.tag.outputs.new_version }} -- 2.45.2 From 77f839583700eac8f1f38bf3cf1a2cfb3480bc8f Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sun, 21 Sep 2025 00:34:20 +0530 Subject: [PATCH 65/87] Adding port config based on environment variables, removing gradle build for prod deployment --- ..._image_build_push.yaml => prod_image_tag_promote.yaml} | 8 ++++---- docker-compose.yaml | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) rename .gitea/workflows/{prod_image_build_push.yaml => prod_image_tag_promote.yaml} (86%) diff --git a/.gitea/workflows/prod_image_build_push.yaml b/.gitea/workflows/prod_image_tag_promote.yaml similarity index 86% rename from .gitea/workflows/prod_image_build_push.yaml rename to .gitea/workflows/prod_image_tag_promote.yaml index ec31a2c..fcef6f0 100644 --- a/.gitea/workflows/prod_image_build_push.yaml +++ b/.gitea/workflows/prod_image_tag_promote.yaml @@ -54,10 +54,10 @@ jobs: registry: 'http://192.168.0.100:8928' username: hitanshu password: ${{ secrets.TOKEN }} - - name: Gradle build - run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:${{ needs.tag.outputs.new_version }} - - name: Tag image as test - run: docker tag 192.168.0.100:8928/hithomelabs/cftunnels:${{ needs.tag.outputs.new_version }} 192.168.0.100:8928/hithomelabs/cftunnels:prod + - name: Tag prod image + run: | + docker tag 192.168.0.100:8928/hithomelabs/cftunnels:test 192.168.0.100:8928/hithomelabs/cftunnels:${{ needs.tag.outputs.new_version }} + docker tag 192.168.0.100:8928/hithomelabs/cftunnels:${{ needs.tag.outputs.new_version }} 192.168.0.100:8928/hithomelabs/cftunnels:prod - name: Push to Gitea Registry run: | docker push 192.168.0.100:8928/hithomelabs/cftunnels:prod diff --git a/docker-compose.yaml b/docker-compose.yaml index 7cac007..29e1529 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,6 +2,8 @@ services: app: image: gitea.hithomelabs.com/hithomelabs/cftunnels:${ENV} container_name: cftunnels_${ENV} + ports: + - "${HOST_PORT:-5002}:8080 environment: - CLOUDFLARE_ACCOUNT_ID=${CLOUDFLARE_ACCOUNT_ID} - CLOUDFLARE_API_KEY=${CLOUDFLARE_API_KEY} @@ -9,6 +11,5 @@ services: - ENV=${ENV} - OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID} - OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET} - ports: - - 5002:8080 + - HOST_PORT=${HOST_PORT} restart: unless-stopped \ No newline at end of file -- 2.45.2 From 4d7a52b0baee015376ada36b04a2ad45ff127ef7 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sun, 21 Sep 2025 00:47:23 +0530 Subject: [PATCH 66/87] removing JDK seup and gradle wrapper validation as not needed --- .gitea/workflows/test_image_build_push.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index f53e140..ab3e539 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -34,13 +34,6 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - - name: JDK setup - uses: actions/setup-java@v4 - with: - distribution: 'zulu' - java-version: '17' - - name: Validate Gradle Wrapper - uses: gradle/actions/wrapper-validation@v3 - name: Create and push tag run: | echo "NEW_VERSION=${{ needs.tag.outputs.new_version }}" -- 2.45.2 From 667f7c81dd52f5c1eea65e4d70adb72983bbfefd Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sun, 21 Sep 2025 00:48:58 +0530 Subject: [PATCH 67/87] Restoring and making changes to the correct workflow --- .gitea/workflows/prod_image_tag_promote.yaml | 7 ------- .gitea/workflows/test_image_build_push.yml | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/prod_image_tag_promote.yaml b/.gitea/workflows/prod_image_tag_promote.yaml index fcef6f0..a2a2a16 100644 --- a/.gitea/workflows/prod_image_tag_promote.yaml +++ b/.gitea/workflows/prod_image_tag_promote.yaml @@ -34,13 +34,6 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - - name: JDK setup - uses: actions/setup-java@v4 - with: - distribution: 'zulu' - java-version: '17' - - name: Validate Gradle Wrapper - uses: gradle/actions/wrapper-validation@v3 - name: Create and push tag run: | echo "NEW_VERSION=${{ needs.tag.outputs.new_version }}" diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index ab3e539..f53e140 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -34,6 +34,13 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + - name: JDK setup + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v3 - name: Create and push tag run: | echo "NEW_VERSION=${{ needs.tag.outputs.new_version }}" -- 2.45.2 From 38a0bd96596121571b8f476c582ce00d1d9323d6 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sun, 21 Sep 2025 01:00:18 +0530 Subject: [PATCH 68/87] Fixing faulty docker-compose --- docker-compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 29e1529..ce91374 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -3,7 +3,7 @@ services: image: gitea.hithomelabs.com/hithomelabs/cftunnels:${ENV} container_name: cftunnels_${ENV} ports: - - "${HOST_PORT:-5002}:8080 + - ${HOST_PORT}:8080 environment: - CLOUDFLARE_ACCOUNT_ID=${CLOUDFLARE_ACCOUNT_ID} - CLOUDFLARE_API_KEY=${CLOUDFLARE_API_KEY} -- 2.45.2 From 24beaf678b31d17fadccb79fb6c58a31ccad6018 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sun, 21 Sep 2025 12:29:30 +0530 Subject: [PATCH 69/87] Adding env file placeholder is manddatory for portainer env variables workflow --- docker-compose.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yaml b/docker-compose.yaml index ce91374..b014137 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -12,4 +12,6 @@ services: - OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID} - OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET} - HOST_PORT=${HOST_PORT} + env_file: + - stack.env restart: unless-stopped \ No newline at end of file -- 2.45.2 From 22d531022368a01070a351492d2375a1b69be220 Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Sun, 12 Oct 2025 21:59:55 +0530 Subject: [PATCH 70/87] Postgres integration --- build.gradle | 4 ++ docker-compose.yaml | 21 ++++++++++- .../resources/application-local.properties | 9 ++++- src/main/resources/application.properties | 13 ++++++- src/main/resources/schema.sql | 37 +++++++++++++++++++ 5 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/schema.sql diff --git a/build.gradle b/build.gradle index bfc0540..2c09e0d 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,10 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + implementation 'org.springframework.boot:spring-boot-starter-actuator' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + runtimeOnly 'org.postgresql:postgresql' + implementation 'org.hibernate.validator:hibernate-validator' } tasks.named('test') { diff --git a/docker-compose.yaml b/docker-compose.yaml index b014137..772008b 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -12,6 +12,23 @@ services: - OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID} - OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET} - HOST_PORT=${HOST_PORT} + - POSTGRES_USER=${POSTGRES_USERNAME} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} env_file: - - stack.env - restart: unless-stopped \ No newline at end of file + - .env + restart: unless-stopped + postgres: + image: postgres:15 + container_name: cftunnel-db + environment: + POSTGRES_DB: cftunnel + POSTGRES_USER: ${POSTGRES_USERNAME} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + restart: unless-stopped + ports: + - "5432:5432" + volumes: + - pgdata:/var/lib/postgresql/data + +volumes: + pgdata: {} \ No newline at end of file diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index 9001ed2..556b2d1 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -1 +1,8 @@ -api.corsResolveUrl=http://localhost:8080 \ No newline at end of file +api.corsResolveUrl=http://localhost:8080 + +management.health.db.enabled=true +management.endpoints.web.exposure.include=health +management.endpoint.health.show-details=always + +logging.level.org.hibernate.SQL=DEBUG +debug=true diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4774989..e6d31e7 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -16,4 +16,15 @@ spring.security.oauth2.client.provider.cftunnels.authorization-uri=https://auth. spring.security.oauth2.client.provider.cftunnels.token-uri=https://auth.hithomelabs.com/application/o/token/ spring.security.oauth2.client.provider.cftunnels.user-info-uri=https://auth.hithomelabs.com/application/o/userinfo/ spring.security.oauth2.client.provider.cftunnels.jwk-set-uri=https://auth.hithomelabs.com/application/o/cftunnels/jwks/ -spring.security.oauth2.client.provider.cftunnels.issuer-uri=https://auth.hithomelabs.com/application/o/cftunnels/ \ No newline at end of file +spring.security.oauth2.client.provider.cftunnels.issuer-uri=https://auth.hithomelabs.com/application/o/cftunnels/ + +spring.datasource.url=jdbc:postgresql://localhost:5432/cftunnel +spring.datasource.username=${POSTGRES_USERNAME} +spring.datasource.password=${POSTGRES_PASSWORD} +spring.datasource.driver-class-name=org.postgresql.Driver +spring.sql.init.mode=always + +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect + diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql new file mode 100644 index 0000000..1fa876d --- /dev/null +++ b/src/main/resources/schema.sql @@ -0,0 +1,37 @@ +-- schema.sql + +-- Roles table +CREATE TABLE IF NOT EXISTS roles ( + role_id SERIAL PRIMARY KEY, + role_name VARCHAR(50) UNIQUE NOT NULL +); + +-- Users table +CREATE TABLE IF NOT EXISTS users ( + user_id SERIAL PRIMARY KEY, + user_name VARCHAR(100) NOT NULL, + password VARCHAR(255) NOT NULL +); + +-- User-Role Mapping table (many-to-many relationship) +CREATE TABLE IF NOT EXISTS user_role_mapping ( + mapping_id SERIAL PRIMARY KEY, + user_id INTEGER NOT NULL REFERENCES users(user_id) ON DELETE CASCADE, + role_id INTEGER NOT NULL REFERENCES roles(role_id) ON DELETE CASCADE +); + +-- Tunnels table +CREATE TABLE IF NOT EXISTS tunnels ( + tunnel_id SERIAL PRIMARY KEY, + tunnel_name VARCHAR(100) NOT NULL, + tunnel_type VARCHAR(50) NOT NULL +); + +-- Mapping Requests table +CREATE TABLE IF NOT EXISTS mapping_requests ( + request_id SERIAL PRIMARY KEY, + request_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + status VARCHAR(20) NOT NULL, + user_id INTEGER REFERENCES users(user_id) ON DELETE SET NULL, + tunnel_id INTEGER REFERENCES tunnels(tunnel_id) ON DELETE SET NULL +); -- 2.45.2 From 9e5af51cf938d04e95b67300c4876f009dcf61d4 Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Sun, 12 Oct 2025 22:55:05 +0530 Subject: [PATCH 71/87] bug fixes --- build.gradle | 1 - docker-compose.yaml | 9 +++------ src/main/resources/application-local.properties | 2 ++ src/main/resources/application.properties | 5 +++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 2c09e0d..4340fce 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,6 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' - implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' runtimeOnly 'org.postgresql:postgresql' implementation 'org.hibernate.validator:hibernate-validator' diff --git a/docker-compose.yaml b/docker-compose.yaml index 772008b..f33b9fe 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -15,10 +15,10 @@ services: - POSTGRES_USER=${POSTGRES_USERNAME} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} env_file: - - .env + - stack.env restart: unless-stopped postgres: - image: postgres:15 + image: postgres:15-alpine container_name: cftunnel-db environment: POSTGRES_DB: cftunnel @@ -28,7 +28,4 @@ services: ports: - "5432:5432" volumes: - - pgdata:/var/lib/postgresql/data - -volumes: - pgdata: {} \ No newline at end of file + - ${DB_PATH}:/var/lib/postgresql/data \ No newline at end of file diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index 556b2d1..c355d6f 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -6,3 +6,5 @@ management.endpoint.health.show-details=always logging.level.org.hibernate.SQL=DEBUG debug=true + +spring.datasource.url=jdbc:postgresql://localhost:5432/cftunnel diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e6d31e7..c241382 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -18,7 +18,7 @@ spring.security.oauth2.client.provider.cftunnels.user-info-uri=https://auth.hith spring.security.oauth2.client.provider.cftunnels.jwk-set-uri=https://auth.hithomelabs.com/application/o/cftunnels/jwks/ spring.security.oauth2.client.provider.cftunnels.issuer-uri=https://auth.hithomelabs.com/application/o/cftunnels/ -spring.datasource.url=jdbc:postgresql://localhost:5432/cftunnel +spring.datasource.url=jdbc:postgresql://192.168.0.100:5432/cftunnel spring.datasource.username=${POSTGRES_USERNAME} spring.datasource.password=${POSTGRES_PASSWORD} spring.datasource.driver-class-name=org.postgresql.Driver @@ -26,5 +26,6 @@ spring.sql.init.mode=always spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect + +spring.jpa.open-in-view=false \ No newline at end of file -- 2.45.2 From 0130ee364a307bdd1b95d54a7e06b34b04da798c Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Sun, 12 Oct 2025 23:28:24 +0530 Subject: [PATCH 72/87] sql init set to never --- src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c241382..72edec8 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -22,7 +22,7 @@ spring.datasource.url=jdbc:postgresql://192.168.0.100:5432/cftunnel spring.datasource.username=${POSTGRES_USERNAME} spring.datasource.password=${POSTGRES_PASSWORD} spring.datasource.driver-class-name=org.postgresql.Driver -spring.sql.init.mode=always +spring.sql.init.mode=never spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true -- 2.45.2 From 2f67dbfbcaf3fcc1f4b114c444a08f901237b909 Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Sun, 12 Oct 2025 23:38:40 +0530 Subject: [PATCH 73/87] dialect readded --- src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 72edec8..a0264d2 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -26,6 +26,6 @@ spring.sql.init.mode=never spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true - +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect spring.jpa.open-in-view=false \ No newline at end of file -- 2.45.2 From 39b3c0bb482078a762e4c594d429849328714caf Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Sun, 12 Oct 2025 23:58:14 +0530 Subject: [PATCH 74/87] db port variable added --- docker-compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index f33b9fe..f8cb6ed 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -26,6 +26,6 @@ services: POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} restart: unless-stopped ports: - - "5432:5432" + - "${DB_PORT}:5432" volumes: - ${DB_PATH}:/var/lib/postgresql/data \ No newline at end of file -- 2.45.2 From 54320b8085dd4ae26ccb7c405135caa6edf5845b Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Sat, 18 Oct 2025 17:30:25 +0530 Subject: [PATCH 75/87] Env name added in container name --- docker-compose.yaml | 2 +- postgres-docker-compose.yaml | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 postgres-docker-compose.yaml diff --git a/docker-compose.yaml b/docker-compose.yaml index f8cb6ed..9eb1198 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -19,7 +19,7 @@ services: restart: unless-stopped postgres: image: postgres:15-alpine - container_name: cftunnel-db + container_name: cftunnel-db-${ENV} environment: POSTGRES_DB: cftunnel POSTGRES_USER: ${POSTGRES_USERNAME} diff --git a/postgres-docker-compose.yaml b/postgres-docker-compose.yaml new file mode 100644 index 0000000..b72cc0d --- /dev/null +++ b/postgres-docker-compose.yaml @@ -0,0 +1,16 @@ +services: + postgres: + image: postgres + container_name: cftunnel-db + restart: always + environment: + POSTGRES_DB: cftunnel + POSTGRES_USER: root + POSTGRES_PASSWORD: password + ports: + - "5432:5432" + volumes: + - pgdata:/var/lib/postgresql/data + +volumes: + pgdata: \ No newline at end of file -- 2.45.2 From 4377b437d17060029b1e11bd7ac4abaeb587bc3c Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Sat, 18 Oct 2025 17:33:06 +0530 Subject: [PATCH 76/87] postgres docker compose file deleted --- postgres-docker-compose.yaml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 postgres-docker-compose.yaml diff --git a/postgres-docker-compose.yaml b/postgres-docker-compose.yaml deleted file mode 100644 index b72cc0d..0000000 --- a/postgres-docker-compose.yaml +++ /dev/null @@ -1,16 +0,0 @@ -services: - postgres: - image: postgres - container_name: cftunnel-db - restart: always - environment: - POSTGRES_DB: cftunnel - POSTGRES_USER: root - POSTGRES_PASSWORD: password - ports: - - "5432:5432" - volumes: - - pgdata:/var/lib/postgresql/data - -volumes: - pgdata: \ No newline at end of file -- 2.45.2 From 7d450e0023957e47c7162e78b0e90baf8c000a59 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sat, 18 Oct 2025 16:35:23 +0530 Subject: [PATCH 77/87] ISSUE-43: Attempting to fix Hithomelabs/HomeLabDocker#43 disbling server side csrf check --- .../com/hithomelabs/CFTunnels/Config/OpenApiConfig.java | 6 +++--- .../CFTunnels/Config/Security/SecuirtyConfig.java | 9 +++++---- .../CFTunnels/Controllers/TunnelController.java | 2 +- src/main/resources/application-local.properties | 2 +- src/main/resources/application-prod.properties | 2 +- src/main/resources/application-test.properties | 2 +- src/main/resources/application.properties | 6 ++++++ 7 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java b/src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java index ef3b098..e24e6f5 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Config/OpenApiConfig.java @@ -11,12 +11,12 @@ import java.util.ArrayList; @Configuration public class OpenApiConfig { - @Value("${api.corsResolveUrl}") - private String corsResolveUrl; + @Value("${api.baseUrl}") + private String baseUrl; @Bean public OpenAPI openAPI(){ - Server httpsServer = new Server().url(corsResolveUrl); + Server httpsServer = new Server().url(baseUrl); OpenAPI openApi = new OpenAPI(); ArrayList servers = new ArrayList<>(); servers.add(httpsServer); diff --git a/src/main/java/com/hithomelabs/CFTunnels/Config/Security/SecuirtyConfig.java b/src/main/java/com/hithomelabs/CFTunnels/Config/Security/SecuirtyConfig.java index 7bd9c1e..81def11 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Config/Security/SecuirtyConfig.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Config/Security/SecuirtyConfig.java @@ -16,8 +16,8 @@ import org.springframework.security.web.SecurityFilterChain; @EnableWebSecurity @EnableMethodSecurity( prePostEnabled = true, - securedEnabled = true, - jsr250Enabled = true + securedEnabled = true, + jsr250Enabled = true ) public class SecuirtyConfig { @@ -29,8 +29,9 @@ public class SecuirtyConfig { http .authorizeHttpRequests(auth -> auth .anyRequest().authenticated() - ) - .with(new OAuth2LoginConfigurer<>(), oauth2 -> oauth2.userInfoEndpoint(u -> u.oidcUserService(customOidcUserConfiguration))); + ).csrf(csrf -> csrf.disable()) + .with(new OAuth2LoginConfigurer<>(), + oauth2 -> oauth2.userInfoEndpoint(u -> u.oidcUserService(customOidcUserConfiguration))); return http.build(); diff --git a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java index 612fc78..902cb55 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java @@ -87,7 +87,7 @@ public class TunnelController implements ErrorController { return ResponseEntity.ok(jsonResponse); } -// 50df9101-f625-4618-b7c5-100338a57124 + // 50df9101-f625-4618-b7c5-100338a57124 @PreAuthorize("hasAnyRole('ADMIN')") @PutMapping("/tunnel/{tunnelId}/add") public ResponseEntity> addTunnelconfiguration(@PathVariable String tunnelId, @RequestBody Ingress ingress) throws JsonProcessingException { diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index c355d6f..febde77 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -1,4 +1,4 @@ -api.corsResolveUrl=http://localhost:8080 +api.baseUrl=http://localhost:8080 management.health.db.enabled=true management.endpoints.web.exposure.include=health diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 5126249..dec0f4b 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -1 +1 @@ -api.corsResolveUrl=https://cftunnels.hithomelabs.com \ No newline at end of file +api.baseUrl=https://cftunnels.hithomelabs.com \ No newline at end of file diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index 1ea328b..e5c014b 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -1 +1 @@ -api.corsResolveUrl=https://testcf.hithomelabs.com \ No newline at end of file +api.baseUrl=https://testcf.hithomelabs.com \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a0264d2..89201b8 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,6 +4,12 @@ cloudflare.apiKey=${CLOUDFLARE_API_KEY} cloudflare.email=${CLOUDFLARE_EMAIL} spring.profiles.active=${ENV} +# set root level +logging.level.root=INFO +# package-specific +logging.level.org.springframework=TRACE +logging.level.com.myapp=INFO + / * * Masking sure app works behind a reverse proxy server.forward-headers-strategy=framework -- 2.45.2 From 82244741ed57efa44c7637ba6a6efe2f67bc35d3 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sun, 26 Oct 2025 18:37:41 +0530 Subject: [PATCH 78/87] ISSUE-44: Hithomelabs/HomeLabDocker#44 Decoupling the controller and the service layer --- .../Services/CloudflareAPIService.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Services/CloudflareAPIService.java diff --git a/src/main/java/com/hithomelabs/CFTunnels/Services/CloudflareAPIService.java b/src/main/java/com/hithomelabs/CFTunnels/Services/CloudflareAPIService.java new file mode 100644 index 0000000..2e0d71c --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Services/CloudflareAPIService.java @@ -0,0 +1,61 @@ +package com.hithomelabs.CFTunnels.Services; + +import com.hithomelabs.CFTunnels.Config.CloudflareConfig; +import com.hithomelabs.CFTunnels.Headers.AuthKeyEmailHeader; +import com.hithomelabs.CFTunnels.Models.Config; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.*; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +import java.util.Map; + +@Service +public class CloudflareAPIService { + + @Autowired + CloudflareConfig cloudflareConfig; + + @Autowired + AuthKeyEmailHeader authKeyEmailHeader; + + @Autowired + RestTemplate restTemplate; + + public ResponseEntity getCloudflareTunnels() { + + // * * Resource URL to hit get request at + String url = "https://api.cloudflare.com/client/v4/accounts/" + cloudflareConfig.getAccountId() + "/cfd_tunnel"; + + HttpEntity httpEntity = new HttpEntity<>("", authKeyEmailHeader.getHttpHeaders()); + ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, Map.class); + return responseEntity; + } + + public ResponseEntity getCloudflareTunnelConfigurations(String tunnelId, RestTemplate restTemplate, Class responseType) { + + // * * Resource URL to hit get request at + String url = "https://api.cloudflare.com/client/v4/accounts/" + cloudflareConfig.getAccountId() + "/cfd_tunnel/" + tunnelId + "/configurations"; + + HttpEntity httpEntity = new HttpEntity<>("",authKeyEmailHeader.getHttpHeaders()); + ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, responseType); + return responseEntity; + } + + public ResponseEntity putCloudflareTunnelConfigurations(String tunnelId, RestTemplate restTemplate, Class responseType, Config config) { + + // * * Resource URL to hit get request at + String url = "https://api.cloudflare.com/client/v4/accounts/" + cloudflareConfig.getAccountId() + "/cfd_tunnel/" + tunnelId + "/configurations"; + + HttpHeaders httpHeaders = authKeyEmailHeader.getHttpHeaders(); + httpHeaders.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity<>(config, httpHeaders); + ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.PUT, entity, responseType); + return responseEntity; + } + + + + + +} -- 2.45.2 From 4c7f0dad4bcdc8c14ad8e47139dc631187e5a07d Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sun, 26 Oct 2025 18:49:18 +0530 Subject: [PATCH 79/87] ISSUE-44: Hithomelabs/HomeLabDocker#44 Adding mockMvc tests for web tier --- .gitignore | 2 + build.gradle | 3 + .../Controllers/TunnelController.java | 42 +-- .../CFTunnels/Models/TunnelResponse.java | 50 +--- .../Controllers/TunnelControllerTest.java | 271 ++++++++++++++++++ .../Services/CloudflareAPIServiceTest.java | 55 ++++ src/test/resources/docker-compose.yaml | 13 + 7 files changed, 364 insertions(+), 72 deletions(-) create mode 100644 src/test/java/com/hithomelabs/CFTunnels/Controllers/TunnelControllerTest.java create mode 100644 src/test/java/com/hithomelabs/CFTunnels/Services/CloudflareAPIServiceTest.java create mode 100644 src/test/resources/docker-compose.yaml diff --git a/.gitignore b/.gitignore index c2065bc..c47508c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ HELP.md .gradle +.run build/ +.env* !gradle/wrapper/gradle-wrapper.jar !**/src/main/**/build/ !**/src/test/**/build/ diff --git a/build.gradle b/build.gradle index 4340fce..4328386 100644 --- a/build.gradle +++ b/build.gradle @@ -24,8 +24,11 @@ repositories { dependencies { implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.8.5' implementation group: 'org.springframework.boot', name:'spring-boot-starter-oauth2-client', version: '3.5.5' + compileOnly 'org.projectlombok:lombok:1.18.30' + annotationProcessor 'org.projectlombok:lombok:1.18.30' implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.springframework.security:spring-security-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' runtimeOnly 'org.postgresql:postgresql' diff --git a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java index 902cb55..3362a83 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java @@ -8,6 +8,7 @@ import com.hithomelabs.CFTunnels.Headers.AuthKeyEmailHeader; import com.hithomelabs.CFTunnels.Models.Config; import com.hithomelabs.CFTunnels.Models.Ingress; import com.hithomelabs.CFTunnels.Models.TunnelResponse; +import com.hithomelabs.CFTunnels.Services.CloudflareAPIService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.http.*; @@ -40,6 +41,9 @@ public class TunnelController implements ErrorController { @Autowired private RestTemplateConfig restTemplateConfig; + @Autowired + CloudflareAPIService cloudflareAPIService; + @PreAuthorize("hasAnyRole('USER')") @GetMapping("/whoami") public Map whoAmI(@AuthenticationPrincipal OidcUser oidcUser) { @@ -57,12 +61,7 @@ public class TunnelController implements ErrorController { @GetMapping("/tunnels") public ResponseEntity> getTunnels(){ - // * * Resource URL to hit get request at - String url = "https://api.cloudflare.com/client/v4/accounts/" + cloudflareConfig.getAccountId() + "/cfd_tunnel"; - - HttpEntity httpEntity = new HttpEntity<>("",authKeyEmailHeader.getHttpHeaders()); - ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, Map.class); - + ResponseEntity responseEntity = cloudflareAPIService.getCloudflareTunnels(); Map jsonResponse = new HashMap<>(); jsonResponse.put("status", "success"); jsonResponse.put("data", responseEntity.getBody()); @@ -72,14 +71,9 @@ public class TunnelController implements ErrorController { @PreAuthorize("hasAnyRole('DEVELOPER')") @GetMapping("/tunnel/{tunnelId}") - public ResponseEntity> getTunnelConfigurations(@PathVariable String tunnelId) throws JsonProcessingException { - - // * * Resource URL to hit get request at - String url = "https://api.cloudflare.com/client/v4/accounts/" + cloudflareConfig.getAccountId() + "/cfd_tunnel/" + tunnelId + "/configurations"; - - HttpEntity httpEntity = new HttpEntity<>("",authKeyEmailHeader.getHttpHeaders()); - ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, Map.class); + public ResponseEntity> getTunnelConfigurations(@PathVariable String tunnelId) { + ResponseEntity responseEntity = cloudflareAPIService.getCloudflareTunnelConfigurations(tunnelId, restTemplate, Map.class); Map jsonResponse = new HashMap<>(); jsonResponse.put("status", "success"); jsonResponse.put("data", responseEntity.getBody()); @@ -92,12 +86,7 @@ public class TunnelController implements ErrorController { @PutMapping("/tunnel/{tunnelId}/add") public ResponseEntity> addTunnelconfiguration(@PathVariable String tunnelId, @RequestBody Ingress ingress) throws JsonProcessingException { - String url = "https://api.cloudflare.com/client/v4/accounts/" + cloudflareConfig.getAccountId() + "/cfd_tunnel/" + tunnelId + "/configurations"; - - // * * Getting existing public hostname mappings - HttpHeaders httpHeaders = authKeyEmailHeader.getHttpHeaders(); - HttpEntity httpEntity = new HttpEntity<>("",httpHeaders); - ResponseEntity responseEntity = restTemplateConfig.restTemplate().exchange(url, HttpMethod.GET, httpEntity, TunnelResponse.class); + ResponseEntity responseEntity = cloudflareAPIService.getCloudflareTunnelConfigurations(tunnelId, restTemplateConfig.restTemplate(), TunnelResponse.class); // * * Inserting new ingress value at second-to last position in list Config config = responseEntity.getBody().getResult().getConfig(); @@ -105,9 +94,7 @@ public class TunnelController implements ErrorController { response_ingress.add(response_ingress.size()-1, ingress); // * * Hitting put endpoint - httpHeaders.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity<>(config, httpHeaders); - ResponseEntity response = restTemplateConfig.restTemplate().exchange(url, HttpMethod.PUT, entity, Map.class); + ResponseEntity response = cloudflareAPIService.putCloudflareTunnelConfigurations(tunnelId, restTemplateConfig.restTemplate(), TunnelResponse.class, config); // * * Displaying response Map jsonResponse = new HashMap<>(); @@ -121,12 +108,7 @@ public class TunnelController implements ErrorController { @PutMapping("/tunnel/{tunnelId}/delete") public ResponseEntity> deleteTunnelConfiguration(@PathVariable String tunnelId, @RequestBody Ingress ingress) throws JsonProcessingException { - String url = "https://api.cloudflare.com/client/v4/accounts/" + cloudflareConfig.getAccountId() + "/cfd_tunnel/" + tunnelId + "/configurations"; - - // * * Getting existing public hostname mappings - HttpHeaders httpHeaders = authKeyEmailHeader.getHttpHeaders(); - HttpEntity httpEntity = new HttpEntity<>("",httpHeaders); - ResponseEntity responseEntity = restTemplateConfig.restTemplate().exchange(url, HttpMethod.GET, httpEntity, TunnelResponse.class); + ResponseEntity responseEntity = cloudflareAPIService.getCloudflareTunnelConfigurations(tunnelId, restTemplateConfig.restTemplate(), TunnelResponse.class); // * * Deleting the selected ingress value Config config = responseEntity.getBody().getResult().getConfig(); @@ -134,9 +116,7 @@ public class TunnelController implements ErrorController { Boolean result = Ingress.deleteByHostName(response_ingress, ingress.getHostname()); // * * Hitting put endpoint - httpHeaders.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity<>(config, httpHeaders); - ResponseEntity response = restTemplateConfig.restTemplate().exchange(url, HttpMethod.PUT, entity, Map.class); + ResponseEntity response = cloudflareAPIService.putCloudflareTunnelConfigurations(tunnelId, restTemplateConfig.restTemplate(), TunnelResponse.class, config); // * * Displaying response Map jsonResponse = new HashMap<>(); diff --git a/src/main/java/com/hithomelabs/CFTunnels/Models/TunnelResponse.java b/src/main/java/com/hithomelabs/CFTunnels/Models/TunnelResponse.java index e51a3d5..f5a4fb4 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Models/TunnelResponse.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Models/TunnelResponse.java @@ -1,8 +1,17 @@ package com.hithomelabs.CFTunnels.Models; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + import java.util.List; import java.util.Map; +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor public class TunnelResponse { private List> errors; @@ -12,45 +21,4 @@ public class TunnelResponse { private Boolean success; private Result result; - - public Result getResult() { - return result; - } - - public void setResult(Result result) { - this.result = result; - } - - public List> getErrors() { - return errors; - } - - public void setErrors(List> errors) { - this.errors = errors; - } - - public List> getMessages() { - return messages; - } - - public void setMessages(List> messages) { - this.messages = messages; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } - - public Boolean getSuccess() { - return success; - } - - public void setSuccess(Boolean success) { - this.success = success; - } - } diff --git a/src/test/java/com/hithomelabs/CFTunnels/Controllers/TunnelControllerTest.java b/src/test/java/com/hithomelabs/CFTunnels/Controllers/TunnelControllerTest.java new file mode 100644 index 0000000..ac85244 --- /dev/null +++ b/src/test/java/com/hithomelabs/CFTunnels/Controllers/TunnelControllerTest.java @@ -0,0 +1,271 @@ +package com.hithomelabs.CFTunnels.Controllers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.hithomelabs.CFTunnels.Config.AuthoritiesToGroupMapping; +import com.hithomelabs.CFTunnels.Config.CloudflareConfig; +import com.hithomelabs.CFTunnels.Config.RestTemplateConfig; +import com.hithomelabs.CFTunnels.Headers.AuthKeyEmailHeader; +import com.hithomelabs.CFTunnels.Models.Authorities; +import com.hithomelabs.CFTunnels.Models.Config; +import com.hithomelabs.CFTunnels.Models.Groups; +import com.hithomelabs.CFTunnels.Models.TunnelResponse; +import com.hithomelabs.CFTunnels.Services.CloudflareAPIService; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.http.*; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.oauth2.core.oidc.OidcIdToken; +import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser; +import org.springframework.test.context.bean.override.mockito.MockitoBean; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.web.client.RestTemplate; + +import java.time.Instant; +import java.util.*; + +import static org.hamcrest.core.IsIterableContaining.hasItem; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.oauth2Login; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.hamcrest.Matchers.not; + + +@WebMvcTest(TunnelController.class) +class TunnelControllerTest { + + @Autowired + MockMvc mockMvc; + + @MockitoBean + AuthoritiesToGroupMapping authoritiesToGroupMapping; + + @MockitoBean + CloudflareConfig cloudflareConfig; + + @MockitoBean + AuthKeyEmailHeader authKeyEmailHeader; + + @MockitoBean + RestTemplate restTemplate; + + @MockitoBean + CloudflareAPIService cloudflareAPIService; + + @MockitoBean + RestTemplateConfig restTemplateConfig; + + private static String withAdditionalIngress = """ + { + "success": true, + "errors": [], + "messages": [], + "result": { + "tunnel_id": "50df9101-f625-4618-b7c5-100338a57124", + "version": 63, + "config": { + "ingress": [ + { + "service": "http://192.168.0.100:8928", + "hostname": "giteabkp.hithomelabs.com", + "originRequest": {} + }, + { + "service": "https://192.168.0.100:9442", + "hostname": "devdocker.hithomelabs.com", + "originRequest": { + "noTLSVerify": true + } + }, + { + "service": "http://192.168.0.100:3457", + "hostname": "random.hithomelabs.com", + "originRequest": {} + }, + { + "service": "http_status:404" + } + ], + "warp-routing": { + "enabled": false + } + }, + "source": "cloudflare", + "created_at": "2025-10-24T18:17:26.914217Z" + } + } + """; + + private static final String withoutAdditionalIngress = """ + { + "success": true, + "errors": [], + "messages": [], + "result": { + "tunnel_id": "50df9101-f625-4618-b7c5-100338a57124", + "version": 63, + "config": { + "ingress": [ + { + "service": "http://192.168.0.100:8928", + "hostname": "giteabkp.hithomelabs.com", + "originRequest": {} + }, + { + "service": "https://192.168.0.100:9442", + "hostname": "devdocker.hithomelabs.com", + "originRequest": { + "noTLSVerify": true + } + }, + { + "service": "http_status:404" + } + ], + "warp-routing": { + "enabled": false + } + }, + "source": "cloudflare", + "created_at": "2025-10-24T18:17:26.914217Z" + } + } + """; + + private static final String ingressJson = """ + { + "service": "http://192.168.0.100:3457", + "hostname": "random.hithomelabs.com", + "originRequest": {} + } + """; + + private DefaultOidcUser buildOidcUser(String username, String role) { + + when(authoritiesToGroupMapping.getAuthorityForGroup()).thenReturn(Map.of(Groups.GITEA_USER, new HashSet<>(Set.of(new SimpleGrantedAuthority(Authorities.ROLE_USER))), + Groups.POWER_USER, new HashSet<>(Set.of(new SimpleGrantedAuthority(Authorities.ROLE_USER))), + Groups.HOMELAB_DEVELOPER, new HashSet<>(Set.of(new SimpleGrantedAuthority(Authorities.ROLE_DEVELOPER))), + Groups.SYSTEM_ADMIN, new HashSet<>(Set.of(new SimpleGrantedAuthority(Authorities.ROLE_APPROVER), new SimpleGrantedAuthority(Authorities.ROLE_ADMIN))))); + + Map> roleAuthorityMapping = authoritiesToGroupMapping.getAuthorityForGroup(); + List authorities = roleAuthorityMapping.get(role).stream().toList(); + + OidcIdToken idToken = new OidcIdToken( + "mock-token", + Instant.now(), + Instant.now().plusSeconds(3600), + Map.of("preferred_username", username, "sub", username) + ); + + return new DefaultOidcUser(authorities, idToken, "preferred_username"); + } + + @Test + @DisplayName("should return appropriate user roles when use belongs to group GITEA_USER") + public void testWhoAmI_user() throws Exception { + mockMvc.perform(get("/cloudflare/whoami") + .with(oauth2Login().oauth2User(buildOidcUser("username", Groups.GITEA_USER)))) + .andExpect(status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$.username").value("username")) + .andExpect(jsonPath("$.roles", hasItem("ROLE_USER"))); + } + + @Test + @DisplayName("should hit tunnels endpoint successfully with ROLE_USER") + public void testGetTunnelsForRoleUser() throws Exception { + + when(cloudflareConfig.getAccountId()).thenReturn("abc123"); + HttpHeaders headers = new HttpHeaders(); + headers.set("X-Auth-Email", "me@example.com"); + when(authKeyEmailHeader.getHttpHeaders()).thenReturn(headers); + + Map tunnelData = Map.of("tunnels", List.of(Map.of("id", "50df9101-f625-4618-b7c5-100338a57124"))); + ResponseEntity mockResponse = new ResponseEntity<>(tunnelData, HttpStatus.OK); + + when(cloudflareAPIService.getCloudflareTunnels()).thenReturn(mockResponse); + + mockMvc.perform(get("/cloudflare/tunnels") + .with(oauth2Login().oauth2User(buildOidcUser("username", Groups.GITEA_USER)))) + .andExpect(status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$.data.tunnels[0].id").value("50df9101-f625-4618-b7c5-100338a57124")); + + } + + @Test + void getTunnelConfigurations() throws Exception { + + Map tunnelData = Map.of("config", Map.of("result", "success", "ingress", "sample ingress object")); + ResponseEntity mockResponse = new ResponseEntity<>(tunnelData, HttpStatus.OK); + + when(cloudflareAPIService.getCloudflareTunnelConfigurations(eq("sampleTunnelId"), any(RestTemplate.class), eq(Map.class))).thenReturn(mockResponse); + + mockMvc.perform(get("/cloudflare/tunnel/{tunnelId}", "sampleTunnelId") + .with(oauth2Login().oauth2User(buildOidcUser("username", Groups.HOMELAB_DEVELOPER)))) + .andExpect(status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$.data.config.ingress").value("sample ingress object")); + } + + @Test + void addTunnelconfiguration() throws Exception { + + when(restTemplateConfig.restTemplate()).thenReturn(new RestTemplate()); + + ObjectMapper mapper = new ObjectMapper(); + TunnelResponse tunnelStateBefore = mapper.readValue(withoutAdditionalIngress, TunnelResponse.class); + ResponseEntity tunnelResponseBefore = new ResponseEntity<>(tunnelStateBefore, HttpStatus.OK); + + when(cloudflareAPIService.getCloudflareTunnelConfigurations(eq("sampleTunnelId"), any(RestTemplate.class), eq(TunnelResponse.class))).thenReturn(tunnelResponseBefore); + + TunnelResponse expectedTunnelConfig = mapper.readValue(withAdditionalIngress, TunnelResponse.class); + ResponseEntity expectedHttpTunnelResponse = new ResponseEntity<>(expectedTunnelConfig, HttpStatus.OK); + when(cloudflareAPIService.putCloudflareTunnelConfigurations(eq("sampleTunnelId"), any(RestTemplate.class), eq(TunnelResponse.class), any(Config.class))).thenReturn(expectedHttpTunnelResponse); + + mockMvc.perform(put("/cloudflare/tunnel/{tunnelId}/add", "sampleTunnelId") + .with(oauth2Login().oauth2User(buildOidcUser("admin", Groups.SYSTEM_ADMIN))) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(ingressJson)) + .andExpect(status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$.data.result.config.ingress[*].hostname", hasItem("random.hithomelabs.com"))); + } + + @Test + void deleteTunnelConfiguration() throws Exception { + + when(restTemplateConfig.restTemplate()).thenReturn(new RestTemplate()); + + ObjectMapper mapper = new ObjectMapper(); + TunnelResponse tunnelStateBefore = mapper.readValue(withAdditionalIngress, TunnelResponse.class); + ResponseEntity tunnelResponseBefore = new ResponseEntity<>(tunnelStateBefore, HttpStatus.OK); + + when(cloudflareAPIService.getCloudflareTunnelConfigurations(eq("sampleTunnelId"), any(RestTemplate.class), eq(TunnelResponse.class))).thenReturn(tunnelResponseBefore); + + TunnelResponse expectedTunnelConfig = mapper.readValue(withoutAdditionalIngress, TunnelResponse.class); + ResponseEntity expectedHttpTunnelResponse = new ResponseEntity<>(expectedTunnelConfig, HttpStatus.OK); + when(cloudflareAPIService.putCloudflareTunnelConfigurations(eq("sampleTunnelId"), any(RestTemplate.class), eq(TunnelResponse.class), any(Config.class))).thenReturn(expectedHttpTunnelResponse); + + mockMvc.perform(put("/cloudflare/tunnel/{tunnelId}/delete", "sampleTunnelId") + .with(oauth2Login().oauth2User(buildOidcUser("admin", Groups.SYSTEM_ADMIN))) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(ingressJson)) + .andExpect(status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$.data.result.config.ingress[*].hostname", not(hasItem("random.hithomelabs.com")))); + } + + +} diff --git a/src/test/java/com/hithomelabs/CFTunnels/Services/CloudflareAPIServiceTest.java b/src/test/java/com/hithomelabs/CFTunnels/Services/CloudflareAPIServiceTest.java new file mode 100644 index 0000000..dbafc60 --- /dev/null +++ b/src/test/java/com/hithomelabs/CFTunnels/Services/CloudflareAPIServiceTest.java @@ -0,0 +1,55 @@ +package com.hithomelabs.CFTunnels.Services; + +import com.hithomelabs.CFTunnels.Config.CloudflareConfig; +import com.hithomelabs.CFTunnels.Headers.AuthKeyEmailHeader; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.*; +import org.springframework.web.client.RestTemplate; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class CloudflareAPIServiceTest { + + @InjectMocks + private CloudflareAPIService cloudflareAPIService; + + @Mock + AuthKeyEmailHeader authKeyEmailHeader; + + @Mock + private RestTemplate restTemplate; + + @Mock + CloudflareConfig cloudflareConfig; + + @Test + void testGetCloudflareTunnels() { + + when(cloudflareConfig.getAccountId()).thenReturn("account-123"); + when(authKeyEmailHeader.getHttpHeaders()).thenReturn(new HttpHeaders()); + Map mockBody = Map.of("tunnels", List.of(Map.of("id", "t1"))); + ResponseEntity mockResponse = new ResponseEntity<>(mockBody, HttpStatus.OK); + + when(restTemplate.exchange( + any(String.class), + eq(HttpMethod.GET), + any(HttpEntity.class), + eq(Map.class) + )).thenReturn(mockResponse); + + ResponseEntity response = cloudflareAPIService.getCloudflareTunnels(); + assertEquals(HttpStatus.OK, response.getStatusCode()); + } + + + } \ No newline at end of file diff --git a/src/test/resources/docker-compose.yaml b/src/test/resources/docker-compose.yaml new file mode 100644 index 0000000..27068c8 --- /dev/null +++ b/src/test/resources/docker-compose.yaml @@ -0,0 +1,13 @@ +services: + postgres: + image: postgres:15-alpine + container_name: cftunnel-db-${ENV} + environment: + POSTGRES_DB: cftunnel + POSTGRES_USER: ${POSTGRES_USERNAME} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + restart: unless-stopped + ports: + - "${DB_PORT}:5432" + volumes: + - ${DB_PATH}:/var/lib/postgresql/data \ No newline at end of file -- 2.45.2 From 5ea76dab56c4bdc334b272813efafa6934db2b5d Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Sun, 26 Oct 2025 20:30:01 +0530 Subject: [PATCH 80/87] ISSUE-44: Hithomelabs/HomeLabDocker#44 Adding unit tests for service layer --- .../Controllers/TunnelControllerTest.java | 98 +++++-------------- .../Services/CloudflareAPIServiceTest.java | 64 +++++++++++- .../hithomelabs/CFTunnels/TestUtils/Util.java | 17 ++++ .../data/tunnelResponseLargeIngress.json | 38 +++++++ .../data/tunnelResponseSmallIngress.json | 33 +++++++ 5 files changed, 174 insertions(+), 76 deletions(-) create mode 100644 src/test/java/com/hithomelabs/CFTunnels/TestUtils/Util.java create mode 100644 src/test/resources/data/tunnelResponseLargeIngress.json create mode 100644 src/test/resources/data/tunnelResponseSmallIngress.json diff --git a/src/test/java/com/hithomelabs/CFTunnels/Controllers/TunnelControllerTest.java b/src/test/java/com/hithomelabs/CFTunnels/Controllers/TunnelControllerTest.java index ac85244..644288e 100644 --- a/src/test/java/com/hithomelabs/CFTunnels/Controllers/TunnelControllerTest.java +++ b/src/test/java/com/hithomelabs/CFTunnels/Controllers/TunnelControllerTest.java @@ -24,9 +24,11 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import org.springframework.web.client.RestTemplate; +import java.io.IOException; import java.time.Instant; import java.util.*; +import static com.hithomelabs.CFTunnels.TestUtils.Util.getClassPathDataResource; import static org.hamcrest.core.IsIterableContaining.hasItem; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -64,82 +66,28 @@ class TunnelControllerTest { @MockitoBean RestTemplateConfig restTemplateConfig; - private static String withAdditionalIngress = """ - { - "success": true, - "errors": [], - "messages": [], - "result": { - "tunnel_id": "50df9101-f625-4618-b7c5-100338a57124", - "version": 63, - "config": { - "ingress": [ - { - "service": "http://192.168.0.100:8928", - "hostname": "giteabkp.hithomelabs.com", - "originRequest": {} - }, - { - "service": "https://192.168.0.100:9442", - "hostname": "devdocker.hithomelabs.com", - "originRequest": { - "noTLSVerify": true - } - }, - { - "service": "http://192.168.0.100:3457", - "hostname": "random.hithomelabs.com", - "originRequest": {} - }, - { - "service": "http_status:404" - } - ], - "warp-routing": { - "enabled": false - } - }, - "source": "cloudflare", - "created_at": "2025-10-24T18:17:26.914217Z" - } - } - """; + private static final String tunnelResponseSmallIngressFile = "tunnelResponseSmallIngress.json"; - private static final String withoutAdditionalIngress = """ - { - "success": true, - "errors": [], - "messages": [], - "result": { - "tunnel_id": "50df9101-f625-4618-b7c5-100338a57124", - "version": 63, - "config": { - "ingress": [ - { - "service": "http://192.168.0.100:8928", - "hostname": "giteabkp.hithomelabs.com", - "originRequest": {} - }, - { - "service": "https://192.168.0.100:9442", - "hostname": "devdocker.hithomelabs.com", - "originRequest": { - "noTLSVerify": true - } - }, - { - "service": "http_status:404" - } - ], - "warp-routing": { - "enabled": false - } - }, - "source": "cloudflare", - "created_at": "2025-10-24T18:17:26.914217Z" - } - } - """; + private static final String tunnelResponseLargeIngressFile = "tunnelResponseLargeIngress.json"; + + private static final String withAdditionalIngress; + + static { + try { + withAdditionalIngress = getClassPathDataResource(tunnelResponseLargeIngressFile); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static final String withoutAdditionalIngress; + static { + try { + withoutAdditionalIngress = getClassPathDataResource(tunnelResponseSmallIngressFile); + } catch (IOException e) { + throw new RuntimeException(e); + } + } private static final String ingressJson = """ { diff --git a/src/test/java/com/hithomelabs/CFTunnels/Services/CloudflareAPIServiceTest.java b/src/test/java/com/hithomelabs/CFTunnels/Services/CloudflareAPIServiceTest.java index dbafc60..03374e5 100644 --- a/src/test/java/com/hithomelabs/CFTunnels/Services/CloudflareAPIServiceTest.java +++ b/src/test/java/com/hithomelabs/CFTunnels/Services/CloudflareAPIServiceTest.java @@ -1,7 +1,11 @@ package com.hithomelabs.CFTunnels.Services; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.hithomelabs.CFTunnels.Config.CloudflareConfig; import com.hithomelabs.CFTunnels.Headers.AuthKeyEmailHeader; +import com.hithomelabs.CFTunnels.Models.Config; +import com.hithomelabs.CFTunnels.Models.TunnelResponse; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -9,9 +13,12 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.*; import org.springframework.web.client.RestTemplate; + +import java.io.IOException; import java.util.List; import java.util.Map; +import static com.hithomelabs.CFTunnels.TestUtils.Util.getClassPathDataResource; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -32,6 +39,18 @@ class CloudflareAPIServiceTest { @Mock CloudflareConfig cloudflareConfig; + private static final String tunnelResponseLargeIngressFile = "tunnelResponseLargeIngress.json"; + + private static final String bigTunnelResponse; + + static { + try { + bigTunnelResponse = getClassPathDataResource(tunnelResponseLargeIngressFile); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + @Test void testGetCloudflareTunnels() { @@ -52,4 +71,47 @@ class CloudflareAPIServiceTest { } - } \ No newline at end of file + @Test + void getCloudflareTunnelConfigurations() throws JsonProcessingException { + + when(cloudflareConfig.getAccountId()).thenReturn("account-123"); + when(authKeyEmailHeader.getHttpHeaders()).thenReturn(new HttpHeaders()); + + TunnelResponse tunnelResponse = new ObjectMapper().readValue(bigTunnelResponse, TunnelResponse.class); + ResponseEntity tunnelResponseResponseEntity = new ResponseEntity<>(tunnelResponse, HttpStatus.OK); + + when(restTemplate.exchange( + any(String.class), + eq(HttpMethod.GET), + any(HttpEntity.class), + eq(TunnelResponse.class) + )).thenReturn(tunnelResponseResponseEntity); + + ResponseEntity response = cloudflareAPIService.getCloudflareTunnelConfigurations("sampleTunnelID", restTemplate, TunnelResponse.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(response.getBody().getResult().getConfig().getIngress().get(0).getHostname(), "giteabkp.hithomelabs.com"); + } + + @Test + void putCloudflareTunnelConfigurations() throws JsonProcessingException { + + when(cloudflareConfig.getAccountId()).thenReturn("account-123"); + when(authKeyEmailHeader.getHttpHeaders()).thenReturn(new HttpHeaders()); + + TunnelResponse tunnelResponse = new ObjectMapper().readValue(bigTunnelResponse, TunnelResponse.class); + ResponseEntity tunnelResponseResponseEntity = new ResponseEntity<>(tunnelResponse, HttpStatus.OK); + + Config config = tunnelResponse.getResult().getConfig(); + + when(restTemplate.exchange( + any(String.class), + eq(HttpMethod.PUT), + any(HttpEntity.class), + eq(TunnelResponse.class) + )).thenReturn(tunnelResponseResponseEntity); + + ResponseEntity response = cloudflareAPIService.putCloudflareTunnelConfigurations("sampleTunnelID", restTemplate, TunnelResponse.class, config); + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(response.getBody().getResult().getConfig().getIngress().get(2).getHostname(), "random.hithomelabs.com"); + } +} \ No newline at end of file diff --git a/src/test/java/com/hithomelabs/CFTunnels/TestUtils/Util.java b/src/test/java/com/hithomelabs/CFTunnels/TestUtils/Util.java new file mode 100644 index 0000000..a5f8c36 --- /dev/null +++ b/src/test/java/com/hithomelabs/CFTunnels/TestUtils/Util.java @@ -0,0 +1,17 @@ +package com.hithomelabs.CFTunnels.TestUtils; + +import org.springframework.core.io.ClassPathResource; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; + +public class Util { + + public static String getClassPathDataResource(String filename) throws IOException { + return Files.readString( + new ClassPathResource(String.format("data/%s", filename)).getFile().toPath(), + StandardCharsets.UTF_8); + } + +} diff --git a/src/test/resources/data/tunnelResponseLargeIngress.json b/src/test/resources/data/tunnelResponseLargeIngress.json new file mode 100644 index 0000000..e24b930 --- /dev/null +++ b/src/test/resources/data/tunnelResponseLargeIngress.json @@ -0,0 +1,38 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "tunnel_id": "50df9101-f625-4618-b7c5-100338a57124", + "version": 63, + "config": { + "ingress": [ + { + "service": "http://192.168.0.100:8928", + "hostname": "giteabkp.hithomelabs.com", + "originRequest": {} + }, + { + "service": "https://192.168.0.100:9442", + "hostname": "devdocker.hithomelabs.com", + "originRequest": { + "noTLSVerify": true + } + }, + { + "service": "http://192.168.0.100:3457", + "hostname": "random.hithomelabs.com", + "originRequest": {} + }, + { + "service": "http_status:404" + } + ], + "warp-routing": { + "enabled": false + } + }, + "source": "cloudflare", + "created_at": "2025-10-24T18:17:26.914217Z" + } +} \ No newline at end of file diff --git a/src/test/resources/data/tunnelResponseSmallIngress.json b/src/test/resources/data/tunnelResponseSmallIngress.json new file mode 100644 index 0000000..9e840f0 --- /dev/null +++ b/src/test/resources/data/tunnelResponseSmallIngress.json @@ -0,0 +1,33 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "tunnel_id": "50df9101-f625-4618-b7c5-100338a57124", + "version": 63, + "config": { + "ingress": [ + { + "service": "http://192.168.0.100:8928", + "hostname": "giteabkp.hithomelabs.com", + "originRequest": {} + }, + { + "service": "https://192.168.0.100:9442", + "hostname": "devdocker.hithomelabs.com", + "originRequest": { + "noTLSVerify": true + } + }, + { + "service": "http_status:404" + } + ], + "warp-routing": { + "enabled": false + } + }, + "source": "cloudflare", + "created_at": "2025-10-24T18:17:26.914217Z" + } +} \ No newline at end of file -- 2.45.2 From a40865e98965904d0ca55bfa311c2f42516e0314 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sun, 4 Jan 2026 23:25:48 +0530 Subject: [PATCH 81/87] db integration --- .../Config/CustomOidcUserConfiguration.java | 15 +++++ .../Controllers/TunnelController.java | 24 ++++++- .../hithomelabs/CFTunnels/Entity/Mapping.java | 34 ++++++++++ .../hithomelabs/CFTunnels/Entity/Request.java | 45 +++++++++++++ .../hithomelabs/CFTunnels/Entity/Tunnel.java | 29 ++++++++ .../hithomelabs/CFTunnels/Entity/User.java | 30 +++++++++ .../hithomelabs/CFTunnels/Models/Ingress.java | 10 +++ .../Repositories/MappingRepository.java | 11 ++++ .../Repositories/RequestRepository.java | 11 ++++ .../Repositories/TunnelRepository.java | 13 ++++ .../Repositories/UserRepository.java | 14 ++++ .../Services/MappingRequestService.java | 53 +++++++++++++++ src/main/resources/schema.sql | 66 ++++++++----------- 13 files changed, 315 insertions(+), 40 deletions(-) create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Entity/Mapping.java create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Entity/Request.java create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Entity/Tunnel.java create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Entity/User.java create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Repositories/MappingRepository.java create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Repositories/RequestRepository.java create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Repositories/TunnelRepository.java create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Repositories/UserRepository.java create mode 100644 src/main/java/com/hithomelabs/CFTunnels/Services/MappingRequestService.java diff --git a/src/main/java/com/hithomelabs/CFTunnels/Config/CustomOidcUserConfiguration.java b/src/main/java/com/hithomelabs/CFTunnels/Config/CustomOidcUserConfiguration.java index 22a4e64..1d06c78 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Config/CustomOidcUserConfiguration.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Config/CustomOidcUserConfiguration.java @@ -1,5 +1,7 @@ package com.hithomelabs.CFTunnels.Config; +import com.hithomelabs.CFTunnels.Entity.User; +import com.hithomelabs.CFTunnels.Repositories.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.security.core.GrantedAuthority; @@ -18,6 +20,9 @@ public class CustomOidcUserConfiguration extends OidcUserService { @Autowired AuthoritiesToGroupMapping authoritiesToGroupMapping; + @Autowired + UserRepository userRepository; + @Override public OidcUser loadUser(OidcUserRequest userRequest) { // * * Delegate to the default implementation for loading user and claims @@ -34,6 +39,16 @@ public class CustomOidcUserConfiguration extends OidcUserService { ); } + String email = oidcUser.getEmail(); + String name = oidcUser.getNickName(); + + userRepository.findByEmail(email).orElseGet(() -> { + User user = new User(); + user.setEmail(email); + user.setName(name); + return userRepository.save(user); + }); + // * * Return a new DefaultOidcUser with merged authorities return new DefaultOidcUser( mappedAuthorities, diff --git a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java index 3362a83..8956177 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java @@ -4,24 +4,26 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.hithomelabs.CFTunnels.Config.AuthoritiesToGroupMapping; import com.hithomelabs.CFTunnels.Config.CloudflareConfig; import com.hithomelabs.CFTunnels.Config.RestTemplateConfig; +import com.hithomelabs.CFTunnels.Entity.User; import com.hithomelabs.CFTunnels.Headers.AuthKeyEmailHeader; import com.hithomelabs.CFTunnels.Models.Config; import com.hithomelabs.CFTunnels.Models.Ingress; import com.hithomelabs.CFTunnels.Models.TunnelResponse; +import com.hithomelabs.CFTunnels.Repositories.UserRepository; import com.hithomelabs.CFTunnels.Services.CloudflareAPIService; +import com.hithomelabs.CFTunnels.Services.MappingRequestService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.http.*; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.oauth2.core.oidc.user.OidcUser; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; @RestController @RequestMapping("/cloudflare") @@ -44,6 +46,12 @@ public class TunnelController implements ErrorController { @Autowired CloudflareAPIService cloudflareAPIService; + @Autowired + UserRepository userRepository; + + @Autowired + MappingRequestService mappingRequestService; + @PreAuthorize("hasAnyRole('USER')") @GetMapping("/whoami") public Map whoAmI(@AuthenticationPrincipal OidcUser oidcUser) { @@ -132,4 +140,14 @@ public class TunnelController implements ErrorController { return ResponseEntity.ok(jsonResponse); } + + @PreAuthorize("hasAnyRole('DEVELOPER')") + @PutMapping("/tunnel/{tunnelId}/request") + public ResponseEntity createTunnelMappingRequest(@PathVariable UUID tunnelId, @AuthenticationPrincipal OidcUser oidcUser, @RequestBody Ingress ingess){ + String email = oidcUser.getEmail(); + User user = userRepository.findByEmail(email).orElseThrow(() -> new RuntimeException("User Not Found: " + email)); + mappingRequestService.createMappingRequest(tunnelId, ingess, user); + return ResponseEntity.ok(ingess); + } + } diff --git a/src/main/java/com/hithomelabs/CFTunnels/Entity/Mapping.java b/src/main/java/com/hithomelabs/CFTunnels/Entity/Mapping.java new file mode 100644 index 0000000..0081205 --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Entity/Mapping.java @@ -0,0 +1,34 @@ +package com.hithomelabs.CFTunnels.Entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + + +import java.util.UUID; + +@Entity +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "mappings") +public class Mapping { + + @Id + @GeneratedValue + @Column(columnDefinition = "uuid", nullable = false, unique = true) + private UUID id; + + @Column(nullable = false) + private int port; + + @Column(length = 50, nullable = false) + private String subdomain; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "tunnel_id", nullable = false) + private Tunnel tunnel; +} diff --git a/src/main/java/com/hithomelabs/CFTunnels/Entity/Request.java b/src/main/java/com/hithomelabs/CFTunnels/Entity/Request.java new file mode 100644 index 0000000..8d73de8 --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Entity/Request.java @@ -0,0 +1,45 @@ +package com.hithomelabs.CFTunnels.Entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.UUID; + +@Entity +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "requests") +public class Request { + + @Id + @GeneratedValue + @Column(columnDefinition = "uuid", unique = true, nullable = false) + private UUID id; + + @OneToOne + @JoinColumn(name = "mapping_id", unique = true, nullable = false) + private Mapping mapping; + + @ManyToOne + @JoinColumn(name = "created_by", nullable = false) + private User createdBy; + + @ManyToOne + @JoinColumn(name = "accepted_by") + private User acceptedBy; + + public enum RequestStatus { + PENDING, + APPROVED, + REJECTED + } + + @Enumerated(EnumType.STRING) + @Column(length = 10, nullable = false) + private RequestStatus status; +} diff --git a/src/main/java/com/hithomelabs/CFTunnels/Entity/Tunnel.java b/src/main/java/com/hithomelabs/CFTunnels/Entity/Tunnel.java new file mode 100644 index 0000000..9c56663 --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Entity/Tunnel.java @@ -0,0 +1,29 @@ +package com.hithomelabs.CFTunnels.Entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.UUID; + +@Entity +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Table(name="tunnels") +public class Tunnel { + + @Id + @GeneratedValue + @Column(columnDefinition = "uuid", insertable = false, updatable = false, nullable = false) + private UUID id; + + @Column(length = 10, unique = true, nullable = false) + private String environment; + + @Column(name = "cf_tunnel_id", columnDefinition = "uuid", unique = true, nullable = false) + private UUID cfTunnelId; +} diff --git a/src/main/java/com/hithomelabs/CFTunnels/Entity/User.java b/src/main/java/com/hithomelabs/CFTunnels/Entity/User.java new file mode 100644 index 0000000..5783357 --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Entity/User.java @@ -0,0 +1,30 @@ +package com.hithomelabs.CFTunnels.Entity; +import jakarta.persistence.*; +import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.UUID; + +@Entity +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "users") +public class User { + @Id + @GeneratedValue + @Column(columnDefinition = "uuid", insertable = false, updatable = false, nullable = false) + private UUID id; + + @Column(length = 50, nullable = false) + @Size(max = 50) + private String name; + + @Column(length = 50, nullable = false) + @Size(max = 50) + private String email; +} diff --git a/src/main/java/com/hithomelabs/CFTunnels/Models/Ingress.java b/src/main/java/com/hithomelabs/CFTunnels/Models/Ingress.java index 7c6c7be..11bfc88 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Models/Ingress.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Models/Ingress.java @@ -1,5 +1,6 @@ package com.hithomelabs.CFTunnels.Models; +import java.net.URI; import java.util.List; import java.util.Map; @@ -46,4 +47,13 @@ public class Ingress { public void setOriginRequest(Map originRequest) { this.originRequest = originRequest; } + + public int getPort(){ + URI url = URI.create(this.service); + return url.getPort(); + } + + public String getSubdomain(){ + return this.hostname.split("//")[0]; + } } diff --git a/src/main/java/com/hithomelabs/CFTunnels/Repositories/MappingRepository.java b/src/main/java/com/hithomelabs/CFTunnels/Repositories/MappingRepository.java new file mode 100644 index 0000000..73b469c --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Repositories/MappingRepository.java @@ -0,0 +1,11 @@ +package com.hithomelabs.CFTunnels.Repositories; + +import com.hithomelabs.CFTunnels.Entity.Mapping; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.UUID; + +@Repository +public interface MappingRepository extends JpaRepository { +} diff --git a/src/main/java/com/hithomelabs/CFTunnels/Repositories/RequestRepository.java b/src/main/java/com/hithomelabs/CFTunnels/Repositories/RequestRepository.java new file mode 100644 index 0000000..fe79625 --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Repositories/RequestRepository.java @@ -0,0 +1,11 @@ +package com.hithomelabs.CFTunnels.Repositories; + +import com.hithomelabs.CFTunnels.Entity.Request; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.UUID; + +@Repository +public interface RequestRepository extends JpaRepository { +} diff --git a/src/main/java/com/hithomelabs/CFTunnels/Repositories/TunnelRepository.java b/src/main/java/com/hithomelabs/CFTunnels/Repositories/TunnelRepository.java new file mode 100644 index 0000000..178f44e --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Repositories/TunnelRepository.java @@ -0,0 +1,13 @@ +package com.hithomelabs.CFTunnels.Repositories; + +import com.hithomelabs.CFTunnels.Entity.Tunnel; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; +import java.util.UUID; + +@Repository +public interface TunnelRepository extends JpaRepository { + Optional findByCfTunnelId(UUID cfTunnelId); +} diff --git a/src/main/java/com/hithomelabs/CFTunnels/Repositories/UserRepository.java b/src/main/java/com/hithomelabs/CFTunnels/Repositories/UserRepository.java new file mode 100644 index 0000000..a1038a7 --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Repositories/UserRepository.java @@ -0,0 +1,14 @@ +package com.hithomelabs.CFTunnels.Repositories; + +import com.hithomelabs.CFTunnels.Entity.User; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; +import java.util.UUID; + +@Repository +public interface UserRepository extends JpaRepository { + + Optional findByEmail(String email); +} diff --git a/src/main/java/com/hithomelabs/CFTunnels/Services/MappingRequestService.java b/src/main/java/com/hithomelabs/CFTunnels/Services/MappingRequestService.java new file mode 100644 index 0000000..65893c1 --- /dev/null +++ b/src/main/java/com/hithomelabs/CFTunnels/Services/MappingRequestService.java @@ -0,0 +1,53 @@ +package com.hithomelabs.CFTunnels.Services; + +import com.hithomelabs.CFTunnels.Entity.Mapping; +import com.hithomelabs.CFTunnels.Entity.Request; +import com.hithomelabs.CFTunnels.Entity.Tunnel; +import com.hithomelabs.CFTunnels.Entity.User; +import com.hithomelabs.CFTunnels.Models.Ingress; +import com.hithomelabs.CFTunnels.Repositories.MappingRepository; +import com.hithomelabs.CFTunnels.Repositories.RequestRepository; +import com.hithomelabs.CFTunnels.Repositories.TunnelRepository; +import com.hithomelabs.CFTunnels.Repositories.UserRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.UUID; + +@Service +public class MappingRequestService { + + @Autowired + UserRepository userRepository; + + @Autowired + MappingRepository mappingRepository; + + @Autowired + RequestRepository requestRepository; + + @Autowired + TunnelRepository tunnelRepository; + + public Mapping createMapping(UUID tunnelId, Ingress ingress){ + Tunnel tunnel = tunnelRepository.findByCfTunnelId(tunnelId).orElseThrow(() -> new RuntimeException("Tunnel not found")); + Mapping mapping = new Mapping(); + mapping.setTunnel(tunnel); + mapping.setPort(ingress.getPort()); + mapping.setSubdomain(ingress.getSubdomain()); + return mappingRepository.save(mapping); + } + + public Request createRequest(Mapping mapping, User user){ + Request request = new Request(); + request.setMapping(mapping); + request.setCreatedBy(user); + request.setStatus(Request.RequestStatus.PENDING); + return requestRepository.save(request); + } + + public Request createMappingRequest(UUID tunnelId, Ingress ingress, User user){ + Mapping mapping = createMapping(tunnelId, ingress); + return createRequest(mapping, user); + } +} diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 1fa876d..4ff5844 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -1,37 +1,29 @@ --- schema.sql - --- Roles table -CREATE TABLE IF NOT EXISTS roles ( - role_id SERIAL PRIMARY KEY, - role_name VARCHAR(50) UNIQUE NOT NULL -); - --- Users table -CREATE TABLE IF NOT EXISTS users ( - user_id SERIAL PRIMARY KEY, - user_name VARCHAR(100) NOT NULL, - password VARCHAR(255) NOT NULL -); - --- User-Role Mapping table (many-to-many relationship) -CREATE TABLE IF NOT EXISTS user_role_mapping ( - mapping_id SERIAL PRIMARY KEY, - user_id INTEGER NOT NULL REFERENCES users(user_id) ON DELETE CASCADE, - role_id INTEGER NOT NULL REFERENCES roles(role_id) ON DELETE CASCADE -); - --- Tunnels table -CREATE TABLE IF NOT EXISTS tunnels ( - tunnel_id SERIAL PRIMARY KEY, - tunnel_name VARCHAR(100) NOT NULL, - tunnel_type VARCHAR(50) NOT NULL -); - --- Mapping Requests table -CREATE TABLE IF NOT EXISTS mapping_requests ( - request_id SERIAL PRIMARY KEY, - request_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - status VARCHAR(20) NOT NULL, - user_id INTEGER REFERENCES users(user_id) ON DELETE SET NULL, - tunnel_id INTEGER REFERENCES tunnels(tunnel_id) ON DELETE SET NULL -); +--CREATE EXTENSION IF NOT EXISTS "pgcrypto"; +-- +--CREATE TABLE IF NOT EXISTS tunnels ( +-- id UUID PRIMARY KEY DEFAULT gen_random_uuid(), +-- environment VARCHAR(10) NOT NULL, +-- cf_tunnel_id UUID UNIQUE NOT NULL +--); +-- +--CREATE TABLE IF NOT EXISTS users ( +-- id UUID PRIMARY KEY DEFAULT gen_random_uuid(), +-- name VARCHAR(50) NOT NULL +--); +-- +--CREATE TABLE IF NOT EXISTS mappings ( +-- id UUID PRIMARY KEY DEFAULT gen_random_uuid(), +-- tunnel_id UUID NOT NULL REFERENCES tunnels(id) ON DELETE CASCADE, +-- port INT NOT NULL, +-- subdomain VARCHAR(50) NOT NULL +---- UNIQUE (tunnel_id, port), +---- UNIQUE (tunnel_id, subdomain) +--); +-- +--CREATE TABLE IF NOT EXISTS requests ( +-- id UUID PRIMARY KEY DEFAULT gen_random_uuid(), +-- mapping_id UUID NOT NULL REFERENCES mappings(id) ON DELETE CASCADE, +-- created_by UUID NOT NULL REFERENCES users(id) ON DELETE RESTRICT, +-- accepted_by UUID REFERENCES users(id) ON DELETE SET NULL, +-- status VARCHAR(20) NOT NULL CHECK (status IN ('PENDING', 'APPROVED', 'REJECTED')) +--); \ No newline at end of file -- 2.45.2 From ccfe79f7f126535b671e64ba4fdb405910aaa8d8 Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Mon, 12 Jan 2026 23:34:05 +0530 Subject: [PATCH 82/87] ISSUE-33: added user flow to create mapping from tunnel ingress --- .../Config/CustomOidcUserConfiguration.java | 13 -------- .../Controllers/TunnelController.java | 13 ++++---- .../hithomelabs/CFTunnels/Models/Ingress.java | 9 ------ .../Services/MappingRequestService.java | 30 +++++++++++++++---- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/hithomelabs/CFTunnels/Config/CustomOidcUserConfiguration.java b/src/main/java/com/hithomelabs/CFTunnels/Config/CustomOidcUserConfiguration.java index 1d06c78..ef077b9 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Config/CustomOidcUserConfiguration.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Config/CustomOidcUserConfiguration.java @@ -20,9 +20,6 @@ public class CustomOidcUserConfiguration extends OidcUserService { @Autowired AuthoritiesToGroupMapping authoritiesToGroupMapping; - @Autowired - UserRepository userRepository; - @Override public OidcUser loadUser(OidcUserRequest userRequest) { // * * Delegate to the default implementation for loading user and claims @@ -39,16 +36,6 @@ public class CustomOidcUserConfiguration extends OidcUserService { ); } - String email = oidcUser.getEmail(); - String name = oidcUser.getNickName(); - - userRepository.findByEmail(email).orElseGet(() -> { - User user = new User(); - user.setEmail(email); - user.setName(name); - return userRepository.save(user); - }); - // * * Return a new DefaultOidcUser with merged authorities return new DefaultOidcUser( mappedAuthorities, diff --git a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java index 8956177..c36fd5b 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.hithomelabs.CFTunnels.Config.AuthoritiesToGroupMapping; import com.hithomelabs.CFTunnels.Config.CloudflareConfig; import com.hithomelabs.CFTunnels.Config.RestTemplateConfig; +import com.hithomelabs.CFTunnels.Entity.Request; import com.hithomelabs.CFTunnels.Entity.User; import com.hithomelabs.CFTunnels.Headers.AuthKeyEmailHeader; import com.hithomelabs.CFTunnels.Models.Config; @@ -141,13 +142,13 @@ public class TunnelController implements ErrorController { return ResponseEntity.ok(jsonResponse); } - @PreAuthorize("hasAnyRole('DEVELOPER')") +// @PreAuthorize("hasAnyRole('DEVELOPER')") @PutMapping("/tunnel/{tunnelId}/request") - public ResponseEntity createTunnelMappingRequest(@PathVariable UUID tunnelId, @AuthenticationPrincipal OidcUser oidcUser, @RequestBody Ingress ingess){ - String email = oidcUser.getEmail(); - User user = userRepository.findByEmail(email).orElseThrow(() -> new RuntimeException("User Not Found: " + email)); - mappingRequestService.createMappingRequest(tunnelId, ingess, user); - return ResponseEntity.ok(ingess); + public ResponseEntity createTunnelMappingRequest(@PathVariable String tunnelId, @AuthenticationPrincipal OidcUser oidcUser, @RequestBody Ingress ingess){ + Request request = mappingRequestService.createMappingRequest(tunnelId, ingess, oidcUser); + if(request.getId() != null) + return ResponseEntity.status(HttpStatus.CREATED).body(request); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).build(); } } diff --git a/src/main/java/com/hithomelabs/CFTunnels/Models/Ingress.java b/src/main/java/com/hithomelabs/CFTunnels/Models/Ingress.java index 11bfc88..0cf84bb 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Models/Ingress.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Models/Ingress.java @@ -47,13 +47,4 @@ public class Ingress { public void setOriginRequest(Map originRequest) { this.originRequest = originRequest; } - - public int getPort(){ - URI url = URI.create(this.service); - return url.getPort(); - } - - public String getSubdomain(){ - return this.hostname.split("//")[0]; - } } diff --git a/src/main/java/com/hithomelabs/CFTunnels/Services/MappingRequestService.java b/src/main/java/com/hithomelabs/CFTunnels/Services/MappingRequestService.java index 65893c1..d026f65 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Services/MappingRequestService.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Services/MappingRequestService.java @@ -10,8 +10,10 @@ import com.hithomelabs.CFTunnels.Repositories.RequestRepository; import com.hithomelabs.CFTunnels.Repositories.TunnelRepository; import com.hithomelabs.CFTunnels.Repositories.UserRepository; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.oauth2.core.oidc.user.OidcUser; import org.springframework.stereotype.Service; +import java.util.Map; import java.util.UUID; @Service @@ -31,10 +33,7 @@ public class MappingRequestService { public Mapping createMapping(UUID tunnelId, Ingress ingress){ Tunnel tunnel = tunnelRepository.findByCfTunnelId(tunnelId).orElseThrow(() -> new RuntimeException("Tunnel not found")); - Mapping mapping = new Mapping(); - mapping.setTunnel(tunnel); - mapping.setPort(ingress.getPort()); - mapping.setSubdomain(ingress.getSubdomain()); + Mapping mapping = createMappingFromTunnelIngress(tunnel, ingress); return mappingRepository.save(mapping); } @@ -46,8 +45,27 @@ public class MappingRequestService { return requestRepository.save(request); } - public Request createMappingRequest(UUID tunnelId, Ingress ingress, User user){ - Mapping mapping = createMapping(tunnelId, ingress); + public Request createMappingRequest(String tunnelId, Ingress ingress, OidcUser oidcUser){ + User user = userRepository.findByEmail(oidcUser.getEmail()).orElseGet(()-> mapUser(oidcUser)); + Mapping mapping = createMapping(UUID.fromString(tunnelId), ingress); return createRequest(mapping, user); } + + public User mapUser(OidcUser oidcUser){ + String email = oidcUser.getEmail(); + String name = oidcUser.getNickName(); + User user = new User(); + user.setEmail(email); + user.setName(name); + userRepository.save(user); + return user; + } + + public Mapping createMappingFromTunnelIngress(Tunnel tunnel, Ingress ingress){ + Mapping mapping = new Mapping(); + mapping.setTunnel(tunnel); + mapping.setPort(Integer.parseInt(ingress.getService().split(":")[2])); + mapping.setSubdomain(ingress.getHostname().split("\\.")[0]); + return mapping; + } } -- 2.45.2 From 6047471ff85860f63a12248a5f43f27b79278af0 Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Tue, 13 Jan 2026 00:37:15 +0530 Subject: [PATCH 83/87] Schema.sql uncommenting to attempt to fix breaking build --- src/main/resources/schema.sql | 58 +++++++++++++++++------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 4ff5844..368b406 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -1,29 +1,29 @@ ---CREATE EXTENSION IF NOT EXISTS "pgcrypto"; --- ---CREATE TABLE IF NOT EXISTS tunnels ( --- id UUID PRIMARY KEY DEFAULT gen_random_uuid(), --- environment VARCHAR(10) NOT NULL, --- cf_tunnel_id UUID UNIQUE NOT NULL ---); --- ---CREATE TABLE IF NOT EXISTS users ( --- id UUID PRIMARY KEY DEFAULT gen_random_uuid(), --- name VARCHAR(50) NOT NULL ---); --- ---CREATE TABLE IF NOT EXISTS mappings ( --- id UUID PRIMARY KEY DEFAULT gen_random_uuid(), --- tunnel_id UUID NOT NULL REFERENCES tunnels(id) ON DELETE CASCADE, --- port INT NOT NULL, --- subdomain VARCHAR(50) NOT NULL ----- UNIQUE (tunnel_id, port), ----- UNIQUE (tunnel_id, subdomain) ---); --- ---CREATE TABLE IF NOT EXISTS requests ( --- id UUID PRIMARY KEY DEFAULT gen_random_uuid(), --- mapping_id UUID NOT NULL REFERENCES mappings(id) ON DELETE CASCADE, --- created_by UUID NOT NULL REFERENCES users(id) ON DELETE RESTRICT, --- accepted_by UUID REFERENCES users(id) ON DELETE SET NULL, --- status VARCHAR(20) NOT NULL CHECK (status IN ('PENDING', 'APPROVED', 'REJECTED')) ---); \ No newline at end of file +CREATE EXTENSION IF NOT EXISTS "pgcrypto"; + +CREATE TABLE IF NOT EXISTS tunnels ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + environment VARCHAR(10) NOT NULL, + cf_tunnel_id UUID UNIQUE NOT NULL +); + +CREATE TABLE IF NOT EXISTS users ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + name VARCHAR(50) NOT NULL +); + +CREATE TABLE IF NOT EXISTS mappings ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + tunnel_id UUID NOT NULL REFERENCES tunnels(id) ON DELETE CASCADE, + port INT NOT NULL, + subdomain VARCHAR(50) NOT NULL +-- UNIQUE (tunnel_id, port), +-- UNIQUE (tunnel_id, subdomain) +); + +CREATE TABLE IF NOT EXISTS requests ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + mapping_id UUID NOT NULL REFERENCES mappings(id) ON DELETE CASCADE, + created_by UUID NOT NULL REFERENCES users(id) ON DELETE RESTRICT, + accepted_by UUID REFERENCES users(id) ON DELETE SET NULL, + status VARCHAR(20) NOT NULL CHECK (status IN ('PENDING', 'APPROVED', 'REJECTED')) +); \ No newline at end of file -- 2.45.2 From 02dc401224eb36f04a252508f7944118f998a633 Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Tue, 13 Jan 2026 00:47:03 +0530 Subject: [PATCH 84/87] Hibernate ddl set to none to fix the breaking test build issue --- src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a0264d2..a150ff9 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -24,7 +24,7 @@ spring.datasource.password=${POSTGRES_PASSWORD} spring.datasource.driver-class-name=org.postgresql.Driver spring.sql.init.mode=never -spring.jpa.hibernate.ddl-auto=update +spring.jpa.hibernate.ddl-auto=none spring.jpa.show-sql=true spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect -- 2.45.2 From 9817d77e7fd2736cfe7f15e2ba8d6ffe3ad70330 Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Tue, 13 Jan 2026 00:56:06 +0530 Subject: [PATCH 85/87] H2 database integrated for testing profile --- src/main/resources/application-test.properties | 8 +++++++- src/main/resources/application.properties | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index e5c014b..a0ccff7 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -1 +1,7 @@ -api.baseUrl=https://testcf.hithomelabs.com \ No newline at end of file +api.baseUrl=https://testcf.hithomelabs.com + +spring.datasource.url: jdbc:h2:mem:testdb +spring.datasource.driver-class-name: org.h2.Driver +spring.datasource.username: sa +spring.datasource.password: +spring.datasource.jpa.hibernate.ddl-auto: none \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a150ff9..a0264d2 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -24,7 +24,7 @@ spring.datasource.password=${POSTGRES_PASSWORD} spring.datasource.driver-class-name=org.postgresql.Driver spring.sql.init.mode=never -spring.jpa.hibernate.ddl-auto=none +spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect -- 2.45.2 From 1f892e449f12007db8f4c2d21d485beaf642a3b1 Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Tue, 13 Jan 2026 01:03:11 +0530 Subject: [PATCH 86/87] H2 dependency added in build.gradle --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 0800341..90dc143 100644 --- a/build.gradle +++ b/build.gradle @@ -54,6 +54,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' runtimeOnly 'org.postgresql:postgresql' implementation 'org.hibernate.validator:hibernate-validator' + runtimeOnly 'com.h2database:h2' } tasks.named('test') { -- 2.45.2 From 28b003a066e9609b9f1bbb7ffca376f982db6abc Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Wed, 14 Jan 2026 22:50:48 +0530 Subject: [PATCH 87/87] Mapping added in test controller to fix the breaking test --- .../hithomelabs/CFTunnels/Controllers/TunnelController.java | 4 ---- .../CFTunnels/Controllers/TunnelControllerTest.java | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java index e3ab203..53fb4f9 100644 --- a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java +++ b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java @@ -9,7 +9,6 @@ import com.hithomelabs.CFTunnels.Headers.AuthKeyEmailHeader; import com.hithomelabs.CFTunnels.Models.Config; import com.hithomelabs.CFTunnels.Models.Ingress; import com.hithomelabs.CFTunnels.Models.TunnelResponse; -import com.hithomelabs.CFTunnels.Repositories.UserRepository; import com.hithomelabs.CFTunnels.Services.CloudflareAPIService; import com.hithomelabs.CFTunnels.Services.MappingRequestService; import org.springframework.beans.factory.annotation.Autowired; @@ -47,9 +46,6 @@ public class TunnelController implements ErrorController { @Autowired CloudflareAPIService cloudflareAPIService; - @Autowired - UserRepository userRepository; - @Autowired MappingRequestService mappingRequestService; diff --git a/src/test/java/com/hithomelabs/CFTunnels/Controllers/TunnelControllerTest.java b/src/test/java/com/hithomelabs/CFTunnels/Controllers/TunnelControllerTest.java index 644288e..ff7d303 100644 --- a/src/test/java/com/hithomelabs/CFTunnels/Controllers/TunnelControllerTest.java +++ b/src/test/java/com/hithomelabs/CFTunnels/Controllers/TunnelControllerTest.java @@ -10,6 +10,7 @@ import com.hithomelabs.CFTunnels.Models.Config; import com.hithomelabs.CFTunnels.Models.Groups; import com.hithomelabs.CFTunnels.Models.TunnelResponse; import com.hithomelabs.CFTunnels.Services.CloudflareAPIService; +import com.hithomelabs.CFTunnels.Services.MappingRequestService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -66,6 +67,9 @@ class TunnelControllerTest { @MockitoBean RestTemplateConfig restTemplateConfig; + @MockitoBean + MappingRequestService mappingRequestService; + private static final String tunnelResponseSmallIngressFile = "tunnelResponseSmallIngress.json"; private static final String tunnelResponseLargeIngressFile = "tunnelResponseLargeIngress.json"; -- 2.45.2