in network/gitlab.go [1032:1094]
func (n *GitLabClient) DownloadArtifacts(
config common.JobCredentials,
artifactsFile io.WriteCloser,
directDownload *bool,
) common.DownloadState {
query := url.Values{}
if directDownload != nil {
query.Set("direct_download", strconv.FormatBool(*directDownload))
}
uri := fmt.Sprintf("jobs/%d/artifacts?%s", config.ID, query.Encode())
res, err := n.doRaw(
context.Background(),
&config,
http.MethodGet,
uri,
nil,
"",
JobTokenHeader(config.Token))
log := logrus.WithFields(logrus.Fields{
"id": config.ID,
"token": helpers.ShortenToken(config.Token),
})
if res != nil {
log = log.WithField("responseStatus", res.Status)
if res.Request != nil && res.Request.URL != nil {
log = log.WithField("host", res.Request.URL.Host)
}
}
if err != nil {
log.Errorln("Downloading artifacts from coordinator...", "error", err.Error())
return common.DownloadFailed
}
defer func() { n.handleResponse(context.TODO(), res, true) }()
switch res.StatusCode {
case http.StatusOK:
return n.downloadArtifactFile(log, artifactsFile, res)
case http.StatusForbidden:
// We generally expect JSON responses from the GitLab API, but a
// 302 redirection to object storage may result in an XML
// response that might include important details why the request
// was rejected (e.g. Google VPC Service Controls).
statusText := getMessageFromJSONOrXMLResponse(res)
log.WithField("status", statusText).Errorln("Downloading artifacts from coordinator...", "forbidden")
return common.DownloadForbidden
case http.StatusUnauthorized:
log.WithField("status", res.Status).Errorln("Downloading artifacts from coordinator...", "unauthorized")
return common.DownloadUnauthorized
case http.StatusNotFound:
log.Errorln("Downloading artifacts from coordinator...", "not found")
return common.DownloadNotFound
default:
log.WithField("status", res.Status).Warningln("Downloading artifacts from coordinator...", "failed")
return common.DownloadFailed
}
}