github.com/crowdsecurity/crowdsec@v1.6.1/cmd/crowdsec-cli/require/branch.go (about) 1 package require 2 3 // Set the appropriate hub branch according to config settings and crowdsec version 4 5 import ( 6 log "github.com/sirupsen/logrus" 7 "golang.org/x/mod/semver" 8 9 "github.com/crowdsecurity/crowdsec/pkg/cwversion" 10 "github.com/crowdsecurity/crowdsec/pkg/csconfig" 11 ) 12 13 func chooseBranch(cfg *csconfig.Config) string { 14 // this was set from config.yaml or flag 15 if cfg.Cscli.HubBranch != "" { 16 log.Debugf("Hub override from config: branch '%s'", cfg.Cscli.HubBranch) 17 return cfg.Cscli.HubBranch 18 } 19 20 latest, err := cwversion.Latest() 21 if err != nil { 22 log.Warningf("Unable to retrieve latest crowdsec version: %s, using hub branch 'master'", err) 23 return "master" 24 } 25 26 csVersion := cwversion.VersionStrip() 27 if csVersion == latest { 28 log.Debugf("Latest crowdsec version (%s), using hub branch 'master'", csVersion) 29 return "master" 30 } 31 32 // if current version is greater than the latest we are in pre-release 33 if semver.Compare(csVersion, latest) == 1 { 34 log.Debugf("Your current crowdsec version seems to be a pre-release (%s), using hub branch 'master'", csVersion) 35 return "master" 36 } 37 38 if csVersion == "" { 39 log.Warning("Crowdsec version is not set, using hub branch 'master'") 40 return "master" 41 } 42 43 log.Warnf("A new CrowdSec release is available (%s). "+ 44 "Your version is '%s'. Please update it to use new parsers/scenarios/collections.", 45 latest, csVersion) 46 return csVersion 47 } 48 49 50 // HubBranch sets the branch (in cscli config) and returns its value 51 // It can be "master", or the branch corresponding to the current crowdsec version, or the value overridden in config/flag 52 func HubBranch(cfg *csconfig.Config) string { 53 branch := chooseBranch(cfg) 54 55 cfg.Cscli.HubBranch = branch 56 57 return branch 58 } 59 60 func HubURLTemplate(cfg *csconfig.Config) string { 61 return cfg.Cscli.HubURLTemplate 62 }