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 1 commit
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
2 changes: 1 addition & 1 deletion artifactory/services/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (ss *SystemService) GetVersion() (string, error) {
var version artifactoryVersion
err = json.Unmarshal(body, &version)
if err != nil {
return "", errorutils.CheckErrorf("couldn't parse Artifactory server response: " + err.Error())
return "", errorutils.CheckErrorf("couldn't parse JFrog Artifactory server response: " + err.Error())
}
return strings.TrimSpace(version.Version), nil
}
Expand Down
6 changes: 3 additions & 3 deletions distribution/services/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ 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 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("failed 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())
return "", errorutils.CheckErrorf("couldn't parse JFrog Distribution server 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
6 changes: 3 additions & 3 deletions pipelines/services/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ 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 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("failed 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())
return nil, errorutils.CheckErrorf("couldn't parse JFrog Pipelines server response: " + err.Error())
}
return &sysInfo, nil
}
Expand Down
4 changes: 2 additions & 2 deletions xray/services/entitlements.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func (es *EntitlementsService) IsEntitled(featureId string) (entitled bool, err
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())
return false, fmt.Errorf("failed while attempting to get JFrog Xray entitlements response for %s:\n%s", featureId, err.Error())
}
var userEntitlements entitlements
if err = json.Unmarshal(body, &userEntitlements); err != nil {
return false, errorutils.CheckErrorf("couldn't parse Xray server response: " + err.Error())
return false, errorutils.CheckErrorf("couldn't parse JFrog Xray server response: " + err.Error())
}
return userEntitlements.Entitled, nil
}
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
6 changes: 3 additions & 3 deletions xray/services/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ 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 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("failed 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())
return "", errorutils.CheckErrorf("couldn't parse JFrog Xray server response: " + err.Error())
}
return strings.TrimSpace(version.Version), nil
}
Expand Down
Loading