Skip to content

Commit

Permalink
Allow anonymous access if auth isn't required.
Browse files Browse the repository at this point in the history
Fixes #25
  • Loading branch information
headcr4sh committed Dec 7, 2018
1 parent 0559bad commit 807f0f3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
([#19](https://github.com/cathive/concourse-sonarqube-resource/issues/19))
- Docker builds should no longer fail because of corrupted sonar-scanner
zip archive. ([#26](https://github.com/cathive/concourse-sonarqube-resource/issues/26))
- Anonymous access to SonarQube servers that don't require authentication
should now be possible. ([#25](https://github.com/cathive/concourse-sonarqube-resource/issues/25))

### Added

Expand Down
15 changes: 9 additions & 6 deletions assets/in
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ if [[ -z "${sonar_host_url}" ]]; then
fi
sonar_login=$(jq -r '.source.login // ""' < "${payload}")
if [[ -z "${sonar_login}" ]]; then
echo "sonar_login param has not been specified."
exit 1
fi
sonar_password=$(jq -r '.source.password // ""' < "${payload}")
if [[ ! -z "${sonar_login}" ]] && [[ "${sonar_login}" != "" ]]; then
sonar_token="${sonar_login}"
if [[ ! -z "${sonar_password}" ]] && [[ "${sonar_password}" != "" ]]; then
sonar_token+=":${sonar_password}"
fi
fi
ce_task_id=$(jq -r '.version.ce_task_id // ""' < "${payload}")
if [[ -z "${ce_task_id}" ]]; then
echo "version to fetch cannot be determined: ce_task_id not set?"
Expand All @@ -48,7 +51,7 @@ cd "${dest}"
ce_task_info="./ce_task.json"
ce_task_status="PENDING"
until [ "${ce_task_status}" != "PENDING" ] && [ "${ce_task_status}" != "IN_PROGRESS" ]; do
sq_ce_task "${sonar_login}:${sonar_password}" "${sonar_host_url}" "${ce_task_id}" > "${ce_task_info}"
sq_ce_task "${sonar_token}" "${sonar_host_url}" "${ce_task_id}" > "${ce_task_info}"
ce_task_status=$(jq -r '.task.status // ""' < "${ce_task_info}")
if [[ "${ce_task_status}" != "PENDING" ]] && [[ "${ce_task_status}" != "IN_PROGRESS" ]]; then
echo "Waiting for compute engine result (sleep: 5s)..."
Expand All @@ -66,7 +69,7 @@ if [[ "${ce_task_status}" == "SUCCESS" ]]; then
fi
project_status="./qualitygate_project_status.json"
sq_qualitygates_project_status "${sonar_login}:${sonar_password}" "${sonar_host_url}" "${analysis_id}" > "${project_status}"
sq_qualitygates_project_status "${sonar_token}" "${sonar_host_url}" "${analysis_id}" > "${project_status}"
project_status=$(jq -r '.projectStatus.status // ""' < "${project_status}")
Expand Down
9 changes: 8 additions & 1 deletion assets/out
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,14 @@ if [[ -f "${scanner_report_file}" ]]; then
# Older versions of SonarQube don't store the serverVersion in
# report-task.txt. There is a REST API though, that can be used
# to fetch the version.
serverVersion="$(sq_server_version "${sonar_login}":"${sonar_password}" "${sonar_host_url}")"
sonar_token=""
if [[ ! -z "${sonar_login}" ]] && [[ "${sonar_login}" != "" ]]; then
sonar_token="${sonar_login}"
if [[ ! -z "${sonar_password}" ]] && [[ "${sonar_password}" != "" ]]; then
sonar_token+=":${sonar_password}"
fi
fi
serverVersion="$(sq_server_version "${sonar_token}" "${sonar_host_url}")"
fi
else
echo "error: SonarQube report could not be located."
Expand Down

0 comments on commit 807f0f3

Please sign in to comment.