github.com/mikesimons/terraform@v0.6.13-0.20160304043642-f11448c69214/checkpoint.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "log" 6 "path/filepath" 7 8 "github.com/hashicorp/go-checkpoint" 9 "github.com/hashicorp/terraform/command" 10 ) 11 12 func init() { 13 checkpointResult = make(chan *checkpoint.CheckResponse, 1) 14 } 15 16 var checkpointResult chan *checkpoint.CheckResponse 17 18 // runCheckpoint runs a HashiCorp Checkpoint request. You can read about 19 // Checkpoint here: https://github.com/hashicorp/go-checkpoint. 20 func runCheckpoint(c *Config) { 21 // If the user doesn't want checkpoint at all, then return. 22 if c.DisableCheckpoint { 23 log.Printf("[INFO] Checkpoint disabled. Not running.") 24 checkpointResult <- nil 25 return 26 } 27 28 configDir, err := ConfigDir() 29 if err != nil { 30 log.Printf("[ERR] Checkpoint setup error: %s", err) 31 checkpointResult <- nil 32 return 33 } 34 35 version := Version 36 if VersionPrerelease != "" { 37 version += fmt.Sprintf("-%s", VersionPrerelease) 38 } 39 40 signaturePath := filepath.Join(configDir, "checkpoint_signature") 41 if c.DisableCheckpointSignature { 42 log.Printf("[INFO] Checkpoint signature disabled") 43 signaturePath = "" 44 } 45 46 resp, err := checkpoint.Check(&checkpoint.CheckParams{ 47 Product: "terraform", 48 Version: version, 49 SignatureFile: signaturePath, 50 CacheFile: filepath.Join(configDir, "checkpoint_cache"), 51 }) 52 if err != nil { 53 log.Printf("[ERR] Checkpoint error: %s", err) 54 resp = nil 55 } 56 57 checkpointResult <- resp 58 } 59 60 // commandVersionCheck implements command.VersionCheckFunc and is used 61 // as the version checker. 62 func commandVersionCheck() (command.VersionCheckInfo, error) { 63 // Wait for the result to come through 64 info := <-checkpointResult 65 if info == nil { 66 var zero command.VersionCheckInfo 67 return zero, nil 68 } 69 70 // Build the alerts that we may have received about our version 71 alerts := make([]string, len(info.Alerts)) 72 for i, a := range info.Alerts { 73 alerts[i] = a.Message 74 } 75 76 return command.VersionCheckInfo{ 77 Outdated: info.Outdated, 78 Latest: info.CurrentVersion, 79 Alerts: alerts, 80 }, nil 81 }