SK-2859: Code smell and quality fixes for vault SDK#337
Open
Devesh-Skyflow wants to merge 1 commit into
Open
Conversation
VaultClient: - remove dead apiKey field; de-duplicate detect token-mapping via buildTokenType/buildTokenEntities (drop unchecked casts, vestigial params) - extract ConnectionPool magic numbers to Constants; simplify entityScores identity map; nullable-Optional -> Optional.empty(); de-dup bleep getter - collapse redundant updateConnectionConfig parameter; brace guard clause ConnectionClient: - drop unused updateConnectionConfig(ConnectionConfig) parameter HttpUtility: - request id comes only from backend x-request-id (ThreadLocal storage, no SDK-generated UUID fallback) - extract header/content-type/status magic strings to Constants - collapse deep nesting; add braces; extract encodeRequestBody - remove swallowed exception via URLEncoder(Charset) overload SkyflowException: - do not echo malformed/non-object response bodies as the message (generic ErrorMessage.ErrorOccurred); guard JSON parse Constants: add HTTP header/content-type/status constants. Tests updated and added for all of the above. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
✅ Gitleaks Findings: No secrets detected. Safe to proceed! |
|
Semgrep Findings: Issues with Error level severity are found (Error is Highest severity in Semgrep), Please resolve the issues before merging. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
A code-smell/quality review of the vault SDK surfaced several maintainability and
correctness issues (dead code, duplicated logic, magic strings, a swallowed
exception, an unsafe shared-static request id, and an error path that echoed raw
response bodies). These are addressed here, separated from unrelated tooling so the
SDK changes can be reviewed on their own.
Goal
Reduce structural debt and a couple of correctness/security smells without changing
public API or wire behavior:
apiKeyfield; de-duplicate detect token-mapping viabuildTokenType/buildTokenEntities(drops unchecked casts + vestigial params);extract
ConnectionPoolmagic numbers; simplifyentityScoresidentity map;nullable-Optional -> Optional.empty(); de-dup repeatedgetBleep(); brace guard.updateConnectionConfig(ConnectionConfig)param(now symmetric with
VaultClient.updateVaultConfig()).x-request-id(thread-safe
ThreadLocalstorage, no SDK-generated UUID fallback — matches theGo/Node/Python SDKs); extract header/content-type/status constants; collapse deep
nesting; remove a swallowed exception via the
URLEncoder(String, Charset)overload.exception message (uses a generic message; standard
{"error":{...}}path unchanged)— aligns with the other SDKs and closes a CWE-209 raw-body leak.
Non-goals: the larger
VaultClientclass split (DetectRequestFactory), the sharedprioritiseCredentialsextraction (blocked by an unreachable defensive catch), andany Claude/tooling config (kept out of this branch).
Testing
mvn compile,mvn checkstyle:check,mvn testall pass on a cleanmainbase.(no
.env/SKYFLOW_CREDENTIALS) documented in the repo — they fail identically onmainand are unrelated to these changes.ConnectionClient
updateConnectionConfig()change; JaCoCo shows net-improvedbranch coverage on the modified classes (e.g. VaultClient 16 → 3 missed branches).
Tech debt
Net reduction. Remaining pre-existing items intentionally not tackled here: the
oversized
VaultClient(Long class) and the duplicatedprioritiseCredentials()across the two clients.