MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / load

Function load

scripts/mars-credentials.mjs:126–157  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

124 let state = load();
125
126 function load() {
127 memoryTokens.clear();
128 if (!filePath) return emptyState();
129 let loaded;
130 try {
131 const parsed = JSON.parse(readFileSync(filePath, "utf8"));
132 if (parsed?.version !== STORE_VERSION) return emptyState();
133 loaded = {
134 ...emptyState(),
135 ...parsed,
136 connections: Array.isArray(parsed.connections)
137 ? parsed.connections
138 : [],
139 };
140 } catch {
141 // Missing or corrupt store — start clean rather than blocking sign-in.
142 return emptyState();
143 }
144 if (secrets) {
145 for (const connection of loaded.connections) {
146 try {
147 const secret = secrets.read(secretAccountFor(connection.id));
148 const token = secret ? tokenFromSecret(secret) : null;
149 if (token) memoryTokens.set(connection.id, token);
150 } catch (error) {
151 // A locked keychain: the connection stays listed, needing sign-in.
152 log(error instanceof Error ? error.message : String(error));
153 }
154 }
155 }
156 return loaded;
157 }
158
159 function persist() {
160 if (!filePath) return;

Callers 2

createCredentialStoreFunction · 0.70
reloadFunction · 0.70

Calls 5

emptyStateFunction · 0.85
secretAccountForFunction · 0.85
tokenFromSecretFunction · 0.85
clearMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected