Browse Source

add data folder parameter to hubMgmt

AlteredCoder 5 năm trước cách đây
mục cha
commit
1b54bbb909

+ 1 - 1
cmd/crowdsec-cli/backup-restore.go

@@ -24,7 +24,7 @@ func silenceInstallItem(name string, obtype string) (string, error) {
 			if download_only && it.Downloaded && it.UpToDate {
 			if download_only && it.Downloaded && it.UpToDate {
 				return fmt.Sprintf("%s is already downloaded and up-to-date", it.Name), nil
 				return fmt.Sprintf("%s is already downloaded and up-to-date", it.Name), nil
 			}
 			}
-			it, err := cwhub.DownloadLatest(it, cwhub.Hubdir, force_install)
+			it, err := cwhub.DownloadLatest(it, cwhub.Hubdir, force_install, config.DataFolder)
 			if err != nil {
 			if err != nil {
 				return "", fmt.Errorf("error while downloading %s : %v", it.Name, err)
 				return "", fmt.Errorf("error while downloading %s : %v", it.Name, err)
 			}
 			}

+ 1 - 1
cmd/crowdsec-cli/install.go

@@ -19,7 +19,7 @@ func InstallItem(name string, obtype string) {
 				log.Warningf("%s is already downloaded and up-to-date", it.Name)
 				log.Warningf("%s is already downloaded and up-to-date", it.Name)
 				return
 				return
 			}
 			}
-			it, err := cwhub.DownloadLatest(it, cwhub.Hubdir, force_install)
+			it, err := cwhub.DownloadLatest(it, cwhub.Hubdir, force_install, config.DataFolder)
 			if err != nil {
 			if err != nil {
 				log.Fatalf("error while downloading %s : %v", it.Name, err)
 				log.Fatalf("error while downloading %s : %v", it.Name, err)
 			}
 			}

+ 1 - 1
cmd/crowdsec-cli/upgrade.go

@@ -35,7 +35,7 @@ func UpgradeConfig(ttype string, name string) {
 			log.Infof("%s : up-to-date", v.Name)
 			log.Infof("%s : up-to-date", v.Name)
 			continue
 			continue
 		}
 		}
-		v, err = cwhub.DownloadLatest(v, cwhub.Hubdir, force_upgrade)
+		v, err = cwhub.DownloadLatest(v, cwhub.Hubdir, force_upgrade, config.DataFolder)
 		if err != nil {
 		if err != nil {
 			log.Fatalf("%s : download failed : %v", v.Name, err)
 			log.Fatalf("%s : download failed : %v", v.Name, err)
 		}
 		}

+ 6 - 6
pkg/cwhub/hubMgmt.go

@@ -613,7 +613,7 @@ func EnableItem(target Item, tdir string, hdir string) (Item, error) {
 	return target, nil
 	return target, nil
 }
 }
 
 
-func DownloadLatest(target Item, tdir string, overwrite bool) (Item, error) {
+func DownloadLatest(target Item, tdir string, overwrite bool, dataFolder string) (Item, error) {
 	var err error
 	var err error
 	log.Debugf("Downloading %s %s", target.Type, target.Name)
 	log.Debugf("Downloading %s %s", target.Type, target.Name)
 	if target.Type == COLLECTIONS {
 	if target.Type == COLLECTIONS {
@@ -626,13 +626,13 @@ func DownloadLatest(target Item, tdir string, overwrite bool) (Item, error) {
 					//recurse as it's a collection
 					//recurse as it's a collection
 					if ptrtype == COLLECTIONS {
 					if ptrtype == COLLECTIONS {
 						log.Debugf("collection, recurse")
 						log.Debugf("collection, recurse")
-						HubIdx[ptrtype][p], err = DownloadLatest(val, tdir, overwrite)
+						HubIdx[ptrtype][p], err = DownloadLatest(val, tdir, overwrite, dataFolder)
 						if err != nil {
 						if err != nil {
 							log.Errorf("Encountered error while downloading sub-item %s %s : %s.", ptrtype, p, err)
 							log.Errorf("Encountered error while downloading sub-item %s %s : %s.", ptrtype, p, err)
 							return target, fmt.Errorf("encountered error while downloading %s for %s, abort", val.Name, target.Name)
 							return target, fmt.Errorf("encountered error while downloading %s for %s, abort", val.Name, target.Name)
 						}
 						}
 					}
 					}
-					HubIdx[ptrtype][p], err = DownloadItem(val, tdir, overwrite)
+					HubIdx[ptrtype][p], err = DownloadItem(val, tdir, overwrite, dataFolder)
 					if err != nil {
 					if err != nil {
 						log.Errorf("Encountered error while downloading sub-item %s %s : %s.", ptrtype, p, err)
 						log.Errorf("Encountered error while downloading sub-item %s %s : %s.", ptrtype, p, err)
 						return target, fmt.Errorf("encountered error while downloading %s for %s, abort", val.Name, target.Name)
 						return target, fmt.Errorf("encountered error while downloading %s for %s, abort", val.Name, target.Name)
@@ -643,17 +643,17 @@ func DownloadLatest(target Item, tdir string, overwrite bool) (Item, error) {
 				}
 				}
 			}
 			}
 		}
 		}
-		target, err = DownloadItem(target, tdir, overwrite)
+		target, err = DownloadItem(target, tdir, overwrite, dataFolder)
 		if err != nil {
 		if err != nil {
 			return target, fmt.Errorf("failed to download item : %s", err)
 			return target, fmt.Errorf("failed to download item : %s", err)
 		}
 		}
 	} else {
 	} else {
-		return DownloadItem(target, tdir, overwrite)
+		return DownloadItem(target, tdir, overwrite, dataFolder)
 	}
 	}
 	return target, nil
 	return target, nil
 }
 }
 
 
-func DownloadItem(target Item, tdir string, overwrite bool) (Item, error) {
+func DownloadItem(target Item, tdir string, overwrite bool, dataFolder string) (Item, error) {
 
 
 	/*if user didn't --force, don't overwrite local, tainted, up-to-date files*/
 	/*if user didn't --force, don't overwrite local, tainted, up-to-date files*/
 	if !overwrite {
 	if !overwrite {