Explorar o código

update the config.yaml file (#674)

AlteredCoder %!s(int64=4) %!d(string=hai) anos
pai
achega
f2d14c8ca2

+ 8 - 2
.github/workflows/ci_functests-install.yml

@@ -22,11 +22,17 @@ jobs:
       id: go
       id: go
     - name: Check out code into the Go module directory
     - name: Check out code into the Go module directory
       uses: actions/checkout@v2
       uses: actions/checkout@v2
+    - id: keydb
+      uses: pozetroninc/github-action-get-latest-release@master
+      with:
+        owner: crowdsecurity
+        repo: crowdsec
+        excludes: draft
     - name: Build release
     - name: Build release
-      run: BUILD_VERSION=xxx make release
+      run: BUILD_VERSION=${{ steps.keydb.outputs.release }} make release
     - name: Install release
     - name: Install release
       run: |
       run: |
-        cd crowdsec-xxx
+        cd crowdsec-${{ steps.keydb.outputs.release }}
         sudo bash -x ./wizard.sh --bininstall
         sudo bash -x ./wizard.sh --bininstall
         sudo cscli machines add -a
         sudo cscli machines add -a
     - name: Post-installation check
     - name: Post-installation check

+ 8 - 2
.github/workflows/ci_functests-upgrade.yml

@@ -25,9 +25,15 @@ jobs:
     - name: install ipset for bouncer
     - name: install ipset for bouncer
       run: |
       run: |
         sudo apt update
         sudo apt update
-        sudo apt install ipset
+        sudo apt install ipset git
+    - id: keydb
+      uses: pozetroninc/github-action-get-latest-release@master
+      with:
+        owner: crowdsecurity
+        repo: crowdsec
+        excludes: draft
     - name: run tests
     - name: run tests
       run: |
       run: |
         cd scripts
         cd scripts
-        sudo ./test_wizard_upgrade.sh
+        sudo ./test_wizard_upgrade.sh --version ${{ steps.keydb.outputs.release }}
 
 

+ 6 - 7
cmd/crowdsec-cli/utils.go

@@ -71,23 +71,22 @@ func setHubBranch() error {
 	/*
 	/*
 		if no branch has been specified in flags for the hub, then use the one corresponding to crowdsec version
 		if no branch has been specified in flags for the hub, then use the one corresponding to crowdsec version
 	*/
 	*/
-
 	if cwhub.HubBranch == "" {
 	if cwhub.HubBranch == "" {
 		latest, err := cwversion.Latest()
 		latest, err := cwversion.Latest()
 		if err != nil {
 		if err != nil {
 			cwhub.HubBranch = "master"
 			cwhub.HubBranch = "master"
 			return err
 			return err
 		}
 		}
-
-		if cwversion.Version == latest {
+		csVersion := cwversion.VersionStrip()
+		if csVersion == latest {
 			cwhub.HubBranch = "master"
 			cwhub.HubBranch = "master"
-		} else if semver.Compare(cwversion.Version, latest) == 1 { // if current version is greater than the latest we are in pre-release
-			log.Debugf("Your current crowdsec version seems to be a pre-release (%s)", cwversion.Version)
+		} else if semver.Compare(csVersion, latest) == 1 { // if current version is greater than the latest we are in pre-release
+			log.Debugf("Your current crowdsec version seems to be a pre-release (%s)", csVersion)
 			cwhub.HubBranch = "master"
 			cwhub.HubBranch = "master"
 		} else {
 		} else {
-			log.Warnf("Crowdsec is not the latest version. Current version is '%s' and latest version is '%s'. Please update it!", cwversion.Version, latest)
+			log.Warnf("Crowdsec is not the latest version. Current version is '%s' and the latest stable version is '%s'. Please update it!", csVersion, latest)
 			log.Warnf("As a result, you will not be able to use parsers/scenarios/collections added to Crowdsec Hub after CrowdSec %s", latest)
 			log.Warnf("As a result, you will not be able to use parsers/scenarios/collections added to Crowdsec Hub after CrowdSec %s", latest)
-			cwhub.HubBranch = cwversion.Version
+			cwhub.HubBranch = csVersion
 		}
 		}
 		log.Debugf("Using branch '%s' for the hub", cwhub.HubBranch)
 		log.Debugf("Using branch '%s' for the hub", cwhub.HubBranch)
 	}
 	}

+ 0 - 1
config/config.yaml

@@ -16,7 +16,6 @@ crowdsec_service:
   parser_routines: 1
   parser_routines: 1
 cscli:
 cscli:
   output: human
   output: human
-  hub_branch: master
 db_config:
 db_config:
   log_level: info
   log_level: info
   type: sqlite
   type: sqlite

+ 6 - 0
pkg/cwversion/version.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"fmt"
 	"log"
 	"log"
 	"net/http"
 	"net/http"
+	"strings"
 
 
 	version "github.com/hashicorp/go-version"
 	version "github.com/hashicorp/go-version"
 )
 )
