2022-09-04 14:26:32 +00:00
|
|
|
package utils
|
2022-04-16 11:02:32 +00:00
|
|
|
|
|
|
|
import (
|
2022-08-14 20:55:52 +00:00
|
|
|
"context"
|
2022-04-16 11:02:32 +00:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2023-01-29 21:20:13 +00:00
|
|
|
func getRealm(ctx context.Context, realmName, id string) (name string, address string, err error) {
|
|
|
|
realms, err := GetRealmsAPI().Realms(ctx)
|
2022-04-16 11:02:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", "", err
|
|
|
|
}
|
|
|
|
for _, realm := range realms {
|
2023-01-29 21:20:13 +00:00
|
|
|
if strings.HasPrefix(realm.Name, realmName) {
|
2022-08-15 00:29:01 +00:00
|
|
|
if id != "" && id != fmt.Sprint(id) {
|
|
|
|
continue
|
|
|
|
}
|
2022-08-22 10:56:02 +00:00
|
|
|
name = realm.Name
|
2022-08-23 19:06:08 +00:00
|
|
|
address, err = realm.Address(ctx)
|
2022-04-16 11:02:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", "", err
|
|
|
|
}
|
2022-08-22 10:56:02 +00:00
|
|
|
return
|
2022-04-16 11:02:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return "", "", fmt.Errorf("realm not found")
|
|
|
|
}
|