Skip to content

Commit c0be79f

Browse files
committed
Code review feedback
1 parent b55c501 commit c0be79f

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

components/gitpod-protocol/src/protocol.ts

+15-14
Original file line numberDiff line numberDiff line change
@@ -293,21 +293,22 @@ export namespace EnvVar {
293293
return res;
294294
}
295295

296-
(imageAuth.value || "").split(",").forEach((entry) => {
297-
const parts = entry.trim().split(":");
298-
if (parts.length === 2) {
299-
const [host, token] = parts;
300-
if (host && token) {
301-
res.set(host, token);
302-
}
303-
} else if (parts.length === 3) {
304-
const [host, port, token] = parts;
305-
const hostWithPort = `${host}:${port}`;
306-
if (hostWithPort && token) {
307-
res.set(hostWithPort, token);
308-
}
296+
// Returns a host value, which can include port, if token also has length.
297+
const getHost = (parts: string[]): string => {
298+
if (parts.length === 2 && parts[0] && parts[1]) {
299+
return parts[0];
300+
} else if (parts.length === 3 && parts[0] && parts[1] && parts[2]) {
301+
return `${parts[0]}:${parts[1]}`;
309302
}
310-
});
303+
return "";
304+
};
305+
306+
(imageAuth.value || "")
307+
.split(",")
308+
.map((e) => e.trim().split(":"))
309+
.forEach((parts) => {
310+
getHost(parts) !== "" ? res.set(getHost(parts), parts[parts.length - 1]) : null;
311+
});
311312

312313
return res;
313314
}

0 commit comments

Comments
 (0)