Skip to content

Commit

Permalink
Merge pull request #234 from fahlmant/sl-url-fix
Browse files Browse the repository at this point in the history
Fix URL usage for servicelog post templates
  • Loading branch information
openshift-merge-robot authored Jul 28, 2022
2 parents 44869c3 + f818c32 commit 298985f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cmd/servicelog/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ func confirmSend() error {

// accessFile returns the contents of a local file or url, and any errors encountered
func accessFile(filePath string) ([]byte, error) {

if utils.IsValidUrl(filePath) {
urlPage, _ := url.Parse(filePath)
if err := utils.IsOnline(*urlPage); err != nil {
return nil, fmt.Errorf("host %q is not accessible", filePath)
}
return utils.CurlThis(urlPage.String())
}

filePath = filepath.Clean(filePath)
if utils.FileExists(filePath) {
// template is file on the disk
Expand All @@ -239,14 +248,6 @@ func accessFile(filePath string) ([]byte, error) {
if utils.FolderExists(filePath) {
return nil, fmt.Errorf("the provided path %q is a directory, not a file", filePath)
}
if utils.IsValidUrl(filePath) {
urlPage, _ := url.Parse(filePath)
if err := utils.IsOnline(*urlPage); err != nil {
return nil, fmt.Errorf("host %q is not accessible", filePath)
} else {
return utils.CurlThis(urlPage.String())
}
}
return nil, fmt.Errorf("cannot read the file %q", filePath)
}

Expand Down

0 comments on commit 298985f

Please sign in to comment.