Skip to content

Commit

Permalink
collect all failures (not just first)
Browse files Browse the repository at this point in the history
  • Loading branch information
lionello committed Dec 3, 2023
1 parent b6796b8 commit a36d43b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 43 deletions.
66 changes: 24 additions & 42 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,45 +313,39 @@ const defangServiceProvider: pulumi.dynamic.ResourceProvider = {
olds: DefangServiceInputs,
news: DefangServiceInputs
): Promise<pulumi.dynamic.CheckResult<DefangServiceInputs>> {
const failures: pulumi.dynamic.CheckFailure[] = [];

if (!news.fabricDNS) {
return {
failures: [{ property: "fabricDNS", reason: "fabricDNS is required" }],
};
failures.push({ property: "fabricDNS", reason: "fabricDNS is required" });
}
// TODO: validate name
if (!news.name) {
return { failures: [{ property: "name", reason: "name is required" }] };
failures.push({ property: "name", reason: "name is required" });
}
if (news.deploy) {
if (!isValidUint(news.deploy.replicas ?? 0)) {
return {
failures: [
failures.push(
{
property: "deploy",
reason: "replicas must be an integer ≥ 0",
},
],
};
);
}
if (!isValidReservation(news.deploy.resources?.reservations?.cpu)) {
return {
failures: [
failures.push(
{
property: "deploy",
reason: "cpu reservation must be > 0",
},
],
};
);
}
if (!isValidReservation(news.deploy.resources?.reservations?.memory)) {
return {
failures: [
failures.push(
{
property: "deploy",
reason: "memory reservation must be > 0",
},
],
};
);
}
}
for (const port of news.ports || []) {
Expand All @@ -361,25 +355,21 @@ const defangServiceProvider: pulumi.dynamic.ResourceProvider = {
port.target > 32767 ||
!Number.isInteger(port.target)
) {
return {
failures: [
failures.push(
{
property: "ports",
reason: "target port must be an integer between 1 and 32767",
},
],
};
);
}
if (port.mode === "ingress") {
if (["udp", "tcp"].includes(port.protocol!)) {
return {
failures: [
failures.push(
{
property: "ports",
reason: "ingress is not support by protocol " + port.protocol,
},
],
};
);
}
if (!news.healthcheck?.test) {
console.warn(
Expand All @@ -391,51 +381,43 @@ const defangServiceProvider: pulumi.dynamic.ResourceProvider = {
for (const secret of news.secrets || []) {
// TODO: validate source name
if (!secret.source) {
return {
failures: [
failures.push(
{
property: "secrets",
reason: "secret source is required",
},
],
};
);
}
}
if (news.build) {
if (!news.build.context) {
return {
failures: [
failures.push(
{
property: "build",
reason: "build context is required",
},
],
};
);
}
if (news.build.dockerfile === "") {
return {
failures: [
failures.push(
{
property: "build",
reason: "dockerfile cannot be empty string",
},
],
};
);
}
if (news.image) {
return {
failures: [
failures.push(
{
property: "image",
reason: "cannot specify both build and image",
},
],
};
);
}
} else if (!news.image) {
return { failures: [{ property: "image", reason: "image is required" }] };
failures.push({ property: "image", reason: "image is required" });
}
return { inputs: news };
return { inputs: news, failures };
},
async create(
inputs: DefangServiceInputs
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"strict": true,
"outDir": "lib",
"target": "es2019",
"module": "commonjs",
"module": "Node16",
"moduleResolution": "Node16",
"declaration": true,
"stripInternal": true,
Expand Down

0 comments on commit a36d43b

Please sign in to comment.