2022-04-12 08:25:18 +00:00
|
|
|
package ns
|
2021-11-17 12:37:55 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
2022-12-13 14:36:35 +00:00
|
|
|
cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id"
|
2021-11-17 12:37:55 +00:00
|
|
|
)
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// DNS looks up FrostFS names using system DNS.
|
2022-03-18 08:32:00 +00:00
|
|
|
//
|
|
|
|
// See also net package.
|
|
|
|
type DNS struct{}
|
|
|
|
|
|
|
|
// ResolveContainerName looks up for DNS TXT records for the given domain name
|
|
|
|
// and returns the first one which represents valid container ID in a string format.
|
|
|
|
// Otherwise, returns an error.
|
|
|
|
//
|
|
|
|
// See also net.LookupTXT.
|
2022-04-11 16:25:14 +00:00
|
|
|
func (x *DNS) ResolveContainerName(name string) (id cid.ID, err error) {
|
2022-03-18 08:32:00 +00:00
|
|
|
records, err := net.LookupTXT(name)
|
2021-11-17 12:37:55 +00:00
|
|
|
if err != nil {
|
2022-04-11 16:25:14 +00:00
|
|
|
return
|
2021-11-17 12:37:55 +00:00
|
|
|
}
|
|
|
|
|
2022-03-18 08:32:00 +00:00
|
|
|
for i := range records {
|
2022-04-11 16:25:14 +00:00
|
|
|
err = id.DecodeString(records[i])
|
2022-03-18 08:32:00 +00:00
|
|
|
if err == nil {
|
2022-04-11 16:25:14 +00:00
|
|
|
return
|
2021-11-17 12:37:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 16:25:14 +00:00
|
|
|
err = errNotFound
|
|
|
|
|
|
|
|
return
|
2021-11-17 12:37:55 +00:00
|
|
|
}
|