MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / DownloadUrlFromRepos

Function DownloadUrlFromRepos

opensca/common/repo.go:28–72  ·  view source on GitHub ↗
(route string, do func(repo RepoConfig, r io.Reader), repos ...RepoConfig)

Source from the content-addressed store, hash-verified

26}
27
28func DownloadUrlFromRepos(route string, do func(repo RepoConfig, r io.Reader), repos ...RepoConfig) bool {
29
30 repoSet := map[string]bool{}
31
32 for _, repo := range repos {
33
34 if repo.Url == "" {
35 continue
36 }
37 if repoSet[repo.Url] {
38 continue
39 }
40 repoSet[repo.Url] = true
41
42 url := fmt.Sprintf("%s/%s", strings.TrimRight(repo.Url, "/"), strings.TrimLeft(route, "/"))
43 req, err := http.NewRequest("GET", url, nil)
44 if err != nil {
45 logs.Warn(err)
46 return false
47 }
48
49 if repo.Username+repo.Password != "" {
50 req.SetBasicAuth(repo.Username, repo.Password)
51 }
52
53 resp, err := HttpDownloadClient.Do(req)
54 if err != nil {
55 logs.Warn(err)
56 continue
57 }
58
59 if resp.StatusCode != 200 {
60 logs.Warnf("%d %s", resp.StatusCode, url)
61 io.Copy(io.Discard, resp.Body)
62 resp.Body.Close()
63 } else {
64 logs.Debugf("%d %s", resp.StatusCode, url)
65 do(repo, resp.Body)
66 resp.Body.Close()
67 return true
68 }
69
70 }
71 return false
72}

Callers 5

initFunction · 0.92
initFunction · 0.92
composer.goFile · 0.92
npm.goFile · 0.92
DownloadPomFromRepoFunction · 0.92

Calls 5

WarnFunction · 0.92
WarnfFunction · 0.92
DebugfFunction · 0.92
CopyMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected