mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-10-15 05:11:26 +00:00
feat(dns): add optional zone to OVH provider
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -166,6 +166,16 @@ describe("ovhClient.listZones", () => {
|
||||
|
||||
await expect(ovhClient.listZones(cfg)).rejects.toThrow("Invalid signature");
|
||||
});
|
||||
|
||||
it("returns only the configured zone without listing every zone", async () => {
|
||||
const cfg = { ...freshConfig(), zone: "example.com" };
|
||||
mockApi();
|
||||
|
||||
const zones = await ovhClient.listZones(cfg);
|
||||
|
||||
expect(zones).toEqual([{ id: "example.com", name: "example.com" }]);
|
||||
expect(apiCalls()).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("ovhClient.listRecords", () => {
|
||||
@@ -578,4 +588,15 @@ describe("ovhClient.testConnection", () => {
|
||||
"Invalid signature",
|
||||
);
|
||||
});
|
||||
|
||||
it("checks the configured zone instead of listing all zones", async () => {
|
||||
const cfg = { ...freshConfig(), zone: "example.com" };
|
||||
mockApi(ovhSuccess({ name: "example.com" }));
|
||||
|
||||
await expect(ovhClient.testConnection(cfg)).resolves.toBeUndefined();
|
||||
|
||||
const calls = apiCalls();
|
||||
expect(calls).toHaveLength(1);
|
||||
expect(calls[0]?.[0]).toBe(`${cfg.baseUrl}/domain/zone/example.com`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -88,6 +88,7 @@ const DnsProviderSchema = z.object({
|
||||
applicationKey: z.string(),
|
||||
applicationSecret: z.string(),
|
||||
consumerKey: z.string(),
|
||||
zone: z.string(),
|
||||
});
|
||||
|
||||
type DnsProviderForm = z.infer<typeof DnsProviderSchema>;
|
||||
@@ -104,6 +105,7 @@ const defaultValues: DnsProviderForm = {
|
||||
applicationKey: "",
|
||||
applicationSecret: "",
|
||||
consumerKey: "",
|
||||
zone: "",
|
||||
};
|
||||
|
||||
const buildConfig = (data: DnsProviderForm) => {
|
||||
@@ -137,6 +139,7 @@ const buildConfig = (data: DnsProviderForm) => {
|
||||
applicationKey: data.applicationKey,
|
||||
applicationSecret: data.applicationSecret,
|
||||
consumerKey: data.consumerKey,
|
||||
zone: data.zone.trim() || undefined,
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -207,6 +210,7 @@ export const HandleDnsProvider = ({ dnsProviderId }: Props) => {
|
||||
applicationKey: provider.config.applicationKey,
|
||||
applicationSecret: provider.config.applicationSecret,
|
||||
consumerKey: provider.config.consumerKey,
|
||||
zone: provider.config.zone ?? "",
|
||||
}),
|
||||
});
|
||||
} else if (!dnsProviderId) {
|
||||
@@ -545,6 +549,24 @@ export const HandleDnsProvider = ({ dnsProviderId }: Props) => {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="zone"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Zone (optional)</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="example.com" {...field} />
|
||||
</FormControl>
|
||||
<FormDescription>
|
||||
Restrict this provider to a single DNS zone. Leave empty
|
||||
to use every zone the credentials can access. When set,
|
||||
the <code>GET /domain/zone</code> right is not needed.
|
||||
</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ export const ovhDnsConfigSchema = z.object({
|
||||
applicationKey: z.string().trim().min(1),
|
||||
applicationSecret: z.string().trim().min(1),
|
||||
consumerKey: z.string().trim().min(1),
|
||||
zone: z.string().trim().min(1).optional(),
|
||||
});
|
||||
|
||||
export const dnsProviderConfigSchema = z.discriminatedUnion("providerType", [
|
||||
|
||||
@@ -254,6 +254,9 @@ const listZoneNames = async (config: OvhConfig) => {
|
||||
|
||||
export const ovhClient: DnsClient<OvhConfig> = {
|
||||
async listZones(config) {
|
||||
if (config.zone) {
|
||||
return [{ id: config.zone, name: config.zone }];
|
||||
}
|
||||
const zones = await listZoneNames(config);
|
||||
return zones.map((zone) => ({ id: zone, name: zone }));
|
||||
},
|
||||
@@ -372,6 +375,10 @@ export const ovhClient: DnsClient<OvhConfig> = {
|
||||
},
|
||||
|
||||
async testConnection(config) {
|
||||
if (config.zone) {
|
||||
await ovhFetch(config, `/domain/zone/${encodeURIComponent(config.zone)}`);
|
||||
return;
|
||||
}
|
||||
await listZoneNames(config);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user