-
Notifications
You must be signed in to change notification settings - Fork 43
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
Audit Log Service - /v1/events endpoint implementation #540
Conversation
dhanyak-btc
commented
Jun 22, 2020
•
edited
Loading
edited
- Moved HealthController class to common-service module
- Used everit-org JSON Schema validator (Apache 2.0 license) for event request validation.
- Used JSoup (MIT license) to extract the error response details from RestClientResponseException thrown by tomcat server
- Added Spring Boot Actuator to view the log file when deployed to DEV/QA environment and the mapping details. This will help during deployment and while integrating the APIs.
- Implemented /v1/events endpoint
- Added token introspection filter and common exception handler for filters in common-service.
Moved filters and health controller to common-service, added actuator, added JSoup to extract error message from Html etc
convert xpath to json path
minor refactoring and removed unused getEncodedAuthorization() from BaseServiceImpl
Added getUriTemplateAndHttpMethodsMap() abstract method to BaseTokenIntrospectionFilter
Removed unused method: getEventInfo() from AuditLogEventEntity
...va/com/google/cloud/healthcare/fdamystudies/auditlog/controller/AuditLogEventController.java
Outdated
Show resolved
Hide resolved
...java/com/google/cloud/healthcare/fdamystudies/auditlog/validator/AuditLogEventValidator.java
Outdated
Show resolved
Hide resolved
"properties": { | ||
"alert": { | ||
"type": "boolean" | ||
}, |
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.
what is alert
used for? and why is it required.
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.
This stores the value of Alert flag. I'll request Shanthala to connect with you to discuss on Audit Log Event fields & requirements.
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.
This file no longer in use. Replaced json schema with validation annotations.
audit-log-module/audit-log-service/src/main/resources/audit-log-event-schema.json
Outdated
Show resolved
Hide resolved
audit-log-module/audit-log-service/src/main/resources/audit-log-event-schema.json
Outdated
Show resolved
Hide resolved
audit-log-module/audit-log-service/src/main/resources/application-local.properties
Outdated
Show resolved
Hide resolved
.../src/main/java/com/google/cloud/healthcare/fdamystudies/filter/TokenIntrospectionFilter.java
Outdated
Show resolved
Hide resolved
.../src/main/java/com/google/cloud/healthcare/fdamystudies/filter/TokenIntrospectionFilter.java
Outdated
Show resolved
Hide resolved
audit-log-module/audit-log-service/audit-log-service.postman_collection.json
Outdated
Show resolved
Hide resolved
.../java/com/google/cloud/healthcare/fdamystudies/auditlog/filter/TokenIntrospectionFilter.java
Show resolved
Hide resolved
Fixed PR#540 comments
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.
This PR could've been split into OAuth code, followed by AuditLog code, to make it easier to review.
...java/com/google/cloud/healthcare/fdamystudies/auditlog/validator/AuditLogEventValidator.java
Outdated
Show resolved
Hide resolved
...ain/java/com/google/cloud/healthcare/fdamystudies/auditlog/service/AuditLogEventService.java
Outdated
Show resolved
Hide resolved
...java/com/google/cloud/healthcare/fdamystudies/auditlog/service/AuditLogEventServiceImpl.java
Outdated
Show resolved
Hide resolved
...c/main/java/com/google/cloud/healthcare/fdamystudies/auditlog/model/AuditLogEventEntity.java
Outdated
Show resolved
Hide resolved
...c/main/java/com/google/cloud/healthcare/fdamystudies/auditlog/model/AuditLogEventEntity.java
Outdated
Show resolved
Hide resolved
.../main/java/com/google/cloud/healthcare/fdamystudies/filter/BaseTokenIntrospectionFilter.java
Outdated
Show resolved
Hide resolved
...c/main/java/com/google/cloud/healthcare/fdamystudies/filter/FilterChainExceptionHandler.java
Show resolved
Hide resolved
ErrorResponse err = new ErrorResponse(url, e); | ||
return ResponseEntity.status(e.getRawStatusCode()).body(err); | ||
} | ||
return restTemplate.exchange(url, method, requestEntity, JsonNode.class, uriVariables); |
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.
avoid wrapping one-liners.
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.
I agree with you. Initially this method had try..catch block but now exception handling moved to RestExceptionHandler
and FilterChainExceptionHandler
so this method became one-liners.
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.
In that case that mean you don't need BaseServiceImpl anymore. The AuditLogEventService isn't doing anything with the methods anyways.
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.
I agree with you, but I've already implemented the Service classes using these methods. We'll keep this class.
...-service/src/main/java/com/google/cloud/healthcare/fdamystudies/service/BaseServiceImpl.java
Show resolved
Hide resolved
...vice/src/main/java/com/google/cloud/healthcare/fdamystudies/controller/HealthController.java
Outdated
Show resolved
Hide resolved
Fixed PR review comments
...vice/src/main/java/com/google/cloud/healthcare/fdamystudies/common/RestExceptionHandler.java
Outdated
Show resolved
Hide resolved
Removed JSoup, Json Schema validator dependencies. Added server-side validation using validation annotations, Added ErrorController, GlobalExceptionHandler, ValidationErrorResponse and AuditLogEventRequest to common-service module Added jsonassert dependency to assert json values.
Added logger statements to GlobalExceptionHandler
Moved AuditLogEventResponse to common-service module
Deleted postman collection
Added @ToString.Exclude to entity class
Removed params from logger.entry
audit-log-module/audit-log-service/src/main/resources/application-local.properties
Outdated
Show resolved
Hide resolved
Fixes #551 |
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.
Looks good. Just a few small things.
.../main/java/com/google/cloud/healthcare/fdamystudies/auditlog/mapper/AuditLogEventMapper.java
Outdated
Show resolved
Hide resolved
...om/google/cloud/healthcare/fdamystudies/auditlog/controller/AuditLogEventControllerTest.java
Show resolved
Hide resolved
...rc/main/java/com/google/cloud/healthcare/fdamystudies/exceptions/GlobalExceptionHandler.java
Outdated
Show resolved
Hide resolved
...rc/main/java/com/google/cloud/healthcare/fdamystudies/exceptions/GlobalExceptionHandler.java
Outdated
Show resolved
Hide resolved
Fixed Imports and Removed beans, request/response from logger statements
Changed the column definition to TIMESTAMP for eventTimestamp and createdTimestamp in AuditLogEventEntity class. Added javdocs to eventTimestamp in AuditLogEventRequest
Removed @SuppressWarnings("rawtypes") Changed log level to trace in handleConstraintValidationException() method
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.
Looks good, added some suggestions; some need to be addressed at some point but nothing immediately concerning.
insertable = false, | ||
updatable = false, | ||
columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") | ||
private Timestamp createdTimestamp; |
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.
Google API guideline suggests calling these timestamp columns simply:
created, modified etc
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.
This link has different naming convention. Please share the Google API guideline link to refer. Renamed both column and property name to 'created', it'll be pushed for review in next PR.
nullable = false, | ||
updatable = false, | ||
columnDefinition = "TIMESTAMP") | ||
private Timestamp eventTimestamp; |
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.
could be renamed to occured
maybe?
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.
Renamed both column and property name to 'occured', it'll be pushed for review in next PR.
|
||
class ApplicationTest extends BaseMockIT { | ||
|
||
@Autowired HealthController controller; | ||
@Autowired AuditLogEventController controller; |
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.
please add back the healthcheck test as well. It should assert that the response status is 200
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.
I've added assertNotNull(healthController);
in this Test. There is already a HealthControllerTest that assert response status is 200. This will be pushed for review in next PR.
"status=%d and response=%s", | ||
healthResponse.getStatusCodeValue(), healthResponse.getBody())); | ||
return healthResponse; | ||
return oauthService.health(); |
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.
why is this method calling oauthservice.health()?
Ideally it should just return a 200 status.
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.
I referred Monitoring Microservices With Health Checks, all services in our project requires token introspection so added downstream services in /healthCheck endpoint. I've changed to code to returns always OK. This will be pushed for review in next PR. Thanks a lot for approving the PR #540.
@@ -0,0 +1,18 @@ | |||
{ | |||
"request": { |
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.
nit: indentation should probably be 2 spaces to be consistent with other files.