From c3deb93489cfb57ad7bb060517eb69ca89068a91 Mon Sep 17 00:00:00 2001 From: kota kanbe Date: Thu, 16 Jun 2016 10:37:49 +0900 Subject: [PATCH] Rename linux.go to base.go --- glide.lock | 4 +-- scan/{linux.go => base.go} | 38 ++++++++++++++-------------- scan/{linux_test.go => base_test.go} | 0 scan/debian.go | 2 +- scan/freebsd.go | 2 +- scan/redhat.go | 2 +- 6 files changed, 24 insertions(+), 24 deletions(-) rename scan/{linux.go => base.go} (85%) rename scan/{linux_test.go => base_test.go} (100%) diff --git a/glide.lock b/glide.lock index c8df0fe7b5..f6103e5536 100644 --- a/glide.lock +++ b/glide.lock @@ -1,10 +1,10 @@ hash: f6451157cbeaa3590d2b62fb9902221f73c81b5aeda722cf61929f88ce1cfc64 -updated: 2016-06-06T09:28:24.182725693+09:00 +updated: 2016-06-16T00:45:19.481421096+09:00 imports: - name: github.com/asaskevich/govalidator version: df81827fdd59d8b4fb93d8910b286ab7a3919520 - name: github.com/aws/aws-sdk-go - version: 1608a1f6ffe7f327007d2aca50ebf1d26c285ef2 + version: d3b6d25135b4e09ecd39ea3c2a5cad35279b0515 subpackages: - aws - aws/credentials diff --git a/scan/linux.go b/scan/base.go similarity index 85% rename from scan/linux.go rename to scan/base.go index 585e28af35..498cba27f3 100644 --- a/scan/linux.go +++ b/scan/base.go @@ -28,7 +28,7 @@ import ( "github.com/future-architect/vuls/models" ) -type linux struct { +type base struct { ServerInfo config.ServerInfo Family string @@ -40,36 +40,36 @@ type linux struct { errs []error } -func (l *linux) ssh(cmd string, sudo bool) sshResult { +func (l *base) ssh(cmd string, sudo bool) sshResult { return sshExec(l.ServerInfo, cmd, sudo, l.log) } -func (l *linux) setServerInfo(c config.ServerInfo) { +func (l *base) setServerInfo(c config.ServerInfo) { l.ServerInfo = c } -func (l linux) getServerInfo() config.ServerInfo { +func (l base) getServerInfo() config.ServerInfo { return l.ServerInfo } -func (l *linux) setDistributionInfo(fam, rel string) { +func (l *base) setDistributionInfo(fam, rel string) { l.Family = fam l.Release = rel } -func (l linux) getDistributionInfo() string { +func (l base) getDistributionInfo() string { return fmt.Sprintf("%s %s", l.Family, l.Release) } -func (l *linux) setPlatform(p models.Platform) { +func (l *base) setPlatform(p models.Platform) { l.Platform = p } -func (l linux) getPlatform() models.Platform { +func (l base) getPlatform() models.Platform { return l.Platform } -func (l linux) allContainers() (containers []config.Container, err error) { +func (l base) allContainers() (containers []config.Container, err error) { switch l.ServerInfo.Container.Type { case "", "docker": stdout, err := l.dockerPs("-a --format '{{.ID}} {{.Names}}'") @@ -83,7 +83,7 @@ func (l linux) allContainers() (containers []config.Container, err error) { } } -func (l *linux) runningContainers() (containers []config.Container, err error) { +func (l *base) runningContainers() (containers []config.Container, err error) { switch l.ServerInfo.Container.Type { case "", "docker": stdout, err := l.dockerPs("--format '{{.ID}} {{.Names}}'") @@ -97,7 +97,7 @@ func (l *linux) runningContainers() (containers []config.Container, err error) { } } -func (l *linux) exitedContainers() (containers []config.Container, err error) { +func (l *base) exitedContainers() (containers []config.Container, err error) { switch l.ServerInfo.Container.Type { case "", "docker": stdout, err := l.dockerPs("--filter 'status=exited' --format '{{.ID}} {{.Names}}'") @@ -111,7 +111,7 @@ func (l *linux) exitedContainers() (containers []config.Container, err error) { } } -func (l *linux) dockerPs(option string) (string, error) { +func (l *base) dockerPs(option string) (string, error) { cmd := fmt.Sprintf("docker ps %s", option) r := l.ssh(cmd, noSudo) if !r.isSuccess() { @@ -122,7 +122,7 @@ func (l *linux) dockerPs(option string) (string, error) { return r.Stdout, nil } -func (l *linux) parseDockerPs(stdout string) (containers []config.Container, err error) { +func (l *base) parseDockerPs(stdout string) (containers []config.Container, err error) { lines := strings.Split(stdout, "\n") for _, line := range lines { fields := strings.Fields(line) @@ -140,7 +140,7 @@ func (l *linux) parseDockerPs(stdout string) (containers []config.Container, err return } -func (l *linux) detectPlatform() error { +func (l *base) detectPlatform() error { ok, instanceID, err := l.detectRunningOnAws() if err != nil { return err @@ -160,7 +160,7 @@ func (l *linux) detectPlatform() error { return nil } -func (l linux) detectRunningOnAws() (ok bool, instanceID string, err error) { +func (l base) detectRunningOnAws() (ok bool, instanceID string, err error) { if r := l.ssh("type curl", noSudo); r.isSuccess() { cmd := "curl --max-time 1 --retry 3 --noproxy 169.254.169.254 http://169.254.169.254/latest/meta-data/instance-id" if r := l.ssh(cmd, noSudo); r.isSuccess() { @@ -190,7 +190,7 @@ func (l linux) detectRunningOnAws() (ok bool, instanceID string, err error) { l.ServerInfo.ServerName, l.ServerInfo.Container.Name) } -func (l *linux) convertToModel() (models.ScanResult, error) { +func (l *base) convertToModel() (models.ScanResult, error) { var scoredCves, unscoredCves models.CveInfos for _, p := range l.UnsecurePackages { if p.CveDetail.CvssScore(config.Conf.Lang) <= 0 { @@ -237,7 +237,7 @@ func (l *linux) convertToModel() (models.ScanResult, error) { } // scanVulnByCpeName search vulnerabilities that specified in config file. -func (l *linux) scanVulnByCpeName() error { +func (l *base) scanVulnByCpeName() error { unsecurePacks := CvePacksList{} serverInfo := l.getServerInfo() @@ -275,10 +275,10 @@ func (l *linux) scanVulnByCpeName() error { return nil } -func (l *linux) setErrs(errs []error) { +func (l *base) setErrs(errs []error) { l.errs = errs } -func (l linux) getErrs() []error { +func (l base) getErrs() []error { return l.errs } diff --git a/scan/linux_test.go b/scan/base_test.go similarity index 100% rename from scan/linux_test.go rename to scan/base_test.go diff --git a/scan/debian.go b/scan/debian.go index 7b4b8244af..5e222234e8 100644 --- a/scan/debian.go +++ b/scan/debian.go @@ -32,7 +32,7 @@ import ( // inherit OsTypeInterface type debian struct { - linux + base } // NewDebian is constructor diff --git a/scan/freebsd.go b/scan/freebsd.go index 00dce6fc8a..9c29ce2c47 100644 --- a/scan/freebsd.go +++ b/scan/freebsd.go @@ -12,7 +12,7 @@ import ( // inherit OsTypeInterface type bsd struct { - linux + base } // NewBSD constructor diff --git a/scan/redhat.go b/scan/redhat.go index ff6cb00eda..d594512871 100644 --- a/scan/redhat.go +++ b/scan/redhat.go @@ -35,7 +35,7 @@ import ( // inherit OsTypeInterface type redhat struct { - linux + base } // NewRedhat is constructor