Skip to content

Commit 9b160da

Browse files
authored
Merge pull request #196 from flanksource/fix-jobs
Fix jobs
2 parents 60617e5 + e64be5e commit 9b160da

File tree

13 files changed

+64
-21
lines changed

13 files changed

+64
-21
lines changed

api/v1/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
// +kubebuilder:object:generate=false
1818
type Scraper interface {
1919
Scrape(ctx *ScrapeContext, config ConfigScraper) ScrapeResults
20+
CanScrape(config ConfigScraper) bool
2021
}
2122

2223
// Analyzer ...

scrapers/aws/aws.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,10 @@ func (aws Scraper) ami(ctx *AWSContext, config v1.AWS, results *v1.ScrapeResults
968968
}
969969
}
970970

971-
// Scrape ...
971+
func (aws Scraper) CanScrape(configs v1.ConfigScraper) bool {
972+
return len(configs.AWS) > 0
973+
}
974+
972975
func (aws Scraper) Scrape(ctx *v1.ScrapeContext, config v1.ConfigScraper) v1.ScrapeResults {
973976
results := &v1.ScrapeResults{}
974977

scrapers/aws/cost.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/aws/aws-sdk-go-v2/service/sts"
1010
"github.com/flanksource/commons/logger"
11-
"github.com/flanksource/config-db/api/v1"
11+
v1 "github.com/flanksource/config-db/api/v1"
1212
"github.com/flanksource/config-db/db"
1313
athena "github.com/uber/athenadriver/go"
1414
)
@@ -129,6 +129,15 @@ func FetchCosts(ctx *v1.ScrapeContext, config v1.AWS) ([]LineItemRow, error) {
129129

130130
type CostScraper struct{}
131131

132+
func (awsCost CostScraper) CanScrape(config v1.ConfigScraper) bool {
133+
for _, awsConfig := range config.AWS {
134+
if awsConfig.CostReporting.S3BucketPath != "" || awsConfig.CostReporting.Table != "" {
135+
return true
136+
}
137+
}
138+
return false
139+
}
140+
132141
func (awsCost CostScraper) Scrape(ctx *v1.ScrapeContext, config v1.ConfigScraper) v1.ScrapeResults {
133142
var results v1.ScrapeResults
134143

scrapers/azure/azure.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ type Scraper struct {
2121
config *v1.Azure
2222
}
2323

24-
// Scrape ...
24+
func (azure Scraper) CanScrape(configs v1.ConfigScraper) bool {
25+
return len(configs.Azure) > 0
26+
}
27+
2528
func (azure Scraper) Scrape(ctx *v1.ScrapeContext, configs v1.ConfigScraper) v1.ScrapeResults {
2629
var results v1.ScrapeResults
2730
for _, config := range configs.Azure {

scrapers/azure/devops/pipelines.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const PipelineRun = "AzureDevops::PipelineRun"
1212
type AzureDevopsScraper struct {
1313
}
1414

15+
func (ado AzureDevopsScraper) CanScrape(configs v1.ConfigScraper) bool {
16+
return len(configs.AzureDevops) > 0
17+
}
18+
1519
// Scrape ...
1620
func (ado AzureDevopsScraper) Scrape(ctx *v1.ScrapeContext, configs v1.ConfigScraper) v1.ScrapeResults {
1721

scrapers/file/file.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ func convertToLocalPath(uri string) string {
6363
return p + path.Base(_uri.Path) + "-" + hex.EncodeToString(hash[:])[0:8]
6464
}
6565

66-
// Scrape ...
66+
func (file FileScraper) CanScrape(configs v1.ConfigScraper) bool {
67+
return len(configs.File) > 0
68+
}
69+
6770
func (file FileScraper) Scrape(ctx *v1.ScrapeContext, configs v1.ConfigScraper) v1.ScrapeResults {
6871
pwd, _ := os.Getwd()
6972
cacheDir := path.Join(pwd, ".config-db", "cache", "files")

scrapers/github/workflows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const WorkflowRun = "GitHubActions::WorkflowRun"
1414
type GithubActionsScraper struct {
1515
}
1616

17+
func (gh GithubActionsScraper) CanScrape(configs v1.ConfigScraper) bool {
18+
return len(configs.GithubActions) > 0
19+
}
20+
1721
// Scrape fetches github workflows and workflow runs from github API and converts the action executions (workflow runs) to change events.
1822
func (gh GithubActionsScraper) Scrape(ctx *v1.ScrapeContext, configs v1.ConfigScraper) v1.ScrapeResults {
1923
results := v1.ScrapeResults{}

scrapers/kubernetes/kubernetes.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ type KubernetesScraper struct {
2020

2121
const ExternalTypePrefix = "Kubernetes::"
2222

23-
// Scrape ...
23+
func (kubernetes KubernetesScraper) CanScrape(configs v1.ConfigScraper) bool {
24+
return len(configs.Kubernetes) > 0
25+
}
26+
2427
func (kubernetes KubernetesScraper) Scrape(ctx *v1.ScrapeContext, configs v1.ConfigScraper) v1.ScrapeResults {
2528
var (
2629
results v1.ScrapeResults

scrapers/kubernetes/kubernetes_file.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ func findBySelector(ctx *v1.ScrapeContext, client *kubernetes.Clientset, config
117117
return pods, nil
118118
}
119119

120+
func (kubernetes KubernetesFileScraper) CanScrape(configs v1.ConfigScraper) bool {
121+
return len(configs.KubernetesFile) > 0
122+
}
123+
120124
// Scrape ...
121125
func (kubernetes KubernetesFileScraper) Scrape(ctx *v1.ScrapeContext, configs v1.ConfigScraper) v1.ScrapeResults {
122126
results := v1.ScrapeResults{}

scrapers/processors/json.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/ohler55/ojg/jp"
1414
"github.com/ohler55/ojg/oj"
1515
"github.com/pkg/errors"
16+
kyaml "sigs.k8s.io/yaml"
1617
)
1718

1819
type Mask struct {
@@ -176,6 +177,12 @@ func (e Extract) Extract(inputs ...v1.ScrapeResult) ([]v1.ScrapeResult, error) {
176177
return results, errors.Wrapf(err, "Failed parse properties %s", input)
177178
}
178179
input.Config = props.Map()
180+
} else if input.Format == "yaml" {
181+
contentByte, err := kyaml.YAMLToJSON([]byte(input.Config.(string)))
182+
if err != nil {
183+
return results, errors.Wrapf(err, "Failed parse yaml %s", input)
184+
}
185+
input.Config = string(contentByte)
179186
} else if input.Format != "" {
180187
input.Config = map[string]any{
181188
"format": input.Format,

0 commit comments

Comments
 (0)