Skip to content

Commit

Permalink
fix endpoint parsing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed Jan 30, 2025
1 parent ef3027f commit 41d4b3e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
33 changes: 24 additions & 9 deletions commons/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,25 +529,40 @@ func (config *Config) FromIRODSUrl(inputURL string) error {
return nil
}

func parseRawURL(rawurl string) (string, string, string, error) {
u, err := url.ParseRequestURI(rawurl)
if err != nil || u.Host == "" {
// try adding //
u, repErr := url.ParseRequestURI("tcp://" + rawurl)
if repErr != nil {
return "", "", "", xerrors.Errorf("could not parse raw url: %s, error: %w", rawurl, err)
}

return u.Scheme, u.Host, u.Path, nil
}

return u.Scheme, u.Host, u.Path, nil
}

// ParsePoolServiceEndpoint parses endpoint string
func ParsePoolServiceEndpoint(endpoint string) (string, string, error) {
u, err := url.Parse(endpoint)
scheme, host, localpath, err := parseRawURL(endpoint)
if err != nil {
return "", "", xerrors.Errorf("could not parse endpoint: %v", err)
return "", "", err
}

scheme := strings.ToLower(u.Scheme)
scheme = strings.ToLower(scheme)
switch scheme {
case "tcp":
return "tcp", u.Host, nil
return "tcp", host, nil
case "unix":
path := path.Join("/", u.Path)
return "unix", path, nil
localpath = path.Join("/", strings.TrimPrefix(localpath, "/"))
return "unix", localpath, nil
case "":
if len(u.Host) > 0 {
return "tcp", u.Host, nil
if len(host) > 0 {
return "tcp", host, nil
}
return "", "", xerrors.Errorf("unknown host: %q", u.Host)
return "", "", xerrors.Errorf("unknown host: %q", host)
default:
return "", "", xerrors.Errorf("unsupported protocol: %q", scheme)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/cyverse/go-irodsclient v0.15.8
github.com/cyverse/irodsfs-common v0.0.0-20250108164354-7520cee23f8a
github.com/cyverse/irodsfs-pool v0.8.3
github.com/cyverse/irodsfs-pool v0.8.5
github.com/hanwen/go-fuse/v2 v2.6.2
github.com/pkg/profile v1.7.0
github.com/rs/xid v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/cyverse/go-irodsclient v0.15.8 h1:ZiO5DDiyTL7+vfhqtNWtZWcHlWO+p6iieWT
github.com/cyverse/go-irodsclient v0.15.8/go.mod h1:NN+PxHfLDUmsqfqSY84JfmqXS4EYiuiNW6ti6oPGCgk=
github.com/cyverse/irodsfs-common v0.0.0-20250108164354-7520cee23f8a h1:Drpl2QtVyJErxh5euv9VGsSsE5G957ZIpXD+mbSp/4E=
github.com/cyverse/irodsfs-common v0.0.0-20250108164354-7520cee23f8a/go.mod h1:1KTDsQpja3ir/TQRGCx/rxzSWBCgrb7Y7J4VY8JAXN8=
github.com/cyverse/irodsfs-pool v0.8.3 h1:FaxsoeeAbfJRe76466t8/R+EbV9RTTzp5jylMPqKZks=
github.com/cyverse/irodsfs-pool v0.8.3/go.mod h1:NrREq8jZhTzwejX27ugpkSuR8wL1E1xMeS+XzeHg6ZA=
github.com/cyverse/irodsfs-pool v0.8.5 h1:j8Xnqh7M73tA14DDnqtqvUaZvzIMM3W+3jeBrwkCv/c=
github.com/cyverse/irodsfs-pool v0.8.5/go.mod h1:NrREq8jZhTzwejX27ugpkSuR8wL1E1xMeS+XzeHg6ZA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down

0 comments on commit 41d4b3e

Please sign in to comment.