Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose inventory errors #502

Merged
merged 3 commits into from
Mar 30, 2024
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: 1 addition & 4 deletions pkg/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/projectdiscovery/cloudlist/pkg/providers/scaleway"
"github.com/projectdiscovery/cloudlist/pkg/providers/terraform"
"github.com/projectdiscovery/cloudlist/pkg/schema"
"github.com/projectdiscovery/gologger"
)

// Inventory is an inventory of providers
Expand All @@ -38,11 +37,9 @@ func New(options schema.Options) (*Inventory, error) {
if !ok {
continue
}
id, _ := block.GetMetadata("id")
provider, err := nameToProvider(value, block)
if err != nil {
gologger.Warning().Msgf("Could not initialize provider %s %s: %s\n", value, id, err)
continue
return nil, fmt.Errorf("could not create provider %s: %s", value, err)
}
inventory.Providers = append(inventory.Providers, provider)
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/providers/gcp/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func register(ctx context.Context, data []byte) (option.ClientOption, error) {

// Authenticate with the token
// If it's nil use Google ADC
err = rest.RegisterAuthProviderPlugin(googleAuthPlugin,
_ = rest.RegisterAuthProviderPlugin(googleAuthPlugin,
func(clusterAddress string, config map[string]string, persister rest.AuthProviderConfigPersister) (rest.AuthProvider, error) {
var err error
if tokenSource == nil {
Expand All @@ -58,9 +58,6 @@ func register(ctx context.Context, data []byte) (option.ClientOption, error) {
}
return &googleAuthProvider{tokenSource: tokenSource}, nil
})
if err != nil {
return nil, errorutil.NewWithErr(err).Msgf("failed to register %s auth plugin", googleAuthPlugin)
}
// return clioptions
return option.WithCredentialsJSON(data), nil
}
3 changes: 2 additions & 1 deletion pkg/providers/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/projectdiscovery/cloudlist/pkg/schema"
"github.com/projectdiscovery/gologger"
errorutil "github.com/projectdiscovery/utils/errors"
"google.golang.org/api/cloudresourcemanager/v1"
"google.golang.org/api/compute/v1"
Expand Down Expand Up @@ -87,7 +88,7 @@ func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) {
GKEProvider := &gkeProvider{svc: p.gke, id: p.id, projects: p.projects}
gkeData, err := GKEProvider.GetResource(ctx)
if err != nil {
return nil, err
gologger.Warning().Msgf("Could not get GKE resources: %s\n", err)
}
finalList.Merge(gkeData)

Expand Down
5 changes: 4 additions & 1 deletion pkg/providers/gcp/gke.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ func (d *gkeProvider) GetResource(ctx context.Context) (*schema.Resources, error
if err != nil {
return nil, fmt.Errorf("failed to create Kubernetes client cluster=%s: %w", clusterName, err)
}
ingress, err := k8sClient.NetworkingV1().Ingresses("").List(ctx, metav1.ListOptions{})
timeoutSeconds := int64(10)
ingress, err := k8sClient.NetworkingV1().Ingresses("").List(ctx, metav1.ListOptions{
TimeoutSeconds: &timeoutSeconds,
})
if err != nil {
return nil, errors.Wrap(err, "could not list kubernetes ingress")
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func (r *Resources) Append(resource *Resource) {

// Merge merges a list of resources into the main list
func (r *Resources) Merge(resources *Resources) {
if resources == nil {
return
}
mergeUniqueMap := &sync.Map{}
for _, item := range resources.Items {
r.appendResource(item, mergeUniqueMap)
Expand Down
Loading