diff --git a/.gitignore b/.gitignore index b20b5496..f6c7c32e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,5 @@ _DS_Store .bin/ vendor -confighub -scraped/ \ No newline at end of file +config-db +scraped/ diff --git a/README.md b/README.md index efd17b10..fcca2b83 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ To explicitly run scrapping. ```bash ./bin/config-db run -vvv -confighub serve +config-db serve ``` See fixtures/ for example scrape configs. diff --git a/analyzers/patches.go b/analyzers/patches.go index e75d6a14..722a93bb 100644 --- a/analyzers/patches.go +++ b/analyzers/patches.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/flanksource/commons/logger" - v1 "github.com/flanksource/confighub/api/v1" + v1 "github.com/flanksource/config-db/api/v1" ) // PatchAnalyzer ... diff --git a/api/v1/file.go b/api/v1/file.go index 63f0aa44..045182d8 100644 --- a/api/v1/file.go +++ b/api/v1/file.go @@ -21,5 +21,4 @@ func (f File) RedactedString() string { } return url.Redacted() - } diff --git a/api/v1/interface.go b/api/v1/interface.go index c7d4cb87..c8db543a 100644 --- a/api/v1/interface.go +++ b/api/v1/interface.go @@ -6,7 +6,7 @@ import ( "time" "github.com/flanksource/commons/logger" - fs "github.com/flanksource/confighub/filesystem" + fs "github.com/flanksource/config-db/filesystem" "github.com/flanksource/kommons" ) @@ -192,5 +192,5 @@ func (ctx ScrapeContext) GetNamespace() string { // IsTrace ... func (ctx ScrapeContext) IsTrace() bool { - return logger.IsTraceEnabled() + return ctx.Scraper != nil && ctx.Scraper.IsTrace() } diff --git a/api/v1/types.go b/api/v1/types.go index 35512e1e..31322814 100644 --- a/api/v1/types.go +++ b/api/v1/types.go @@ -2,6 +2,7 @@ package v1 // ConfigScraper ... type ConfigScraper struct { + LogLevel string `json:"logLevel,omitempty"` Schedule string `json:"schedule,omitempty"` AWS []AWS `json:"aws,omitempty" yaml:"aws,omitempty"` File []File `json:"file,omitempty" yaml:"file,omitempty"` @@ -11,3 +12,7 @@ type ConfigScraper struct { func (c ConfigScraper) IsEmpty() bool { return len(c.AWS) == 0 && len(c.File) == 0 } + +func (c ConfigScraper) IsTrace() bool { + return c.LogLevel == "trace" +} diff --git a/cmd/analyze.go b/cmd/analyze.go index 16d4d4b0..15586d1a 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -5,9 +5,9 @@ import ( "io/ioutil" "github.com/flanksource/commons/logger" - "github.com/flanksource/confighub/analyzers" - v1 "github.com/flanksource/confighub/api/v1" - "github.com/flanksource/confighub/scrapers/aws" + "github.com/flanksource/config-db/analyzers" + v1 "github.com/flanksource/config-db/api/v1" + "github.com/flanksource/config-db/scrapers/aws" "github.com/spf13/cobra" ) diff --git a/cmd/config.go b/cmd/config.go index 72e1e6e6..1dad64c4 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -10,7 +10,7 @@ import ( gotemplate "text/template" "github.com/flanksource/commons/text" - v1 "github.com/flanksource/confighub/api/v1" + v1 "github.com/flanksource/config-db/api/v1" "github.com/pkg/errors" "gopkg.in/flanksource/yaml.v3" diff --git a/cmd/offline.go b/cmd/offline.go index d29f096f..7a8f6637 100644 --- a/cmd/offline.go +++ b/cmd/offline.go @@ -2,14 +2,14 @@ package cmd import ( "github.com/flanksource/commons/logger" - "github.com/flanksource/confighub/db" + "github.com/flanksource/config-db/db" "github.com/spf13/cobra" ) // GoOffline ... var GoOffline = &cobra.Command{ Use: "go-offline", - Long: "Download all dependencies so that confighub can work without an internet connection", + Long: "Download all dependencies so that config-db can work without an internet connection", Run: func(cmd *cobra.Command, args []string) { if err := db.GoOffline(); err != nil { logger.Fatalf("Failed to go offline: %+v", err) diff --git a/cmd/root.go b/cmd/root.go index 37f41f4b..54b0f28d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,8 +5,8 @@ import ( "os" "github.com/flanksource/commons/logger" - "github.com/flanksource/confighub/db" - "github.com/flanksource/confighub/utils/kube" + "github.com/flanksource/config-db/db" + "github.com/flanksource/config-db/utils/kube" "github.com/flanksource/kommons" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -34,7 +34,7 @@ func readFromEnv(v string) string { // Root ... var Root = &cobra.Command{ - Use: "confighub", + Use: "config-db", PersistentPreRun: func(cmd *cobra.Command, args []string) { count, _ := cmd.Flags().GetCount("loglevel") // logger.StandardLogger().(logsrusapi.Logger).Out = os.Stderr @@ -75,7 +75,7 @@ func init() { } Root.AddCommand(&cobra.Command{ Use: "version", - Short: "Print the version of confighub", + Short: "Print the version of config-db", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { fmt.Println(version) diff --git a/cmd/run.go b/cmd/run.go index b91cda92..172a7976 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -8,10 +8,10 @@ import ( "path" "github.com/flanksource/commons/logger" - v1 "github.com/flanksource/confighub/api/v1" - "github.com/flanksource/confighub/db" - fs "github.com/flanksource/confighub/filesystem" - "github.com/flanksource/confighub/scrapers" + v1 "github.com/flanksource/config-db/api/v1" + "github.com/flanksource/config-db/db" + fs "github.com/flanksource/config-db/filesystem" + "github.com/flanksource/config-db/scrapers" "github.com/spf13/cobra" ) @@ -43,13 +43,15 @@ var Run = &cobra.Command{ if err != nil { logger.Fatalf(err.Error()) } - logger.Infof("Found %d resources", len(results)) if db.ConnectionString != "" { + logger.Infof("Exporting %d resources to DB", len(results)) if err = db.Update(ctx, results); err != nil { logger.Errorf("Failed to update db: %+v", err) } } else if outputDir != "" { + logger.Infof("Exporting %d resources to %s", outputDir) + for _, result := range results { if err := exportResource(result, filename, outputDir); err != nil { logger.Fatalf("failed to export results %v", err) @@ -57,7 +59,7 @@ var Run = &cobra.Command{ } } else { - logger.Infof("skipping export: neither --output-dir or --db is specified") + logger.Fatalf("skipping export: neither --output-dir or --db is specified") } }, diff --git a/cmd/server.go b/cmd/server.go index 03068bae..8a1aad43 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -6,12 +6,12 @@ import ( "net/url" "github.com/flanksource/commons/logger" - v1 "github.com/flanksource/confighub/api/v1" - "github.com/flanksource/confighub/db" - fs "github.com/flanksource/confighub/filesystem" - "github.com/flanksource/confighub/query" + v1 "github.com/flanksource/config-db/api/v1" + "github.com/flanksource/config-db/db" + fs "github.com/flanksource/config-db/filesystem" + "github.com/flanksource/config-db/query" - "github.com/flanksource/confighub/scrapers" + "github.com/flanksource/config-db/scrapers" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" "github.com/robfig/cron/v3" diff --git a/db/ext.go b/db/ext.go index ad671506..754ba987 100644 --- a/db/ext.go +++ b/db/ext.go @@ -4,8 +4,8 @@ import ( "encoding/json" "github.com/flanksource/commons/logger" - v1 "github.com/flanksource/confighub/api/v1" - "github.com/flanksource/confighub/db/models" + v1 "github.com/flanksource/config-db/api/v1" + "github.com/flanksource/config-db/db/models" ) func GetJSON(ci models.ConfigItem) []byte { diff --git a/db/init.go b/db/init.go index 1a3a2016..66c755d5 100644 --- a/db/init.go +++ b/db/init.go @@ -8,7 +8,7 @@ import ( "time" "github.com/flanksource/commons/logger" - repoimpl "github.com/flanksource/confighub/db/repository" + repoimpl "github.com/flanksource/config-db/db/repository" "github.com/jackc/pgx/v4/log/logrusadapter" "github.com/jackc/pgx/v4/pgxpool" "github.com/jackc/pgx/v4/stdlib" @@ -38,6 +38,9 @@ func Flags(flags *pflag.FlagSet) { //go:embed migrations/*.sql var embedMigrations embed.FS +//go:embed migrations/_always/*.sql +var embedScripts embed.FS + // Pool ... var Pool *pgxpool.Pool var repository repoimpl.Database @@ -119,8 +122,26 @@ func Migrate() error { } defer db.Close() - if err := goose.Up(db, "migrations", goose.WithAllowMissing()); err != nil { - return err + for { + err = goose.UpByOne(db, "migrations", goose.WithAllowMissing()) + if err == goose.ErrNoNextVersion { + break + } + if err != nil { + return err + } + } + + scripts, _ := embedScripts.ReadDir("migrations/_always") + + for _, file := range scripts { + script, err := embedScripts.ReadFile("migrations/_always/" + file.Name()) + if err != nil { + return err + } + if _, err := Pool.Exec(context.TODO(), string(script)); err != nil { + return err + } } return nil } diff --git a/db/migrations/003_seed.sql b/db/migrations/003_seed.sql index f370a10a..44b81bd3 100644 --- a/db/migrations/003_seed.sql +++ b/db/migrations/003_seed.sql @@ -7,6 +7,7 @@ CREATE TABLE config_scrapers ( description TEXT NULL, scraper_type text NOT NULL, spec jsonb, + created_by UUID null, created_at timestamp NOT NULL DEFAULT now(), updated_at timestamp NOT NULL DEFAULT now() ); @@ -28,6 +29,7 @@ CREATE TABLE config_items ( config jsonb null, source TEXT null, tags jsonb null, + created_by UUID null, created_at timestamp NOT NULL DEFAULT now(), updated_at timestamp NOT NULL DEFAULT now(), FOREIGN KEY (scraper_id) REFERENCES config_scrapers(id) @@ -52,12 +54,14 @@ CREATE TABLE config_changes ( id UUID DEFAULT generate_ulid() PRIMARY KEY, config_id UUID NOT NULL, external_change_id text NULL, + external_created_by TEXT NULL, change_type text NULL, severity text NULL, source text NULL, summary text, patches jsonb null, details jsonb null, + created_by UUID null, created_at timestamp NOT NULL DEFAULT now(), FOREIGN KEY (config_id) REFERENCES config_items(id) ); @@ -89,8 +93,6 @@ CREATE TABLE saved_query ( updated_at timestamp NOT NULL DEFAULT now() ); --- INSERT INTO config_db_version (version_id,is_applied,tstamp) values ('3',true, now()) - -- +goose StatementEnd -- +goose Down diff --git a/db/migrations/004_views.sql b/db/migrations/004_views.sql deleted file mode 100644 index 8f389e1a..00000000 --- a/db/migrations/004_views.sql +++ /dev/null @@ -1,24 +0,0 @@ --- +goose Up --- +goose StatementBegin ---- -CREATE or REPLACE VIEW configs AS - SELECT - ci.*, - analysis, - changes - FROM config_items as ci - full join ( - SELECT config_id, - array_agg(analyzer) as analysis - FROM config_analysis - GROUP BY config_id - ) as ca on ca.config_id = ci.id - full join ( - SELECT config_id, - json_agg(total) as changes - FROM - (SELECT config_id, json_build_object(change_type, count(*)) as total FROM config_changes GROUP BY config_id, change_type) as config_change_types - GROUP BY config_id - ) as cc on cc.config_id = ci.id; - --- +goose StatementEnd diff --git a/db/migrations/099_post_seed.sql b/db/migrations/099_post_seed.sql new file mode 100644 index 00000000..c8c07ef2 --- /dev/null +++ b/db/migrations/099_post_seed.sql @@ -0,0 +1,8 @@ +-- +goose Up + + +INSERT INTO config_db_version(version_id, tstamp, is_applied) ( + SELECT version_id, now() as tstamp, true as is_applied + FROM generate_series(100, 101) version_id +); + diff --git a/db/migrations/101_created_by.sql b/db/migrations/101_created_by.sql new file mode 100644 index 00000000..26ce648f --- /dev/null +++ b/db/migrations/101_created_by.sql @@ -0,0 +1,6 @@ +-- +goose Up + +ALTER TABLE config_scrapers ADD COLUMN created_by UUID NULL; +ALTER TABLE config_items ADD COLUMN created_by UUID NULL; +ALTER TABLE config_changes ADD COLUMN IF NOT EXISTS created_by UUID NULL; +ALTER TABLE config_changes ADD COLUMN IF NOT EXISTS external_created_by TEXT NULL; diff --git a/db/migrations/_always/views.sql b/db/migrations/_always/views.sql new file mode 100644 index 00000000..4a873f68 --- /dev/null +++ b/db/migrations/_always/views.sql @@ -0,0 +1,37 @@ +DROP VIEW IF EXISTS configs; + +CREATE or REPLACE VIEW configs AS + SELECT + ci.*, + analysis, + changes + FROM config_items as ci + full join ( + SELECT config_id, + json_agg(json_build_object('analyzer',analyzer,'analysis_type',analysis_type,'severity',severity)) as analysis + FROM config_analysis + GROUP BY config_id + ) as ca on ca.config_id = ci.id + full join ( + SELECT config_id, + json_agg(total) as changes + FROM + (SELECT config_id,json_build_object('change_type',change_type, 'severity', severity, 'total', count(*)) as total FROM config_changes GROUP BY config_id, change_type, severity) as config_change_types + GROUP BY config_id + ) as cc on cc.config_id = ci.id; + + +CREATE or REPLACE VIEW config_names AS + SELECT id, config_type, external_id, name FROM config_items; + +CREATE or REPLACE VIEW config_types AS + SELECT DISTINCT config_type FROM config_items; + +CREATE or REPLACE VIEW analyzer_types AS + SELECT DISTINCT analyzer FROM config_analysis; + +CREATE or REPLACE VIEW analysis_types AS + SELECT DISTINCT analysis_type FROM config_analysis; + +CREATE or REPLACE VIEW change_types AS + SELECT DISTINCT change_type FROM config_changes; diff --git a/db/models/analysis.go b/db/models/analysis.go index bef2033d..9d761e2d 100644 --- a/db/models/analysis.go +++ b/db/models/analysis.go @@ -5,7 +5,7 @@ import ( "strings" "time" - v1 "github.com/flanksource/confighub/api/v1" + v1 "github.com/flanksource/config-db/api/v1" ) type Analysis struct { diff --git a/db/models/config_change.go b/db/models/config_change.go index dd6948f0..65df1b91 100644 --- a/db/models/config_change.go +++ b/db/models/config_change.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - v1 "github.com/flanksource/confighub/api/v1" + v1 "github.com/flanksource/config-db/api/v1" ) // ConfigChange represents the config change database table diff --git a/db/models/config_item.go b/db/models/config_item.go index 7eacef31..5d5eaf98 100644 --- a/db/models/config_item.go +++ b/db/models/config_item.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - v1 "github.com/flanksource/confighub/api/v1" + v1 "github.com/flanksource/config-db/api/v1" "github.com/lib/pq" ) diff --git a/db/repository/db.go b/db/repository/db.go index d42b3509..dcb10d79 100644 --- a/db/repository/db.go +++ b/db/repository/db.go @@ -5,8 +5,8 @@ import ( "fmt" "github.com/flanksource/commons/logger" - v1 "github.com/flanksource/confighub/api/v1" - "github.com/flanksource/confighub/db/models" + v1 "github.com/flanksource/config-db/api/v1" + "github.com/flanksource/config-db/db/models" "github.com/google/uuid" "github.com/lib/pq" "gorm.io/gorm" diff --git a/db/repository/interface.go b/db/repository/interface.go index e03932ff..4d912892 100644 --- a/db/repository/interface.go +++ b/db/repository/interface.go @@ -1,8 +1,8 @@ package repository import ( - v1 "github.com/flanksource/confighub/api/v1" - "github.com/flanksource/confighub/db/models" + v1 "github.com/flanksource/config-db/api/v1" + "github.com/flanksource/config-db/db/models" ) // Database holds all the repository function contracts diff --git a/db/update.go b/db/update.go index a84930a8..a98a8e60 100644 --- a/db/update.go +++ b/db/update.go @@ -6,9 +6,9 @@ import ( jsonpatch "github.com/evanphx/json-patch" "github.com/flanksource/commons/logger" - v1 "github.com/flanksource/confighub/api/v1" - "github.com/flanksource/confighub/db/models" - "github.com/flanksource/confighub/db/ulid" + v1 "github.com/flanksource/config-db/api/v1" + "github.com/flanksource/config-db/db/models" + "github.com/flanksource/config-db/db/ulid" "github.com/pkg/errors" "gorm.io/gorm" ) diff --git a/go.mod b/go.mod index b70da2d3..cea2df18 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/flanksource/confighub +module github.com/flanksource/config-db go 1.17 diff --git a/main.go b/main.go index 2ccaf0ac..23fe5ceb 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,7 @@ package main import ( "os" - "github.com/flanksource/confighub/cmd" + "github.com/flanksource/config-db/cmd" ) func main() { diff --git a/query/query.go b/query/query.go index 82e42fd6..baa0c6a1 100644 --- a/query/query.go +++ b/query/query.go @@ -3,8 +3,8 @@ package query import ( "net/http" - v1 "github.com/flanksource/confighub/api/v1" - "github.com/flanksource/confighub/db" + v1 "github.com/flanksource/config-db/api/v1" + "github.com/flanksource/config-db/db" "github.com/labstack/echo/v4" ) diff --git a/scrapers/analysis/rules.go b/scrapers/analysis/rules.go new file mode 100644 index 00000000..5236e60b --- /dev/null +++ b/scrapers/analysis/rules.go @@ -0,0 +1,24 @@ +package analysis + +import ( + _ "embed" + + "github.com/flanksource/commons/logger" + "gopkg.in/yaml.v3" +) + +//go:embed rules.yaml +var configRules []byte + +type Category struct { + Category, Severity string +} + +var Rules map[string]Category + +func init() { + if err := yaml.Unmarshal(configRules, &Rules); err != nil { + logger.Errorf("Failed to unmarshal config rules: %s", err) + } + logger.Infof("Loaded %d config rules", len(Rules)) +} diff --git a/scrapers/analysis/rules.yaml b/scrapers/analysis/rules.yaml new file mode 100644 index 00000000..299f91b6 --- /dev/null +++ b/scrapers/analysis/rules.yaml @@ -0,0 +1,21 @@ +ec2-instance-no-public-ip: + category: security + severity: critical +cloudtrail-enabled: + category: security + severity: critical +iam-user-mfa-enabled: + category: security + severity: critical +root-account-hardware-mfa-enabled: + category: security + severity: critical +eks-endpoint-no-public-access: + category: security + severity: critical +vpc-flow-logs-enabled: + category: security + severity: warning +Exposed Access Keys: + category: security + severity: critical diff --git a/scrapers/aws/analyzer.go b/scrapers/aws/analyzer.go index 331204c7..bd5f8d7c 100644 --- a/scrapers/aws/analyzer.go +++ b/scrapers/aws/analyzer.go @@ -6,7 +6,7 @@ import ( "github.com/flanksource/commons/console" "github.com/flanksource/commons/logger" - v1 "github.com/flanksource/confighub/api/v1" + v1 "github.com/flanksource/config-db/api/v1" ) // EC2InstanceAnalyzer ... diff --git a/scrapers/aws/aws.go b/scrapers/aws/aws.go index cf92bb7c..0ff91f6b 100644 --- a/scrapers/aws/aws.go +++ b/scrapers/aws/aws.go @@ -23,7 +23,7 @@ import ( "github.com/aws/aws-sdk-go-v2/service/support" "github.com/flanksource/commons/logger" - v1 "github.com/flanksource/confighub/api/v1" + v1 "github.com/flanksource/config-db/api/v1" "github.com/pkg/errors" ) diff --git a/scrapers/aws/aws_session.go b/scrapers/aws/aws_session.go index 12fbacec..b8798937 100644 --- a/scrapers/aws/aws_session.go +++ b/scrapers/aws/aws_session.go @@ -6,7 +6,7 @@ import ( "fmt" "net/http" - v1 "github.com/flanksource/confighub/api/v1" + v1 "github.com/flanksource/config-db/api/v1" "github.com/flanksource/kommons" "github.com/henvic/httpretty" diff --git a/scrapers/aws/cloudtrail.go b/scrapers/aws/cloudtrail.go index 0724b8c0..42ea5a62 100644 --- a/scrapers/aws/cloudtrail.go +++ b/scrapers/aws/cloudtrail.go @@ -10,7 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/service/cloudtrail/types" "github.com/aws/smithy-go/ptr" "github.com/flanksource/commons/logger" - v1 "github.com/flanksource/confighub/api/v1" + v1 "github.com/flanksource/config-db/api/v1" ) func lookupEvents(ctx *AWSContext, input *cloudtrail.LookupEventsInput, c chan types.Event) error { diff --git a/scrapers/aws/config.go b/scrapers/aws/config.go index 370c00f2..fa816cdb 100644 --- a/scrapers/aws/config.go +++ b/scrapers/aws/config.go @@ -3,7 +3,7 @@ package aws import ( "github.com/aws/aws-sdk-go-v2/service/configservice" "github.com/aws/aws-sdk-go-v2/service/configservice/types" - v1 "github.com/flanksource/confighub/api/v1" + v1 "github.com/flanksource/config-db/api/v1" ) func (aws Scraper) config(ctx *AWSContext, config v1.AWS, results *v1.ScrapeResults) { diff --git a/scrapers/aws/trusted_advisor.go b/scrapers/aws/trusted_advisor.go index 5e5b159e..0e5018ea 100644 --- a/scrapers/aws/trusted_advisor.go +++ b/scrapers/aws/trusted_advisor.go @@ -5,9 +5,37 @@ import ( "github.com/aws/aws-sdk-go-v2/service/support" "github.com/flanksource/commons/logger" - v1 "github.com/flanksource/confighub/api/v1" + v1 "github.com/flanksource/config-db/api/v1" ) +func mapCategory(category string) string { + switch category { + case "cost_optimizing": + return "cost" + case "performance": + return "performance" + case "fault_tolerance": + return "reliability" + case "cost": + return "Cost" + case "recommendation": + return "Recommendation" + case "other": + return "Other" + } + return category +} + +func mapSeverity(severity string) string { + switch severity { + case "Red": + return "critical" + case "Yellow": + return "warning" + } + return "info" +} + func (aws Scraper) trustedAdvisor(ctx *AWSContext, config v1.AWS, results *v1.ScrapeResults) { if config.Excludes("trusted_advisor") { return @@ -72,7 +100,9 @@ func (aws Scraper) trustedAdvisor(ctx *AWSContext, config v1.AWS, results *v1.Sc } } analysis := results.Analysis(*check.Name, externalType, id) - analysis.AnalysisType = *check.Category + analysis.AnalysisType = mapCategory(*check.Category) + analysis.Severity = mapSeverity(metadata["Status"]) + delete(metadata, "Status") analysis.Message(deref(check.Description)) analysis.Analysis = metadata diff --git a/scrapers/aws/types.go b/scrapers/aws/types.go index 7868f142..fc9cbb1a 100644 --- a/scrapers/aws/types.go +++ b/scrapers/aws/types.go @@ -8,7 +8,7 @@ import ( "github.com/aws/aws-sdk-go-v2/service/ec2/types" ssmTypes "github.com/aws/aws-sdk-go-v2/service/ssm/types" supportTypes "github.com/aws/aws-sdk-go-v2/service/support/types" - v1 "github.com/flanksource/confighub/api/v1" + v1 "github.com/flanksource/config-db/api/v1" ) func deref(s *string) string { diff --git a/scrapers/common.go b/scrapers/common.go index 887ed681..4ea9c9fa 100644 --- a/scrapers/common.go +++ b/scrapers/common.go @@ -1,9 +1,9 @@ package scrapers import ( - v1 "github.com/flanksource/confighub/api/v1" - "github.com/flanksource/confighub/scrapers/aws" - "github.com/flanksource/confighub/scrapers/file" + v1 "github.com/flanksource/config-db/api/v1" + "github.com/flanksource/config-db/scrapers/aws" + "github.com/flanksource/config-db/scrapers/file" ) // All is the scrappers registry diff --git a/scrapers/file/file.go b/scrapers/file/file.go index 5185c82e..13fe56e7 100644 --- a/scrapers/file/file.go +++ b/scrapers/file/file.go @@ -8,8 +8,8 @@ import ( "time" "github.com/flanksource/commons/logger" - v1 "github.com/flanksource/confighub/api/v1" - "github.com/flanksource/confighub/filesystem" + v1 "github.com/flanksource/config-db/api/v1" + "github.com/flanksource/config-db/filesystem" "github.com/gobwas/glob" "github.com/hashicorp/go-getter" "sigs.k8s.io/yaml" diff --git a/scrapers/processors/json.go b/scrapers/processors/json.go index 908b7b98..56189fa4 100644 --- a/scrapers/processors/json.go +++ b/scrapers/processors/json.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/flanksource/commons/logger" - v1 "github.com/flanksource/confighub/api/v1" + v1 "github.com/flanksource/config-db/api/v1" "github.com/ohler55/ojg/jp" "github.com/ohler55/ojg/oj" ) diff --git a/scrapers/runscrapers.go b/scrapers/runscrapers.go index c0e215a9..53e3329d 100644 --- a/scrapers/runscrapers.go +++ b/scrapers/runscrapers.go @@ -2,8 +2,9 @@ package scrapers import ( "github.com/flanksource/commons/logger" - v1 "github.com/flanksource/confighub/api/v1" - "github.com/flanksource/confighub/scrapers/processors" + v1 "github.com/flanksource/config-db/api/v1" + "github.com/flanksource/config-db/scrapers/analysis" + "github.com/flanksource/config-db/scrapers/processors" ) // Run ... @@ -14,6 +15,13 @@ func Run(ctx v1.ScrapeContext, manager v1.Manager, configs ...v1.ConfigScraper) for _, scraper := range All { for _, result := range scraper.Scrape(ctx, config, manager) { + if result.AnalysisResult != nil { + if rule, ok := analysis.Rules[result.AnalysisResult.Analyzer]; ok { + result.AnalysisResult.AnalysisType = rule.Category + result.AnalysisResult.Severity = rule.Severity + } + } + if result.Config == nil && result.AnalysisResult != nil { results = append(results, result) } else if result.Config != nil { diff --git a/scrapers/runscrapers_test.go b/scrapers/runscrapers_test.go index aaf47c32..ef420aef 100644 --- a/scrapers/runscrapers_test.go +++ b/scrapers/runscrapers_test.go @@ -5,8 +5,8 @@ import ( "testing" jsonpatch "github.com/evanphx/json-patch" - v1 "github.com/flanksource/confighub/api/v1" - fs "github.com/flanksource/confighub/filesystem" + v1 "github.com/flanksource/config-db/api/v1" + fs "github.com/flanksource/config-db/filesystem" ) func TestRun(t *testing.T) { @@ -107,7 +107,7 @@ func TestRun(t *testing.T) { t.Errorf("expected %d results, got: %d", len(tc.expectedResult), len(results)) } - for i := 0; i < len(results); i++ { + for i := 0; i < len(tc.expectedResult); i++ { want := tc.expectedResult[i] got := results[i] diff --git a/utils/templating/template.go b/utils/templating/template.go index 6502970c..660524b0 100644 --- a/utils/templating/template.go +++ b/utils/templating/template.go @@ -15,7 +15,7 @@ import ( "github.com/flanksource/commons/logger" "github.com/flanksource/commons/text" - v1 "github.com/flanksource/confighub/api/v1" + v1 "github.com/flanksource/config-db/api/v1" "github.com/robertkrimen/otto/registry" _ "github.com/robertkrimen/otto/underscore" )