Skip to content

Commit ff3ebef

Browse files
mitc-gjugeclaude
andcommitted
feat: add Infomaniak DNS provider support
Adds Infomaniak alongside Cloudflare, AWS Route53 and Porkbun, following the existing DnsClient interface in packages/server/src/utils/dns/. - infomaniak.ts implements listZones, listRecords, upsertRecord, updateRecord, deleteRecord and testConnection against the Infomaniak API. Zones come from /1/product?service_name=domain and records from the v2 /2/zones/{zone}/records endpoints, which are keyed by zone name rather than by product id. - A new `infomaniak` value was added to the DnsProviderType enum along with an infomaniakDnsConfigSchema (apiToken) in the discriminated union, plus the Drizzle migration for the enum change. - The token is masked/merged like the other providers in services/dns-provider.ts. - UI: Infomaniak icon and API Token field in the DNS provider dialog, plus registration in the provider selector. Infomaniak's `source` is relative to the zone (empty for the apex), so record names are translated between Dokploy's fully-qualified format and Infomaniak's subdomain-only format internally, with the trailing dot handled. TXT targets are stored quoted by the API and are unquoted on read / quoted on write so that editing a record does not stack quotes on every save. Also fills in the missing Porkbun label in show-dns-providers.tsx, which fell back to displaying the raw enum value. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent c225188 commit ff3ebef

11 files changed

Lines changed: 9729 additions & 1 deletion

File tree

