Skip to content

Commit

Permalink
Merge pull request #189 from future-architect/Fix-not-working-changel…
Browse files Browse the repository at this point in the history
…og-cache-on-docker

Fix not working changelog cache on Container
  • Loading branch information
kotakanbe authored Sep 20, 2016
2 parents 97c3f5d + e3fc3aa commit cb445c9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
9 changes: 9 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ type ServerInfo struct {
Distro Distro
}

// GetServerName returns ServerName if this serverInfo is about host.
// If this serverInfo is abount a container, returns containerID@ServerName
func (s ServerInfo) GetServerName() string {
if len(s.Container.ContainerID) == 0 {
return s.ServerName
}
return fmt.Sprintf("%s@%s", s.Container.ContainerID, s.ServerName)
}

// Distro has distribution info
type Distro struct {
Family string
Expand Down
6 changes: 3 additions & 3 deletions scan/debian.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (o *debian) scanUnsecurePackages(packs []models.PackageInfo) ([]CvePacksInf
}

current := cache.Meta{
Name: o.getServerInfo().ServerName,
Name: o.getServerInfo().GetServerName(),
Distro: o.getServerInfo().Distro,
Packs: unsecurePacks,
}
Expand Down Expand Up @@ -377,7 +377,7 @@ func (o *debian) parseAptGetUpgrade(stdout string) (upgradableNames []string, er

func (o *debian) scanPackageCveInfos(unsecurePacks []models.PackageInfo) (cvePacksList CvePacksList, err error) {
meta := cache.Meta{
Name: o.getServerInfo().ServerName,
Name: o.getServerInfo().GetServerName(),
Distro: o.getServerInfo().Distro,
Packs: unsecurePacks,
}
Expand Down Expand Up @@ -520,7 +520,7 @@ func (o *debian) scanPackageCveIDs(pack models.PackageInfo) ([]string, error) {
return nil, nil

}
err := cache.DB.PutChangelog(o.getServerInfo().ServerName, pack.Name, r.Stdout)
err := cache.DB.PutChangelog(o.getServerInfo().GetServerName(), pack.Name, r.Stdout)
if err != nil {
return nil, fmt.Errorf("Failed to put changelog into cache")
}
Expand Down
2 changes: 1 addition & 1 deletion scan/serverapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func detectContainerOSes() (actives []osTypeInterface) {
defer func() {
if p := recover(); p != nil {
Log.Debugf("Panic: %s on %s",
p, s.getServerInfo().ServerName)
p, s.getServerInfo().GetServerName())
}
}()
osTypesChan <- detectContainerOSesOnServer(s)
Expand Down
6 changes: 3 additions & 3 deletions scan/sshutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func parallelSSHExec(fn func(osTypeInterface) error, timeoutSec ...int) (errs []
defer func() {
if p := recover(); p != nil {
logrus.Debugf("Panic: %s on %s",
p, s.getServerInfo().ServerName)
p, s.getServerInfo().GetServerName())
}
}()
if err := fn(s); err != nil {
Expand All @@ -100,7 +100,7 @@ func parallelSSHExec(fn func(osTypeInterface) error, timeoutSec ...int) (errs []
err,
)
} else {
resChan <- s.getServerInfo().ServerName
resChan <- s.getServerInfo().GetServerName()
}
}(s)
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func parallelSSHExec(fn func(osTypeInterface) error, timeoutSec ...int) (errs []
var timedoutSnames []string
if isTimedout {
for _, s := range servers {
name := s.getServerInfo().ServerName
name := s.getServerInfo().GetServerName()
found := false
for _, t := range snames {
if name == t {
Expand Down
8 changes: 1 addition & 7 deletions util/logutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package util

import (
"fmt"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -53,12 +52,7 @@ func NewCustomLogger(c config.ServerInfo) *logrus.Entry {

whereami := "localhost"
if 0 < len(c.ServerName) {
if 0 < len(c.Container.ContainerID) {
whereami = fmt.Sprintf(
"%s_%s", c.ServerName, c.Container.Name)
} else {
whereami = fmt.Sprintf("%s", c.ServerName)
}
whereami = c.GetServerName()
}

if _, err := os.Stat(logDir); err == nil {
Expand Down

0 comments on commit cb445c9

Please sign in to comment.