diff --git a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java
index 33c4d07..cb77525 100644
--- a/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java
+++ b/src/main/java/com/hithomelabs/CFTunnels/Controllers/TunnelController.java
@@ -22,7 +22,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.dao.DataAccessException;
import org.springframework.http.*;
-import org.springframework.http.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
@@ -36,6 +35,41 @@ import java.util.Map;
import java.util.NoSuchElementException;
import java.util.UUID;
+/**
+ * REST Controller for managing Cloudflare Tunnels.
+ *
+ *
This controller provides the public API for managing Cloudflare Tunnels
+ * and their ingress mappings. All endpoints require authentication via OIDC
+ * and are protected by role-based access control.
+ *
+ * Base URL: {@code /cloudflare}
+ *
+ * Authentication: OIDC-based with role-based access
+ *
+ * Available Roles:
+ *
+ * - USER - View tunnels and requests
+ * - DEVELOPER - Create/modify/delete mappings
+ * - APPROVER - Approve/reject requests
+ * - ADMIN - Full tunnel configuration access
+ *
+ *
+ * Example Usage:
+ *
+ * # Get all tunnels (requires USER role)
+ * curl -H "Authorization: Bearer <token>" \
+ * https://api.example.com/cloudflare/tunnels
+ *
+ * # Add a mapping (requires ADMIN role)
+ * curl -X POST -H "Authorization: Bearer <token>" \
+ * -H "Content-Type: application/json" \
+ * -d '{"hostname":"api.example.com","service":"http://localhost:8080"}' \
+ * https://api.example.com/cloudflare/tunnels/{tunnelId}/mappings
+ *
+ *
+ * @see CloudflareAPIService
+ * @see MappingRequestService
+ */
@RestController
@RequestMapping("/cloudflare")
public class TunnelController implements ErrorController {
@@ -63,9 +97,23 @@ public class TunnelController implements ErrorController {
@Autowired
private UserRepository userRepository;
+ /**
+ * Current environment (loaded from spring.profiles.active).
+ */
@Value("${spring.profiles.active}")
private String environment;
+ /**
+ * Get current user information.
+ *
+ * Returns the authenticated user's username and roles.
+ *
+ * @param oidcUser The authenticated OIDC user
+ * @return Map containing username and roles
+ *
+ * @security Requires USER role
+ * @response 200 OK
+ */
@PreAuthorize("hasAnyRole('USER')")
@GetMapping("/whoami")
public Map whoAmI(@AuthenticationPrincipal OidcUser oidcUser) {
@@ -79,6 +127,19 @@ public class TunnelController implements ErrorController {
);
}
+ /**
+ * Get all tunnels from Cloudflare API.
+ *
+ * Fetches the complete list of tunnels from Cloudflare,
+ * including their status and configuration from the Cloudflare API.
+ *
+ * @return Map containing list of all tunnels
+ *
+ * @security Requires USER role
+ * @response 200 OK with tunnel list
+ * @response 500 Internal Server Error if API call fails
+ * @see Cloudflare API
+ */
@PreAuthorize("hasAnyRole('USER')")
@GetMapping("/tunnels")
@Operation( security = { @SecurityRequirement(name = "oidcAuth") } )
@@ -92,6 +153,19 @@ public class TunnelController implements ErrorController {
return ResponseEntity.ok(jsonResponse);
}
+ /**
+ * Get locally configured tunnels.
+ *
+ * Returns the tunnels that have been configured locally
+ * with environment associations.
+ *
+ * @return Map containing list of configured tunnels
+ *
+ * @security Requires USER role
+ * @response 200 OK with tunnel list
+ * @response 500 Internal Server Error if database access fails
+ * @see CloudflareAPIService#getAllConfiguredTunnels()
+ */
@PreAuthorize("hasAnyRole('USER')")
@GetMapping("/configured/tunnels")
public ResponseEntity