@@ -57,6 +58,11 @@ func VersionStr() string {
 	return fmt.Sprintf("%s-%s", Version, Tag)
 	return fmt.Sprintf("%s-%s", Version, Tag)
 }
 }
 
 
+func VersionStrip() string {
+	version := strings.Split(Version, "-")
+	return version[0]
+}
+
 func Statisfies(strvers string, constraint string) (bool, error) {
 func Statisfies(strvers string, constraint string) (bool, error) {
 	vers, err := version.NewVersion(strvers)
 	vers, err := version.NewVersion(strvers)
 	if err != nil {
 	if err != nil {

+ 3 - 5
pkg/database/machines.go

@@ -70,8 +70,7 @@ func (c *Client) QueryMachineByID(machineID string) (*ent.Machine, error) {
 func (c *Client) ListMachines() ([]*ent.Machine, error) {
 func (c *Client) ListMachines() ([]*ent.Machine, error) {
 	machines, err := c.Ent.Machine.Query().All(c.CTX)
 	machines, err := c.Ent.Machine.Query().All(c.CTX)
 	if err != nil {
 	if err != nil {
-		log.Warningf("ListMachines : %s", err)
-		return []*ent.Machine{}, errors.Wrap(UpdateFail, "setting machine status")
+		return []*ent.Machine{}, errors.Wrapf(QueryFail, "listing machines: %s", err)
 	}
 	}
 	return machines, nil
 	return machines, nil
 }
 }
@@ -79,8 +78,7 @@ func (c *Client) ListMachines() ([]*ent.Machine, error) {
 func (c *Client) ValidateMachine(machineID string) error {
 func (c *Client) ValidateMachine(machineID string) error {
 	_, err := c.Ent.Machine.Update().Where(machine.MachineIdEQ(machineID)).SetIsValidated(true).Save(c.CTX)
 	_, err := c.Ent.Machine.Update().Where(machine.MachineIdEQ(machineID)).SetIsValidated(true).Save(c.CTX)
 	if err != nil {
 	if err != nil {
-		log.Warningf("ValidateMachine : %s", err)
-		return errors.Wrap(UpdateFail, "setting machine status")
+		return errors.Wrapf(UpdateFail, "validating machine: %s", err)
 	}
 	}
 	return nil
 	return nil
 }
 }
@@ -92,7 +90,7 @@ func (c *Client) QueryPendingMachine() ([]*ent.Machine, error) {
 	machines, err = c.Ent.Machine.Query().Where(machine.IsValidatedEQ(false)).All(c.CTX)
 	machines, err = c.Ent.Machine.Query().Where(machine.IsValidatedEQ(false)).All(c.CTX)
 	if err != nil {
 	if err != nil {
 		log.Warningf("QueryPendingMachine : %s", err)
 		log.Warningf("QueryPendingMachine : %s", err)
-		return []*ent.Machine{}, errors.Wrap(UpdateFail, "setting machine status")
+		return []*ent.Machine{}, errors.Wrapf(QueryFail, "querying pending machines: %s", err)
 	}
 	}
 	return machines, nil
 	return machines, nil
 }
 }

+ 10 - 2
scripts/test_wizard_upgrade.sh

@@ -11,7 +11,6 @@ FAIL_STR="${RED}FAIL${NC}"
 CURRENT_FOLDER=$(pwd)
 CURRENT_FOLDER=$(pwd)
 
 
 BOUNCER_VERSION="v0.0.6"
 BOUNCER_VERSION="v0.0.6"
-CROWDSEC_VERSION="xxx"
 RELEASE_FOLDER=""
 RELEASE_FOLDER=""
 
 
 HUB_AVAILABLE_PARSERS="/etc/crowdsec/hub/parsers"
 HUB_AVAILABLE_PARSERS="/etc/crowdsec/hub/parsers"
@@ -40,6 +39,10 @@ MUST_FAIL=0
 
 
 function init
 function init
 {
 {
+    which git > /dev/null
+    if [ $? -ne 0 ]; then
+        echo "git is needed this test, exiting ..."
+    fi
     if [[ -z ${RELEASE_FOLDER} ]];
     if [[ -z ${RELEASE_FOLDER} ]];
     then
     then
       cd ..
       cd ..
@@ -324,7 +327,12 @@ while [[ $# -gt 0 ]]
 do
 do
     key="${1}"
     key="${1}"
     case ${key} in
     case ${key} in
-    --release)
+    --version|-v)
+        CROWDSEC_VERSION="${2}"
+        shift #past argument
+        shift
+        ;;   
+    --release|-r)
         RELEASE_FOLDER="${2}"
         RELEASE_FOLDER="${2}"
         shift #past argument
         shift #past argument
         shift
         shift

+ 3 - 0
wizard.sh

@@ -22,6 +22,8 @@ CROWDSEC_DB_PATH="${CROWDSEC_DATA_DIR}/crowdsec.db"
 CROWDSEC_PATH="/etc/crowdsec"
 CROWDSEC_PATH="/etc/crowdsec"
 CROWDSEC_CONFIG_PATH="${CROWDSEC_PATH}"
 CROWDSEC_CONFIG_PATH="${CROWDSEC_PATH}"
 CROWDSEC_LOG_FILE="/var/log/crowdsec.log"
 CROWDSEC_LOG_FILE="/var/log/crowdsec.log"
+LAPI_LOG_FILE="/var/log/crowdsec_api.log"
+
 
 
 CROWDSEC_BIN="./cmd/crowdsec/crowdsec"
 CROWDSEC_BIN="./cmd/crowdsec/crowdsec"
 CSCLI_BIN="./cmd/crowdsec-cli/cscli"
 CSCLI_BIN="./cmd/crowdsec-cli/cscli"
@@ -477,6 +479,7 @@ uninstall_crowdsec() {
 
 
     find /etc/crowdsec -maxdepth 1 -mindepth 1 | grep -v "bouncer" | xargs rm -rf || echo ""
     find /etc/crowdsec -maxdepth 1 -mindepth 1 | grep -v "bouncer" | xargs rm -rf || echo ""
     rm -f ${CROWDSEC_LOG_FILE} || echo ""
     rm -f ${CROWDSEC_LOG_FILE} || echo ""
+    rm -f ${LAPI_LOG_FILE} || echo ""
     rm -f ${CROWDSEC_DB_PATH} || echo ""
     rm -f ${CROWDSEC_DB_PATH} || echo ""
     rm -rf ${CROWDSEC_LIB_DIR} || echo ""
     rm -rf ${CROWDSEC_LIB_DIR} || echo ""
     rm -rf ${CROWDSEC_USR_DIR} || echo ""
     rm -rf ${CROWDSEC_USR_DIR} || echo ""