Skip to content

Commit

Permalink
fix: corrected upload logic
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-cardenas-coding committed Oct 16, 2020
1 parent c100f3b commit 138dbd9
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 84 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Expand Up @@ -187,10 +187,10 @@ jobs:
steps:
-
id: go
name: "Set up Go 1.14"
name: "Set up Go version"
uses: actions/setup-go@v1
with:
go-version: 1.14
go-version: 1.15
-
name: "Check out code into the Go module directory"
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -12,7 +12,7 @@ A Golang based CLI tool for determining natural catastrophe near you, or a locat


## Installation
Disaster-CLI is distributed as a single binary. [Download](https://github.com/karl-cardenas-coding/disaster-cli/releases) the binary and install Disaster-CLI by unzipping it and moving it to a directory included in your system's [PATH](https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them).
Disaster-CLI is distributed as a single binary. [Download](https://github.com/karl-cardenas-coding/disaster-cli/releases) the binary and install Disaster-CLI by unzipping it and moving it to a directory included in your system's [PATH](https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them). `~/bin` is the recommended path for UNIX/LINUX environments.


## Usage
Expand Down
2 changes: 1 addition & 1 deletion cmd/categories.go
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/jedib0t/go-pretty/table"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/karl-cardenas-coding/disaster-cli/library"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down
2 changes: 1 addition & 1 deletion cmd/events.go
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/jedib0t/go-pretty/table"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/karl-cardenas-coding/disaster-cli/library"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down
26 changes: 13 additions & 13 deletions cmd/update.go
Expand Up @@ -292,7 +292,7 @@ func DownloadFile(filePath string, url string) error {
"function": "os.Create",
"error": err,
"data": fmt.Sprint((tmpDir + pathOSeperator + "download.tmp")),
}).Error("Error creating temp directory.", ISSUE_MSG)
}).Error("Error creating temp directory.\n\n", ISSUE_MSG)
return err
}

Expand All @@ -304,7 +304,7 @@ func DownloadFile(filePath string, url string) error {
"function": "os.Chmod",
"error": err,
"data": fmt.Sprint((tmpDir + pathOSeperator + "download.tmp")),
}).Error("Error changing permissions.", ISSUE_MSG)
}).Error("Error changing permissions.\n\n", ISSUE_MSG)
return err
}

Expand All @@ -318,7 +318,7 @@ func DownloadFile(filePath string, url string) error {
"function": "http.Get",
"error": err,
"data": fmt.Sprint(url),
}).Error("Error creating downlaod counter", ISSUE_MSG)
}).Error("Error creating the download counter\n\n", ISSUE_MSG)
out.Close()
return err
}
Expand All @@ -334,7 +334,7 @@ func DownloadFile(filePath string, url string) error {
"function": "io.Copy",
"error": err,
"data": fmt.Sprint(out, io.TeeReader(resp.Body, counter)),
}).Error("Error creating downlaod counter", ISSUE_MSG)
}).Error("Error creating the download counter.\n\n", ISSUE_MSG)
out.Close()
return err
}
Expand All @@ -354,7 +354,7 @@ func DownloadFile(filePath string, url string) error {
"function": "os.Rename",
"error": err,
"data": fmt.Sprint(tmpDir+pathOSeperator+"download.tmp", filePath),
}).Fatal("Error when renaming the zipfile.", ISSUE_MSG)
}).Fatal("Error when renaming the zipfile.\n\n", ISSUE_MSG)
return err
}

Expand All @@ -368,7 +368,7 @@ func DownloadFile(filePath string, url string) error {
"function": "zip.OpenReader",
"error": err,
"data": "disaster.tmp",
}).Fatal("Error when attempting to open up the Zip file.", ISSUE_MSG)
}).Fatal("Error when attempting to open up the Zip file.\n\n", ISSUE_MSG)
return err

}
Expand All @@ -383,7 +383,7 @@ func DownloadFile(filePath string, url string) error {
"function": "os.Create",
"error": err,
"data": "disaster.tmp",
}).Fatal("Error when attempting to create a new file.", ISSUE_MSG)
}).Fatal("Error when attempting to create a new file.\n\n", ISSUE_MSG)
return err

}
Expand All @@ -396,7 +396,7 @@ func DownloadFile(filePath string, url string) error {
"function": "os.Chmod",
"error": err,
"data": "disaster.tmp",
}).Error("Error changing permissions.", ISSUE_MSG)
}).Error("Error changing permissions.\n\n", ISSUE_MSG)
return err
}

Expand All @@ -413,7 +413,7 @@ func DownloadFile(filePath string, url string) error {
"function": "f.Open",
"error": err,
"data": nil,
}).Fatal("Error when attempting to open the file inside the zipped asset:", ISSUE_MSG)
}).Fatal("Error when attempting to open the file inside the zipped asset: \n\n", ISSUE_MSG)
return err

}
Expand Down Expand Up @@ -442,7 +442,7 @@ func DownloadFile(filePath string, url string) error {
"function": "strings.HasPrefix",
"error": err,
"data": fmt.Sprint(destpath, filepath.Clean(currentDir)+string(os.PathSeparator)),
}).Fatal("illegal file path detected inside the zip file content.\nTerminating operation as it may contain zip-slip vulnerability!\nVisit https://snyk.io/research/zip-slip-vulnerability to learn more.", ISSUE_MSG)
}).Fatal("illegal file path detected inside the zip file content.\nTerminating operation as it may contain zip-slip vulnerability!\n\n. Visit https://snyk.io/research/zip-slip-vulnerability to learn more.\n\n", ISSUE_MSG)
}

// Copy all content from binary to a new file.
Expand Down Expand Up @@ -484,7 +484,7 @@ func DownloadFile(filePath string, url string) error {
binDir := getSystemPathForDisaster()

// Move existing binary to the temp directory

fmt.Println("New file pre-move: ", os.TempDir()+pathOSeperator+"old-disaster")
if err := os.Rename(binDir, os.TempDir()+pathOSeperator+"old-disaster"); err != nil {
log.WithFields(log.Fields{
"package": "cmd",
Expand All @@ -493,7 +493,7 @@ func DownloadFile(filePath string, url string) error {
"function": "os.Rename",
"error": err,
"data": fmt.Sprint(binDir, os.TempDir()+pathOSeperator+"old-disaster"),
}).Fatal("Error when attempting to move the original binary", ISSUE_MSG)
}).Fatal("Error when attempting to move the original binary. Try using elevated permissions (sudo).\n\n", ISSUE_MSG)
return err
}

Expand All @@ -512,7 +512,7 @@ func DownloadFile(filePath string, url string) error {
return err
}
} else {
err := os.Rename("disaster.tmp", "disaster")
err := os.Rename("disaster.tmp", binDir)
if err != nil {
log.WithFields(log.Fields{
"package": "cmd",
Expand Down
Binary file removed disaster
Binary file not shown.
6 changes: 2 additions & 4 deletions go.mod
Expand Up @@ -4,10 +4,8 @@ go 1.15

require (
github.com/dustin/go-humanize v1.0.0
github.com/go-openapi/strfmt v0.19.5 // indirect
github.com/jedib0t/go-pretty v4.3.0+incompatible
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/jedib0t/go-pretty/v6 v6.0.5
github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v1.1.0
golang.org/x/sys v0.0.0-20200821140526-fda516888d29 // indirect
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 // indirect
)

0 comments on commit 138dbd9

Please sign in to comment.