diff options
| author | wangwei <[email protected]> | 2024-01-29 17:42:16 +0800 |
|---|---|---|
| committer | wangwei <[email protected]> | 2024-01-29 17:42:16 +0800 |
| commit | db3d90b505175a05265a39d35a4afe13a853df69 (patch) | |
| tree | 5a4baef52827d0e34d9509ca373a0a6d5b4c913c /src/main/java/com/geedge/common/util/TsgUtil.java | |
| parent | a7aad6e357599db0c570d1c862d9e3335c4c3efe (diff) | |
Diffstat (limited to 'src/main/java/com/geedge/common/util/TsgUtil.java')
| -rw-r--r-- | src/main/java/com/geedge/common/util/TsgUtil.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/main/java/com/geedge/common/util/TsgUtil.java b/src/main/java/com/geedge/common/util/TsgUtil.java index 3e5b995..9bf9134 100644 --- a/src/main/java/com/geedge/common/util/TsgUtil.java +++ b/src/main/java/com/geedge/common/util/TsgUtil.java @@ -57,6 +57,25 @@ public class TsgUtil { throw new IllegalArgumentException("failed to get TSG system token."); } + public static JSONObject getObjectItemList(Integer objectId, String objectType) { + Stopwatch watch = Stopwatch.createStarted(); + String response = HttpRequest.get(TSG_URL + "/v1/policy/object/" + objectId + "/item?page_no=1&page_size=1&type=" + objectType) + .header(Header.AUTHORIZATION, getToken()) + .timeout(httpTimeOut) + .execute().body(); + log.info("get tsg-api, cost {} seconds", watch.elapsed(TimeUnit.SECONDS)); + if (StrUtil.isBlank(response)) { + log.error("get {} Object error, response: {}", objectId, response); + throw new RuntimeException("get " + objectId + " Object error, response: " + response); + } + JSONObject jsonObject = JSONUtil.parseObj(response); + if (!"200".equals(jsonObject.get("code").toString())) { + log.error("get {} Object error, response: {}", objectId, response); + throw new RuntimeException("get " + objectId + " Object error, response: " + response); + } + return jsonObject; + } + public static void updateObjectById(Integer id, Map<String, Object> body) { Stopwatch watch = Stopwatch.createStarted(); String response = HttpRequest.put(TSG_URL + "/v1/policy/object/" + id) |
