New Upstream Release - golang-github-gmazoyer-peeringdb

Ready changes

Summary

Merged new upstream version: 0.0~git20221216.ec4f6d9 (was: 0.0~git20180219.dd23298).

Resulting package

Built on 2023-02-27T00:52 (took 4m20s)

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-gmazoyer-peeringdb-dev

Lintian Result

Diff

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..f20ce8a
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,24 @@
+name: CI
+on:
+- push
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        go-version:
+        - '1.16'
+        - '1.17'
+        - '1.18'
+        - '1.19'
+    steps:
+    - uses: actions/checkout@v3
+    - name: Setup Go ${{ matrix.go-version }}
+      uses: actions/setup-go@v3
+      with:
+        go-version: ${{ matrix.go-version }}
+    - name: Display Go version
+      run: go version
+    - name: Run tests
+      run: go test
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 236daa7..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-language: go
-go:
-  - 1.4.x
-  - 1.5.x
-  - 1.6.x
-  - 1.7.x
-  - 1.8.x
-  - 1.9.x
-  - 1.10.x
-  - tip
-
-matrix:
-  allow_failures:
-    - go: tip
diff --git a/README.md b/README.md
index a601fb5..ff6ec2e 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,7 @@
 # PeeringDB API - Go package
 
-[![Code Health](https://landscape.io/github/respawner/peeringdb/master/landscape.svg?style=flat)](https://landscape.io/github/respawner/peeringdb/master)
-[![Build Status](https://travis-ci.org/respawner/peeringdb.svg?branch=master)](https://travis-ci.org/respawner/peeringdb)
-[![GoDoc](https://godoc.org/github.com/respawner/peeringdb?status.svg)](https://godoc.org/github.com/respawner/peeringdb)
-[![Go Report Card](https://goreportcard.com/badge/github.com/respawner/peeringdb)](https://goreportcard.com/report/github.com/respawner/peeringdb)
+[![GoDoc](https://godoc.org/github.com/gmazoyer/peeringdb?status.svg)](https://godoc.org/github.com/gmazoyer/peeringdb)
+[![Go Report Card](https://goreportcard.com/badge/github.com/gmazoyer/peeringdb)](https://goreportcard.com/report/github.com/gmazoyer/peeringdb)
 
 This is a Go package that allows developer to interact with the
 [PeeringDB API](https://peeringdb.com/apidocs/) in the easiest way possible.
@@ -12,12 +10,12 @@ library.
 
 ## Installation
 
-Install the library package with `go get github.com/respawner/peeringdb`.
+Install the library package with `go get github.com/gmazoyer/peeringdb`.
 
 ## Example
 
 There are small examples in the
-[package documentation](https://godoc.org/github.com/respawner/peeringdb).
+[package documentation](https://godoc.org/github.com/gmazoyer/peeringdb).
 
 You can also found a real life example with the
-[PeeringDB synchronization tool](https://github.com/respawner/peeringdb-sync).
+[PeeringDB synchronization tool](https://github.com/gmazoyer/peeringdb-sync).
diff --git a/api.go b/api.go
index f189a08..56cf0f6 100644
--- a/api.go
+++ b/api.go
@@ -4,11 +4,12 @@ import (
 	"errors"
 	"fmt"
 	"net/http"
+	"net/url"
 	"sort"
 )
 
 const (
-	baseAPI                             = "https://peeringdb.com/api/"
+	baseAPI                             = "https://www.peeringdb.com/api/"
 	facilityNamespace                   = "fac"
 	internetExchangeNamespace           = "ix"
 	internetExchangeFacilityNamespace   = "ixfac"
@@ -24,13 +25,13 @@ const (
 var (
 	// ErrBuildingURL is the error that will be returned if the URL to call the
 	// API cannot be built as expected.
-	ErrBuildingURL = errors.New("Error while building the URL to call the PeeringDB API.")
+	ErrBuildingURL = errors.New("error while building the URL to call the peeringdb api")
 	// ErrBuildingRequest is the error that will be returned if the HTTP
 	// request to call the API cannot be built as expected.
-	ErrBuildingRequest = errors.New("Error while building the request to send to the PeeringDB API.")
+	ErrBuildingRequest = errors.New("error while building the request to send to the peeringdb api")
 	// ErrQueryingAPI is the error that will be returned if there is an issue
 	// while making the request to the API.
-	ErrQueryingAPI = errors.New("Error while querying PeeringDB API.")
+	ErrQueryingAPI = errors.New("error while querying peeringdb api")
 )
 
 // API is the structure used to interact with the PeeringDB API. This is the
@@ -40,6 +41,7 @@ type API struct {
 	url      string
 	login    string
 	password string
+	apiKey   string
 }
 
 // NewAPI returns a pointer to a new API structure. It uses the publicly known
@@ -63,6 +65,16 @@ func NewAPIWithAuth(login, password string) *API {
 	}
 }
 
+// NewAPIWithAuth returns a pointer to a new API structure. The API will point
+// to the publicly known PeeringDB API endpoint and will use the provided login
+// and password to attempt an authentication while making API calls.
+func NewAPIWithAPIKey(apiKey string) *API {
+	return &API{
+		url:    baseAPI,
+		apiKey: apiKey,
+	}
+}
+
 // NewAPIFromURL returns a pointer to a new API structure from a given URL. If
 // the given URL is empty it will use the default PeeringDB API URL.
 func NewAPIFromURL(url string) *API {
@@ -114,7 +126,7 @@ func formatSearchParameters(parameters map[string]interface{}) string {
 
 	// For each element, append it to the request separated by a & symbol.
 	for _, key := range keys {
-		search = fmt.Sprintf("%s&%s=%v", search, key, parameters[key])
+		search = search + "&" + key + "=" + url.QueryEscape(fmt.Sprintf("%v", parameters[key]))
 	}
 
 	return search
@@ -147,6 +159,10 @@ func (api *API) lookup(namespace string, search map[string]interface{}) (*http.R
 		request.SetBasicAuth(api.login, api.password)
 	}
 
+	if api.apiKey != "" {
+		request.Header.Add("Authorization", fmt.Sprintf("Api-Key %s", api.apiKey))
+	}
+
 	// Send the request to the API using a simple HTTP client
 	client := &http.Client{}
 	response, err := client.Do(request)
@@ -172,5 +188,8 @@ func (api *API) GetASN(asn int) *Network {
 		return nil
 	}
 
+	if len(*network) == 0 {
+		return nil
+	}
 	return &(*network)[0]
 }
diff --git a/api_test.go b/api_test.go
index 0a02ed4..85aa121 100644
--- a/api_test.go
+++ b/api_test.go
@@ -50,75 +50,75 @@ func TestFormatURL(t *testing.T) {
 	var expected string
 	var url string
 
-	base := "https://peeringdb.com/api/"
+	base := "https://www.peeringdb.com/api/"
 	searchMap := make(map[string]interface{})
 	searchMap["id"] = 10
 
 	// Test fac namespace with search parameter
-	expected = "https://peeringdb.com/api/fac?depth=1&id=10"
+	expected = "https://www.peeringdb.com/api/fac?depth=1&id=10"
 	url = formatURL(base, facilityNamespace, searchMap)
 	if url != expected {
 		t.Errorf("formatURL, want '%s' got '%s'", expected, url)
 	}
 
 	// Test ix namespace with search parameter
-	expected = "https://peeringdb.com/api/ix?depth=1&id=10"
+	expected = "https://www.peeringdb.com/api/ix?depth=1&id=10"
 	url = formatURL(base, internetExchangeNamespace, searchMap)
 	if url != expected {
 		t.Errorf("formatURL, want '%s' got '%s'", expected, url)
 	}
 
 	// Test ixfac namespace with search parameter
-	expected = "https://peeringdb.com/api/ixfac?depth=1&id=10"
+	expected = "https://www.peeringdb.com/api/ixfac?depth=1&id=10"
 	url = formatURL(base, internetExchangeFacilityNamespace, searchMap)
 	if url != expected {
 		t.Errorf("formatURL, want '%s' got '%s'", expected, url)
 	}
 
 	// Test ixlan namespace with search parameter
-	expected = "https://peeringdb.com/api/ixlan?depth=1&id=10"
+	expected = "https://www.peeringdb.com/api/ixlan?depth=1&id=10"
 	url = formatURL(base, internetExchangeLANNamespace, searchMap)
 	if url != expected {
 		t.Errorf("formatURL, want '%s' got '%s'", expected, url)
 	}
 
 	// Test ixpfx namespace with search parameter
-	expected = "https://peeringdb.com/api/ixpfx?depth=1&id=10"
+	expected = "https://www.peeringdb.com/api/ixpfx?depth=1&id=10"
 	url = formatURL(base, internetExchangePrefixNamespace, searchMap)
 	if url != expected {
 		t.Errorf("formatURL, want '%s' got '%s'", expected, url)
 	}
 
 	// Test net namespace with search parameter
-	expected = "https://peeringdb.com/api/net?depth=1&id=10"
+	expected = "https://www.peeringdb.com/api/net?depth=1&id=10"
 	url = formatURL(base, networkNamespace, searchMap)
 	if url != expected {
 		t.Errorf("formatURL, want '%s' got '%s'", expected, url)
 	}
 
 	// Test netfac namespace with search parameter
-	expected = "https://peeringdb.com/api/netfac?depth=1&id=10"
+	expected = "https://www.peeringdb.com/api/netfac?depth=1&id=10"
 	url = formatURL(base, networkFacilityNamespace, searchMap)
 	if url != expected {
 		t.Errorf("formatURL, want '%s' got '%s'", expected, url)
 	}
 
 	// Test netixlan namespace with search parameter
-	expected = "https://peeringdb.com/api/netixlan?depth=1&id=10"
+	expected = "https://www.peeringdb.com/api/netixlan?depth=1&id=10"
 	url = formatURL(base, networkInternetExchangeLANNamepsace, searchMap)
 	if url != expected {
 		t.Errorf("formatURL, want '%s' got '%s'", expected, url)
 	}
 
 	// Test org namespace with search parameter
-	expected = "https://peeringdb.com/api/org?depth=1&id=10"
+	expected = "https://www.peeringdb.com/api/org?depth=1&id=10"
 	url = formatURL(base, organizationNamespace, searchMap)
 	if url != expected {
 		t.Errorf("formatURL, want '%s' got '%s'", expected, url)
 	}
 
 	// Test poc namespace with search parameter
-	expected = "https://peeringdb.com/api/poc?depth=1&id=10"
+	expected = "https://www.peeringdb.com/api/poc?depth=1&id=10"
 	url = formatURL(base, networkContactNamespace, searchMap)
 	if url != expected {
 		t.Errorf("formatURL, want '%s' got '%s'", expected, url)
@@ -127,11 +127,10 @@ func TestFormatURL(t *testing.T) {
 
 func TestNewAPI(t *testing.T) {
 	var expectedURL string
-	var api *API
 
 	// Test to use the public PeeringDB API
-	api = NewAPI()
-	expectedURL = "https://peeringdb.com/api/"
+	api := NewAPI()
+	expectedURL = "https://www.peeringdb.com/api/"
 	if api.url != expectedURL {
 		t.Errorf("formatURL, want '%s' got '%s'", expectedURL, api.url)
 	}
@@ -139,11 +138,10 @@ func TestNewAPI(t *testing.T) {
 
 func TestNewAPIWithAuth(t *testing.T) {
 	var expectedURL, expectedLogin, expectedPassword string
-	var api *API
 
 	// Test to use the public PeeringDB API with authentication
-	api = NewAPIWithAuth("test", "123")
-	expectedURL = "https://peeringdb.com/api/"
+	api := NewAPIWithAuth("test", "123")
+	expectedURL = "https://www.peeringdb.com/api/"
 	expectedLogin = "test"
 	expectedPassword = "123"
 	if api.url != expectedURL {
@@ -164,7 +162,7 @@ func TestNewAPIFromURL(t *testing.T) {
 	// Test to see if an empty string parameter will force to use the public
 	// PeeringDB API.
 	api = NewAPIFromURL("")
-	expectedURL = "https://peeringdb.com/api/"
+	expectedURL = "https://www.peeringdb.com/api/"
 	if api.url != expectedURL {
 		t.Errorf("formatURL, want '%s' got '%s'", expectedURL, api.url)
 	}
@@ -184,7 +182,7 @@ func TestNewAPIFromURLWithAuth(t *testing.T) {
 	// Test to see if an empty string parameter will force to use the public
 	// PeeringDB API.
 	api = NewAPIFromURLWithAuth("", "test", "123")
-	expectedURL = "https://peeringdb.com/api/"
+	expectedURL = "https://www.peeringdb.com/api/"
 	expectedLogin = "test"
 	expectedPassword = "123"
 	if api.url != expectedURL {
@@ -215,7 +213,7 @@ func TestNewAPIFromURLWithAuth(t *testing.T) {
 
 func TestGetASN(t *testing.T) {
 	api := NewAPI()
-	expectedASN := 29467
+	expectedASN := 201281
 	net := api.GetASN(expectedASN)
 
 	if net.ASN != expectedASN {
diff --git a/debian/changelog b/debian/changelog
index fd991a4..eab0362 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+golang-github-gmazoyer-peeringdb (0.0~git20221216.ec4f6d9-1) UNRELEASED; urgency=low
+
+  * New upstream snapshot.
+  * Drop patch deactivate-network-test.patch, present upstream.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Mon, 27 Feb 2023 00:48:42 -0000
+
 golang-github-gmazoyer-peeringdb (0.0~git20180219.dd23298-3) unstable; urgency=medium
 
   [ Debian Janitor ]
diff --git a/debian/patches/deactivate-network-test.patch b/debian/patches/deactivate-network-test.patch
deleted file mode 100644
index f27d9d2..0000000
--- a/debian/patches/deactivate-network-test.patch
+++ /dev/null
@@ -1,86 +0,0 @@
-Description: do not test anything that needs network access
-Index: golang-github-gmazoyer-peeringdb/api_test.go
-===================================================================
---- golang-github-gmazoyer-peeringdb.orig/api_test.go	2021-09-14 23:33:33.110248667 +0000
-+++ golang-github-gmazoyer-peeringdb/api_test.go	2021-09-14 23:33:33.102248111 +0000
-@@ -212,13 +212,3 @@
- 		t.Errorf("formatURL, want '%s' got '%s'", expectedPassword, api.password)
- 	}
- }
--
--func TestGetASN(t *testing.T) {
--	api := NewAPI()
--	expectedASN := 29467
--	net := api.GetASN(expectedASN)
--
--	if net.ASN != expectedASN {
--		t.Errorf("GetASN, want ASN '%d' got '%d'", expectedASN, net.ASN)
--	}
--}
-Index: golang-github-gmazoyer-peeringdb/examples_test.go
-===================================================================
---- golang-github-gmazoyer-peeringdb.orig/examples_test.go	2021-09-14 23:16:28.363112683 +0000
-+++ golang-github-gmazoyer-peeringdb/examples_test.go	2021-09-14 23:34:21.297593736 +0000
-@@ -1,62 +1,4 @@
- package peeringdb
- 
--import "fmt"
--
- func Example() {
--	api := NewAPI()
--
--	// Look for the organization given a name
--	search := make(map[string]interface{})
--	search["name"] = "LuxNetwork S.A."
--
--	// Get the organization, pointer to slice returned
--	organizations, err := api.GetOrganization(search)
--
--	// If an error as occurred, print it
--	if err != nil {
--		fmt.Println(err)
--		return
--	}
--
--	// No organization found
--	if len(*organizations) < 1 {
--		fmt.Printf("No organization found with name '%s'\n", search["name"])
--		return
--	}
--
--	// Several organizations found
--	if len(*organizations) > 1 {
--		fmt.Printf("More than one organizations found with name '%s'\n",
--			search["name"])
--		return
--	}
--
--	// Get the first found organization
--	org := (*organizations)[0]
--
--	// Find if there are networks linked to the organization
--	if len(org.NetworkSet) > 0 {
--		// For each network
--		for _, networkID := range org.NetworkSet {
--			// Get the details and print it
--			network, err := api.GetNetworkByID(networkID)
--			if err != nil {
--				fmt.Println(err)
--			} else {
--				fmt.Print(network.Name)
--			}
--		}
--	}
--	// Output: LuxNetwork S.A.
--}
--
--func ExampleAPI_GetASN() {
--	api := NewAPI()
--	as29467 := api.GetASN(29467)
--
--	fmt.Printf("Name:      %s\n", as29467.Name)
--	fmt.Printf("AS number: %d\n", as29467.ASN)
--	// Output:
--	// Name:      LuxNetwork S.A.
--	// AS number: 29467
- }
diff --git a/debian/patches/series b/debian/patches/series
index 1e8f28e..e69de29 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +0,0 @@
-deactivate-network-test.patch
diff --git a/examples_test.go b/examples_test.go
index 46e93b8..834f8ff 100644
--- a/examples_test.go
+++ b/examples_test.go
@@ -7,7 +7,7 @@ func Example() {
 
 	// Look for the organization given a name
 	search := make(map[string]interface{})
-	search["name"] = "LuxNetwork S.A."
+	search["name"] = "Guillaume Mazoyer"
 
 	// Get the organization, pointer to slice returned
 	organizations, err := api.GetOrganization(search)
@@ -47,16 +47,16 @@ func Example() {
 			}
 		}
 	}
-	// Output: LuxNetwork S.A.
+	// Output: Guillaume Mazoyer
 }
 
 func ExampleAPI_GetASN() {
 	api := NewAPI()
-	as29467 := api.GetASN(29467)
+	as201281 := api.GetASN(201281)
 
-	fmt.Printf("Name:      %s\n", as29467.Name)
-	fmt.Printf("AS number: %d\n", as29467.ASN)
+	fmt.Printf("Name: %s\n", as201281.Name)
+	fmt.Printf("ASN:  %d\n", as201281.ASN)
 	// Output:
-	// Name:      LuxNetwork S.A.
-	// AS number: 29467
+	// Name: Guillaume Mazoyer
+	// ASN:  201281
 }
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..fc6192d
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,3 @@
+module github.com/gmazoyer/peeringdb
+
+go 1.16
diff --git a/ix.go b/ix.go
index 2602ef9..abff0fd 100644
--- a/ix.go
+++ b/ix.go
@@ -154,6 +154,8 @@ type InternetExchangeLAN struct {
 	NetworkSet                []int            `json:"net_set"`
 	InternetExchangePrefixSet []int            `json:"ixpfx_set"`
 	Status                    string           `json:"status"`
+	IXFURL                    string           `json:"ixf_ixp_member_list_url"`
+	IXFURLVisibility          string           `json:"ixf_ixp_member_list_url_visible"`
 	Updated                   time.Time        `json:"updated"`
 	Created                   time.Time        `json:"created"`
 }

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/gmazoyer/peeringdb/go.mod

No differences were encountered in the control files

More details

Full run details