AlteredCoder 5 年之前
父节点
当前提交
907674f10c
共有 4 个文件被更改,包括 20 次插入11 次删除
  1. 12 5
      pkg/cwhub/hubMgmt.go
  2. 1 1
      pkg/cwhub/utils.go
  3. 1 1
      pkg/cwversion/version.go
  4. 6 4
      scripts/test_env.sh

+ 12 - 5
pkg/cwhub/hubMgmt.go

@@ -497,12 +497,14 @@ func LoadPkgIndex(buff []byte) (map[string]map[string]Item, error) {
 
 //DisableItem to disable an item managed by the hub, removes the symlink
 func DisableItem(target Item, tdir string, hdir string, purge bool) (Item, error) {
-	syml := tdir + "/" + target.Type + "/" + target.Stage + "/" + target.FileName
+	syml, err := filepath.Abs(tdir + "/" + target.Type + "/" + target.Stage + "/" + target.FileName)
+	if err != nil {
+		return Item{}, err
+	}
 	if target.Local {
 		return target, fmt.Errorf("%s isn't managed by hub. Please delete manually", target.Name)
 	}
 
-	var err error
 	/*for a COLLECTIONS, disable sub-items*/
 	if target.Type == COLLECTIONS {
 		var tmp = [][]string{target.Parsers, target.PostOverflows, target.Scenarios, target.Collections}
@@ -536,8 +538,12 @@ func DisableItem(target Item, tdir string, hdir string, purge bool) (Item, error
 		if err != nil {
 			return target, fmt.Errorf("unable to read symlink of %s (%s)", target.Name, syml)
 		}
-		if hubpath != filepath.Clean(hdir+"/"+target.RemotePath) {
-			log.Warningf("%s (%s) isn't a symlink to %s", target.Name, syml, filepath.Clean(hdir+"/"+target.RemotePath))
+		absPath, err := filepath.Abs(hdir + "/" + target.RemotePath)
+		if err != nil {
+			return target, err
+		}
+		if hubpath != absPath {
+			log.Warningf("%s (%s) isn't a symlink to %s", target.Name, syml, absPath)
 			return target, fmt.Errorf("%s isn't managed by hub", target.Name)
 		}
 
@@ -742,6 +748,7 @@ func DownloadItem(target Item, tdir string, overwrite bool, dataFolder string) (
 	target.Tainted = false
 	target.UpToDate = true
 
+	log.Infof("Installing : %+v \n", string(body))
 	dec := yaml.NewDecoder(bytes.NewReader(body))
 	for {
 		data := &dataSet{}
@@ -753,7 +760,7 @@ func DownloadItem(target Item, tdir string, overwrite bool, dataFolder string) (
 				return target, fmt.Errorf("unable to read file %s data: %s", tdir+"/"+target.RemotePath, err)
 			}
 		}
-		err = getData(data.data, dataFolder)
+		err = getData(data.Data, dataFolder)
 		if err != nil {
 			return target, fmt.Errorf("unable to get data: %s", err)
 		}

+ 1 - 1
pkg/cwhub/utils.go

@@ -16,7 +16,7 @@ type dataSource struct {
 }
 
 type dataSet struct {
-	data []*dataSource `yaml:"data",omitempty`
+	Data []*dataSource `yaml:"data",omitempty`
 }
 
 func downloadFile(url string, destPath string) error {

+ 1 - 1
pkg/cwversion/version.go

@@ -26,7 +26,7 @@ var (
 	Tag                 string // = "dev"
 	GoVersion           string // = "1.13"
 	Constraint_parser   = ">= 1.0, < 2.0"
-	Constraint_scenario = ">= 1.0, < 2.0"
+	Constraint_scenario = ">= 1.0, < 3.0"
 	Constraint_api      = "v1"
 	Constraint_acquis   = ">= 1.0, < 2.0"
 )

+ 6 - 4
scripts/test_env.sh

@@ -30,6 +30,7 @@ DATA_DIR="$BASE/data"
 LOG_DIR="$BASE/logs/"
 
 CONFIG_DIR="$BASE/config"
+CONFIG_FILE="$BASE/dev.yaml"
 CSCLI_DIR="$CONFIG_DIR/crowdsec-cli"
 PARSER_DIR="$CONFIG_DIR/parsers"
 PARSER_S00="$PARSER_DIR/s00-raw"
@@ -81,10 +82,8 @@ copy_files() {
 
 
 setup() {
-	$BASE/cscli -c "$CSCLI_DIR" config installdir "$CONFIG_DIR"
-	$BASE/cscli -c "$CSCLI_DIR" config backend "$PLUGIN_BACKEND_DIR"
-	$BASE/cscli -c "$CSCLI_DIR" update
-	$BASE/cscli -c "$CSCLI_DIR" install collection crowdsecurity/linux
+	$BASE/cscli -c "$CONFIG_FILE" update
+	$BASE/cscli -c "$CONFIG_FILE" install collection crowdsecurity/linux
 }
 
 
@@ -96,7 +95,10 @@ main() {
 	copy_files
 	log_info "Files copied"
 	log_info "Setting up configurations"
+	CURRENT_PWD=$(pwd)
+	cd $BASE
 	setup
+	cd $CURRENT_PWD
 	gen_sqlite_config
 	log_info "Environment is ready in $BASE"
 }