-
Notifications
You must be signed in to change notification settings - Fork 53
Refactor michelle #114
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
base: main
Are you sure you want to change the base?
Refactor michelle #114
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,18 @@ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| FROM eclipse-temurin:21-jdk-alpine AS build | ||||||||||||||||||||||||||||
| WORKDIR /app | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| COPY .mvn/ .mvn | ||||||||||||||||||||||||||||
| COPY mvnw pom.xml ./ | ||||||||||||||||||||||||||||
| RUN ./mvnw dependency:go-offline | ||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maven wrapper will fail: Per the cross-file context, 🛠️ Suggested fix COPY .mvn/ .mvn
COPY mvnw pom.xml ./
+RUN chmod +x mvnw
RUN ./mvnw dependency:go-offlineAlso commit 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| COPY src ./src | ||||||||||||||||||||||||||||
| RUN ./mvnw clean package -DskipTests | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| FROM eclipse-temurin:21-jre-alpine | ||||||||||||||||||||||||||||
| WORKDIR /app | ||||||||||||||||||||||||||||
| COPY --from=build /app/target/*.jar app.jar | ||||||||||||||||||||||||||||
| EXPOSE 8080 | ||||||||||||||||||||||||||||
| ENTRYPOINT ["java", "-jar", "app.jar"] | ||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Run as a non-root user and narrow the JAR copy glob. Trivy DS-0002: no 🔒 Suggested fix FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
-COPY --from=build /app/target/*.jar app.jar
+RUN addgroup -S app && adduser -S app -G app
+COPY --from=build /app/target/*.jar app.jar
+RUN chown app:app app.jar
+USER app
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| services: | ||
| db: | ||
| image: mysql:8.0 | ||
| container_name: libraryman-db | ||
| environment: | ||
| MYSQL_DATABASE: libraryman | ||
| MYSQL_ROOT_PASSWORD: root | ||
| ports: | ||
| - "3306:3306" | ||
|
Comment on lines
+5
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded root credentials and DB port exposed on host.
🔧 Suggested adjustment db:
image: mysql:8.0
container_name: libraryman-db
environment:
MYSQL_DATABASE: libraryman
- MYSQL_ROOT_PASSWORD: root
- ports:
- - "3306:3306"
+ MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
+ MYSQL_USER: ${MYSQL_USER}
+ MYSQL_PASSWORD: ${MYSQL_PASSWORD}
+ expose:
+ - "3306"
+ volumes:
+ - db-data:/var/lib/mysqland add at the bottom: volumes:
db-data:🤖 Prompt for AI Agents |
||
| healthcheck: | ||
| test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] | ||
| timeout: 20s | ||
| retries: 10 | ||
|
|
||
| api: | ||
| build: . | ||
| container_name: libraryman-api-staging | ||
| ports: | ||
| - "8080:8080" | ||
| depends_on: | ||
| db: | ||
| condition: service_healthy | ||
| environment: | ||
| - SPRING_DATASOURCE_URL=jdbc:mysql://db:3306/libraryman | ||
| - SPRING_DATASOURCE_USERNAME=root | ||
| - SPRING_DATASOURCE_PASSWORD=root | ||
|
Comment on lines
+24
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. App should not connect as MySQL
🤖 Prompt for AI Agents |
||
| - SPRING_MAIL_HOST=localhost | ||
| - SPRING_MAIL_PORT=25 | ||
| - SPRING_MAIL_PROPERTIES_MAIL_SMTP_AUTH=false | ||
| - SPRING_MAIL_PROPERTIES_MAIL_SMTP_STARTTLS_ENABLE=false | ||
| - SPRING_MAIL_PROPERTIES_DOMAIN_NAME=libraryman.com | ||
| # DISABLE OAUTH2 FEATURES COMPLETELY | ||
| - SPRING_SECURITY_OAUTH2_CLIENT_ENABLED=false | ||
| - SPRING_SECURITY_OAUTH2_RESOURCESERVER_ENABLED=false | ||
| # PROVIDE A DUMMY REGISTRATION JUST IN CASE THE BEAN SCANNER STILL LOOKS | ||
| - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GOOGLE_CLIENT_ID=dummy | ||
| - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GOOGLE_CLIENT_SECRET=dummy | ||
|
Comment on lines
+32
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: No, there is no Spring Boot property spring.security.oauth2.client.enabled that disables the OAuth2 client auto-configuration. The correct mechanism is to use spring.autoconfigure.exclude (or the exclude attribute on Citations:
🏁 Script executed: # Search for WebConfiguration file
fd -i WebConfiguration
# Search for oauth2Login references
rg "oauth2Login" -i --type javaRepository: ajaynegi45/LibraryMan-API Length of output: 252 🏁 Script executed: # Check docker-compose.yml full content
cat -n docker-compose.yml | head -60
# Search for SPRING_AUTOCONFIGURE_EXCLUDE usage
rg "SPRING_AUTOCONFIGURE_EXCLUDE|spring.autoconfigure.exclude" -iRepository: ajaynegi45/LibraryMan-API Length of output: 1563 Remove dummy OAuth2 credentials; use SPRING_AUTOCONFIGURE_EXCLUDE to properly disable OAuth2 auto-configuration. The Alternatively, define a Spring profile that excludes 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,10 @@ | |
| * This controller provides endpoints for performing CRUD operations on books, | ||
| * including retrieving all books, getting a book by its ID, adding a new book, | ||
| * updating an existing book, and deleting a book. | ||
| * * Version: 1.1 | ||
| */ | ||
| @RestController | ||
| @RequestMapping("/api") | ||
| @RequestMapping("/api/v1/books") //Versioning API path -> provide more context | ||
|
Comment on lines
22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Find references to old BookController paths anywhere in the repo.
rg -nP '/api/(get-all-books|get-book-by-id|add-book|update-book|delete-book|book/search)' -C1
# Find MockMvc or test usages of book endpoints.
rg -nP --type=java -C2 '(perform|get|post|put|delete)\s*\(\s*"[^"]*(book|api)[^"]*"'
# Check MemberController base path for cross-controller consistency.
rg -nP --type=java -C1 '@RequestMapping\('Repository: ajaynegi45/LibraryMan-API Length of output: 2183 🏁 Script executed: # Check what methods exist in BookController now
rg -A 30 '@RestController' src/main/java/com/libraryman_api/book/BookController.java | head -50
# Verify WebConfiguration is actually using those old paths
cat src/main/java/com/libraryman_api/security/config/WebConfiguration.java | grep -A 2 -B 2 '/api/get-all-books\|/api/book/search'
# Check if there are any other references to the old /api paths for books
rg -i '/api/(add-book|get-book|update-book|delete-book)' --type=javaRepository: ajaynegi45/LibraryMan-API Length of output: 2023 🏁 Script executed: # Check if there are test files for BookController
find . -name "*BookControllerTest*" -o -name "*BookTest*" | grep -i test
# Check the README or API documentation for endpoint references
rg -i 'api/.*book' README.md OpenAPI* docs* 2>/dev/null || echo "No docs found matching pattern"
# See the full WebConfiguration to understand the impact
cat src/main/java/com/libraryman_api/security/config/WebConfiguration.javaRepository: ajaynegi45/LibraryMan-API Length of output: 4313 🏁 Script executed: # Check if WebConfiguration has been updated to permit the new /api/v1/books paths
rg '/api/v1' src/main/java/com/libraryman_api/security/config/WebConfiguration.java
# List all endpoints in BookController to understand the full scope of the breaking change
rg -B 1 '@(GetMapping|PostMapping|PutMapping|DeleteMapping|PatchMapping)' src/main/java/com/libraryman_api/book/BookController.java | head -40Repository: ajaynegi45/LibraryMan-API Length of output: 340 🏁 Script executed: # Confirm there are no permission rules for /api/v1/books in WebConfiguration
rg '/api/v1/books' src/main/java/com/libraryman_api/security/config/WebConfiguration.java
# Check if there are any test files and their current endpoints
find . -path "*/test/*" -name "*BookController*" -type f
find . -path "*/test/*" -name "*Test.java" | xargs grep -l "book" 2>/dev/null | head -5Repository: ajaynegi45/LibraryMan-API Length of output: 348 🏁 Script executed: # Check if BookServiceTest or any test actually tests the endpoints
cat src/test/java/com/libraryman_api/book/BookServiceTest.java | head -30
# Search for any MockMvc tests that test book endpoints
rg -i 'mockmvc|perform.*book' --type=java src/test/
# Check if there's a general integration test or e2e test
find . -path "*/test/*" -name "*IntegrationTest*" -o -path "*/test/*" -name "*E2E*"Repository: ajaynegi45/LibraryMan-API Length of output: 1082 🏁 Script executed: # Check the other endpoints and see what methods they reference
rg -A 1 '@(GetMapping|PostMapping|PutMapping|DeleteMapping)' src/main/java/com/libraryman_api/book/BookController.java | grep -E '@|value|path'
# Verify what the actual endpoint paths will be when fully qualified (base path + method mapping)
echo "BookController base: /api/v1/books"
rg '@(GetMapping|PostMapping|PutMapping|DeleteMapping)\(' src/main/java/com/libraryman_api/book/BookController.javaRepository: ajaynegi45/LibraryMan-API Length of output: 1040 Security configuration out of sync with new BookController paths — endpoints will be inaccessible. The base path change from
Required fixes:
🤖 Prompt for AI Agents |
||
| public class BookController { | ||
|
|
||
| @Autowired | ||
|
|
@@ -80,7 +81,8 @@ public BookDto addBook(@Valid @RequestBody BookDto bookDto) { | |
|
|
||
| /** | ||
| * Updates an existing book in the library. | ||
| * | ||
| * This operation is restricted to LIBRARIAN and ADMIN roles. | ||
| * | ||
| * @param id the ID of the book to update. | ||
| * @param bookDtoDetails the {@link Book} object containing the updated book details. | ||
| * @return the updated {@link Book} object. | ||
|
|
@@ -93,13 +95,15 @@ public BookDto updateBook(@PathVariable int id, @Valid @RequestBody BookDto book | |
|
|
||
| /** | ||
| * Deletes a book from the library by its ID. | ||
| * Provides confirmation message upon successful deletion. | ||
| * | ||
| * @param id the ID of the book to delete. | ||
| */ | ||
| @DeleteMapping("delete-book/{id}") | ||
| @PreAuthorize("hasRole('LIBRARIAN') or hasRole('ADMIN')") | ||
| public void deleteBook(@PathVariable int id) { | ||
| public ResponseEntity<String> deleteBook(@PathVariable int id) { | ||
| bookService.deleteBook(id); | ||
| return ResponseEntity.ok("Book with ID " + id + " has been successfully deleted from the system."); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
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.
JDK version mismatch with
pom.xml(java.version=17).The build and runtime images use JDK/JRE 21 while
pom.xmltargets Java 17. The build will succeed (21 ≥ 17), but running the resulting JAR on a JRE that differs from the declared target can hide compatibility issues and drift between local/CI and container runtimes. Either bump<java.version>to 21 or switch the images toeclipse-temurin:17-...to keep them aligned.🤖 Prompt for AI Agents