-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f6d912
commit 43fee94
Showing
3 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/doron-cohen/antidot/internal/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(updateCmd) | ||
} | ||
|
||
var rulesSource = "https://raw.githubusercontent.com/doron-cohen/antidot/master/rules.yaml" | ||
|
||
var updateCmd = &cobra.Command{ | ||
Use: "update", | ||
Short: "Update rules file", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
log.Printf("Updating rules...") | ||
err := utils.Download(rulesSource, rulesFilePath) | ||
if err != nil { | ||
log.Fatalf("Failed to update rules: %v", err) | ||
} | ||
|
||
log.Printf("Rules updated") | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package utils | ||
|
||
import ( | ||
"io" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
func Download(src, dest string) error { | ||
resp, err := http.Get(src) | ||
if err != nil { | ||
return err | ||
} | ||
// TODO: check for close() errors (across the code) | ||
defer resp.Body.Close() | ||
|
||
tempFile, err := ioutil.TempFile("", "rules.*.yaml") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer os.Remove(tempFile.Name()) | ||
|
||
_, err = io.Copy(tempFile, resp.Body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = MoveFile(tempFile.Name(), dest) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters