Skip to content
Open
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
2 changes: 2 additions & 0 deletions internal/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Options struct {
Providers goflags.StringSlice // Providers specifies what providers to fetch assets for.
Id goflags.StringSlice // Id specifies what id's to fetch assets for.
Services goflags.StringSlice // Services specifies what services to fetch assets for a provider.
ExcludeServices goflags.StringSlice // ExcludeServices specifies what services to exclude for a provider.
ExtendedMetadata bool // ExtendedMetadata enables extended metadata for providers.
ProviderConfig string // ProviderConfig is the location of the provider config file.
DisableUpdateCheck bool // DisableUpdateCheck disable automatic update check
Expand Down Expand Up @@ -85,6 +86,7 @@ func ParseOptions() *Options {
flagSet.BoolVar(&options.IPAddress, "ip", false, "display only ips in results"),
flagSet.BoolVar(&options.ExtendedMetadata, "extended-metadata", false, "enable extended metadata for providers"),
flagSet.StringSliceVarP(&options.Services, "service", "s", nil, "query and display results from given service (comma-separated)) (default "+strings.Join(defaultServies, ",")+")", goflags.CommaSeparatedStringSliceOptions),
flagSet.StringSliceVarP(&options.ExcludeServices, "exclude-service", "es", nil, "exclude given services from query results (comma-separated)", goflags.CommaSeparatedStringSliceOptions),
flagSet.BoolVarP(&options.ExcludePrivate, "exclude-private", "ep", false, "exclude private ips in cli output"),
)
flagSet.CreateGroup("update", "Update",
Expand Down
3 changes: 3 additions & 0 deletions internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func (r *Runner) Enumerate() {
if len(services) > 0 {
item["services"] = strings.Join(services, ",")
}
if len(r.options.ExcludeServices) > 0 {
item["exclude_services"] = strings.Join(r.options.ExcludeServices, ",")
}
if r.options.ExtendedMetadata {
item["extended_metadata"] = "true"
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/providers/alibaba/alibaba.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,24 @@ func New(options schema.OptionBlock) (*Provider, error) {
supportedServicesMap[s] = struct{}{}
}
services := make(schema.ServiceMap)
if ss, ok := options.GetMetadata("services"); ok {
ss, servicesSpecified := options.GetMetadata("services")
if servicesSpecified {
for _, s := range strings.Split(ss, ",") {
if _, ok := supportedServicesMap[s]; ok {
services[s] = struct{}{}
}
}
}
if len(services) == 0 {
if !servicesSpecified {
for _, s := range Services {
services[s] = struct{}{}
}
}
if es, ok := options.GetMetadata("exclude_services"); ok {
for _, s := range strings.Split(es, ",") {
delete(services, strings.TrimSpace(s))
}
}
provider.services = services

if services.Has("instance") {
Expand Down
10 changes: 8 additions & 2 deletions pkg/providers/arvancloud/arvancloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,24 @@ func New(options schema.OptionBlock) (*Provider, error) {
}

services := make(schema.ServiceMap)
if ss, ok := options.GetMetadata("services"); ok {
ss, servicesSpecified := options.GetMetadata("services")
if servicesSpecified {
for _, s := range strings.Split(ss, ",") {
if _, ok := supportedServicesMap[s]; ok {
services[s] = struct{}{}
}
}
}
if len(services) == 0 {
if !servicesSpecified {
for _, s := range Services {
services[s] = struct{}{}
}
}
if es, ok := options.GetMetadata("exclude_services"); ok {
for _, s := range strings.Split(es, ",") {
delete(services, strings.TrimSpace(s))
}
}

return &Provider{id: id, client: api, services: services}, nil
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,25 @@ func (p *ProviderOptions) ParseOptionBlock(block schema.OptionBlock) error {
supportedServicesMap[s] = struct{}{}
}
services := make(schema.ServiceMap)
if ss, ok := block.GetMetadata("services"); ok {
ss, servicesSpecified := block.GetMetadata("services")
if servicesSpecified {
for _, s := range strings.Split(ss, ",") {
if _, ok := supportedServicesMap[s]; ok {
services[s] = struct{}{}
}
}
}
// if no services provided from -service flag, includes all services
if len(services) == 0 {
if !servicesSpecified {
for _, s := range Services {
services[s] = struct{}{}
}
}
if es, ok := block.GetMetadata("exclude_services"); ok {
for _, s := range strings.Split(es, ",") {
delete(services, strings.TrimSpace(s))
}
}
p.Services = services

if extendedMetadata, ok := block.GetMetadata("extended_metadata"); ok {
Expand Down
10 changes: 8 additions & 2 deletions pkg/providers/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,24 @@ func New(options schema.OptionBlock) (*Provider, error) {
supportedServicesMap[s] = struct{}{}
}
services := make(schema.ServiceMap)
if ss, ok := options.GetMetadata("services"); ok {
ss, servicesSpecified := options.GetMetadata("services")
if servicesSpecified {
for _, s := range strings.Split(ss, ",") {
if _, ok := supportedServicesMap[s]; ok {
services[s] = struct{}{}
}
}
}
if len(services) == 0 {
if !servicesSpecified {
for _, s := range Services {
services[s] = struct{}{}
}
}
if es, ok := options.GetMetadata("exclude_services"); ok {
for _, s := range strings.Split(es, ",") {
delete(services, strings.TrimSpace(s))
}
}

provider := &Provider{
Credential: credential, // Track 2: use credential instead of authorizer
Expand Down
10 changes: 8 additions & 2 deletions pkg/providers/cloudflare/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,24 @@ func New(options schema.OptionBlock) (*Provider, error) {
}

services := make(schema.ServiceMap)
if ss, ok := options.GetMetadata("services"); ok {
ss, servicesSpecified := options.GetMetadata("services")
if servicesSpecified {
for _, s := range strings.Split(ss, ",") {
if _, ok := supportedServicesMap[s]; ok {
services[s] = struct{}{}
}
}
}
if len(services) == 0 {
if !servicesSpecified {
for _, s := range Services {
services[s] = struct{}{}
}
}
if es, ok := options.GetMetadata("exclude_services"); ok {
for _, s := range strings.Split(es, ",") {
delete(services, strings.TrimSpace(s))
}
}

// Parse extended metadata option
extendedMetadata := false
Expand Down
10 changes: 8 additions & 2 deletions pkg/providers/custom/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,25 @@ func (p *ProviderOptions) ParseOptionBlock(block schema.OptionBlock) error {
supportedServicesMap[s] = struct{}{}
}
services := make(schema.ServiceMap)
if ss, ok := block.GetMetadata("services"); ok {
ss, servicesSpecified := block.GetMetadata("services")
if servicesSpecified {
for _, s := range strings.Split(ss, ",") {
if _, ok := supportedServicesMap[s]; ok {
services[s] = struct{}{}
}
}
}
// if no services provided from -service flag, includes all services
if len(services) == 0 {
if !servicesSpecified {
for _, s := range Services {
services[s] = struct{}{}
}
}
if es, ok := block.GetMetadata("exclude_services"); ok {
for _, s := range strings.Split(es, ",") {
delete(services, strings.TrimSpace(s))
}
}

np, err := networkpolicy.New(networkpolicy.DefaultOptions)
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions pkg/providers/digitalocean/digitalocean.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,24 @@ func New(options schema.OptionBlock) (*Provider, error) {
supportedServicesMap[s] = struct{}{}
}
services := make(schema.ServiceMap)
if ss, ok := options.GetMetadata("services"); ok {
ss, servicesSpecified := options.GetMetadata("services")
if servicesSpecified {
for _, s := range strings.Split(ss, ",") {
if _, ok := supportedServicesMap[s]; ok {
services[s] = struct{}{}
}
}
}
if len(services) == 0 {
if !servicesSpecified {
for _, s := range Services {
services[s] = struct{}{}
}
}
if es, ok := options.GetMetadata("exclude_services"); ok {
for _, s := range strings.Split(es, ",") {
delete(services, strings.TrimSpace(s))
}
}

// Check for extended metadata option
extendedMetadata := false
Expand Down
10 changes: 8 additions & 2 deletions pkg/providers/dnssimple/dnssimple.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,24 @@ func New(options schema.OptionBlock) (*Provider, error) {
supportedServicesMap[s] = struct{}{}
}
services := make(schema.ServiceMap)
if ss, ok := options.GetMetadata("services"); ok {
ss, servicesSpecified := options.GetMetadata("services")
if servicesSpecified {
for _, s := range strings.Split(ss, ",") {
if _, ok := supportedServicesMap[s]; ok {
services[s] = struct{}{}
}
}
}
if len(services) == 0 {
if !servicesSpecified {
for _, s := range Services {
services[s] = struct{}{}
}
}
if es, ok := options.GetMetadata("exclude_services"); ok {
for _, s := range strings.Split(es, ",") {
delete(services, strings.TrimSpace(s))
}
}

provider := &Provider{
id: id,
Expand Down
13 changes: 10 additions & 3 deletions pkg/providers/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,24 @@ func newIndividualProvider(options schema.OptionBlock, id, JSONData string) (*Pr
supportedServicesMap[s] = struct{}{}
}
services := make(schema.ServiceMap)
if ss, ok := options.GetMetadata("services"); ok {
ss, servicesSpecified := options.GetMetadata("services")
if servicesSpecified {
for _, s := range strings.Split(ss, ",") {
if _, ok := supportedServicesMap[s]; ok {
services[s] = struct{}{}
}
}
}
if len(services) == 0 {
if !servicesSpecified {
for _, s := range Services {
services[s] = struct{}{}
}
}
if es, ok := options.GetMetadata("exclude_services"); ok {
for _, s := range strings.Split(es, ",") {
delete(services, strings.TrimSpace(s))
}
}
provider.services = services

configuredProjects := getProjectIDsFromOptions(options)
Expand Down Expand Up @@ -663,7 +669,8 @@ func newOrganizationProvider(options schema.OptionBlock, id, JSONData, organizat
}

services := make(schema.ServiceMap)
if ss, ok := options.GetMetadata("services"); ok {
ss, servicesSpecified := options.GetMetadata("services")
if servicesSpecified {
for _, s := range strings.Split(ss, ",") {
if _, ok := supportedServicesMap[s]; ok {
services[s] = struct{}{}
Expand Down
10 changes: 8 additions & 2 deletions pkg/providers/heroku/heroku.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,24 @@ func New(options schema.OptionBlock) (*Provider, error) {
supportedServicesMap[s] = struct{}{}
}
services := make(schema.ServiceMap)
if ss, ok := options.GetMetadata("services"); ok {
ss, servicesSpecified := options.GetMetadata("services")
if servicesSpecified {
for _, s := range strings.Split(ss, ",") {
if _, ok := supportedServicesMap[s]; ok {
services[s] = struct{}{}
}
}
}
if len(services) == 0 {
if !servicesSpecified {
for _, s := range Services {
services[s] = struct{}{}
}
}
if es, ok := options.GetMetadata("exclude_services"); ok {
for _, s := range strings.Split(es, ",") {
delete(services, strings.TrimSpace(s))
}
}

return &Provider{id: id, client: heroku.NewService(heroku.DefaultClient), services: services}, nil
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/providers/hetzner/hetzner.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,24 @@ func New(options schema.OptionBlock) (*Provider, error) {
supportedServicesMap[s] = struct{}{}
}
services := make(schema.ServiceMap)
if ss, ok := options.GetMetadata("services"); ok {
ss, servicesSpecified := options.GetMetadata("services")
if servicesSpecified {
for _, s := range strings.Split(ss, ",") {
if _, ok := supportedServicesMap[s]; ok {
services[s] = struct{}{}
}
}
}
if len(services) == 0 {
if !servicesSpecified {
for _, s := range Services {
services[s] = struct{}{}
}
}
if es, ok := options.GetMetadata("exclude_services"); ok {
for _, s := range strings.Split(es, ",") {
delete(services, strings.TrimSpace(s))
}
}
return &Provider{id: id, client: hetzner.NewClient(opts), services: services}, nil
}

Expand Down
18 changes: 12 additions & 6 deletions pkg/providers/k8s/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,24 @@ func New(options schema.OptionBlock) (*Provider, error) {
supportedServicesMap[s] = struct{}{}
}
services := make(schema.ServiceMap)
if ss, ok := options.GetMetadata("services"); ok {
ss, servicesSpecified := options.GetMetadata("services")
if servicesSpecified {
for _, s := range strings.Split(ss, ",") {
if _, ok := supportedServicesMap[s]; ok {
services[s] = struct{}{}
}
}
}
if len(services) == 0 {
if !servicesSpecified {
for _, s := range Services {
services[s] = struct{}{}
}
}
if es, ok := options.GetMetadata("exclude_services"); ok {
for _, s := range strings.Split(es, ",") {
delete(services, strings.TrimSpace(s))
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
var providerExtendedMetadata bool
if extendedMetadata, ok := options.GetMetadata("extended_metadata"); ok {
providerExtendedMetadata = extendedMetadata == "true"
Expand All @@ -106,11 +112,11 @@ func (p *Provider) Services() []string {
// Resources returns the provider for an resource deployment source.
func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) {
finalList := schema.NewResources()
services, err := p.clientSet.CoreV1().Services("").List(ctx, metav1.ListOptions{})
if err != nil {
return nil, errkit.Wrap(err, "could not list kubernetes services")
}
if p.services.Has("service") {
services, err := p.clientSet.CoreV1().Services("").List(ctx, metav1.ListOptions{})
if err != nil {
return nil, errkit.Wrap(err, "could not list kubernetes services")
}
k8sServiceProvider := K8sServiceProvider{serviceClient: services, id: p.id}
serviceIPs, _ := k8sServiceProvider.GetResource(ctx)
finalList.Merge(serviceIPs)
Expand Down
Loading