Lines changed: 330 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,330 @@
1+
import { beforeEach, describe, expect, it, vi } from "vitest";
2+
3+
const mockFetch = vi.fn();
4+
global.fetch = mockFetch as typeof fetch;
5+
6+
import { infomaniakClient } from "@dokploy/server/utils/dns/infomaniak";
7+
8+
const jsonResponse = (body: unknown, ok = true, status = 200) =>
9+
({
10+
ok,
11+
status,
12+
json: async () => body,
13+
}) as Response;
14+
15+
const ikSuccess = (data: unknown) => jsonResponse({ result: "success", data });
16+
17+
const ikError = (description: string, status = 400) =>
18+
jsonResponse(
19+
{ result: "error", error: { code: "not_authorized", description } },
20+
false,
21+
status,
22+
);
23+
24+
const config = {
25+
providerType: "infomaniak" as const,
26+
apiToken: "ik_test_token",
27+
};
28+
29+
const lastCall = () =>
30+
mockFetch.mock.calls.at(-1) as [string, RequestInit & { method?: string }];
31+
32+
const lastBody = () => JSON.parse(lastCall()[1].body as string);
33+
34+
beforeEach(() => {
35+
mockFetch.mockReset();
36+
});
37+
38+
describe("infomaniakClient.listZones", () => {
39+
it("exposes each domain product as a zone keyed by its name", async () => {
40+
mockFetch.mockResolvedValue(
41+
ikSuccess([
42+
{ id: 1, customer_name: "example.com" },
43+
{ id: 2, customer_name: "example.ch" },
44+
]),
45+
);
46+
47+
const zones = await infomaniakClient.listZones(config);
48+
49+
expect(zones).toEqual([
50+
{ id: "example.com", name: "example.com" },
51+
{ id: "example.ch", name: "example.ch" },
52+
]);
53+
const [url, init] = lastCall();
54+
expect(url).toBe(
55+
"https://api.infomaniak.com/1/product?service_name=domain",
56+
);
57+
expect(init.headers).toMatchObject({
58+
Authorization: "Bearer ik_test_token",
59+
});
60+
});
61+
62+
it("propagates the API error description", async () => {
63+
mockFetch.mockResolvedValue(ikError("Authorization required", 401));
64+
65+
await expect(infomaniakClient.listZones(config)).rejects.toThrow(
66+
"Authorization required",
67+
);
68+
});
69+
});
70+
71+
describe("infomaniakClient.listRecords", () => {
72+
it("rebuilds the fqdn from the relative source", async () => {
73+
mockFetch.mockResolvedValue(
74+
ikSuccess([
75+
{ id: 10, type: "A", source: "app", target: "1.2.3.4", ttl: 300 },
76+
{ id: 11, type: "A", source: "", target: "5.6.7.8", ttl: 600 },
77+
]),
78+
);
79+
80+
const records = await infomaniakClient.listRecords(config, "example.com");
81+
82+
expect(records).toEqual([
83+
{
84+
id: "10",
85+
type: "A",
86+
name: "app.example.com",
87+
content: "1.2.3.4",
88+
ttl: 300,
89+
},
90+
{
91+
id: "11",
92+
type: "A",
93+
name: "example.com",
94+
content: "5.6.7.8",
95+
ttl: 600,
96+
},
97+
]);
98+
expect(lastCall()[0]).toBe(
99+
"https://api.infomaniak.com/2/zones/example.com/records?with=records_description",
100+
);
101+
});
102+
103+
it("treats an @ source as the apex", async () => {
104+
mockFetch.mockResolvedValue(
105+
ikSuccess([
106+
{ id: 12, type: "A", source: "@", target: "1.2.3.4", ttl: 300 },
107+
]),
108+
);
109+
110+
const records = await infomaniakClient.listRecords(config, "example.com");
111+
112+
expect(records[0]?.name).toBe("example.com");
113+
});
114+
115+
it("unquotes TXT targets", async () => {
116+
mockFetch.mockResolvedValue(
117+
ikSuccess([
118+
{
119+
id: 13,
120+
type: "TXT",
121+
source: "_acme-challenge",
122+
target: '"token-value"',
123+
ttl: 300,
124+
},
125+
]),
126+
);
127+
128+
const records = await infomaniakClient.listRecords(config, "example.com");
129+
130+
expect(records[0]?.content).toBe("token-value");
131+
});
132+
133+
it("leaves a CAA target untouched", async () => {
134+
mockFetch.mockResolvedValue(
135+
ikSuccess([
136+
{
137+
id: 14,
138+
type: "CAA",
139+
source: "",
140+
target: '0 issue "letsencrypt.org"',
141+
ttl: 300,
142+
},
143+
]),
144+
);
145+
146+
const records = await infomaniakClient.listRecords(config, "example.com");
147+
148+
expect(records[0]?.content).toBe('0 issue "letsencrypt.org"');
149+
});
150+
});
151+
152+
describe("infomaniakClient.upsertRecord", () => {
153+
it("creates the record when no matching source and type exists", async () => {
154+
mockFetch
155+
.mockResolvedValueOnce(ikSuccess([]))
156+
.mockResolvedValueOnce(ikSuccess({ id: 42 }));
157+
158+
const result = await infomaniakClient.upsertRecord(config, {
159+
zoneId: "example.com",
160+
type: "A",
161+
name: "app.example.com",
162+
content: "1.2.3.4",
163+
ttl: 600,
164+
});
165+
166+
expect(result).toEqual({ id: "42" });
167+
const [url, init] = lastCall();
168+
expect(url).toBe("https://api.infomaniak.com/2/zones/example.com/records");
169+
expect(init.method).toBe("POST");
170+
expect(lastBody()).toEqual({
171+
type: "A",
172+
source: "app",
173+
target: "1.2.3.4",
174+
ttl: 600,
175+
});
176+
});
177+
178+
it("updates the existing record instead of creating a duplicate", async () => {
179+
mockFetch
180+
.mockResolvedValueOnce(
181+
ikSuccess([
182+
{ id: 7, type: "A", source: "app", target: "1.1.1.1", ttl: 300 },
183+
]),
184+
)
185+
.mockResolvedValueOnce(ikSuccess({ id: 7 }));
186+
187+
const result = await infomaniakClient.upsertRecord(config, {
188+
zoneId: "example.com",
189+
type: "A",
190+
name: "app.example.com",
191+
content: "1.2.3.4",
192+
});
193+
194+
expect(result).toEqual({ id: "7" });
195+
const [url, init] = lastCall();
196+
expect(url).toBe(
197+
"https://api.infomaniak.com/2/zones/example.com/records/7",
198+
);
199+
expect(init.method).toBe("PUT");
200+
expect(lastBody().ttl).toBe(300);
201+
});
202+
203+
it("writes an empty source for an apex record and strips the trailing dot", async () => {
204+
mockFetch
205+
.mockResolvedValueOnce(ikSuccess([]))
206+
.mockResolvedValueOnce(ikSuccess({ id: 43 }));
207+
208+
await infomaniakClient.upsertRecord(config, {
209+
zoneId: "example.com",
210+
type: "A",
211+
name: "example.com.",
212+
content: "1.2.3.4",
213+
});
214+
215+
expect(lastBody().source).toBe("");
216+
});
217+
218+
it("quotes a TXT target on write", async () => {
219+
mockFetch
220+
.mockResolvedValueOnce(ikSuccess([]))
221+
.mockResolvedValueOnce(ikSuccess({ id: 44 }));
222+
223+
await infomaniakClient.upsertRecord(config, {
224+
zoneId: "example.com",
225+
type: "TXT",
226+
name: "_acme-challenge.example.com",
227+
content: "token-value",
228+
});
229+
230+
expect(lastBody().target).toBe('"token-value"');
231+
});
232+
233+
it("does not double-quote a TXT target that is already quoted", async () => {
234+
mockFetch
235+
.mockResolvedValueOnce(ikSuccess([]))
236+
.mockResolvedValueOnce(ikSuccess({ id: 45 }));
237+
238+
await infomaniakClient.upsertRecord(config, {
239+
zoneId: "example.com",
240+
type: "TXT",
241+
name: "_acme-challenge.example.com",
242+
content: '"token-value"',
243+
});
244+
245+
expect(lastBody().target).toBe('"token-value"');
246+
});
247+
});
248+
249+
describe("infomaniakClient.updateRecord", () => {
250+
it("updates the record and keeps its id", async () => {
251+
mockFetch.mockResolvedValue(ikSuccess({ id: 7 }));
252+
253+
const result = await infomaniakClient.updateRecord(
254+
config,
255+
"example.com",
256+
"7",
257+
{
258+
type: "CNAME",
259+
name: "www.example.com",
260+
content: "example.com",
261+
ttl: 900,
262+
},
263+
);
264+
265+
expect(result).toEqual({ id: "7" });
266+
const [url, init] = lastCall();
267+
expect(url).toBe(
268+
"https://api.infomaniak.com/2/zones/example.com/records/7",
269+
);
270+
expect(init.method).toBe("PUT");
271+
expect(lastBody()).toEqual({
272+
type: "CNAME",
273+
source: "www",
274+
target: "example.com",
275+
ttl: 900,
276+
});
277+
});
278+
279+
it("falls back to the default ttl when none is provided", async () => {
280+
mockFetch.mockResolvedValue(ikSuccess({ id: 7 }));
281+
282+
await infomaniakClient.updateRecord(config, "example.com", "7", {
283+
type: "A",
284+
name: "app.example.com",
285+
content: "1.2.3.4",
286+
});
287+
288+
expect(lastBody().ttl).toBe(300);
289+
});
290+
});
291+
292+
describe("infomaniakClient.deleteRecord", () => {
293+
it("deletes the record", async () => {
294+
mockFetch.mockResolvedValue(ikSuccess(null));
295+
296+
await infomaniakClient.deleteRecord(config, "example.com", "7");
297+
298+
const [url, init] = lastCall();
299+
expect(url).toBe(
300+
"https://api.infomaniak.com/2/zones/example.com/records/7",
301+
);
302+
expect(init.method).toBe("DELETE");
303+
});
304+
305+
it("propagates a delete failure", async () => {
306+
mockFetch.mockResolvedValue(ikError("Record not found", 404));
307+
308+
await expect(
309+
infomaniakClient.deleteRecord(config, "example.com", "7"),
310+
).rejects.toThrow("Record not found");
311+
});
312+
});
313+
314+
describe("infomaniakClient.testConnection", () => {
315+
it("resolves when the domain listing succeeds", async () => {
316+
mockFetch.mockResolvedValue(ikSuccess([]));
317+
318+
await expect(
319+
infomaniakClient.testConnection(config),
320+
).resolves.toBeUndefined();
321+
});
322+
323+
it("rejects on an invalid token", async () => {
324+
mockFetch.mockResolvedValue(ikError("Authorization required", 401));
325+
326+
await expect(infomaniakClient.testConnection(config)).rejects.toThrow(
327+
"Infomaniak: request to /1/product?service_name=domain failed: Authorization required",
328+
);
329+
});
330+
});

