Skip to content

Commit

Permalink
Merge pull request #19 from anchore/remove-unused-code
Browse files Browse the repository at this point in the history
feat: remove adhoc mode
  • Loading branch information
bradleyjones committed Jan 5, 2023
2 parents fc22f9d + 806467d commit 156cbd1
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 107 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ version show the version
Flags:
-c, --config string application config file
-h, --help help for ecg
-m, --mode string execution mode, options=[adhoc periodic] (default "adhoc")
-o, --output string report output formatter, options=[json table] (default "json")
-p, --polling-interval-seconds string If mode is 'periodic', this specifies the interval (default "300")
-p, --polling-interval-seconds string This specifies the polling interval of the ECS API in seconds (default "300")
-r, --region string If set overrides the AWS_REGION environment variable/region specified in ECG config
-v, --verbose count increase verbosity (-v = info, -vv = debug)
Expand Down
43 changes: 2 additions & 41 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package cmd
import (
"fmt"
"os"
"runtime/pprof"

"github.com/anchore/elastic-container-gatherer/ecg"
"github.com/anchore/elastic-container-gatherer/ecg/mode"
"github.com/anchore/elastic-container-gatherer/ecg/presenter"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -19,18 +17,6 @@ var rootCmd = &cobra.Command{
Long: "ECG (Elastic Container Gatherer) can poll Amazon ECS (Elastic Container Service) APIs to tell Anchore which Images are currently in-use",
Args: cobra.MaximumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
if appConfig.Dev.ProfileCPU {
f, err := os.Create("cpu.profile")
if err != nil {
log.Error("unable to create CPU profile", err)
} else {
err := pprof.StartCPUProfile(f)
if err != nil {
log.Error("unable to start CPU profile", err)
}
}
}

if len(args) > 0 {
err := cmd.Help()
if err != nil {
Expand All @@ -53,25 +39,7 @@ var rootCmd = &cobra.Command{
//log.Debug("Anchore details not specified, will not report inventory")
//}

switch appConfig.RunMode {
case mode.PeriodicPolling:
ecg.PeriodicallyGetInventoryReport(appConfig)
default:
report, err := ecg.GetInventoryReport(appConfig)
if appConfig.Dev.ProfileCPU {
pprof.StopCPUProfile()
}
if err != nil {
log.Error("Failed to get Image Results", err)
os.Exit(1)
} else {
err := ecg.HandleReport(report, appConfig)
if err != nil {
log.Error("Failed to handle Image Results", err)
os.Exit(1)
}
}
}
ecg.PeriodicallyGetInventoryReport(appConfig)
},
}

Expand All @@ -87,15 +55,8 @@ func init() {
os.Exit(1)
}

opt = "mode"
rootCmd.Flags().StringP(opt, "m", mode.AdHoc.String(), fmt.Sprintf("execution mode, options=%v", mode.Modes))
if err := viper.BindPFlag(opt, rootCmd.Flags().Lookup(opt)); err != nil {
fmt.Printf("unable to bind flag '%s': %+v", opt, err)
os.Exit(1)
}

opt = "polling-interval-seconds"
rootCmd.Flags().StringP(opt, "p", "300", "If mode is 'periodic', this specifies the interval")
rootCmd.Flags().StringP(opt, "p", "300", "This specifies the polling interval of the ECS API in seconds")
if err := viper.BindPFlag(opt, rootCmd.Flags().Lookup(opt)); err != nil {
fmt.Printf("unable to bind flag '%s': %+v", opt, err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion ecg/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func PeriodicallyGetInventoryReport(cfg *config.Application) {
}

// Wait at least as long as the ticker
log.Debug("Start new gather", <-ticker.C)
log.Debugf("Start new gather %s", <-ticker.C)
}
}

Expand Down
1 change: 1 addition & 0 deletions ecg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ type Logger interface {
Warn(msg string, args ...interface{})
Info(msg string, args ...interface{})
Debug(msg string, args ...interface{})
Debugf(msg string, args ...interface{})
}
44 changes: 0 additions & 44 deletions ecg/mode/mode.go

This file was deleted.

23 changes: 4 additions & 19 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (

"gopkg.in/yaml.v2"

"github.com/anchore/elastic-container-gatherer/ecg/mode"

"github.com/adrg/xdg"
"github.com/anchore/elastic-container-gatherer/ecg/presenter"
"github.com/anchore/elastic-container-gatherer/internal"
Expand All @@ -42,14 +40,11 @@ type Application struct {
Output string `mapstructure:"output"`
Log Logging `mapstructure:"log"`
CliOptions CliOnlyOptions
Dev Development `mapstructure:"dev"`
MissingTagPolicy MissingTagConf `mapstructure:"missing-tag-policy"`
RunMode mode.Mode
Mode string `mapstructure:"mode"`
IgnoreNotRunning bool `mapstructure:"ignore-not-running"`
PollingIntervalSeconds int `mapstructure:"polling-interval-seconds"`
AnchoreDetails AnchoreInfo `mapstructure:"anchore"`
Region string `mapstructure:"region"`
IgnoreNotRunning bool `mapstructure:"ignore-not-running"`
PollingIntervalSeconds int `mapstructure:"polling-interval-seconds"`
AnchoreDetails AnchoreInfo `mapstructure:"anchore"`
Region string `mapstructure:"region"`
}

// MissingTagConf details the policy for handling missing tags when reporting images
Expand Down Expand Up @@ -79,11 +74,6 @@ type Logging struct {
FileLocation string `mapstructure:"file"`
}

// Development Configuration (only profile-cpu at the moment)
type Development struct {
ProfileCPU bool `mapstructure:"profile-cpu"`
}

// Return whether or not AnchoreDetails are specified
func (anchore *AnchoreInfo) IsValid() bool {
return anchore.URL != "" &&
Expand All @@ -94,8 +84,6 @@ func (anchore *AnchoreInfo) IsValid() bool {
func setNonCliDefaultValues(v *viper.Viper) {
v.SetDefault("log.level", "")
v.SetDefault("log.file", "")
v.SetDefault("dev.profile-cpu", false)
v.SetDefault("dev.log", false)
v.SetDefault("anchore.account", "admin")
v.SetDefault("anchore.http.insecure", false)
v.SetDefault("anchore.http.timeout-seconds", 10)
Expand Down Expand Up @@ -140,9 +128,6 @@ func (cfg *Application) Build() error {
}
cfg.PresenterOpt = presenterOption

runMode := mode.ParseMode(cfg.Mode)
cfg.RunMode = runMode

if cfg.Log.Level != "" {
if cfg.CliOptions.Verbosity > 0 {
return fmt.Errorf("cannot explicitly set log level (cfg file or env var) and use -v flag together")
Expand Down

0 comments on commit 156cbd1

Please sign in to comment.