MCPcopy Create free account
hub / github.com/AdRoll/baker / choosePathComponents

Method choosePathComponents

input/inpututils/s3.go:135–168  ·  view source on GitHub ↗

If the path is a full s3/s3a/s3n url the extract the bucket, key and scheme from it and return them, else use the bucket from the instance, path as key and default scheme "s3"

(path string)

Source from the content-addressed store, hash-verified

133// it and return them, else use the bucket from the instance, path as key and
134// default scheme "s3"
135func (s *S3Input) choosePathComponents(path string) (scheme, bucket, key string, err error) {
136 s3Url, err := url.Parse(path)
137 scheme = ""
138 bucket = ""
139 key = ""
140 // If the path is url compliant and its scheme is s3 or none and there is a
141 // path (downloading a whole bucket is not supported/safe) we can proceed
142 // to assign the bucket and path
143 if err != nil {
144 return "", "", "", err
145 }
146
147 validScheme, err := isValidScheme(s3Url.Scheme)
148 if err != nil {
149 return "", "", "", err
150 }
151
152 if s3Url.Path == "" || (s3Url.Scheme != "" && !validScheme) {
153 return "", "", "", errUnsupportedURLScheme(path)
154 }
155
156 scheme = ""
157 bucket = s.Bucket
158 key = path
159
160 if validScheme {
161 // The bucket is the "host" portion of the s3 url and the key is
162 // the "path"
163 scheme = s3Url.Scheme
164 bucket = s3Url.Host
165 key = s3Url.Path[1:]
166 }
167 return scheme, bucket, key, nil
168}

Callers 5

ProcessDirectoryMethod · 0.95
openS3FileMethod · 0.95
sizeS3FileMethod · 0.95

Calls 3

isValidSchemeFunction · 0.85
errUnsupportedURLSchemeTypeAlias · 0.85
ParseMethod · 0.65