‎apps/dokploy/components/dashboard/settings/dns/handle-dns-provider.tsx‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const providerLabels = {
4444
cloudflare: "Cloudflare",
4545
route53: "AWS Route53",
4646
porkbun: "Porkbun",
47+
infomaniak: "Infomaniak",
4748
} as const;
4849

4950
type ProviderType = keyof typeof providerLabels;
@@ -55,7 +56,7 @@ const DnsProviderSchema = z.object({
5556
.regex(/^[a-zA-Z0-9_-]+$/, {
5657
message: "Only letters, numbers, dashes and underscores",
5758
}),
58-
providerType: z.enum(["cloudflare", "route53", "porkbun"]),
59+
providerType: z.enum(["cloudflare", "route53", "porkbun", "infomaniak"]),
5960
apiToken: z.string(),
6061
accessKeyId: z.string(),
6162
secretAccessKey: z.string(),
@@ -94,6 +95,11 @@ const buildConfig = (data: DnsProviderForm) => {
9495
apiKey: data.apiKey,
9596
secretApiKey: data.secretApiKey,
9697
};
98+
case "infomaniak":
99+
return {
100+
providerType: "infomaniak" as const,
101+
apiToken: data.apiToken,
102+
};
97103
}
98104
};
99105

@@ -155,6 +161,9 @@ export const HandleDnsProvider = ({ dnsProviderId }: Props) => {
155161
apiKey: provider.config.apiKey,
156162
secretApiKey: provider.config.secretApiKey,
157163
}),
164+
...(provider.config.providerType === "infomaniak" && {
165+
apiToken: provider.config.apiToken,
166+
}),
158167
});
159168
} else if (!dnsProviderId) {
160169
form.reset(defaultValues);
@@ -383,6 +392,27 @@ export const HandleDnsProvider = ({ dnsProviderId }: Props) => {
383392
</>
384393
)}
385394

395+
{providerType === "infomaniak" && (
396+
<FormField
397+
control={form.control}
398+
name="apiToken"
399+
render={({ field }) => (
400+
<FormItem>
401+
<FormLabel>API Token</FormLabel>
402+
<FormControl>
403+
<Input type="password" {...field} />
404+
</FormControl>
405+
<FormDescription>
406+
Create a token at manager.infomaniak.com with the{" "}
407+
<code>domain:read</code>, <code>dns:read</code> and{" "}
408+
<code>dns:write</code> scopes.
409+
</FormDescription>
410+
<FormMessage />
411+
</FormItem>
412+
)}
413+
/>
414+
)}
415+
386416
<DialogFooter className="flex w-full flex-row justify-between gap-2 sm:justify-between">
387417
<Button
388418
type="button"

0 commit comments

Comments
 (0)