Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve JFrog platform get version error logs #842

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions artifactory/services/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ func (ss *SystemService) GetVersion() (string, error) {
return "", err
}
var version artifactoryVersion
err = json.Unmarshal(body, &version)
if err != nil {
return "", errorutils.CheckErrorf("couldn't parse Artifactory server response: " + err.Error())
if err = json.Unmarshal(body, &version); err != nil {
return "", errorutils.CheckErrorf("couldn't parse JFrog Artifactory server version response: " + err.Error())
}
return strings.TrimSpace(version.Version), nil
}
Expand Down Expand Up @@ -123,7 +122,7 @@ func (ss *SystemService) sendGet(endpoint string) ([]byte, error) {
return nil, err
}
if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK, http.StatusCreated); err != nil {
return nil, fmt.Errorf("failed while attempting to get Artifactory %s:\n%s", endpoint, err.Error())
return nil, fmt.Errorf("got unexpected server response while attempting to get JFrog Artifactory %s:\n%s", endpoint, err.Error())
}
log.Debug("Artifactory response:", resp.Status)
return body, nil
Expand Down
9 changes: 4 additions & 5 deletions distribution/services/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ func (vs *VersionService) GetDistributionVersion() (string, error) {
httpDetails := vs.DistDetails.CreateHttpClientDetails()
resp, body, _, err := vs.client.SendGet(vs.DistDetails.GetUrl()+"api/v1/system/info", true, &httpDetails)
if err != nil {
return "", err
return "", errors.New("failed while attempting to get JFrog Distribution version: " + err.Error())
}

if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK); err != nil {
return "", errors.New("failed while attempting to get Distribution version:\n" + err.Error())
return "", errors.New("got unexpected server response while attempting to get JFrog Distribution version:\n" + err.Error())
}
var version distributionVersion
err = json.Unmarshal(body, &version)
if err != nil {
return "", errorutils.CheckErrorf("couldn't parse Distribution server response: " + err.Error())
if err = json.Unmarshal(body, &version); err != nil {
return "", errorutils.CheckErrorf("couldn't parse JFrog Distribution server version version response: " + err.Error())
}
return strings.TrimSpace(version.Version), nil
}
Expand Down
3 changes: 2 additions & 1 deletion http/httpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ func (jc *HttpClient) Send(method, url string, content []byte, followRedirect, c
LogMsgPrefix: logMsgPrefix,
ErrorMessage: fmt.Sprintf("Failure occurred while sending %s request to %s", method, url),
ExecutionHandler: func() (bool, error) {
req, err := jc.createReq(method, url, content)
var req *http.Request
sverdlov93 marked this conversation as resolved.
Show resolved Hide resolved
req, err = jc.createReq(method, url, content)
if err != nil {
return true, err
}
Expand Down
9 changes: 4 additions & 5 deletions pipelines/services/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@ func (ss *SystemService) GetSystemInfo() (*PipelinesSystemInfo, error) {
httpDetails := ss.ServiceDetails.CreateHttpClientDetails()
resp, body, _, err := ss.client.SendGet(ss.ServiceDetails.GetUrl()+"api/v1/system/info", true, &httpDetails)
if err != nil {
return nil, err
return nil, errors.New("failed while attempting to get JFrog Pipelines version: " + err.Error())
}
if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK); err != nil {
if resp.StatusCode == http.StatusNotFound {
return nil, &PipelinesNotAvailableError{InnerError: err}
}
return nil, errors.New("failed while attempting to get Pipelines version:\n" + err.Error())
return nil, errors.New("got unexpected server response while attempting to get JFrog Pipelines version:\n" + err.Error())
}
var sysInfo PipelinesSystemInfo
err = json.Unmarshal(body, &sysInfo)
if err != nil {
return nil, errorutils.CheckErrorf("couldn't parse Pipelines server response: " + err.Error())
if err = json.Unmarshal(body, &sysInfo); err != nil {
return nil, errorutils.CheckErrorf("couldn't parse JFrog Pipelines server response: " + err.Error())
}
return &sysInfo, nil
}
Expand Down
11 changes: 8 additions & 3 deletions xray/services/entitlements.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package services

import (
"encoding/json"
"errors"
"fmt"
"net/http"

Expand Down Expand Up @@ -30,16 +31,20 @@ func (es *EntitlementsService) IsEntitled(featureId string) (entitled bool, err
httpDetails := es.XrayDetails.CreateHttpClientDetails()
resp, body, _, err := es.client.SendGet(es.XrayDetails.GetUrl()+"api/v1/entitlements/feature/"+featureId, true, &httpDetails)
if err != nil {
err = errors.New("failed while attempting to get JFrog Xray entitlements response: " + err.Error())
return
}
if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK); err != nil {
return false, fmt.Errorf("failed while attempting to get Xray entitlements response for %s:\n%s", featureId, err.Error())
err = fmt.Errorf("got unexpected server response while attempting to get JFrog Xray entitlements response for %s:\n%s", featureId, err.Error())
return
}
var userEntitlements entitlements
if err = json.Unmarshal(body, &userEntitlements); err != nil {
return false, errorutils.CheckErrorf("couldn't parse Xray server response: " + err.Error())
err = errorutils.CheckErrorf("couldn't parse JFrog Xray server entitlements response: " + err.Error())
return
}
return userEntitlements.Entitled, nil
entitled = userEntitlements.Entitled
return
}

type entitlements struct {
Expand Down
4 changes: 2 additions & 2 deletions xray/services/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (ss *ScanService) IsXscEnabled() (xsxVersion string, err error) {
url = ss.xrayToXscUrl()
resp, body, _, err := ss.client.SendGet(url+XscVersionAPI, false, &httpClientsDetails)
if err != nil {
err = errorutils.CheckErrorf("failed to get XSC version, response: " + err.Error())
err = errorutils.CheckErrorf("failed to get JFrog XSC version, response: " + err.Error())
return
}
if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK, http.StatusNotFound); err != nil {
Expand All @@ -257,7 +257,7 @@ func (ss *ScanService) IsXscEnabled() (xsxVersion string, err error) {
}
versionResponse := XscVersionResponse{}
if err = json.Unmarshal(body, &versionResponse); err != nil {
err = errorutils.CheckErrorf("failed to parse XSC server response: " + err.Error())
err = errorutils.CheckErrorf("failed to parse JFrog XSC server response: " + err.Error())
return
}
xsxVersion = versionResponse.Version
Expand Down
9 changes: 4 additions & 5 deletions xray/services/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ func (vs *VersionService) GetVersion() (string, error) {
httpDetails := vs.XrayDetails.CreateHttpClientDetails()
resp, body, _, err := vs.client.SendGet(vs.XrayDetails.GetUrl()+"api/v1/system/version", true, &httpDetails)
if err != nil {
return "", err
return "", errors.New("failed while attempting to get JFrog Xray version: " + err.Error())
}
if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK); err != nil {
return "", errors.New("failed while attempting to get Xray version:\n" + err.Error())
return "", errors.New("got unexpected server response while attempting to get JFrog Xray version:\n" + err.Error())
}
var version xrayVersion
err = json.Unmarshal(body, &version)
if err != nil {
return "", errorutils.CheckErrorf("couldn't parse Xray server response: " + err.Error())
if err = json.Unmarshal(body, &version); err != nil {
return "", errorutils.CheckErrorf("couldn't parse JFrog Xray server version response: " + err.Error())
}
return strings.TrimSpace(version.Version), nil
}
Expand Down
Loading