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

Method processURL

filter/external_match.go:175–225  ·  view source on GitHub ↗
(u string)

Source from the content-addressed store, hash-verified

173}
174
175func (f *ExternalMatch) processURL(u string) (map[string]struct{}, error) {
176 parsed, err := url.Parse(u)
177 if err != nil {
178 return nil, fmt.Errorf("error parsing URL: %v", err)
179 }
180
181 var r io.Reader
182
183 log.WithField("url", u).Info("begin parsing file")
184 switch parsed.Scheme {
185 case "s3":
186 sess, err := session.NewSession(&aws.Config{Region: aws.String(f.cfg.Region)})
187 if err != nil {
188 return nil, fmt.Errorf("error creating aws session: %v", err)
189 }
190 resp, err := s3.New(sess).GetObject(&s3.GetObjectInput{
191 Bucket: aws.String(parsed.Host),
192 Key: aws.String(parsed.Path),
193 })
194 if err != nil {
195 return nil, fmt.Errorf("error downloading file: %v", err)
196 }
197
198 defer resp.Body.Close()
199 r = resp.Body
200
201 case "file":
202 path := filepath.Join(parsed.Host, parsed.Path) // On Windows Host contains the drive letter.
203 f, err := os.Open(path)
204 if err != nil {
205 return nil, fmt.Errorf("error opening file: %v", err)
206 }
207
208 defer f.Close()
209 r = f
210
211 default:
212 // scheme error should be caught during the validation of configuration.
213 panic("unexpected scheme")
214 }
215
216 // Wrap the reader into a zt reader to transparently read gzip,
217 // zstd or non compressed CSV data.
218 zar, err := zt.NewReader(r)
219 if err != nil {
220 return nil, fmt.Errorf("can't read from %s: %s", u, err)
221 }
222 defer zar.Close()
223
224 return valuesFromCSV(zar, f.cfg.CSVColumn)
225}
226
227func (f *ExternalMatch) updateValues() error {
228 values := make(map[string]struct{})

Callers 1

updateValuesMethod · 0.95

Calls 5

valuesFromCSVFunction · 0.85
GetObjectMethod · 0.80
ParseMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected