Refactor mirror feature
This commit is contained in:
parent
b9e944a8a6
commit
b3146354d4
14 changed files with 178 additions and 128 deletions
|
|
@ -18,6 +18,7 @@ package parser
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
|
@ -152,3 +153,22 @@ func AnnotationsReferencesConfigmap(ing *networking.Ingress) bool {
|
|||
|
||||
return false
|
||||
}
|
||||
|
||||
// StringToURL parses the provided string into URL and returns error
|
||||
// message in case of failure
|
||||
func StringToURL(input string) (*url.URL, error) {
|
||||
parsedURL, err := url.Parse(input)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%v is not a valid URL: %v", input, err)
|
||||
}
|
||||
|
||||
if parsedURL.Scheme == "" {
|
||||
return nil, fmt.Errorf("url scheme is empty")
|
||||
} else if parsedURL.Host == "" {
|
||||
return nil, fmt.Errorf("url host is empty")
|
||||
} else if strings.Contains(parsedURL.Host, "..") {
|
||||
return nil, fmt.Errorf("invalid url host")
|
||||
}
|
||||
|
||||
return parsedURL, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue