vendor: Update github.com/hashicorp/go-checkpoint

This commit is contained in:
Kyle Havlovitz 2020-09-16 07:34:28 -07:00
parent 13df5d5bf8
commit 40481e2b8f
8 changed files with 245 additions and 135 deletions

2
go.mod
View File

@ -34,7 +34,7 @@ require (
github.com/hashicorp/consul/sdk v0.6.0 github.com/hashicorp/consul/sdk v0.6.0
github.com/hashicorp/errwrap v1.0.0 github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-bexpr v0.1.2 github.com/hashicorp/go-bexpr v0.1.2
github.com/hashicorp/go-checkpoint v0.0.0-20171009173528-1545e56e46de github.com/hashicorp/go-checkpoint v0.5.0
github.com/hashicorp/go-cleanhttp v0.5.1 github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/go-connlimit v0.3.0 github.com/hashicorp/go-connlimit v0.3.0
github.com/hashicorp/go-discover v0.0.0-20200501174627-ad1e96bde088 github.com/hashicorp/go-discover v0.0.0-20200501174627-ad1e96bde088

4
go.sum
View File

@ -220,8 +220,8 @@ github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/U
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-bexpr v0.1.2 h1:ijMXI4qERbzxbCnkxmfUtwMyjrrk3y+Vt0MxojNCbBs= github.com/hashicorp/go-bexpr v0.1.2 h1:ijMXI4qERbzxbCnkxmfUtwMyjrrk3y+Vt0MxojNCbBs=
github.com/hashicorp/go-bexpr v0.1.2/go.mod h1:ANbpTX1oAql27TZkKVeW8p1w8NTdnyzPe/0qqPCKohU= github.com/hashicorp/go-bexpr v0.1.2/go.mod h1:ANbpTX1oAql27TZkKVeW8p1w8NTdnyzPe/0qqPCKohU=
github.com/hashicorp/go-checkpoint v0.0.0-20171009173528-1545e56e46de h1:XDCSythtg8aWSRSO29uwhgh7b127fWr+m5SemqjSUL8= github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
github.com/hashicorp/go-checkpoint v0.0.0-20171009173528-1545e56e46de/go.mod h1:xIwEieBHERyEvaeKF/TcHh1Hu+lxPM+n2vT1+g9I4m4= github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=

View File

@ -1,11 +1,7 @@
// checkpoint is a package for checking version information and alerts
// for a HashiCorp product.
package checkpoint package checkpoint
import ( import (
"bytes" crand "crypto/rand"
"context"
"crypto/rand"
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
"fmt" "fmt"
@ -23,112 +19,9 @@ import (
"time" "time"
"github.com/hashicorp/go-cleanhttp" "github.com/hashicorp/go-cleanhttp"
uuid "github.com/hashicorp/go-uuid"
) )
var magicBytes [4]byte = [4]byte{0x35, 0x77, 0x69, 0xFB} var magicBytes = [4]byte{0x35, 0x77, 0x69, 0xFB}
// ReportParams are the parameters for configuring a telemetry report.
type ReportParams struct {
// Signature is some random signature that should be stored and used
// as a cookie-like value. This ensures that alerts aren't repeated.
// If the signature is changed, repeat alerts may be sent down. The
// signature should NOT be anything identifiable to a user (such as
// a MAC address). It should be random.
//
// If SignatureFile is given, then the signature will be read from this
// file. If the file doesn't exist, then a random signature will
// automatically be generated and stored here. SignatureFile will be
// ignored if Signature is given.
Signature string `json:"signature"`
SignatureFile string `json:"-"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Arch string `json:"arch"`
OS string `json:"os"`
Payload interface{} `json:"payload,omitempty"`
Product string `json:"product"`
RunID string `json:"run_id"`
SchemaVersion string `json:"schema_version"`
Version string `json:"version"`
}
func (i *ReportParams) signature() string {
signature := i.Signature
if i.Signature == "" && i.SignatureFile != "" {
var err error
signature, err = checkSignature(i.SignatureFile)
if err != nil {
return ""
}
}
return signature
}
// Report sends telemetry information to checkpoint
func Report(ctx context.Context, r *ReportParams) error {
if disabled := os.Getenv("CHECKPOINT_DISABLE"); disabled != "" {
return nil
}
req, err := ReportRequest(r)
if err != nil {
return err
}
client := cleanhttp.DefaultClient()
resp, err := client.Do(req.WithContext(ctx))
if err != nil {
return err
}
if resp.StatusCode != 201 {
return fmt.Errorf("Unknown status: %d", resp.StatusCode)
}
return nil
}
// ReportRequest creates a request object for making a report
func ReportRequest(r *ReportParams) (*http.Request, error) {
// Populate some fields automatically if we can
if r.RunID == "" {
uuid, err := uuid.GenerateUUID()
if err != nil {
return nil, err
}
r.RunID = uuid
}
if r.Arch == "" {
r.Arch = runtime.GOARCH
}
if r.OS == "" {
r.OS = runtime.GOOS
}
if r.Signature == "" {
r.Signature = r.signature()
}
b, err := json.Marshal(r)
if err != nil {
return nil, err
}
u := &url.URL{
Scheme: "https",
Host: "checkpoint-api.hashicorp.com",
Path: fmt.Sprintf("/v1/telemetry/%s", r.Product),
}
req, err := http.NewRequest("POST", u.String(), bytes.NewReader(b))
if err != nil {
return nil, err
}
req.Header.Add("Accept", "application/json")
req.Header.Add("User-Agent", "HashiCorp/go-checkpoint")
return req, nil
}
// CheckParams are the parameters for configuring a check request. // CheckParams are the parameters for configuring a check request.
type CheckParams struct { type CheckParams struct {
@ -177,14 +70,14 @@ type CheckParams struct {
// CheckResponse is the response for a check request. // CheckResponse is the response for a check request.
type CheckResponse struct { type CheckResponse struct {
Product string Product string `json:"product"`
CurrentVersion string `json:"current_version"` CurrentVersion string `json:"current_version"`
CurrentReleaseDate int `json:"current_release_date"` CurrentReleaseDate int `json:"current_release_date"`
CurrentDownloadURL string `json:"current_download_url"` CurrentDownloadURL string `json:"current_download_url"`
CurrentChangelogURL string `json:"current_changelog_url"` CurrentChangelogURL string `json:"current_changelog_url"`
ProjectWebsite string `json:"project_website"` ProjectWebsite string `json:"project_website"`
Outdated bool `json:"outdated"` Outdated bool `json:"outdated"`
Alerts []*CheckAlert Alerts []*CheckAlert `json:"alerts"`
} }
// CheckAlert is a single alert message from a check request. // CheckAlert is a single alert message from a check request.
@ -192,11 +85,11 @@ type CheckResponse struct {
// These never have to be manually constructed, and are typically populated // These never have to be manually constructed, and are typically populated
// into a CheckResponse as a result of the Check request. // into a CheckResponse as a result of the Check request.
type CheckAlert struct { type CheckAlert struct {
ID int ID int `json:"id"`
Date int Date int `json:"date"`
Message string Message string `json:"message"`
URL string URL string `json:"url"`
Level string Level string `json:"level"`
} }
// Check checks for alerts and new version information. // Check checks for alerts and new version information.
@ -205,7 +98,7 @@ func Check(p *CheckParams) (*CheckResponse, error) {
return &CheckResponse{}, nil return &CheckResponse{}, nil
} }
// set a default timeout of 3 sec for the check request (in milliseconds) // Set a default timeout of 3 sec for the check request (in milliseconds)
timeout := 3000 timeout := 3000
if _, err := strconv.Atoi(os.Getenv("CHECKPOINT_TIMEOUT")); err == nil { if _, err := strconv.Atoi(os.Getenv("CHECKPOINT_TIMEOUT")); err == nil {
timeout, _ = strconv.Atoi(os.Getenv("CHECKPOINT_TIMEOUT")) timeout, _ = strconv.Atoi(os.Getenv("CHECKPOINT_TIMEOUT"))
@ -253,8 +146,8 @@ func Check(p *CheckParams) (*CheckResponse, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
req.Header.Add("Accept", "application/json") req.Header.Set("Accept", "application/json")
req.Header.Add("User-Agent", "HashiCorp/go-checkpoint") req.Header.Set("User-Agent", "HashiCorp/go-checkpoint")
client := cleanhttp.DefaultClient() client := cleanhttp.DefaultClient()
@ -266,6 +159,8 @@ func Check(p *CheckParams) (*CheckResponse, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer resp.Body.Close()
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
return nil, fmt.Errorf("Unknown status: %d", resp.StatusCode) return nil, fmt.Errorf("Unknown status: %d", resp.StatusCode)
} }
@ -390,14 +285,11 @@ func checkCache(current string, path string, d time.Duration) (io.ReadCloser, er
return f, nil return f, nil
} }
func checkResult(r io.Reader) (*CheckResponse, error) { func checkResult(r io.Reader) (*CheckResponse, error) {
var result CheckResponse var result CheckResponse
dec := json.NewDecoder(r) if err := json.NewDecoder(r).Decode(&result); err != nil {
if err := dec.Decode(&result); err != nil {
return nil, err return nil, err
} }
return &result, nil return &result, nil
} }
@ -426,7 +318,7 @@ func checkSignature(path string) (string, error) {
var b [16]byte var b [16]byte
n := 0 n := 0
for n < 16 { for n < 16 {
n2, err := rand.Read(b[n:]) n2, err := crand.Read(b[n:])
if err != nil { if err != nil {
return "", err return "", err
} }
@ -456,7 +348,7 @@ func writeCacheHeader(f io.Writer, v string) error {
} }
// Write out our current version length // Write out our current version length
var length uint32 = uint32(len(v)) length := uint32(len(v))
if err := binary.Write(f, binary.LittleEndian, length); err != nil { if err := binary.Write(f, binary.LittleEndian, length); err != nil {
return err return err
} }

6
vendor/github.com/hashicorp/go-checkpoint/go.mod generated vendored Normal file
View File

@ -0,0 +1,6 @@
module github.com/hashicorp/go-checkpoint
require (
github.com/hashicorp/go-cleanhttp v0.5.0
github.com/hashicorp/go-uuid v1.0.0
)

4
vendor/github.com/hashicorp/go-checkpoint/go.sum generated vendored Normal file
View File

@ -0,0 +1,4 @@
github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=

118
vendor/github.com/hashicorp/go-checkpoint/telemetry.go generated vendored Normal file
View File

@ -0,0 +1,118 @@
package checkpoint
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"os"
"runtime"
"time"
"github.com/hashicorp/go-cleanhttp"
uuid "github.com/hashicorp/go-uuid"
)
// ReportParams are the parameters for configuring a telemetry report.
type ReportParams struct {
// Signature is some random signature that should be stored and used
// as a cookie-like value. This ensures that alerts aren't repeated.
// If the signature is changed, repeat alerts may be sent down. The
// signature should NOT be anything identifiable to a user (such as
// a MAC address). It should be random.
//
// If SignatureFile is given, then the signature will be read from this
// file. If the file doesn't exist, then a random signature will
// automatically be generated and stored here. SignatureFile will be
// ignored if Signature is given.
Signature string `json:"signature"`
SignatureFile string `json:"-"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Arch string `json:"arch"`
OS string `json:"os"`
Payload interface{} `json:"payload,omitempty"`
Product string `json:"product"`
RunID string `json:"run_id"`
SchemaVersion string `json:"schema_version"`
Version string `json:"version"`
}
func (i *ReportParams) signature() string {
signature := i.Signature
if i.Signature == "" && i.SignatureFile != "" {
var err error
signature, err = checkSignature(i.SignatureFile)
if err != nil {
return ""
}
}
return signature
}
// Report sends telemetry information to checkpoint
func Report(ctx context.Context, r *ReportParams) error {
if disabled := os.Getenv("CHECKPOINT_DISABLE"); disabled != "" {
return nil
}
req, err := ReportRequest(r)
if err != nil {
return err
}
client := cleanhttp.DefaultClient()
resp, err := client.Do(req.WithContext(ctx))
if err != nil {
return err
}
if resp.StatusCode != 201 {
return fmt.Errorf("Unknown status: %d", resp.StatusCode)
}
return nil
}
// ReportRequest creates a request object for making a report
func ReportRequest(r *ReportParams) (*http.Request, error) {
// Populate some fields automatically if we can
if r.RunID == "" {
uuid, err := uuid.GenerateUUID()
if err != nil {
return nil, err
}
r.RunID = uuid
}
if r.Arch == "" {
r.Arch = runtime.GOARCH
}
if r.OS == "" {
r.OS = runtime.GOOS
}
if r.Signature == "" {
r.Signature = r.signature()
}
b, err := json.Marshal(r)
if err != nil {
return nil, err
}
u := &url.URL{
Scheme: "https",
Host: "checkpoint-api.hashicorp.com",
Path: fmt.Sprintf("/v1/telemetry/%s", r.Product),
}
req, err := http.NewRequest("POST", u.String(), bytes.NewReader(b))
if err != nil {
return nil, err
}
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", "HashiCorp/go-checkpoint")
return req, nil
}

90
vendor/github.com/hashicorp/go-checkpoint/versions.go generated vendored Normal file
View File

@ -0,0 +1,90 @@
package checkpoint
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"os"
"strconv"
"time"
"github.com/hashicorp/go-cleanhttp"
)
// VersionsParams are the parameters for a versions request.
type VersionsParams struct {
// Service is used to lookup the correct service.
Service string
// Product is used to filter the version contraints.
Product string
// Force, if true, will force the check even if CHECKPOINT_DISABLE
// is set. Within HashiCorp products, this is ONLY USED when the user
// specifically requests it. This is never automatically done without
// the user's consent.
Force bool
}
// VersionsResponse is the response for a versions request.
type VersionsResponse struct {
Service string `json:"service"`
Product string `json:"product"`
Minimum string `json:"minimum"`
Maximum string `json:"maximum"`
Excluding []string `json:"excluding"`
}
// Versions returns the version constrains for a given service and product.
func Versions(p *VersionsParams) (*VersionsResponse, error) {
if disabled := os.Getenv("CHECKPOINT_DISABLE"); disabled != "" && !p.Force {
return &VersionsResponse{}, nil
}
// Set a default timeout of 1 sec for the versions request (in milliseconds)
timeout := 1000
if _, err := strconv.Atoi(os.Getenv("CHECKPOINT_TIMEOUT")); err == nil {
timeout, _ = strconv.Atoi(os.Getenv("CHECKPOINT_TIMEOUT"))
}
v := url.Values{}
v.Set("product", p.Product)
u := &url.URL{
Scheme: "https",
Host: "checkpoint-api.hashicorp.com",
Path: fmt.Sprintf("/v1/versions/%s", p.Service),
RawQuery: v.Encode(),
}
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
return nil, err
}
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", "HashiCorp/go-checkpoint")
client := cleanhttp.DefaultClient()
// We use a short timeout since checking for new versions is not critical
// enough to block on if checkpoint is broken/slow.
client.Timeout = time.Duration(timeout) * time.Millisecond
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.Errorf("Unknown status: %d", resp.StatusCode)
}
result := &VersionsResponse{}
if err := json.NewDecoder(resp.Body).Decode(result); err != nil {
return nil, err
}
return result, nil
}

2
vendor/modules.txt vendored
View File

@ -204,7 +204,7 @@ github.com/gophercloud/gophercloud/pagination
github.com/hashicorp/errwrap github.com/hashicorp/errwrap
# github.com/hashicorp/go-bexpr v0.1.2 # github.com/hashicorp/go-bexpr v0.1.2
github.com/hashicorp/go-bexpr github.com/hashicorp/go-bexpr
# github.com/hashicorp/go-checkpoint v0.0.0-20171009173528-1545e56e46de # github.com/hashicorp/go-checkpoint v0.5.0
github.com/hashicorp/go-checkpoint github.com/hashicorp/go-checkpoint
# github.com/hashicorp/go-cleanhttp v0.5.1 # github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/go-cleanhttp github.com/hashicorp/go-cleanhttp