From 2702ed26f852cd761c238bfc0911d34a501e9144 Mon Sep 17 00:00:00 2001 From: boB Rudis Date: Wed, 25 Jul 2018 09:31:36 -0400 Subject: [PATCH] new/addtl column for bulk_query and new RR global data --- DESCRIPTION | 2 +- NEWS.md | 4 +++- R/gdns-package.r | 15 +++++++++++++++ R/utils.R | 4 ++++ R/zbulk-query.R | 38 ++++++++++++++++++++++++++++++++++++++ R/zgdns.r | 29 ----------------------------- data/resource_record_tbl.rda | Bin 0 -> 3015 bytes man/bulk_query.Rd | 4 ++-- man/resource_record_tbl.Rd | 23 +++++++++++++++++++++++ tests/testthat/test-gdns.R | 2 +- 10 files changed, 87 insertions(+), 34 deletions(-) create mode 100644 R/utils.R create mode 100644 R/zbulk-query.R create mode 100644 data/resource_record_tbl.rda create mode 100644 man/resource_record_tbl.Rd diff --git a/DESCRIPTION b/DESCRIPTION index fd3d447..b008734 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: gdns Title: Tools to Work with Google's 'DNS-over-HTTPS' ('DoH') 'API' -Version: 0.2.1 +Version: 0.3.0 Authors@R: c( person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5670-2640")) diff --git a/NEWS.md b/NEWS.md index 54a8878..14b8a94 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ -# gdns 0.2.2 +# gdns 0.3.0 * removed purrr, dplyr and tibble dependencies +* `bulk_query()` now returns the original query string in a `query` column +* added `resource_record_tbl` data frame of DNS RR metadata # gdns 0.2.1 diff --git a/R/gdns-package.r b/R/gdns-package.r index 18e5466..f912692 100644 --- a/R/gdns-package.r +++ b/R/gdns-package.r @@ -26,3 +26,18 @@ #' stri_detect_fixed #' @importFrom jsonlite fromJSON NULL + + +#' An overview of resource records (RRs) permissible in zone files of the Domain Name System (DNS) +#' +#' A dataset containing the DNS resource record types, names, description and purpose +#' +#' @format A data frame with 39 rows and 4 variables: +#' \describe{ +#' \item{type}{numeric type of the resource record} +#' \item{name}{short name of the resource record} +#' \item{description}{short description of the resource record} +#' \item{purpose}{long-form description of the resource record purpose/function/usage} +#' } +#' @source \url{https://en.wikipedia.org/wiki/List_of_DNS_record_types} +"resource_record_tbl" diff --git a/R/utils.R b/R/utils.R new file mode 100644 index 0000000..95d7631 --- /dev/null +++ b/R/utils.R @@ -0,0 +1,4 @@ +set_names <- function (object = nm, nm) { + names(object) <- nm + object +} diff --git a/R/zbulk-query.R b/R/zbulk-query.R new file mode 100644 index 0000000..17a8ae4 --- /dev/null +++ b/R/zbulk-query.R @@ -0,0 +1,38 @@ +#' Vectorized query, returning only answers in a data frame +#' +#' @param entities character vector of entities to query +#' @param type RR type can be represented as a number in [1, 65535] or canonical +#' string (A, aaaa, etc). More information on RR types can be +#' found \href{http://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4}{here}. +#' @param edns_client_subnet The edns0-client-subnet option. Format is an IP +#' address with a subnet mask. Examples: \code{1.2.3.4/24}, +#' \code{2001:700:300::/48}.\cr +#' If you are using DNS-over-HTTPS because of privacy concerns, and do +#' not want any part of your IP address to be sent to authoritative +#' nameservers for geographic location accuracy, use +#' \code{edns_client_subnet=0.0.0.0/0}. Google Public DNS normally sends +#' approximate network information (usually replacing the last part of +#' your IPv4 address with zeroes). \code{0.0.0.0/0} is the default. +#' @return \code{data.frame} of only answers (use \code{query()} for detailed responses) +#' @references \url{https://developers.google.com/speed/public-dns/docs/dns-over-https} +#' @export +#' @note this is a fairly naive function. It expects \code{Answer} to be one of the +#' return value list slots. The intent for it was to make it easier +#' to do bulk forward queries. It will get smarter in future versions. +#' @examples +#' hosts <- c("rud.is", "r-project.org", "rstudio.com", "apple.com") +#' gdns::bulk_query(hosts) +bulk_query <- function(entities, type = 1, edns_client_subnet = "0.0.0.0/0") { + + map( + entities, + gdns::query, + type = type, + edns_client_subnet = edns_client_subnet + ) -> results + + results <- set_names(results, entities) + + map_df(results, ~.x$Answer, .id = "query") + +} diff --git a/R/zgdns.r b/R/zgdns.r index 72899e7..21970c9 100644 --- a/R/zgdns.r +++ b/R/zgdns.r @@ -77,32 +77,3 @@ query <- function(name, type="1", edns_client_subnet="0.0.0.0/0") { } } - -#' Vectorized query, returning only answers in a data frame -#' -#' @param entities character vector of entities to query -#' @param type RR type can be represented as a number in [1, 65535] or canonical -#' string (A, aaaa, etc). More information on RR types can be -#' found \href{http://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4}{here}. -#' @param edns_client_subnet The edns0-client-subnet option. Format is an IP -#' address with a subnet mask. Examples: \code{1.2.3.4/24}, -#' \code{2001:700:300::/48}.\cr -#' If you are using DNS-over-HTTPS because of privacy concerns, and do -#' not want any part of your IP address to be sent to authoritative -#' nameservers for geographic location accuracy, use -#' \code{edns_client_subnet=0.0.0.0/0}. Google Public DNS normally sends -#' approximate network information (usually replacing the last part of -#' your IPv4 address with zeroes). \code{0.0.0.0/0} is the default. -#' @return \code{data.frame} of only answers (use \code{query()} for detailed responses) -#' @references \url{https://developers.google.com/speed/public-dns/docs/dns-over-https} -#' @export -#' @note this is a fairly naive function. It expects \code{Answer} to be one of the -#' return value list slots. The intent for it was to make it easier -#' to do bulk forward queries. It will get smarter in future versions. -#' @examples -#' hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com", "apple.com") -#' gdns::bulk_query(hosts) -bulk_query <- function(entities, type=1, edns_client_subnet="0.0.0.0/0") { - results <- map(entities, gdns::query, type=type, edns_client_subnet=edns_client_subnet) - map_df(results, ~.x$Answer) -} diff --git a/data/resource_record_tbl.rda b/data/resource_record_tbl.rda new file mode 100644 index 0000000000000000000000000000000000000000..e03a1c05b900f64b33103e757afc8de258b6934f GIT binary patch literal 3015 zcmV;&3pn&bT4*^jL0KkKSt4$O`~U^Z|NsB{|9o5L|Nj5~|LVX0-|)ZyL;^s72#5d* zfFe);K>^?lPnVxw6zI_Vt=xR<$#vEiZIcUF0Fs#&%5EBJ5v4r|srqG4)YH;xV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HQoP*Xj?QeF9_Thn5)Cb;uZ@|~s}PU+ z(adXuf@dk;X@g`r7E_rq=DFLnB!#GcS#D`+LLm%8%*N8b&E*_$qmK7x!c&}p-y<@R zfbeA`U1rl54ynRPg$sLV%2|nSY18ca{SMQ+vDT9ltKytFPXRzR%)tJdz+gY|cO+AV J2?8eQKfqMMktqNG literal 0 HcmV?d00001 diff --git a/man/bulk_query.Rd b/man/bulk_query.Rd index d298b99..a8061eb 100644 --- a/man/bulk_query.Rd +++ b/man/bulk_query.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/zgdns.r +% Please edit documentation in R/zbulk-query.R \name{bulk_query} \alias{bulk_query} \title{Vectorized query, returning only answers in a data frame} @@ -35,7 +35,7 @@ this is a fairly naive function. It expects \code{Answer} to be one of the to do bulk forward queries. It will get smarter in future versions. } \examples{ -hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com", "apple.com") +hosts <- c("rud.is", "r-project.org", "rstudio.com", "apple.com") gdns::bulk_query(hosts) } \references{ diff --git a/man/resource_record_tbl.Rd b/man/resource_record_tbl.Rd new file mode 100644 index 0000000..cd63d6a --- /dev/null +++ b/man/resource_record_tbl.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/gdns-package.r +\docType{data} +\name{resource_record_tbl} +\alias{resource_record_tbl} +\title{An overview of resource records (RRs) permissible in zone files of the Domain Name System (DNS)} +\format{A data frame with 39 rows and 4 variables: +\describe{ + \item{type}{numeric type of the resource record} + \item{name}{short name of the resource record} + \item{description}{short description of the resource record} + \item{purpose}{long-form description of the resource record purpose/function/usage} +}} +\source{ +\url{https://en.wikipedia.org/wiki/List_of_DNS_record_types} +} +\usage{ +resource_record_tbl +} +\description{ +A dataset containing the DNS resource record types, names, description and purpose +} +\keyword{datasets} diff --git a/tests/testthat/test-gdns.R b/tests/testthat/test-gdns.R index 858135a..eba36f0 100644 --- a/tests/testthat/test-gdns.R +++ b/tests/testthat/test-gdns.R @@ -6,6 +6,6 @@ test_that("we can do something", { doms <- c("example.com", "example.org", "example.net") qry <- gdns::bulk_query(doms) - expect_that(dim(qry), equals(c(3, 4))) + expect_that(dim(qry), equals(c(3, 5))) })