2026-05-05 12:59:36 +02:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
|
2026-04-23 08:55:49 +02:00
|
|
|
package netbirdutil
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"slices"
|
|
|
|
|
|
|
|
|
|
netbird "github.com/netbirdio/netbird/shared/management/client/rest"
|
|
|
|
|
"github.com/netbirdio/netbird/shared/management/http/api"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func GetDNSZoneByName(ctx context.Context, nbClient *netbird.Client, name string) (api.Zone, error) {
|
|
|
|
|
resp, err := nbClient.DNSZones.ListZones(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return api.Zone{}, err
|
|
|
|
|
}
|
|
|
|
|
zoneIdx := slices.IndexFunc(resp, func(zone api.Zone) bool {
|
|
|
|
|
return zone.Name == name
|
|
|
|
|
})
|
|
|
|
|
if zoneIdx == -1 {
|
|
|
|
|
return api.Zone{}, fmt.Errorf("zone with name %s cannot be found", name)
|
|
|
|
|
}
|
|
|
|
|
return resp[zoneIdx], nil
|
|
|
|
|
}
|