-
Notifications
You must be signed in to change notification settings - Fork 615
fix: fix inconsistent naming pattern #2945
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
JisoLya
wants to merge
5
commits into
apache:master
Choose a base branch
from
JisoLya:arthas-sec
base: master
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
5 commits
Select commit
Hold shift + click to select a range
b105e2c
sec(store, server): disable remote access for arthasstart
JisoLya bda5d52
fix(server): arthas configuration is ignored due to inconsistent nami…
JisoLya 339117d
fix: unify the return value and block non-web request
JisoLya 5e5063d
fix: unify the return value and block non-web request
JisoLya a4abb37
trigger-ci
JisoLya 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
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
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
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 |
|---|---|---|
|
|
@@ -23,6 +23,8 @@ | |
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import javax.servlet.http.HttpServletRequest; | ||
|
|
||
| import org.apache.hugegraph.pd.common.PDException; | ||
| import org.apache.hugegraph.pd.grpc.Metapb; | ||
| import org.apache.hugegraph.rocksdb.access.RocksDBSession; | ||
|
|
@@ -37,7 +39,9 @@ | |
| import org.apache.hugegraph.store.node.grpc.HgStoreNodeService; | ||
| import org.apache.hugegraph.util.Bytes; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
|
|
@@ -64,7 +68,7 @@ public class PartitionAPI { | |
| AppConfig appConfig; | ||
|
|
||
| @GetMapping(value = "/partitions", produces = "application/json") | ||
| public Map<String, Object> getPartitions( | ||
| public ResponseEntity<Map<String, Object>> getPartitions( | ||
| @RequestParam(required = false, defaultValue = "") String flags) { | ||
|
|
||
| boolean accurate = false; | ||
|
|
@@ -109,11 +113,11 @@ public Map<String, Object> getPartitions( | |
| rafts.add(raft); | ||
| } | ||
|
|
||
| return okMap("partitions", rafts); | ||
| return ok("partitions", rafts); | ||
| } | ||
|
|
||
| @GetMapping(value = "/partition/{id}", produces = "application/json") | ||
| public Raft getPartition(@PathVariable(value = "id") int id) { | ||
| public ResponseEntity<Map<String, Object>> getPartition(@PathVariable(value = "id") int id) { | ||
|
|
||
| HgStoreEngine storeEngine = nodeService.getStoreEngine(); | ||
|
|
||
|
|
@@ -138,16 +142,15 @@ public Raft getPartition(@PathVariable(value = "id") int id) { | |
| raft.getPartitions().add(partition); | ||
| } | ||
|
|
||
| return raft; | ||
| //return okMap("partition", rafts); | ||
| return ok("raft", raft); | ||
|
JisoLya marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
| * Print all keys in the partition | ||
| */ | ||
| @GetMapping(value = "/partition/dump/{id}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
| public Map<String, Object> dumpPartition(@PathVariable(value = "id") int id) throws | ||
| PDException { | ||
| public ResponseEntity<Map<String, Object>> dumpPartition( | ||
| @PathVariable(value = "id") int id) throws PDException { | ||
| HgStoreEngine storeEngine = nodeService.getStoreEngine(); | ||
| BusinessHandler handler = storeEngine.getBusinessHandler(); | ||
| InnerKeyCreator innerKeyCreator = new InnerKeyCreator(handler); | ||
|
|
@@ -168,27 +171,40 @@ public Map<String, Object> dumpPartition(@PathVariable(value = "id") int id) thr | |
| } | ||
| cfIterator.close(); | ||
| }); | ||
| return okMap("ok", null); | ||
| return ok("ok", null); | ||
|
Contributor
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. High: Null success payloads now throw
Evidence
Impact
Requested fix
|
||
| } | ||
|
|
||
| /** | ||
| * Print all keys in the partition | ||
| */ | ||
| @GetMapping(value = "/partition/clean/{id}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
| public Map<String, Object> cleanPartition(@PathVariable(value = "id") int id) throws | ||
| PDException { | ||
| public ResponseEntity<Map<String, Object>> cleanPartition( | ||
| @PathVariable(value = "id") int id) throws PDException { | ||
| HgStoreEngine storeEngine = nodeService.getStoreEngine(); | ||
|
JisoLya marked this conversation as resolved.
|
||
| BusinessHandler handler = storeEngine.getBusinessHandler(); | ||
|
|
||
| storeEngine.getPartitionEngine(id).getPartitions().forEach((graph, partition) -> { | ||
| handler.cleanPartition(graph, id); | ||
| }); | ||
| return okMap("ok", null); | ||
| return ok("ok", null); | ||
| } | ||
|
|
||
| @GetMapping(value = "/arthasstart", produces = "application/json") | ||
|
JisoLya marked this conversation as resolved.
|
||
| public Map<String, Object> arthasstart( | ||
| @RequestParam(required = false, defaultValue = "") String flags) { | ||
| public ResponseEntity<Map<String, Object>> arthasstart( | ||
|
JisoLya marked this conversation as resolved.
|
||
| @RequestParam(required = false, defaultValue = "") String flags, | ||
| HttpServletRequest request) { | ||
| // Ignore proxy headers to prevent IP spoofing. | ||
| // NOTE: If behind a reverse proxy (e.g., Nginx), getRemoteAddr() returns the proxy's IP. | ||
| // Ensure the proxy is configured to block untrusted external access. | ||
| String remoteAddr = getCleanIp(request.getRemoteAddr()); | ||
| boolean isLocalRequest = | ||
| "127.0.0.1".equals(remoteAddr) || "0:0:0:0:0:0:0:1".equals(remoteAddr) || | ||
| "::1".equals(remoteAddr); | ||
| if (!isLocalRequest) { | ||
| List<String> ret = new ArrayList<>(); | ||
| ret.add("Arthas start is ONLY allowed from localhost."); | ||
| return forbidden("arthasstart", ret); | ||
| } | ||
| HashMap<String, String> configMap = new HashMap<>(); | ||
| configMap.put("arthas.telnetPort", appConfig.getArthasConfig().getTelnetPort()); | ||
| configMap.put("arthas.httpPort", appConfig.getArthasConfig().getHttpPort()); | ||
|
|
@@ -198,11 +214,11 @@ public Map<String, Object> arthasstart( | |
| // DashResponse retPose = new DashResponse(); | ||
| List<String> ret = new ArrayList<>(); | ||
| ret.add("Arthas started successfully"); | ||
| return okMap("arthasstart", ret); | ||
| return ok("arthasstart", ret); | ||
| } | ||
|
|
||
| @PostMapping("/compat") | ||
| public Map<String, Object> compact(@RequestParam(value = "id") int id) { | ||
| public ResponseEntity<Map<String, Object>> compact(@RequestParam(value = "id") int id) { | ||
| boolean submitted = | ||
| nodeService.getStoreEngine().getBusinessHandler().blockingCompact("", id); | ||
| Map<String, Object> map = new HashMap<>(); | ||
|
|
@@ -215,14 +231,28 @@ public Map<String, Object> compact(@RequestParam(value = "id") int id) { | |
| map.put("msg", | ||
| "compaction task fail to submit, and there could be another task in progress"); | ||
| } | ||
| return map; | ||
| return ok("body", map); | ||
|
JisoLya marked this conversation as resolved.
|
||
| } | ||
|
|
||
| public Map<String, Object> okMap(String k, Object v) { | ||
| Map<String, Object> map = new HashMap<>(); | ||
| map.put("status", 0); | ||
| map.put(k, v); | ||
| return map; | ||
| public ResponseEntity<Map<String, Object>> ok(String k, Object v) { | ||
| return ResponseEntity.ok(Map.of("status", 200, k, v)); | ||
|
JisoLya marked this conversation as resolved.
|
||
| } | ||
|
|
||
| public ResponseEntity<Map<String, Object>> forbidden(String k, Object v) { | ||
| return ResponseEntity.status(HttpStatus.FORBIDDEN) | ||
| .body(Map.of("status", 403, k, v)); | ||
| } | ||
|
|
||
| private String getCleanIp(String remoteAddr) { | ||
| if (remoteAddr != null) { | ||
| if (remoteAddr.startsWith("[")) { | ||
| remoteAddr = remoteAddr.substring(1); | ||
| } | ||
| if (remoteAddr.endsWith("]")) { | ||
| remoteAddr = remoteAddr.substring(0, remoteAddr.length() - 1); | ||
| } | ||
| } | ||
| return remoteAddr; | ||
| } | ||
|
|
||
| @Data | ||
|
|
||
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.