Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/providers/linode/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package linode

import (
"context"
"strings"

"github.com/linode/linodego"
"github.com/projectdiscovery/cloudlist/pkg/schema"
Expand Down Expand Up @@ -32,11 +33,13 @@ func (d *instanceProvider) GetResource(ctx context.Context) (*schema.Resources,
for _, inst := range instances {
// Assuming (and obseved the same) first IP in the list is the public IP
ip4 := inst.IPv4[0].String()
// The API returns the IPv6 address with its prefix length (e.g. "/128").
ip6, _, _ := strings.Cut(inst.IPv6, "/")

list.Append(&schema.Resource{
Provider: providerName,
PublicIPv4: ip4,
PublicIPv6: inst.IPv6,
PublicIPv6: ip6,
ID: d.id,
Public: ip4 != "",
Service: d.name(),
Expand Down
35 changes: 35 additions & 0 deletions pkg/providers/linode/instances_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package linode

import (
"context"
"net/http"
"net/http/httptest"
"testing"

"github.com/linode/linodego"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestInstanceIPv6(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
// The API returns the SLAAC address with its prefix length.
_, _ = w.Write([]byte(`{"data":[{"id":1,"label":"web","ipv4":["172.105.10.20"],"ipv6":"2600:3c03::f03c:91ff:fe24:3a2f/128"}],"page":1,"pages":1,"results":1}`))
}))
t.Cleanup(server.Close)

client := linodego.NewClient(server.Client())
client.SetBaseURL(server.URL)

resources, err := (&instanceProvider{id: "test", client: &client}).GetResource(context.Background())
require.NoError(t, err)

var ipv6 []string
for _, r := range resources.Items {
if r.PublicIPv6 != "" {
ipv6 = append(ipv6, r.PublicIPv6)
}
}
assert.Equal(t, []string{"2600:3c03::f03c:91ff:fe24:3a2f"}, ipv6)
}
Loading