Fix Civil ID S3 handling and env-based S3 credentials#77
Fix Civil ID S3 handling and env-based S3 credentials#77sureshchouksey8 wants to merge 2 commits into
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR hardens civil ID photo handling in S3 by externalizing AWS credentials to environment variables, improving S3 file operations with better existence checks, reorganizing civil photo storage from ChangesS3 Civil ID Photo Hardening
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
tests/check-s3-civil-id-hardening.sh (1)
17-21: ⚡ Quick winHarden regression checks against false pass/fail conditions.
The exact-line
DeleteMarkergrep is brittle, andgrep -q 'try {'is too broad to prove civil-photo remove hardening.Suggested tightening
-grep -q "return isset(\$result\\['DeleteMarker'\\]) ? \$result\\['DeleteMarker'\\] : true;" "$s3_manager" +grep -Eq "DeleteMarker" "$s3_manager" -grep -q 'try {' "$account_controller" +grep -q 'actionRemoveCivilPhotoBack' "$account_controller" +grep -q 'actionRemoveCivilPhotoFront' "$account_controller" +grep -q 'Unable to remove civil photo back.' "$account_controller" +grep -q 'Unable to remove civil photo front.' "$account_controller"🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/check-s3-civil-id-hardening.sh` around lines 17 - 21, The current checks are brittle: replace the exact-line grep for DeleteMarker with a more robust pattern that just ensures DeleteMarker is referenced in the result handling (e.g., grep -q "isset(\\\$result\\['DeleteMarker'\\])" or grep -q "DeleteMarker" against the s3 manager to avoid exact formatting dependence), and tighten the broad grep for 'try {' so it only matches the try block that hardens civil-photo removal by scoping the search to the civil-photo removal routine (e.g., use a PCRE/ multiline search that looks for a function or method name containing "civil" or "remove" followed soon after by "try {"), while keeping the existing greps for candidate_civil_need_verification and 'Invalid civil ID or expiry date' intact. Ensure you reference the same symbols (DeleteMarker, candidate_civil_need_verification, 'Invalid civil ID or expiry date', and the 'try {' try-block) when updating the three grep checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@candidate/modules/v1/controllers/AccountController.php`:
- Line 1322: The call to updateCivilId('back') (and the similar call at the
other location) currently ignores its return value; change the code to check the
boolean/falsey result from updateCivilId before proceeding, and if it indicates
failure, abort further processing (do not call save()) and return or throw an
appropriate error response from the controller; specifically, after calling
updateCivilId(...) in AccountController, inspect its result, handle error by
returning a failure response (or throwing an exception) with a clear message,
and only call save() when updateCivilId() succeeds.
- Around line 384-404: In actionRemoveCivilPhotoBack and
actionRemoveCivilPhotoFront, guard against a null $model returned by
Candidate::findOne(Yii::$app->user->getId()) by throwing a NotFoundHttpException
if $model is null, then proceed to check and clear
$model->candidate_civil_photo_back / $model->candidate_civil_photo_front, call
$model->deleteFile('civil-id','back'|'front') and set the scenario
('updateCivilPhotoBack' / corresponding front scenario) before save; also change
the error handler to catch \Throwable instead of \Exception so Errors/TypeErrors
are caught and logged with Yii::error.
In `@common/config/main.php`:
- Around line 11-12: The config currently sets 'key' =>
getenv('AWS_TEMP_BUCKET_KEY') ?: '' and 'secret' =>
getenv('AWS_TEMP_BUCKET_SECRET') ?: '', which masks missing env vars by
returning empty strings and prevents S3ResourceManager::init() from catching
nulls; change these to return null when the env var is unset (i.e., remove the
empty-string fallback) so the values are null if not provided, or explicitly
validate and throw a clear configuration error during bootstrap; update the
entries for 'key' and 'secret' (the getenv calls) accordingly so
S3ResourceManager::init() sees null for missing credentials.
In `@environments/prod-railway/common/config/main-local.php`:
- Around line 157-158: The config currently sets 'key' and 'secret' to empty
strings when getenv returns nothing; update the entries for 'key' and 'secret'
in the config array (the AWS_PERMANENT_S3_ACCESS_KEY_ID and
AWS_PERMANENT_S3_SECRET_ACCESS_KEY getenv calls) to use null as the fallback
instead of '' so missing permanent S3 credentials are represented as null;
ensure the consuming S3 initialization/validation logic that reads these config
keys ('key' and 'secret') treats null as "not provided" and fails fast or throws
a clear error.
---
Nitpick comments:
In `@tests/check-s3-civil-id-hardening.sh`:
- Around line 17-21: The current checks are brittle: replace the exact-line grep
for DeleteMarker with a more robust pattern that just ensures DeleteMarker is
referenced in the result handling (e.g., grep -q
"isset(\\\$result\\['DeleteMarker'\\])" or grep -q "DeleteMarker" against the s3
manager to avoid exact formatting dependence), and tighten the broad grep for
'try {' so it only matches the try block that hardens civil-photo removal by
scoping the search to the civil-photo removal routine (e.g., use a PCRE/
multiline search that looks for a function or method name containing "civil" or
"remove" followed soon after by "try {"), while keeping the existing greps for
candidate_civil_need_verification and 'Invalid civil ID or expiry date' intact.
Ensure you reference the same symbols (DeleteMarker,
candidate_civil_need_verification, 'Invalid civil ID or expiry date', and the
'try {' try-block) when updating the three grep checks.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: af91ee6d-3c5e-4120-928d-fea2ccab241f
📒 Files selected for processing (6)
candidate/modules/v1/controllers/AccountController.phpcommon/components/S3ResourceManager.phpcommon/config/main.phpcommon/models/Candidate.phpenvironments/prod-railway/common/config/main-local.phptests/check-s3-civil-id-hardening.sh
|
Maintainer-facing update: the CodeRabbit S3/Civil ID findings are addressed on the branch. The current code now fails fast when Civil ID copy/verification fails, returns |
/claim #55
Summary
operation:errorinstead of raw 500s, mark Civil ID verification needed after removals, and validate Civil ID plus expiry date input.candidate-civil-id/tophotos/, delete old objects best-effort only when present, and avoid adding Civil ID delete errors tocandidate_resume.headObject.Acceptance Criteria Covered
photos/instead ofcandidate-civil-id/.candidate_resumeerrors.S3ResourceManager::fileExists()uses S3headObjectfor bucket keys.Verification
sh tests/check-s3-civil-id-hardening.shgit diff --checkPHP is not installed in this local environment, so I could not run
php -llocally.Summary by CodeRabbit
Release Notes
New Features
Bug Fixes