New Upstream Release - golang-github-nrdcg-desec

Ready changes

Summary

Merged new upstream version: 0.7.0 (was: 0.6.0).

Resulting package

Built on 2023-01-26T10:19 (took 2m1s)

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-releases golang-github-nrdcg-desec-dev

Lintian Result

Diff

diff --git a/.github/workflows/go-cross.yml b/.github/workflows/go-cross.yml
index 4b71408..1bd470c 100644
--- a/.github/workflows/go-cross.yml
+++ b/.github/workflows/go-cross.yml
@@ -11,7 +11,7 @@ jobs:
 
     strategy:
       matrix:
-        go-version: [ 1.16, 1.17, 1.x ]
+        go-version: [ 1.18, 1.19, 1.x ]
         os: [ubuntu-latest, macos-latest, windows-latest]
 
     steps:
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 2a04408..761f804 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -14,8 +14,8 @@ jobs:
     name: Main Process
     runs-on: ubuntu-latest
     env:
-      GO_VERSION: 1.17
-      GOLANGCI_LINT_VERSION: v1.42.0
+      GO_VERSION: 1.19
+      GOLANGCI_LINT_VERSION: v1.50.1
       CGO_ENABLED: 0
 
     steps:
diff --git a/.golangci.yml b/.golangci.yml
index b65a7e8..089584b 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -52,12 +52,19 @@ linters-settings:
 linters:
   enable-all: true
   disable:
-    - maligned # deprecated
+    - deadcode # deprecated
+    - exhaustivestruct # deprecated
+    - golint # deprecated
+    - ifshort # deprecated
     - interfacer # deprecated
+    - maligned # deprecated
+    - nosnakecase # deprecated
     - scopelint # deprecated
-    - golint # deprecated
+    - structcheck # deprecated
+    - varcheck # deprecated
     - sqlclosecheck # not relevant (SQL)
     - rowserrcheck # not relevant (SQL)
+    - execinquery # not relevant (SQL)
     - cyclop # duplicate of gocyclo
     - lll
     - dupl
@@ -67,20 +74,23 @@ linters:
     - goerr113
     - wrapcheck
     - exhaustive
-    - exhaustivestruct
+    - exhaustruct
     - testpackage
     - tparallel
     - paralleltest
     - prealloc
     - ifshort
     - forcetypeassert
+    - nilnil
+    - varnamelen
 
 issues:
   exclude-use-default: false
   max-per-linter: 0
   max-same-issues: 0
   exclude:
-    - "ST1000:"
+    - 'ST1000: at least one file in a package should have a package comment'
+    - 'package-comments: should have a package comment'
   exclude-rules:
     - path: .*_test.go
       linters:
diff --git a/debian/changelog b/debian/changelog
index 2ee180c..3232a87 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+golang-github-nrdcg-desec (0.7.0-1) UNRELEASED; urgency=low
+
+  * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Thu, 26 Jan 2023 10:17:52 -0000
+
 golang-github-nrdcg-desec (0.6.0-1) unstable; urgency=medium
 
   * Team upload.
diff --git a/domains.go b/domains.go
index b20fbae..dd5b641 100644
--- a/domains.go
+++ b/domains.go
@@ -4,6 +4,7 @@ import (
 	"context"
 	"fmt"
 	"net/http"
+	"net/url"
 	"time"
 )
 
