Skip to content

Commit d444551

Browse files
committed
Handle center values & code review feedback
1 parent 6939398 commit d444551

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

components/gitpod-protocol/src/protocol.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class TestEnvVar {
182182
const envVars: EnvVarWithValue[] = [
183183
{
184184
name: EnvVar.GITPOD_IMAGE_AUTH_ENV_VAR_NAME,
185-
value: "justhost,hostonly:,:credonly,:::,",
185+
value: "justhost,hostonly:,:credonly,:::,:,",
186186
},
187187
];
188188
const result = EnvVar.getGitpodImageAuth(envVars);
@@ -199,7 +199,7 @@ class TestEnvVar {
199199
];
200200
const result = EnvVar.getGitpodImageAuth(envVars);
201201
expect(result.size).to.equal(2);
202-
expect(result.get("my-registry.foo.net ")).to.equal(" Zm9vOmJhcg==");
202+
expect(result.get("my-registry.foo.net")).to.equal("Zm9vOmJhcg==");
203203
expect(result.get("my-registry2.bar.com")).to.equal("YWJjOmRlZg==");
204204
}
205205
}

components/gitpod-protocol/src/protocol.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,22 +293,31 @@ export namespace EnvVar {
293293
return res;
294294
}
295295

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]}`;
296+
const parse = (parts: string[]): { host: string; auth: string } | undefined => {
297+
if (parts.some((e) => e === "")) {
298+
return undefined;
302299
}
303-
return "";
300+
if (parts.length === 2) {
301+
return { host: parts[0], auth: parts[1] };
302+
} else if (parts.length === 3) {
303+
return { host: `${parts[0]}:${parts[1]}`, auth: parts[2] };
304+
}
305+
return undefined;
304306
};
305307

306308
(imageAuth.value || "")
307309
.split(",")
308-
.map((e) => e.trim().split(":"))
310+
.map((e) =>
311+
e
312+
.trim()
313+
.split(":")
314+
.map((part) => part.trim()),
315+
)
309316
.forEach((parts) => {
310-
const host = getHost(parts);
311-
host !== "" ? res.set(host, parts[parts.length - 1]) : null;
317+
const parsed = parse(parts);
318+
if (parsed) {
319+
res.set(parsed.host, parsed.auth);
320+
}
312321
});
313322

314323
return res;

0 commit comments

Comments
 (0)