MCPcopy Index your code
hub / github.com/codenameone/CodenameOne / fetch

Method fetch

CodenameOne/src/com/codename1/security/Secrets.java:79–110  ·  view source on GitHub ↗
(String name)

Source from the content-addressed store, hash-verified

77 }
78
79 private static String fetch(String name) {
80 String key = Display.getInstance().getProperty(PROP_BUILD_KEY, "");
81 if (key == null || key.length() == 0) {
82 return null; // simulator / local build: no cloud secrets
83 }
84 String url = Display.getInstance().getProperty(PROP_ENDPOINT, DEFAULT_ENDPOINT);
85 if (url == null || url.length() == 0) {
86 return null;
87 }
88 try {
89 StringBuilder sb = new StringBuilder();
90 sb.append('{');
91 field(sb, "buildKey", key);
92 sb.append(',');
93 field(sb, "packageName", Display.getInstance().getProperty(PROP_PACKAGE, ""));
94 sb.append(',');
95 field(sb, "name", name);
96 sb.append('}');
97 Response resp = Rest.post(url + "/fetch").jsonContent().body(sb.toString()).getAsJsonMap();
98 if (resp.getResponseCode() < 200 || resp.getResponseCode() >= 300) {
99 return null;
100 }
101 Object data = resp.getResponseData();
102 if (data instanceof Map) {
103 Object val = ((Map) data).get("value");
104 return val == null ? null : val.toString();
105 }
106 } catch (Throwable t) {
107 Log.p("Secrets.fetch failed: " + t);
108 }
109 return null;
110 }
111
112 private static void field(StringBuilder sb, String key, String value) {
113 sb.append('"').append(key).append('"').append(':');

Callers 1

refreshMethod · 0.95

Calls 15

getInstanceMethod · 0.95
lengthMethod · 0.95
appendMethod · 0.95
fieldMethod · 0.95
postMethod · 0.95
toStringMethod · 0.95
getResponseCodeMethod · 0.95
getResponseDataMethod · 0.95
toStringMethod · 0.95
pMethod · 0.95
getAsJsonMapMethod · 0.80
jsonContentMethod · 0.80

Tested by

no test coverage detected