Skip to content

Commit

Permalink
fix import not ignoring url path
Browse files Browse the repository at this point in the history
fix containers#3609
Podman import used to check filename to only allow tarball path as a file. It should also allow an url as the doc mentioned. This PR allows the program to continue if the input is a valid URL

Signed-off-by: Qi Wang <qiwan@redhat.com>
  • Loading branch information
QiWang19 committed Jul 23, 2019
1 parent 7dbc6d8 commit 915ef8a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/podman/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ func importCmd(c *cliconfig.ImportValues) error {
return errors.Errorf("too many arguments. Usage TARBALL [REFERENCE]")
}

if err := parse.ValidateFileName(source); err != nil {
return err
errFileName := parse.ValidateFileName(source)
errURL := parse.ValidURL(source)

if errFileName != nil && errURL != nil {
return errors.Errorf("%q, %q invalid tarball path", errFileName, errURL)
}

quiet := c.Quiet
Expand Down
10 changes: 10 additions & 0 deletions cmd/podman/shared/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bufio"
"fmt"
"net"
"net/url"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -162,3 +163,12 @@ func ValidateFileName(filename string) error {
}
return nil
}

// ValidURL checks a string urlStr is a url or not
func ValidURL(urlStr string) error {
_, err := url.ParseRequestURI(urlStr)
if err != nil {
return errors.Wrapf(err, "invalid url path: %q", urlStr)
}
return nil
}

0 comments on commit 915ef8a

Please sign in to comment.