mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 17:51:21 +00:00
Update go-checkpoint library and add link to README.
This commit is contained in:
24
vendor/github.com/weaveworks/go-checkpoint/Makefile
generated
vendored
Normal file
24
vendor/github.com/weaveworks/go-checkpoint/Makefile
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
BUILD_IN_CONTAINER ?= true
|
||||
RM=--rm
|
||||
BUILD_IMAGE=golang:1.5.3
|
||||
|
||||
ifeq ($(BUILD_IN_CONTAINER),true)
|
||||
|
||||
all test:
|
||||
$(SUDO) docker run $(RM) -ti \
|
||||
-v $(shell pwd):/go/src/github.com/weaveworks/go-checkpoint \
|
||||
-e GOARCH -e GOOS -e BUILD_IN_CONTAINER=false \
|
||||
$(BUILD_IMAGE) make -C /go/src/github.com/weaveworks/go-checkpoint $@
|
||||
|
||||
else
|
||||
|
||||
all:
|
||||
go get .
|
||||
go build .
|
||||
|
||||
test:
|
||||
go get .
|
||||
go test
|
||||
|
||||
endif
|
||||
|
||||
31
vendor/github.com/weaveworks/go-checkpoint/checkpoint.go
generated
vendored
31
vendor/github.com/weaveworks/go-checkpoint/checkpoint.go
generated
vendored
@@ -4,9 +4,11 @@ package checkpoint
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"golang.org/x/crypto/scrypt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
mrand "math/rand"
|
||||
@@ -116,11 +118,15 @@ func Check(p *CheckParams) (*CheckResponse, error) {
|
||||
p.OS = runtime.GOOS
|
||||
}
|
||||
|
||||
// If we're given a SignatureFile, then attempt to read that.
|
||||
// If we're not given a Signature, then attempt to read one.
|
||||
signature := p.Signature
|
||||
if p.Signature == "" && p.SignatureFile != "" {
|
||||
if p.Signature == "" {
|
||||
var err error
|
||||
signature, err = checkSignature(p.SignatureFile)
|
||||
if p.SignatureFile == "" {
|
||||
signature, err = getSystemUUID()
|
||||
} else {
|
||||
signature, err = checkSignature(p.SignatureFile)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -145,6 +151,7 @@ func Check(p *CheckParams) (*CheckResponse, error) {
|
||||
req.Header.Add("User-Agent", "HashiCorp/go-checkpoint")
|
||||
|
||||
client := cleanhttp.DefaultClient()
|
||||
defer client.Transport.(*http.Transport).CloseIdleConnections()
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -154,6 +161,7 @@ func Check(p *CheckParams) (*CheckResponse, error) {
|
||||
}
|
||||
|
||||
var r io.Reader = resp.Body
|
||||
defer resp.Body.Close()
|
||||
if p.CacheFile != "" {
|
||||
// Make sure the directory holding our cache exists.
|
||||
if err := os.MkdirAll(filepath.Dir(p.CacheFile), 0755); err != nil {
|
||||
@@ -284,6 +292,23 @@ func checkResult(r io.Reader) (*CheckResponse, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// getSystemUUID returns the base64 encoded, scrypt hashed contents of
|
||||
// /sys/class/dmi/id/product_uuid.
|
||||
func getSystemUUID() (string, error) {
|
||||
uuid, err := ioutil.ReadFile("/sys/class/dmi/id/product_uuid")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(uuid) <= 0 {
|
||||
return "", fmt.Errorf("Empty system uuid")
|
||||
}
|
||||
hash, err := scrypt.Key(uuid, uuid, 16384, 8, 1, 32)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return base64.StdEncoding.EncodeToString(hash), nil
|
||||
}
|
||||
|
||||
func checkSignature(path string) (string, error) {
|
||||
_, err := os.Stat(path)
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user