From edd36db8dcde4461d1747fa85dc27b10a4cbb091 Mon Sep 17 00:00:00 2001 From: jgsqware Date: Tue, 17 May 2016 18:31:53 +0200 Subject: [PATCH] rename hyperclair to clairctl in config and test --- cmd/clairctl/README.md | 2 +- ...clair.yml.default => clairctl.yml.default} | 0 cmd/clairctl/cmd/login.go | 4 +- cmd/clairctl/cmd/logout.go | 6 +- cmd/clairctl/cmd/root.go | 2 +- cmd/clairctl/config/config.go | 86 +++++++++---------- cmd/clairctl/config/config_test.go | 16 ++-- cmd/clairctl/docker/image.go | 2 +- cmd/clairctl/server/server.go | 4 +- cmd/clairctl/test/test.go | 2 +- 10 files changed, 62 insertions(+), 62 deletions(-) rename cmd/clairctl/{hyperclair.yml.default => clairctl.yml.default} (100%) diff --git a/cmd/clairctl/README.md b/cmd/clairctl/README.md index 38c88262..56c3f4ac 100644 --- a/cmd/clairctl/README.md +++ b/cmd/clairctl/README.md @@ -36,7 +36,7 @@ Available Commands: version Get Versions of clairctl and underlying services Flags: - --config string config file (default is ./.hyperclair.yml) + --config string config file (default is ./.clairctl.yml) --log-level string log level [Panic,Fatal,Error,Warn,Info,Debug] Use "clairctl [command] --help" for more information about a command. diff --git a/cmd/clairctl/hyperclair.yml.default b/cmd/clairctl/clairctl.yml.default similarity index 100% rename from cmd/clairctl/hyperclair.yml.default rename to cmd/clairctl/clairctl.yml.default diff --git a/cmd/clairctl/cmd/login.go b/cmd/clairctl/cmd/login.go index 1311667c..708fa13b 100644 --- a/cmd/clairctl/cmd/login.go +++ b/cmd/clairctl/cmd/login.go @@ -36,7 +36,7 @@ var loginCmd = &cobra.Command{ var users userMapping - if err := readConfigFile(&users, config.HyperclairConfig()); err != nil { + if err := readConfigFile(&users, config.ClairctlConfig()); err != nil { fmt.Println(errInternalError) logrus.Fatalf("reading clairctl file: %v", err) } @@ -55,7 +55,7 @@ var loginCmd = &cobra.Command{ users[reg] = usr - if err := writeConfigFile(users, config.HyperclairConfig()); err != nil { + if err := writeConfigFile(users, config.ClairctlConfig()); err != nil { fmt.Println(errInternalError) logrus.Fatalf("indenting login: %v", err) } diff --git a/cmd/clairctl/cmd/logout.go b/cmd/clairctl/cmd/logout.go index 2ef8f8b4..cb43a1e1 100644 --- a/cmd/clairctl/cmd/logout.go +++ b/cmd/clairctl/cmd/logout.go @@ -26,17 +26,17 @@ var logoutCmd = &cobra.Command{ reg = args[0] } - if _, err := os.Stat(config.HyperclairConfig()); err == nil { + if _, err := os.Stat(config.ClairctlConfig()); err == nil { var users userMapping - if err := readConfigFile(&users, config.HyperclairConfig()); err != nil { + if err := readConfigFile(&users, config.ClairctlConfig()); err != nil { fmt.Println(errInternalError) logrus.Fatalf("reading clairctl file: %v", err) } if _, present := users[reg]; present { delete(users, reg) - if err := writeConfigFile(users, config.HyperclairConfig()); err != nil { + if err := writeConfigFile(users, config.ClairctlConfig()); err != nil { fmt.Println(errInternalError) logrus.Fatalf("indenting login: %v", err) } diff --git a/cmd/clairctl/cmd/root.go b/cmd/clairctl/cmd/root.go index 766651c7..62f11cea 100644 --- a/cmd/clairctl/cmd/root.go +++ b/cmd/clairctl/cmd/root.go @@ -50,7 +50,7 @@ func Execute() { func init() { cobra.OnInitialize(initConfig) - RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.hyperclair.yml)") + RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.clairctl.yml)") RootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "", "log level [Panic,Fatal,Error,Warn,Info,Debug]") } diff --git a/cmd/clairctl/config/config.go b/cmd/clairctl/config/config.go index 89a7d2db..aa7de44a 100644 --- a/cmd/clairctl/config/config.go +++ b/cmd/clairctl/config/config.go @@ -23,25 +23,25 @@ import ( var ErrLoginNotFound = errors.New("user is not log in") -type r struct { +type reportConfig struct { Path, Format string } -type c struct { +type clairConfig struct { URI, Priority string Port, HealthPort int - Report r + Report reportConfig } -type a struct { +type authConfig struct { InsecureSkipVerify bool } -type h struct { +type clairctlConfig struct { IP, TempFolder string Port int } type config struct { - Clair c - Auth a - Hyperclair h + Clair clairConfig + Auth authConfig + Clairctl clairctlConfig } // Init reads in config file and ENV variables if set. @@ -57,11 +57,11 @@ func Init(cfgFile string, logLevel string) { } logrus.SetLevel(lvl) - viper.SetEnvPrefix("hyperclair") - viper.SetConfigName("hyperclair") // name of config file (without extension) - viper.AddConfigPath("$HOME/.hyperclair") // adding home directory as first search path - viper.AddConfigPath(".") // adding home directory as first search path - viper.AutomaticEnv() // read in environment variables that match + viper.SetEnvPrefix("clairctl") + viper.SetConfigName("clairctl") // name of config file (without extension) + viper.AddConfigPath("$HOME/.clairctl") // adding home directory as first search path + viper.AddConfigPath(".") // adding home directory as first search path + viper.AutomaticEnv() // read in environment variables that match if cfgFile != "" { viper.SetConfigFile(cfgFile) } @@ -93,37 +93,37 @@ func Init(cfgFile string, logLevel string) { if viper.Get("auth.insecureSkipVerify") == nil { viper.Set("auth.insecureSkipVerify", "true") } - if viper.Get("hyperclair.ip") == nil { - viper.Set("hyperclair.ip", "") + if viper.Get("clairctl.ip") == nil { + viper.Set("clairctl.ip", "") } - if viper.Get("hyperclair.port") == nil { - viper.Set("hyperclair.port", 0) + if viper.Get("clairctl.port") == nil { + viper.Set("clairctl.port", 0) } - if viper.Get("hyperclair.tempFolder") == nil { - viper.Set("hyperclair.tempFolder", "/tmp/hyperclair") + if viper.Get("clairctl.tempFolder") == nil { + viper.Set("clairctl.tempFolder", "/tmp/clairctl") } clair.Config() } func values() config { return config{ - Clair: c{ + Clair: clairConfig{ URI: viper.GetString("clair.uri"), Port: viper.GetInt("clair.port"), HealthPort: viper.GetInt("clair.healthPort"), Priority: viper.GetString("clair.priority"), - Report: r{ + Report: reportConfig{ Path: viper.GetString("clair.report.path"), Format: viper.GetString("clair.report.format"), }, }, - Auth: a{ + Auth: authConfig{ InsecureSkipVerify: viper.GetBool("auth.insecureSkipVerify"), }, - Hyperclair: h{ - IP: viper.GetString("hyperclair.ip"), - Port: viper.GetInt("hyperclair.port"), - TempFolder: viper.GetString("hyperclair.tempFolder"), + Clairctl: clairctlConfig{ + IP: viper.GetString("clairctl.ip"), + Port: viper.GetInt("clairctl.port"), + TempFolder: viper.GetString("clairctl.tempFolder"), }, } } @@ -139,12 +139,12 @@ func Print() { fmt.Printf("%v", string(cfgBytes)) } -func HyperclairHome() string { +func ClairctlHome() string { usr, err := user.Current() if err != nil { panic(err) } - p := usr.HomeDir + "/.hyperclair" + p := usr.HomeDir + "/.clairctl" if _, err := os.Stat(p); os.IsNotExist(err) { os.Mkdir(p, 0700) @@ -159,31 +159,31 @@ type Login struct { type loginMapping map[string]Login -func HyperclairConfig() string { - return HyperclairHome() + "/config.json" +func ClairctlConfig() string { + return ClairctlHome() + "/config.json" } func AddLogin(registry string, login Login) error { var logins loginMapping - if err := readConfigFile(&logins, HyperclairConfig()); err != nil { - return fmt.Errorf("reading hyperclair file: %v", err) + if err := readConfigFile(&logins, ClairctlConfig()); err != nil { + return fmt.Errorf("reading clairctl file: %v", err) } logins[registry] = login - if err := writeConfigFile(logins, HyperclairConfig()); err != nil { + if err := writeConfigFile(logins, ClairctlConfig()); err != nil { return fmt.Errorf("indenting login: %v", err) } return nil } func GetLogin(registry string) (Login, error) { - if _, err := os.Stat(HyperclairConfig()); err == nil { + if _, err := os.Stat(ClairctlConfig()); err == nil { var logins loginMapping - if err := readConfigFile(&logins, HyperclairConfig()); err != nil { - return Login{}, fmt.Errorf("reading hyperclair file: %v", err) + if err := readConfigFile(&logins, ClairctlConfig()); err != nil { + return Login{}, fmt.Errorf("reading clairctl file: %v", err) } if login, present := logins[registry]; present { @@ -199,17 +199,17 @@ func GetLogin(registry string) (Login, error) { } func RemoveLogin(registry string) (bool, error) { - if _, err := os.Stat(HyperclairConfig()); err == nil { + if _, err := os.Stat(ClairctlConfig()); err == nil { var logins loginMapping - if err := readConfigFile(&logins, HyperclairConfig()); err != nil { - return false, fmt.Errorf("reading hyperclair file: %v", err) + if err := readConfigFile(&logins, ClairctlConfig()); err != nil { + return false, fmt.Errorf("reading clairctl file: %v", err) } if _, present := logins[registry]; present { delete(logins, registry) - if err := writeConfigFile(logins, HyperclairConfig()); err != nil { + if err := writeConfigFile(logins, ClairctlConfig()); err != nil { return false, fmt.Errorf("indenting login: %v", err) } @@ -247,10 +247,10 @@ func writeConfigFile(logins loginMapping, file string) error { return nil } -//LocalServerIP return the local hyperclair server IP +//LocalServerIP return the local clairctl server IP func LocalServerIP() (string, error) { - localPort := viper.GetString("hyperclair.port") - localIP := viper.GetString("hyperclair.ip") + localPort := viper.GetString("clairctl.port") + localIP := viper.GetString("clairctl.ip") if localIP == "" { logrus.Infoln("retrieving docker0 interface as local IP") var err error diff --git a/cmd/clairctl/config/config_test.go b/cmd/clairctl/config/config_test.go index 142e5d07..e0429ce1 100644 --- a/cmd/clairctl/config/config_test.go +++ b/cmd/clairctl/config/config_test.go @@ -5,8 +5,8 @@ import ( "os" "testing" - "github.com/spf13/viper" "github.com/coreos/clair/cmd/clairctl/test" + "github.com/spf13/viper" "gopkg.in/yaml.v2" ) @@ -22,9 +22,9 @@ clair: format: html auth: insecureskipverify: true -hyperclair: +clairctl: ip: "" - tempfolder: /tmp/hyperclair + tempfolder: /tmp/clairctl port: 0 ` @@ -39,9 +39,9 @@ clair: format: json auth: insecureskipverify: false -hyperclair: +clairctl: ip: "localhost" - tempfolder: /tmp/hyperclair/test + tempfolder: /tmp/clairctl/test port: 64157 ` @@ -63,7 +63,7 @@ func TestInitDefault(t *testing.T) { } func TestInitCustomLocal(t *testing.T) { - tmpfile := test.CreateConfigFile(customValues, "hyperclair.yml", ".") + tmpfile := test.CreateConfigFile(customValues, "clairctl.yml", ".") defer os.Remove(tmpfile) // clean up fmt.Println(tmpfile) Init("", "INFO") @@ -83,7 +83,7 @@ func TestInitCustomLocal(t *testing.T) { } func TestInitCustomHome(t *testing.T) { - tmpfile := test.CreateConfigFile(customValues, "hyperclair.yml", HyperclairHome()) + tmpfile := test.CreateConfigFile(customValues, "clairctl.yml", ClairctlHome()) defer os.Remove(tmpfile) // clean up fmt.Println(tmpfile) Init("", "INFO") @@ -103,7 +103,7 @@ func TestInitCustomHome(t *testing.T) { } func TestInitCustom(t *testing.T) { - tmpfile := test.CreateConfigFile(customValues, "hyperclair.yml", "/tmp") + tmpfile := test.CreateConfigFile(customValues, "clairctl.yml", "/tmp") defer os.Remove(tmpfile) // clean up fmt.Println(tmpfile) Init(tmpfile, "INFO") diff --git a/cmd/clairctl/docker/image.go b/cmd/clairctl/docker/image.go index 7c8d39b7..2d21cb10 100644 --- a/cmd/clairctl/docker/image.go +++ b/cmd/clairctl/docker/image.go @@ -33,7 +33,7 @@ const hubURI = "https://" + DockerHub + "/v2" var IsLocal = false func TmpLocal() string { - return viper.GetString("hyperclair.tempFolder") + return viper.GetString("clairctl.tempFolder") } // Parse is used to parse a docker image command diff --git a/cmd/clairctl/server/server.go b/cmd/clairctl/server/server.go index 0dce6342..940f98d6 100644 --- a/cmd/clairctl/server/server.go +++ b/cmd/clairctl/server/server.go @@ -41,10 +41,10 @@ func tcpListener(sURL string) (listener net.Listener) { logrus.Fatalf("cannot instanciate listener: %v", err) } - if viper.GetInt("hyperclair.port") == 0 { + if viper.GetInt("clairctl.port") == 0 { port := strings.Split(listener.Addr().String(), ":")[1] logrus.Debugf("Update local server port from %q to %q", "0", port) - viper.Set("hyperclair.port", port) + viper.Set("clairctl.port", port) } return diff --git a/cmd/clairctl/test/test.go b/cmd/clairctl/test/test.go index 13eb8c20..c5b4ae99 100644 --- a/cmd/clairctl/test/test.go +++ b/cmd/clairctl/test/test.go @@ -9,7 +9,7 @@ import ( func CreateTmpConfigFile(content string) string { c := []byte(content) - tmpfile, err := ioutil.TempFile("", "test-hyperclair") + tmpfile, err := ioutil.TempFile("", "test-clairctl") if err != nil { log.Fatal(err) }