Test Setup Failed
Pull Request — master (#807)
by
unknown
07:07
created

scan.*staticContainer.checkDeps   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
nop 0
1
/* Vuls - Vulnerability Scanner
2
Copyright (C) 2016  Future Corporation , Japan.
3
4
This program is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
package scan
19
20
import (
21
	"context"
22
23
	"golang.org/x/xerrors"
24
25
	"github.com/knqyf263/fanal/analyzer"
26
27
	"github.com/future-architect/vuls/config"
28
	"github.com/future-architect/vuls/models"
29
	"github.com/future-architect/vuls/util"
30
31
	// Register os and package analyzers
32
	_ "github.com/knqyf263/fanal/analyzer/os/alpine"
33
	_ "github.com/knqyf263/fanal/analyzer/os/amazonlinux"
34
	_ "github.com/knqyf263/fanal/analyzer/os/debian"
35
	_ "github.com/knqyf263/fanal/analyzer/os/opensuse"
36
	_ "github.com/knqyf263/fanal/analyzer/os/redhatbase"
37
	_ "github.com/knqyf263/fanal/analyzer/os/ubuntu"
38
	_ "github.com/knqyf263/fanal/analyzer/pkg/apk"
39
	_ "github.com/knqyf263/fanal/analyzer/pkg/dpkg"
40
	_ "github.com/knqyf263/fanal/analyzer/pkg/rpm"
41
)
42
43
// inherit OsTypeInterface
44
type staticContainer struct {
45
	base
46
}
47
48
func detectContainerImage(c config.ServerInfo) (itsMe bool, containerImage osTypeInterface, err error) {
49
	if c.Type != config.ServerTypeStaticContainer {
50
		return false, containerImage, nil
51
	}
52
53
	os, pkgs, err := scanImage(c)
54
	if err != nil {
55
		return false, containerImage, err
56
	}
57
	p := newContainerImage(c, pkgs)
58
	p.setDistro(os.Family, os.Name)
59
	return true, p, nil
60
}
61
62
// scanImage returns os, packages on image layers
63
func scanImage(c config.ServerInfo) (os *analyzer.OS, pkgs []analyzer.Package, err error) {
64
	if err = config.IsValidStaticContainerConf(c.StaticContainer); err != nil {
65
		return nil, nil, err
66
	}
67
68
	ctx := context.Background()
69
	domain := c.StaticContainer.Name + ":" + c.StaticContainer.Tag
70
	files, err := analyzer.Analyze(ctx, domain)
71
	if err != nil {
72
		return nil, nil, xerrors.Errorf("Failed scan files %q, %w", domain, err)
0 ignored issues
show
introduced by
unrecognized printf verb 'w'
Loading history...
73
	}
74
	pkgs, err = analyzer.GetPackages(files)
75
	if err != nil {
76
		return nil, nil, xerrors.Errorf("Failed scan pkgs %q, %w", domain, err)
0 ignored issues
show
introduced by
unrecognized printf verb 'w'
Loading history...
77
	}
78
79
	containerOs, err := analyzer.GetOS(files)
80
	if err != nil {
81
		return nil, nil, xerrors.Errorf("Failed scan os %q, %w", domain, err)
0 ignored issues
show
introduced by
unrecognized printf verb 'w'
Loading history...
82
	}
83
	return &containerOs, pkgs, nil
84
}
85
86
func newContainerImage(c config.ServerInfo, pkgs []analyzer.Package) *staticContainer {
87
	modelPkgs := map[string]models.Package{}
88
	for _, pkg := range pkgs {
89
		modelPkgs[pkg.Name] = models.Package{
90
			Name:       pkg.Name,
91
			Release:    pkg.Release,
92
			Version:    pkg.Version,
93
			Repository: pkg.Type,
94
		}
95
	}
96
	d := &staticContainer{
97
		base: base{
98
			osPackages: osPackages{
99
				Packages:  modelPkgs,
100
				VulnInfos: models.VulnInfos{},
101
			},
102
		},
103
	}
104
	d.log = util.NewCustomLogger(c)
105
	d.setServerInfo(c)
106
	return d
107
}
108
109
func (o *staticContainer) checkScanMode() error {
110
	return nil
111
}
112
113
func (o *staticContainer) checkIfSudoNoPasswd() error {
114
	return nil
115
}
116
117
func (o *staticContainer) checkDeps() error {
118
	return nil
119
}
120
121
func (o *staticContainer) preCure() error {
122
	return nil
123
}
124
125
func (o *staticContainer) postScan() error {
126
	return nil
127
}
128
129
func (o *staticContainer) scanPackages() error {
130
	return nil
131
}
132
133
func (o *staticContainer) parseInstalledPackages(string) (models.Packages, models.SrcPackages, error) {
134
	return nil, nil, nil
135
}
136
137
func (o *staticContainer) detectPlatform() {
138
	o.setPlatform(models.Platform{Name: "staticContainer"})
139
	return
140
}
141