MCPcopy
hub / github.com/NVIDIA/aistore / parseSource

Function parseSource

cmd/cli/commands/utils.go:1041–1113  ·  view source on GitHub ↗

Replace protocol (gs://, s3://, az://) with proper GCP/AWS/Azure URL

(rawURL string)

Source from the content-addressed store, hash-verified

1039
1040// Replace protocol (gs://, s3://, az://) with proper GCP/AWS/Azure URL
1041func parseSource(rawURL string) (source dlSource, err error) {
1042 u, err := url.Parse(rawURL)
1043 if err != nil {
1044 return
1045 }
1046
1047 var (
1048 cloudSource dlSourceBackend
1049 scheme = u.Scheme
1050 host = u.Host
1051 fullPath = u.Path
1052 )
1053
1054 // If `rawURL` is using `gs` or `s3` scheme ({gs/s3}://<bucket>/...)
1055 // then <bucket> is considered a `Host` by `url.Parse`.
1056 switch u.Scheme {
1057 case apc.GSScheme, apc.ProviderGoogle:
1058 cloudSource = dlSourceBackend{
1059 bck: cmn.Bck{Name: host, Provider: apc.ProviderGoogle},
1060 prefix: strings.TrimPrefix(fullPath, "/"),
1061 }
1062
1063 scheme = "https"
1064 host = gsHost
1065 fullPath = path.Join(u.Host, fullPath)
1066 case apc.S3Scheme, apc.ProviderAmazon:
1067 cloudSource = dlSourceBackend{
1068 bck: cmn.Bck{Name: host, Provider: apc.ProviderAmazon},
1069 prefix: strings.TrimPrefix(fullPath, "/"),
1070 }
1071
1072 scheme = "http"
1073 host = s3Host
1074 fullPath = path.Join(u.Host, fullPath)
1075 case apc.AZScheme, apc.ProviderAzure:
1076 // NOTE: We don't set the link here because there is no way to translate
1077 // `az://bucket/object` into Azure link without account name.
1078 return dlSource{
1079 link: "",
1080 backend: dlSourceBackend{
1081 bck: cmn.Bck{Name: host, Provider: apc.ProviderAzure},
1082 prefix: strings.TrimPrefix(fullPath, "/"),
1083 },
1084 }, nil
1085 case apc.AISScheme:
1086 // TODO: add support for the remote cluster
1087 scheme = "http" // TODO: How about `https://`?
1088 if !strings.Contains(host, ":") {
1089 host += ":8080" // TODO: What if host is listening on `:80` so we don't need port?
1090 }
1091 fullPath = path.Join(apc.Version, apc.Objects, fullPath)
1092 case "":
1093 scheme = apc.DefaultScheme
1094 case "https", "http":
1095 default:
1096 err = fmt.Errorf("invalid scheme: %s", scheme)
1097 return
1098 }

Callers 2

TestParseSourceValidURIsFunction · 0.85
startDownloadHandlerFunction · 0.85

Calls 4

ParseMethod · 0.80
JoinMethod · 0.80
StringMethod · 0.65
ContainsMethod · 0.45

Tested by 1

TestParseSourceValidURIsFunction · 0.68