Пример #1
0
// checkSourceURI performs a check on the URI associated with the build
// to make sure that it is valid.  It also optionally tests the connection
// to the source uri.
func checkSourceURI(git git.Git, rawurl string, testConnection bool, timeout time.Duration) error {
	if !git.ValidCloneSpec(rawurl) {
		return fmt.Errorf("Invalid git source url: %s", rawurl)
	}
	if strings.HasPrefix(rawurl, "git@") || strings.HasPrefix(rawurl, "git://") {
		return nil
	}
	srcURL, err := url.Parse(rawurl)
	if err != nil {
		return err
	}
	if !testConnection {
		return nil
	}
	host := srcURL.Host
	if strings.Index(host, ":") == -1 {
		switch srcURL.Scheme {
		case "http":
			host += ":80"
		case "https":
			host += ":443"
		}
	}
	dialer := net.Dialer{Timeout: timeout}
	conn, err := dialer.Dial("tcp", host)
	if err != nil {
		return err
	}
	return conn.Close()
}
Пример #2
0
// checkSourceURI performs a check on the URI associated with the build
// to make sure that it is valid.  It also optionally tests the connection
// to the source uri.
func checkSourceURI(git git.Git, rawurl string, timeout time.Duration) error {
	if !git.ValidCloneSpec(rawurl) {
		return fmt.Errorf("Invalid git source url: %s", rawurl)
	}
	return checkRemoteGit(rawurl, timeout)
}