Project

General

Profile

Actions

Feature #14771

open

Add method to create DNS resource from data string

Added by ioquatix (Samuel Williams) over 6 years ago. Updated over 6 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:87138]

Description

I recently played around with DNS over HTTPS.

I found that it's a little bit tricky to generate the appropriate resource using the Resolv::DNS::Resource hierarchy.

Here is what my code ended up:

        if klass = Resolv::DNS::Resource.get_class(answer["type"], resource_class::ClassValue)
          if klass < Resolv::DNS::Resource::DomainName
            resource = klass.new(Resolv::DNS::Name.create(answer["data"]))
          else
            resource = klass.new(answer["data"])
          end

It would be nice to have a simpler interface, e.g.

        if klass = Resolv::DNS::Resource.get_class(answer["type"], resource_class::ClassValue)
          klass.create(answer["data"])
        end

In this case, the Resource#create method would take a data string and convert it to a name if required.

The base resource class could just have alias create new, while the DomainName class could have:

def create(data)
  self.new(Name.create(data))
end

Or something like that.

Updated by ioquatix (Samuel Williams) over 6 years ago

The suggested code should be (missing resource =):

        if klass = Resolv::DNS::Resource.get_class(answer["type"], resource_class::ClassValue)
          resource = klass.create(answer["data"])
        end

Updated by shevegen (Robert A. Heiler) over 6 years ago

Although I myself have not used/needed Resolv::DNS::Resource yet,
if the proposed #create method does not conflict with anything in
Resolv, then I think it is fine to add it. (If I understood it correctly
then this is mostly alias-related, with the toplevel create doing a
bit more than just an alias, so it should not be a problem I think?)

Documentation should not be forgotten for the new toplevel create
method, if it is accepted by matz/the ruby core team.

Updated by ioquatix (Samuel Williams) over 6 years ago

The other record where it could be useful would be the TXT record which required to use a chunked string format.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0