@@ -67,6 +68,30 @@ func (s *DomainsService) Create(ctx context.Context, domainName string) (*Domain
 // GetAll listing domains.
 // https://desec.readthedocs.io/en/latest/dns/domains.html#listing-domains
 func (s *DomainsService) GetAll(ctx context.Context) ([]Domain, error) {
+	return s.getAll(ctx, nil)
+}
+
+// GetResponsible returns the responsible domain for a given DNS query name.
+// https://desec.readthedocs.io/en/latest/dns/domains.html#identifying-the-responsible-domain-for-a-dns-name
+func (s *DomainsService) GetResponsible(ctx context.Context, domainName string) (*Domain, error) {
+	queryValues := url.Values{}
+	queryValues.Set("owns_qname", domainName)
+
+	domains, err := s.getAll(ctx, queryValues)
+	if err != nil {
+		return nil, err
+	}
+
+	if len(domains) == 0 {
+		return nil, &NotFoundError{Detail: "no responsible domain found"}
+	}
+
+	return &domains[0], nil
+}
+
+// getAll listing domains.
+// https://desec.readthedocs.io/en/latest/dns/domains.html#listing-domains
+func (s *DomainsService) getAll(ctx context.Context, query url.Values) ([]Domain, error) {
 	endpoint, err := s.client.createEndpoint("domains")
 	if err != nil {
 		return nil, fmt.Errorf("failed to create endpoint: %w", err)
@@ -77,6 +102,10 @@ func (s *DomainsService) GetAll(ctx context.Context) ([]Domain, error) {
 		return nil, err
 	}
 
+	if len(query) > 0 {
+		req.URL.RawQuery = query.Encode()
+	}
+
 	resp, err := s.client.httpClient.Do(req)
 	if err != nil {
 		return nil, fmt.Errorf("failed to call API: %w", err)
diff --git a/domains_test.go b/domains_test.go
index 661ea8e..18dab07 100644
--- a/domains_test.go
+++ b/domains_test.go
@@ -140,6 +140,72 @@ func TestDomainsService_Get(t *testing.T) {
 	assert.Equal(t, expected, domain)
 }
 
+func TestDomainsService_GetResponsible(t *testing.T) {
+	mux := http.NewServeMux()
+	server := httptest.NewServer(mux)
+	t.Cleanup(server.Close)
+
+	client := New("token", NewDefaultClientOptions())
+	client.BaseURL = server.URL
+
+	mux.HandleFunc("/domains/", func(rw http.ResponseWriter, req *http.Request) {
+		if req.Method != http.MethodGet {
+			http.Error(rw, "invalid method", http.StatusMethodNotAllowed)
+			return
+		}
+		if req.URL.Query().Get("owns_qname") != "git.dev.example.org" {
+			http.Error(rw, "owns_qname not passed correctly", http.StatusBadRequest)
+			return
+		}
+
+		file, err := os.Open("./fixtures/domains_getresponsible.json")
+		if err != nil {
+			http.Error(rw, err.Error(), http.StatusInternalServerError)
+			return
+		}
+		defer func() { _ = file.Close() }()
+
+		_, err = io.Copy(rw, file)
+		if err != nil {
+			http.Error(rw, err.Error(), http.StatusInternalServerError)
+			return
+		}
+	})
+
+	domain, err := client.Domains.GetResponsible(context.Background(), "git.dev.example.org")
+	require.NoError(t, err)
+
+	expected := &Domain{
+		Name:       "dev.example.org",
+		MinimumTTL: 3600,
+		Created:    mustParseTime("2022-11-12T18:01:35.454616Z"),
+		Published:  mustParseTime("2022-11-12T18:03:19.516440Z"),
+	}
+	assert.Equal(t, expected, domain)
+}
+
+func TestDomainsService_GetResponsible_error(t *testing.T) {
+	mux := http.NewServeMux()
+	server := httptest.NewServer(mux)
+	t.Cleanup(server.Close)
+
+	client := New("token", NewDefaultClientOptions())
+	client.BaseURL = server.URL
+
+	mux.HandleFunc("/domains/", func(rw http.ResponseWriter, req *http.Request) {
+		if req.Method != http.MethodGet {
+			http.Error(rw, "invalid method", http.StatusMethodNotAllowed)
+			return
+		}
+
+		_, _ = rw.Write([]byte("[]"))
+	})
+
+	_, err := client.Domains.GetResponsible(context.Background(), "git.dev.example.org")
+	var notFoundError *NotFoundError
+	require.ErrorAs(t, err, &notFoundError)
+}
+
 func TestDomainsService_GetAll(t *testing.T) {
 	mux := http.NewServeMux()
 	server := httptest.NewServer(mux)
diff --git a/fixtures/domains_getresponsible.json b/fixtures/domains_getresponsible.json
new file mode 100644
index 0000000..4eda718
--- /dev/null
+++ b/fixtures/domains_getresponsible.json
@@ -0,0 +1,8 @@
+[
+  {
+    "created": "2022-11-12T18:01:35.454616Z",
+    "published": "2022-11-12T18:03:19.516440Z",
+    "name": "dev.example.org",
+    "minimum_ttl": 3600
+  }
+]
diff --git a/go.mod b/go.mod
index 0708ad1..6128d7a 100644
--- a/go.mod
+++ b/go.mod
@@ -1,8 +1,15 @@
 module github.com/nrdcg/desec
 
-go 1.16
+go 1.18
 
 require (
-	github.com/hashicorp/go-retryablehttp v0.7.0
-	github.com/stretchr/testify v1.7.0
+	github.com/hashicorp/go-retryablehttp v0.7.1
+	github.com/stretchr/testify v1.8.1
+)
+
+require (
+	github.com/davecgh/go-spew v1.1.1 // indirect
+	github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
+	github.com/pmezard/go-difflib v1.0.0 // indirect
+	gopkg.in/yaml.v3 v3.0.1 // indirect
 )
diff --git a/go.sum b/go.sum
index 1510e12..52ad67a 100644
--- a/go.sum
+++ b/go.sum
@@ -5,15 +5,20 @@ github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVo
 github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
 github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
 github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
-github.com/hashicorp/go-retryablehttp v0.7.0 h1:eu1EI/mbirUgP5C8hVsTNaGZreBDlYiwC1FZWkvQPQ4=
-github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
+github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ=
+github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
+github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
-github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
-github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
+github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
+github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

Debdiff

[The following lists of changes regard files as different if they have different names, permissions or owners.]

Files in second set of .debs but not in first

-rw-r--r--  root/root   /usr/share/gocode/src/github.com/nrdcg/desec/fixtures/domains_getresponsible.json

No differences were encountered in the control files

More details

Full run details