-
Notifications
You must be signed in to change notification settings - Fork 30
Implement /health and /version endpoints for Admin API #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Suraj-kumar00
wants to merge
4
commits into
PSMRI:main
Choose a base branch
from
Suraj-kumar00:contributor/suraj
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e71943a
Implement /health and /version endpoints for Admin API
Suraj-kumar00 50bbaa0
fix: changes for /health and /version endpoints
Suraj-kumar00 a373482
changes for /health and /version.
Suraj-kumar00 bded299
fix: remove sensitive database metadata from health endpoint
Suraj-kumar00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/com/iemr/admin/config/SecurityFilterConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.iemr.admin.config; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import com.iemr.admin.utils.JwtAuthenticationUtil; | ||
import com.iemr.admin.utils.JwtUserIdValidationFilter; | ||
|
||
@Configuration | ||
public class SecurityFilterConfig { | ||
|
||
@Autowired | ||
private JwtAuthenticationUtil jwtAuthenticationUtil; | ||
|
||
@Value("${cors.allowed-origins}") | ||
private String allowedOrigins; | ||
|
||
@Bean | ||
public FilterRegistrationBean<JwtUserIdValidationFilter> jwtFilterRegistration() { | ||
FilterRegistrationBean<JwtUserIdValidationFilter> registration = new FilterRegistrationBean<>(); | ||
registration.setFilter(new JwtUserIdValidationFilter(jwtAuthenticationUtil, allowedOrigins)); | ||
registration.addUrlPatterns("/*"); | ||
registration.setOrder(1); | ||
|
||
// Set name for easier debugging | ||
registration.setName("JwtUserIdValidationFilter"); | ||
|
||
return registration; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/iemr/admin/controller/health/HealthController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* AMRIT – Accessible Medical Records via Integrated Technology | ||
* Integrated EHR (Electronic Health Records) Solution | ||
* | ||
* Copyright (C) "Piramal Swasthya Management and Research Institute" | ||
* | ||
* This file is part of AMRIT. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see https://www.gnu.org/licenses/. | ||
*/ | ||
package com.iemr.admin.controller.health; | ||
|
||
import java.util.Map; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.iemr.admin.service.health.HealthService; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
|
||
@RestController | ||
public class HealthController { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(HealthController.class); | ||
|
||
@Autowired | ||
private HealthService healthService; | ||
|
||
@Operation(summary = "Health check endpoint") | ||
@GetMapping("/health") | ||
public ResponseEntity<Map<String, Object>> health() { | ||
logger.info("Health check endpoint called"); | ||
|
||
Map<String, Object> healthStatus = healthService.checkHealth(); | ||
|
||
// Return 503 if any service is down, 200 if all are up | ||
String status = (String) healthStatus.get("status"); | ||
HttpStatus httpStatus = "UP".equals(status) ? HttpStatus.OK : HttpStatus.SERVICE_UNAVAILABLE; | ||
|
||
logger.info("Health check completed with status: {}", status); | ||
return ResponseEntity.status(httpStatus).body(healthStatus); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can move the logic (like reading Git properties and building the JSON) into a separate service method instead of writing everything inside the controller. Also, let’s review all the suggestions given by CodeRabbit once again. One of the points to check is the use of StringBuilder, as it might cause issues in some cases.