|
1 | 1 | package com.skyflow.utils; |
2 | 2 |
|
| 3 | +import com.google.gson.JsonObject; |
3 | 4 | import com.skyflow.config.Credentials; |
4 | 5 | import com.skyflow.enums.Env; |
5 | 6 | import com.skyflow.errors.ErrorCode; |
6 | 7 | import com.skyflow.errors.ErrorMessage; |
7 | 8 | import com.skyflow.errors.SkyflowException; |
8 | 9 | import com.skyflow.logs.ErrorLogs; |
| 10 | +import com.skyflow.logs.InfoLogs; |
9 | 11 | import com.skyflow.serviceaccount.util.BearerToken; |
10 | 12 | import com.skyflow.utils.logger.LogUtil; |
11 | 13 | import org.apache.commons.codec.binary.Base64; |
@@ -95,6 +97,52 @@ public static String parameterizedString(String base, String... args) { |
95 | 97 | return base; |
96 | 98 | } |
97 | 99 |
|
| 100 | + protected static JsonObject getCommonMetrics() { |
| 101 | + JsonObject details = new JsonObject(); |
| 102 | + String deviceModel; |
| 103 | + String osDetails; |
| 104 | + String javaVersion; |
| 105 | + // Retrieve device model |
| 106 | + try { |
| 107 | + deviceModel = System.getProperty("os.name"); |
| 108 | + if (deviceModel == null) throw new Exception(); |
| 109 | + } catch (Exception e) { |
| 110 | + LogUtil.printInfoLog(parameterizedString( |
| 111 | + InfoLogs.UNABLE_TO_GENERATE_SDK_METRIC.getLog(), |
| 112 | + BaseConstants.SDK_METRIC_CLIENT_DEVICE_MODEL |
| 113 | + )); |
| 114 | + deviceModel = ""; |
| 115 | + } |
| 116 | + |
| 117 | + // Retrieve OS details |
| 118 | + try { |
| 119 | + osDetails = System.getProperty("os.version"); |
| 120 | + if (osDetails == null) throw new Exception(); |
| 121 | + } catch (Exception e) { |
| 122 | + LogUtil.printInfoLog(parameterizedString( |
| 123 | + InfoLogs.UNABLE_TO_GENERATE_SDK_METRIC.getLog(), |
| 124 | + BaseConstants.SDK_METRIC_CLIENT_OS_DETAILS |
| 125 | + )); |
| 126 | + osDetails = ""; |
| 127 | + } |
| 128 | + |
| 129 | + // Retrieve Java version details |
| 130 | + try { |
| 131 | + javaVersion = System.getProperty("java.version"); |
| 132 | + if (javaVersion == null) throw new Exception(); |
| 133 | + } catch (Exception e) { |
| 134 | + LogUtil.printInfoLog(parameterizedString( |
| 135 | + InfoLogs.UNABLE_TO_GENERATE_SDK_METRIC.getLog(), |
| 136 | + BaseConstants.SDK_METRIC_RUNTIME_DETAILS |
| 137 | + )); |
| 138 | + javaVersion = ""; |
| 139 | + } |
| 140 | + details.addProperty(BaseConstants.SDK_METRIC_CLIENT_DEVICE_MODEL, deviceModel); |
| 141 | + details.addProperty(BaseConstants.SDK_METRIC_RUNTIME_DETAILS, BaseConstants.SDK_METRIC_RUNTIME_DETAILS_PREFIX + javaVersion); |
| 142 | + details.addProperty(BaseConstants.SDK_METRIC_CLIENT_OS_DETAILS, osDetails); |
| 143 | + return details; |
| 144 | + } |
| 145 | + |
98 | 146 | private static PrivateKey parsePkcs8PrivateKey(byte[] pkcs8Bytes) throws SkyflowException { |
99 | 147 | KeyFactory keyFactory; |
100 | 148 | PrivateKey privateKey = null; |
|
0 commit comments