mirror of
https://github.com/YuzuZensai/netbird-kubernetes-operator.git
synced 2026-09-13 10:49:15 +00:00
25 lines
605 B
Go
25 lines
605 B
Go
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
|
||
|
|
}
|