Skip to content

Commit ebe1127

Browse files
committed
Merge branch 'dev'
2 parents 89c4990 + 54465a7 commit ebe1127

9 files changed

Lines changed: 149 additions & 33 deletions

File tree

go.mod

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ require (
2525
github.com/linode/linodego v1.22.0
2626
github.com/namecheap/go-namecheap-sdk/v2 v2.1.0
2727
github.com/pkg/errors v0.9.1
28-
github.com/projectdiscovery/goflags v0.1.40
28+
github.com/projectdiscovery/goflags v0.1.45
2929
github.com/projectdiscovery/gologger v1.1.12
30-
github.com/projectdiscovery/utils v0.0.79
30+
github.com/projectdiscovery/utils v0.0.85
3131
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14
32-
github.com/stretchr/testify v1.8.4
32+
github.com/stretchr/testify v1.9.0
3333
golang.org/x/oauth2 v0.12.0
3434
google.golang.org/api v0.126.0
3535
gopkg.in/yaml.v2 v2.4.0
@@ -64,13 +64,13 @@ require (
6464
github.com/cheggaaa/pb/v3 v3.1.4 // indirect
6565
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 // indirect
6666
github.com/davecgh/go-spew v1.1.1 // indirect
67-
github.com/denisbrodbeck/machineid v1.0.1 // indirect
6867
github.com/dimchansky/utfbom v1.1.1 // indirect
6968
github.com/dlclark/regexp2 v1.8.1 // indirect
7069
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
7170
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
7271
github.com/fatih/color v1.15.0 // indirect
7372
github.com/go-logr/logr v1.2.4 // indirect
73+
github.com/go-ole/go-ole v1.2.6 // indirect
7474
github.com/go-openapi/jsonpointer v0.19.6 // indirect
7575
github.com/go-openapi/jsonreference v0.20.2 // indirect
7676
github.com/go-openapi/swag v0.22.3 // indirect
@@ -107,6 +107,7 @@ require (
107107
github.com/klauspost/pgzip v1.2.5 // indirect
108108
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
109109
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
110+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
110111
github.com/mailru/easyjson v0.7.7 // indirect
111112
github.com/mattn/go-colorable v0.1.13 // indirect
112113
github.com/mattn/go-isatty v0.0.19 // indirect
@@ -129,35 +130,45 @@ require (
129130
github.com/pborman/uuid v1.2.0 // indirect
130131
github.com/pierrec/lz4/v4 v4.1.2 // indirect
131132
github.com/pmezard/go-difflib v1.0.0 // indirect
133+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
132134
github.com/projectdiscovery/blackrock v0.0.1 // indirect
135+
github.com/projectdiscovery/machineid v0.0.0-20240226150047-2e2c51e35983 // indirect
133136
github.com/prometheus/client_golang v1.15.1 // indirect
134137
github.com/prometheus/client_model v0.3.0 // indirect
135138
github.com/prometheus/common v0.42.0 // indirect
136139
github.com/prometheus/procfs v0.9.0 // indirect
137140
github.com/rivo/uniseg v0.4.4 // indirect
138141
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
142+
github.com/shirou/gopsutil/v3 v3.23.7 // indirect
143+
github.com/shoenig/go-m1cpu v0.1.6 // indirect
139144
github.com/spf13/pflag v1.0.5 // indirect
145+
github.com/tidwall/gjson v1.14.3 // indirect
146+
github.com/tidwall/match v1.1.1 // indirect
147+
github.com/tidwall/pretty v1.2.0 // indirect
148+
github.com/tklauser/go-sysconf v0.3.12 // indirect
149+
github.com/tklauser/numcpus v0.6.1 // indirect
140150
github.com/ulikunitz/xz v0.5.11 // indirect
141151
github.com/weppos/publicsuffix-go v0.30.1-0.20230422193905-8fecedd899db // indirect
142152
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
143153
github.com/yuin/goldmark v1.5.4 // indirect
144154
github.com/yuin/goldmark-emoji v1.0.1 // indirect
155+
github.com/yusufpapurcu/wmi v1.2.4 // indirect
145156
go.opencensus.io v0.24.0 // indirect
146157
go.uber.org/atomic v1.10.0 // indirect
147158
go.uber.org/multierr v1.11.0 // indirect
148159
golang.org/x/crypto v0.17.0 // indirect
149160
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect
150161
golang.org/x/mod v0.12.0 // indirect
151162
golang.org/x/net v0.17.0 // indirect
152-
golang.org/x/sys v0.16.0 // indirect
163+
golang.org/x/sys v0.17.0 // indirect
153164
golang.org/x/term v0.16.0 // indirect
154165
golang.org/x/text v0.14.0 // indirect
155166
golang.org/x/time v0.3.0 // indirect
156167
golang.org/x/tools v0.13.0 // indirect
157168
google.golang.org/appengine v1.6.7 // indirect
158169
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
159170
google.golang.org/grpc v1.55.0 // indirect
160-
google.golang.org/protobuf v1.31.0 // indirect
171+
google.golang.org/protobuf v1.33.0 // indirect
161172
gopkg.in/djherbis/times.v1 v1.3.0 // indirect
162173
gopkg.in/inf.v0 v0.9.1 // indirect
163174
gopkg.in/ini.v1 v1.66.6 // indirect

go.sum

Lines changed: 50 additions & 14 deletions
Large diffs are not rendered by default.

internal/runner/banner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const banner = `
1313
`
1414

1515
// version is the current version of cloudlist
16-
const version = `1.0.7`
16+
const version = `1.0.8`
1717

1818
// showBanner is used to show the banner to the user
1919
func showBanner() {

pkg/inventory/inventory.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/projectdiscovery/cloudlist/pkg/providers/scaleway"
2222
"github.com/projectdiscovery/cloudlist/pkg/providers/terraform"
2323
"github.com/projectdiscovery/cloudlist/pkg/schema"
24-
"github.com/projectdiscovery/gologger"
2524
)
2625

2726
// Inventory is an inventory of providers
@@ -38,11 +37,9 @@ func New(options schema.Options) (*Inventory, error) {
3837
if !ok {
3938
continue
4039
}
41-
id, _ := block.GetMetadata("id")
4240
provider, err := nameToProvider(value, block)
4341
if err != nil {
44-
gologger.Warning().Msgf("Could not initialize provider %s %s: %s\n", value, id, err)
45-
continue
42+
return nil, fmt.Errorf("could not create provider %s: %s", value, err)
4643
}
4744
inventory.Providers = append(inventory.Providers, provider)
4845
}

pkg/providers/gcp/auth.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func register(ctx context.Context, data []byte) (option.ClientOption, error) {
4747

4848
// Authenticate with the token
4949
// If it's nil use Google ADC
50-
err = rest.RegisterAuthProviderPlugin(googleAuthPlugin,
50+
_ = rest.RegisterAuthProviderPlugin(googleAuthPlugin,
5151
func(clusterAddress string, config map[string]string, persister rest.AuthProviderConfigPersister) (rest.AuthProvider, error) {
5252
var err error
5353
if tokenSource == nil {
@@ -58,9 +58,6 @@ func register(ctx context.Context, data []byte) (option.ClientOption, error) {
5858
}
5959
return &googleAuthProvider{tokenSource: tokenSource}, nil
6060
})
61-
if err != nil {
62-
return nil, errorutil.NewWithErr(err).Msgf("failed to register %s auth plugin", googleAuthPlugin)
63-
}
6461
// return clioptions
6562
return option.WithCredentialsJSON(data), nil
6663
}

pkg/providers/gcp/gcp.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import (
44
"context"
55

66
"github.com/projectdiscovery/cloudlist/pkg/schema"
7+
"github.com/projectdiscovery/gologger"
78
errorutil "github.com/projectdiscovery/utils/errors"
89
"google.golang.org/api/cloudresourcemanager/v1"
10+
"google.golang.org/api/compute/v1"
911
container "google.golang.org/api/container/v1beta1"
1012
"google.golang.org/api/dns/v1"
1113
)
@@ -14,6 +16,7 @@ import (
1416
type Provider struct {
1517
dns *dns.Service
1618
gke *container.Service
19+
compute *compute.Service
1720
id string
1821
projects []string
1922
}
@@ -47,7 +50,10 @@ func New(options schema.OptionBlock) (*Provider, error) {
4750
if err != nil {
4851
return nil, errorutil.NewWithErr(err).Msgf("could not create dns service with api key")
4952
}
50-
53+
computeService, err := compute.NewService(context.Background(), creds)
54+
if err != nil {
55+
return nil, errorutil.NewWithErr(err).Msgf("could not create compute service with api key")
56+
}
5157
containerService, err := container.NewService(context.Background(), creds)
5258
if err != nil {
5359
return nil, errorutil.NewWithErr(err).Msgf("could not create container service with api key")
@@ -65,23 +71,33 @@ func New(options schema.OptionBlock) (*Provider, error) {
6571
}
6672
return nil
6773
})
68-
return &Provider{dns: dnsService, gke: containerService, projects: projects, id: id}, err
74+
return &Provider{dns: dnsService, gke: containerService, projects: projects, id: id, compute: computeService}, err
6975
}
7076

7177
// Resources returns the provider for an resource deployment source.
7278
func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) {
7379
finalList := schema.NewResources()
80+
7481
cloudDNSProvider := &cloudDNSProvider{dns: p.dns, id: p.id, projects: p.projects}
7582
zones, err := cloudDNSProvider.GetResource(ctx)
7683
if err != nil {
7784
return nil, err
7885
}
7986
finalList.Merge(zones)
87+
8088
GKEProvider := &gkeProvider{svc: p.gke, id: p.id, projects: p.projects}
8189
gkeData, err := GKEProvider.GetResource(ctx)
8290
if err != nil {
83-
return nil, err
91+
gologger.Warning().Msgf("Could not get GKE resources: %s\n", err)
8492
}
8593
finalList.Merge(gkeData)
94+
95+
VMProvider := &cloudVMProvider{compute: p.compute, id: p.id, projects: p.projects}
96+
vmData, err := VMProvider.GetResource(ctx)
97+
if err != nil {
98+
return nil, err
99+
}
100+
finalList.Merge(vmData)
101+
86102
return finalList, nil
87103
}

pkg/providers/gcp/gke.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ func (d *gkeProvider) GetResource(ctx context.Context) (*schema.Resources, error
4343
if err != nil {
4444
return nil, fmt.Errorf("failed to create Kubernetes client cluster=%s: %w", clusterName, err)
4545
}
46-
ingress, err := k8sClient.NetworkingV1().Ingresses("").List(ctx, metav1.ListOptions{})
46+
timeoutSeconds := int64(10)
47+
ingress, err := k8sClient.NetworkingV1().Ingresses("").List(ctx, metav1.ListOptions{
48+
TimeoutSeconds: &timeoutSeconds,
49+
})
4750
if err != nil {
4851
return nil, errors.Wrap(err, "could not list kubernetes ingress")
4952
}

pkg/providers/gcp/vms.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package gcp
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/projectdiscovery/cloudlist/pkg/schema"
8+
"google.golang.org/api/compute/v1"
9+
)
10+
11+
type cloudVMProvider struct {
12+
id string
13+
compute *compute.Service
14+
projects []string
15+
}
16+
17+
// GetResource returns all the resources in the store for a provider.
18+
func (d *cloudVMProvider) GetResource(ctx context.Context) (*schema.Resources, error) {
19+
list := schema.NewResources()
20+
21+
for _, project := range d.projects {
22+
instances := d.compute.Instances.AggregatedList(project)
23+
err := instances.Pages(context.Background(), func(ial *compute.InstanceAggregatedList) error {
24+
for _, instancesScopedList := range ial.Items {
25+
for _, instance := range instancesScopedList.Instances {
26+
instance := instance
27+
28+
if len(instance.NetworkInterfaces) == 0 {
29+
continue
30+
}
31+
nic := instance.NetworkInterfaces[0]
32+
if len(nic.AccessConfigs) == 0 {
33+
continue
34+
}
35+
cfg := nic.AccessConfigs[0]
36+
37+
list.Append(&schema.Resource{
38+
ID: d.id,
39+
Public: true,
40+
Provider: providerName,
41+
PublicIPv4: cfg.NatIP,
42+
})
43+
}
44+
}
45+
return nil
46+
})
47+
if err != nil {
48+
log.Printf("Could not get all instances for project %s: %s\n", project, err)
49+
continue
50+
}
51+
}
52+
return list, nil
53+
}

pkg/schema/schema.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ func (r *Resources) Append(resource *Resource) {
9797

9898
// Merge merges a list of resources into the main list
9999
func (r *Resources) Merge(resources *Resources) {
100+
if resources == nil {
101+
return
102+
}
100103
mergeUniqueMap := &sync.Map{}
101104
for _, item := range resources.Items {
102105
r.appendResource(item, mergeUniqueMap)

0 commit comments

Comments
 (0)