You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.9 KiB
60 lines
1.9 KiB
9 years ago
|
// Copyright 2015 clair authors
|
||
|
//
|
||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
// you may not use this file except in compliance with the License.
|
||
|
// You may obtain a copy of the License at
|
||
|
//
|
||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||
|
//
|
||
|
// Unless required by applicable law or agreed to in writing, software
|
||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
// See the License for the specific language governing permissions and
|
||
|
// limitations under the License.
|
||
|
|
||
9 years ago
|
package redhatrelease
|
||
9 years ago
|
|
||
|
import (
|
||
|
"regexp"
|
||
|
"strings"
|
||
|
|
||
9 years ago
|
"github.com/coreos/clair/database"
|
||
9 years ago
|
"github.com/coreos/clair/worker/detectors"
|
||
|
)
|
||
|
|
||
|
var redhatReleaseRegexp = regexp.MustCompile(`(?P<os>[^\s]*) (Linux release|release) (?P<version>[\d]+)`)
|
||
|
|
||
9 years ago
|
// RedhatReleaseNamespaceDetector implements NamespaceDetector and detects the OS from the
|
||
9 years ago
|
// /etc/centos-release, /etc/redhat-release and /etc/system-release files.
|
||
9 years ago
|
//
|
||
9 years ago
|
// Typically for CentOS and Red-Hat like systems
|
||
|
// eg. CentOS release 5.11 (Final)
|
||
|
// eg. CentOS release 6.6 (Final)
|
||
|
// eg. CentOS Linux release 7.1.1503 (Core)
|
||
9 years ago
|
type RedhatReleaseNamespaceDetector struct{}
|
||
|
|
||
|
func init() {
|
||
|
detectors.RegisterNamespaceDetector("redhat-release", &RedhatReleaseNamespaceDetector{})
|
||
|
}
|
||
|
|
||
|
func (detector *RedhatReleaseNamespaceDetector) Detect(data map[string][]byte) *database.Namespace {
|
||
9 years ago
|
for _, filePath := range detector.GetRequiredFiles() {
|
||
|
f, hasFile := data[filePath]
|
||
|
if !hasFile {
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
r := redhatReleaseRegexp.FindStringSubmatch(string(f))
|
||
|
if len(r) == 4 {
|
||
9 years ago
|
return &database.Namespace{Name: strings.ToLower(r[1]) + ":" + r[3]}
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
return nil
|
||
9 years ago
|
}
|
||
|
|
||
|
// GetRequiredFiles returns the list of files that are required for Detect()
|
||
9 years ago
|
func (detector *RedhatReleaseNamespaceDetector) GetRequiredFiles() []string {
|
||
9 years ago
|
return []string{"etc/centos-release", "etc/redhat-release", "etc/system-release"}
|
||
|
}
|