mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-19 04:06:24 +00:00
Add github.com/cobaugh/osrelease as dependency
This done via: GO111MODULE=on go get github.com/cobaugh/osrelease GO111MODULE=on go mod vendor
This commit is contained in:
@@ -9,6 +9,7 @@ require (
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2 // indirect
|
||||
github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 // indirect
|
||||
github.com/beorn7/perks v1.0.0 // indirect
|
||||
github.com/cobaugh/osrelease v0.0.0-20181218015638-a93a0a55a249
|
||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e
|
||||
github.com/coreos/pkg v0.0.0-20160620232715-fa29b1d70f0b // indirect
|
||||
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633 // indirect
|
||||
|
||||
@@ -16,6 +16,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
|
||||
github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cobaugh/osrelease v0.0.0-20181218015638-a93a0a55a249 h1:R0IDH8daQ3lODvu8YtxnIqqth5qMGCJyADoUQvmLx4o=
|
||||
github.com/cobaugh/osrelease v0.0.0-20181218015638-a93a0a55a249/go.mod h1:EHKW9yNEYSBpTKzuu7Y9oOrft/UlzH57rMIB03oev6M=
|
||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8=
|
||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/pkg v0.0.0-20160620232715-fa29b1d70f0b h1:IqgHacj6F3QnV+0H9PXFWAmML5HdxkZakBQgZgfD+FU=
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
language: go
|
||||
go:
|
||||
- 1.8.x
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
Copyright 2017 Andrew Cobaugh
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
# osrelease [](https://travis-ci.org/cobaugh/osrelease)
|
||||
|
||||
A Go package to make reading in os-release files easy.
|
||||
|
||||
See https://www.freedesktop.org/software/systemd/man/os-release.html
|
||||
|
||||
## Installation
|
||||
`$ go get github.com/cobaugh/osrelease`
|
||||
|
||||
## Usage
|
||||
|
||||
See [godoc](https://godoc.org/github.com/cobaugh/osrelease)
|
||||
|
||||
```golang
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cobaugh/osrelease"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// for reference, two variables are provided:
|
||||
fmt.Printf("EtcOsRelease = %v\n", osrelease.EtcOsRelease)
|
||||
fmt.Printf("UsrLibOsRelease = %v\n", osrelease.UsrLibOsRelease)
|
||||
|
||||
// let osrelease find what file to load
|
||||
osrelease, err := osrelease.Read()
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("PRETTY_NAME = %v\n", osrelease["PRETTY_NAME"])
|
||||
|
||||
// specify the file to load explicitly
|
||||
osrelease, err = osrelease.ReadFile("/etc/os-release")
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("PRETTY_NAME = %v\n", osrelease["PRETTY_NAME"])
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Output:
|
||||
```
|
||||
$ ./examples
|
||||
EtcOsRelease = /etc/os-release
|
||||
UsrLibOsRelease = /usr/lib/os-release
|
||||
PRETTY_NAME = void
|
||||
PRETTY_NAME = void```
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
// osrelease is a go package to make reading the contents of os-release files easier
|
||||
//
|
||||
// See https://www.freedesktop.org/software/systemd/man/os-release.html
|
||||
package osrelease
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const EtcOsRelease string = "/etc/os-release"
|
||||
const UsrLibOsRelease string = "/usr/lib/os-release"
|
||||
|
||||
// Read and return os-release, trying EtcOsRelease, followed by UsrLibOsRelease.
|
||||
// err will contain an error message if neither file exists or failed to parse
|
||||
func Read() (osrelease map[string]string, err error) {
|
||||
osrelease, err = ReadFile(EtcOsRelease)
|
||||
if err != nil {
|
||||
osrelease, err = ReadFile(UsrLibOsRelease)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Similar to Read(), but takes the name of a file to load instead
|
||||
func ReadFile(filename string) (osrelease map[string]string, err error) {
|
||||
osrelease = make(map[string]string)
|
||||
err = nil
|
||||
|
||||
lines, err := parseFile(filename)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range lines {
|
||||
key, value, err := parseLine(v)
|
||||
if err == nil {
|
||||
osrelease[key] = value
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ReadString is similar to Read(), but takes a string to load instead
|
||||
func ReadString(content string) (osrelease map[string]string, err error) {
|
||||
osrelease = make(map[string]string)
|
||||
err = nil
|
||||
|
||||
lines, err := parseString(content)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range lines {
|
||||
key, value, err := parseLine(v)
|
||||
if err == nil {
|
||||
osrelease[key] = value
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func parseFile(filename string) (lines []string, err error) {
|
||||
file, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
lines = append(lines, scanner.Text())
|
||||
}
|
||||
return lines, scanner.Err()
|
||||
}
|
||||
|
||||
func parseString(content string) (lines []string, err error) {
|
||||
in := bytes.NewBufferString(content)
|
||||
reader := bufio.NewReader(in)
|
||||
scanner := bufio.NewScanner(reader)
|
||||
|
||||
for scanner.Scan() {
|
||||
lines = append(lines, scanner.Text())
|
||||
}
|
||||
return lines, scanner.Err()
|
||||
|
||||
}
|
||||
|
||||
func parseLine(line string) (key string, value string, err error) {
|
||||
err = nil
|
||||
|
||||
// skip empty lines
|
||||
if len(line) == 0 {
|
||||
err = errors.New("Skipping: zero-length")
|
||||
return
|
||||
}
|
||||
|
||||
// skip comments
|
||||
if line[0] == '#' {
|
||||
err = errors.New("Skipping: comment")
|
||||
return
|
||||
}
|
||||
|
||||
// try to split string at the first '='
|
||||
splitString := strings.SplitN(line, "=", 2)
|
||||
if len(splitString) != 2 {
|
||||
err = errors.New("Can not extract key=value")
|
||||
return
|
||||
}
|
||||
|
||||
// trim white space from key and value
|
||||
key = splitString[0]
|
||||
key = strings.Trim(key, " ")
|
||||
value = splitString[1]
|
||||
value = strings.Trim(value, " ")
|
||||
|
||||
// Handle double quotes
|
||||
if strings.ContainsAny(value, `"`) {
|
||||
first := string(value[0:1])
|
||||
last := string(value[len(value)-1:])
|
||||
|
||||
if first == last && strings.ContainsAny(first, `"'`) {
|
||||
value = strings.TrimPrefix(value, `'`)
|
||||
value = strings.TrimPrefix(value, `"`)
|
||||
value = strings.TrimSuffix(value, `'`)
|
||||
value = strings.TrimSuffix(value, `"`)
|
||||
}
|
||||
}
|
||||
|
||||
// expand anything else that could be escaped
|
||||
value = strings.Replace(value, `\"`, `"`, -1)
|
||||
value = strings.Replace(value, `\$`, `$`, -1)
|
||||
value = strings.Replace(value, `\\`, `\`, -1)
|
||||
value = strings.Replace(value, "\\`", "`", -1)
|
||||
return
|
||||
}
|
||||
Vendored
+2
@@ -11,6 +11,8 @@ github.com/PuerkitoBio/urlesc
|
||||
github.com/StackExchange/wmi
|
||||
# github.com/beorn7/perks v1.0.0
|
||||
github.com/beorn7/perks/quantile
|
||||
# github.com/cobaugh/osrelease v0.0.0-20181218015638-a93a0a55a249
|
||||
github.com/cobaugh/osrelease
|
||||
# github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e
|
||||
github.com/coreos/go-systemd/sdjournal
|
||||
# github.com/coreos/pkg v0.0.0-20160620232715-fa29b1d70f0b
|
||||
|
||||
Reference in New Issue
Block a user